Skip to content

Commit 80789ab

Browse files
vitorbalilyavolodin
authored andcommitted
Chore: don't throw if rule is in old format (fixes #6848) (#6850)
1 parent d47c505 commit 80789ab

File tree

2 files changed

+32
-3
lines changed

2 files changed

+32
-3
lines changed

lib/internal-rules/internal-no-invalid-meta.js

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,16 @@ function checkMetaValidity(context, exportsNode, ruleIsFixable) {
151151
}
152152
}
153153

154+
/**
155+
* Whether this node is the correct format for a rule definition or not.
156+
*
157+
* @param {ASTNode} node node that the rule exports.
158+
* @returns {boolean} `true` if the exported node is the correct format for a rule definition
159+
*/
160+
function isCorrectExportsFormat(node) {
161+
return node.type === "ObjectExpression";
162+
}
163+
154164
//------------------------------------------------------------------------------
155165
// Rule Definition
156166
//------------------------------------------------------------------------------
@@ -167,7 +177,7 @@ module.exports = {
167177
},
168178

169179
create: function(context) {
170-
let metaExportsValue;
180+
let exportsNode;
171181
let ruleIsFixable = false;
172182

173183
return {
@@ -178,7 +188,7 @@ module.exports = {
178188
node.left.object.name === "module" &&
179189
node.left.property.name === "exports") {
180190

181-
metaExportsValue = node.right;
191+
exportsNode = node.right;
182192
}
183193
},
184194

@@ -205,7 +215,12 @@ module.exports = {
205215
},
206216

207217
"Program:exit": function() {
208-
checkMetaValidity(context, metaExportsValue, ruleIsFixable);
218+
if (!isCorrectExportsFormat(exportsNode)) {
219+
context.report(exportsNode, "Rule does not export an Object. Make sure the rule follows the new rule format.");
220+
return;
221+
}
222+
223+
checkMetaValidity(context, exportsNode, ruleIsFixable);
209224
}
210225
};
211226
}

tests/lib/internal-rules/internal-no-valid-meta.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,20 @@ ruleTester.run("internal-no-invalid-meta", rule, {
9696
].join("\n")
9797
],
9898
invalid: [
99+
{
100+
code: [
101+
"module.exports = function(context) {",
102+
" return {",
103+
" Program: function(node) {}",
104+
" };",
105+
"};"
106+
].join("\n"),
107+
errors: [{
108+
message: "Rule does not export an Object. Make sure the rule follows the new rule format.",
109+
line: 1,
110+
column: 18
111+
}]
112+
},
99113
{
100114
code: [
101115
"module.exports = {",

0 commit comments

Comments
 (0)