Skip to content

Commit

Permalink
Chore: don't throw if rule is in old format (fixes #6848) (#6850)
Browse files Browse the repository at this point in the history
  • Loading branch information
vitorbal authored and ilyavolodin committed Aug 9, 2016
1 parent d47c505 commit 80789ab
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 3 deletions.
21 changes: 18 additions & 3 deletions lib/internal-rules/internal-no-invalid-meta.js
Expand Up @@ -151,6 +151,16 @@ function checkMetaValidity(context, exportsNode, ruleIsFixable) {
}
}

/**
* Whether this node is the correct format for a rule definition or not.
*
* @param {ASTNode} node node that the rule exports.
* @returns {boolean} `true` if the exported node is the correct format for a rule definition
*/
function isCorrectExportsFormat(node) {
return node.type === "ObjectExpression";
}

//------------------------------------------------------------------------------
// Rule Definition
//------------------------------------------------------------------------------
Expand All @@ -167,7 +177,7 @@ module.exports = {
},

create: function(context) {
let metaExportsValue;
let exportsNode;
let ruleIsFixable = false;

return {
Expand All @@ -178,7 +188,7 @@ module.exports = {
node.left.object.name === "module" &&
node.left.property.name === "exports") {

metaExportsValue = node.right;
exportsNode = node.right;
}
},

Expand All @@ -205,7 +215,12 @@ module.exports = {
},

"Program:exit": function() {
checkMetaValidity(context, metaExportsValue, ruleIsFixable);
if (!isCorrectExportsFormat(exportsNode)) {
context.report(exportsNode, "Rule does not export an Object. Make sure the rule follows the new rule format.");
return;
}

checkMetaValidity(context, exportsNode, ruleIsFixable);
}
};
}
Expand Down
14 changes: 14 additions & 0 deletions tests/lib/internal-rules/internal-no-valid-meta.js
Expand Up @@ -96,6 +96,20 @@ ruleTester.run("internal-no-invalid-meta", rule, {
].join("\n")
],
invalid: [
{
code: [
"module.exports = function(context) {",
" return {",
" Program: function(node) {}",
" };",
"};"
].join("\n"),
errors: [{
message: "Rule does not export an Object. Make sure the rule follows the new rule format.",
line: 1,
column: 18
}]
},
{
code: [
"module.exports = {",
Expand Down

0 comments on commit 80789ab

Please sign in to comment.