From af900305e58aba0fdf3633c1a52a573f20de7a9f Mon Sep 17 00:00:00 2001 From: Shashank Saxena Date: Thu, 19 Apr 2018 17:02:02 +0530 Subject: [PATCH 1/2] Check for called function exports --- lib/common/getExportedName.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/common/getExportedName.js b/lib/common/getExportedName.js index dfa8ba4..64d800c 100644 --- a/lib/common/getExportedName.js +++ b/lib/common/getExportedName.js @@ -6,6 +6,10 @@ function getNodeName(node) { if (node.id && node.id.type === "Identifier") { return node.id.name; } + + if (node.type === "CallExpression" && node.callee.type === "Identifier") { + return node.callee.name; + } } module.exports = function getExportedName(programNode) { From f54fab9442841d97206fe93517a71ba7f453cc79 Mon Sep 17 00:00:00 2001 From: Shashank Saxena Date: Fri, 1 Jun 2018 11:02:53 +0530 Subject: [PATCH 2/2] Fixed test case for default export --- test/rules/match-exported.js | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/test/rules/match-exported.js b/test/rules/match-exported.js index 3b18f72..9daee87 100644 --- a/test/rules/match-exported.js +++ b/test/rules/match-exported.js @@ -7,6 +7,8 @@ var testCode = "var foo = 'bar';", exportedJsxClassCode = "module.exports = class Foo { render() { return Test Class; } };", exportedClassCode = "module.exports = class Foo {};", exportedFunctionCode = "module.exports = function foo() {};", + exportUnnamedFunctionCode = "module.exports = function() {};", + exportedCalledFunctionCode = "module.exports = foo();", exportedJsxFunctionCode = "module.exports = function foo() { return Test Fn };", exportedEs6VariableCode = "export default exported;", exportedEs6ClassCode = "export default class Foo {};", @@ -30,13 +32,17 @@ ruleTester.run("lib/rules/match-exported", exportedRule, { code: testCode, filename: "" }, + { + code: exportUnnamedFunctionCode, + filename: "testFile.js" + }, { code: testCode, filename: "/some/dir/exported.js" }, { code: testCallCode, - filename: "/some/dir/exported.js", + filename: "/some/dir/foo.js", parserOptions: { ecmaVersion: 6, sourceType: "module" } }, { @@ -57,6 +63,10 @@ ruleTester.run("lib/rules/match-exported", exportedRule, { code: exportedFunctionCode, filename: "/some/dir/foo.js" }, + { + code: exportedCalledFunctionCode, + filename: "/some/dir/foo.js" + }, { code: exportedJsxFunctionCode, filename: "/some/dir/foo.js", @@ -142,6 +152,13 @@ ruleTester.run("lib/rules/match-exported", exportedRule, { { message: "Filename 'bar' must match the exported name 'foo'.", column: 1, line: 1 } ] }, + { + code: exportedCalledFunctionCode, + filename: "/some/dir/bar.js", + errors: [ + { message: "Filename 'bar' must match the exported name 'foo'.", column: 1, line: 1 } + ] + }, { code: exportedJsxFunctionCode, filename: "/some/dir/bar.js",