Skip to content

Commit

Permalink
Merge pull request #29 from shashank-saxena/master
Browse files Browse the repository at this point in the history
Check for called function exports
  • Loading branch information
selaux authored Jun 8, 2018
2 parents bb49b4a + f54fab9 commit 0833a43
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
4 changes: 4 additions & 0 deletions lib/common/getExportedName.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
19 changes: 18 additions & 1 deletion test/rules/match-exported.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ var testCode = "var foo = 'bar';",
exportedJsxClassCode = "module.exports = class Foo { render() { return <span>Test Class</span>; } };",
exportedClassCode = "module.exports = class Foo {};",
exportedFunctionCode = "module.exports = function foo() {};",
exportUnnamedFunctionCode = "module.exports = function() {};",
exportedCalledFunctionCode = "module.exports = foo();",
exportedJsxFunctionCode = "module.exports = function foo() { return <span>Test Fn</span> };",
exportedEs6VariableCode = "export default exported;",
exportedEs6ClassCode = "export default class Foo {};",
Expand All @@ -30,13 +32,17 @@ ruleTester.run("lib/rules/match-exported", exportedRule, {
code: testCode,
filename: "<input>"
},
{
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" }
},
{
Expand All @@ -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",
Expand Down Expand Up @@ -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",
Expand Down

0 comments on commit 0833a43

Please sign in to comment.