Skip to content

Commit

Permalink
Chore: no-invalid-meta crash if no export assignment (refs #9534) (#9698
Browse files Browse the repository at this point in the history
)
  • Loading branch information
platinumazure committed Dec 9, 2017
1 parent 29c3610 commit 4564fe0
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 6 deletions.
34 changes: 34 additions & 0 deletions tests/tools/internal-rules/no-invalid-meta.js
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,40 @@ ruleTester.run("no-invalid-meta", rule, {
line: 2,
column: 5
}]
},

/*
* Rule doesn't export anything: Should warn on the Program node.
* See https://github.com/eslint/eslint/issues/9534
*/

/*
* Should be invalid, but will currently show as valid due to #9534.
* FIXME: Uncomment when #9534 is fixed in major release.
* {
* code: "",
* errors: [{
* message: "Rule does not export anything. Make sure rule exports an object according to new rule format.",
* line: 1,
* column: 1
* }]
* },
*/
{
code: "foo();",
errors: [{
message: "Rule does not export anything. Make sure rule exports an object according to new rule format.",
line: 1,
column: 1
}]
},
{
code: "foo = bar;",
errors: [{
message: "Rule does not export anything. Make sure rule exports an object according to new rule format.",
line: 1,
column: 1
}]
}
]
});
19 changes: 13 additions & 6 deletions tools/internal-rules/no-invalid-meta.js
Original file line number Diff line number Diff line change
Expand Up @@ -175,13 +175,20 @@ module.exports = {
}
},

"Program:exit"() {
if (!isCorrectExportsFormat(exportsNode)) {
context.report({ node: exportsNode, message: "Rule does not export an Object. Make sure the rule follows the new rule format." });
return;
"Program:exit"(node) {
if (!exportsNode) {
context.report({
node,
message: "Rule does not export anything. Make sure rule exports an object according to new rule format."
});
} else if (!isCorrectExportsFormat(exportsNode)) {
context.report({
node: exportsNode,
message: "Rule does not export an Object. Make sure the rule follows the new rule format."
});
} else {
checkMetaValidity(context, exportsNode);
}

checkMetaValidity(context, exportsNode);
}
};
}
Expand Down

0 comments on commit 4564fe0

Please sign in to comment.