Skip to content

Commit 421b2a7

Browse files
committed
Fix: Ensure require-meta-* rules test null/undefined property values
We need to ensure that the rules correctly handle `null` / `undefined` as the value of the meta properties since these values are commonly used as placeholder values.
1 parent 0459f12 commit 421b2a7

File tree

4 files changed

+69
-1
lines changed

4 files changed

+69
-1
lines changed

lib/rules/require-meta-schema.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ module.exports = {
6868
}
6969

7070
let { value } = schemaNode;
71-
if (value.type === 'Identifier') {
71+
if (value.type === 'Identifier' && value.name !== 'undefined') {
7272
const variable = findVariable(
7373
scopeManager.acquire(value) || scopeManager.globalScope,
7474
value

tests/lib/rules/require-meta-docs-description.js

+20
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,26 @@ ruleTester.run('require-meta-docs-description', rule, {
133133
output: null,
134134
errors: [{ messageId: 'wrongType', type: 'Literal' }],
135135
},
136+
{
137+
code: `
138+
module.exports = {
139+
meta: { docs: { description: null } },
140+
create(context) {}
141+
};
142+
`,
143+
output: null,
144+
errors: [{ messageId: 'wrongType', type: 'Literal' }],
145+
},
146+
{
147+
code: `
148+
module.exports = {
149+
meta: { docs: { description: undefined } },
150+
create(context) {}
151+
};
152+
`,
153+
output: null,
154+
errors: [{ messageId: 'wrongType', type: 'Identifier' }],
155+
},
136156
{
137157
code: `
138158
const DESCRIPTION = true;

tests/lib/rules/require-meta-has-suggestions.js

+38
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,24 @@ ruleTester.run('require-meta-has-suggestions', rule, {
7474
}
7575
};
7676
`,
77+
// No suggestions reported, hasSuggestions property set to `null`.
78+
`
79+
module.exports = {
80+
meta: { hasSuggestions: null },
81+
create(context) {
82+
context.report({node, message});
83+
}
84+
};
85+
`,
86+
// No suggestions reported, hasSuggestions property set to `undefined`.
87+
`
88+
module.exports = {
89+
meta: { hasSuggestions: undefined },
90+
create(context) {
91+
context.report({node, message});
92+
}
93+
};
94+
`,
7795
// No suggestions reported, hasSuggestions property set to false (as variable).
7896
`
7997
const hasSuggestions = false;
@@ -197,6 +215,26 @@ ruleTester.run('require-meta-has-suggestions', rule, {
197215
`,
198216
errors: [{ messageId: 'shouldBeSuggestable', type: 'Literal', line: 3, column: 35, endLine: 3, endColumn: 40 }],
199217
},
218+
{
219+
// Reports suggestions, hasSuggestions property set to `null`, violation should be on `null`
220+
code: `
221+
module.exports = {
222+
meta: { hasSuggestions: null },
223+
create(context) { context.report({node, message, suggest: [{}]}); }
224+
};
225+
`,
226+
errors: [{ messageId: 'shouldBeSuggestable', type: 'Literal', line: 3, column: 35, endLine: 3, endColumn: 39 }],
227+
},
228+
{
229+
// Reports suggestions, hasSuggestions property set to `undefined`, violation should be on `undefined`
230+
code: `
231+
module.exports = {
232+
meta: { hasSuggestions: undefined },
233+
create(context) { context.report({node, message, suggest: [{}]}); }
234+
};
235+
`,
236+
errors: [{ messageId: 'shouldBeSuggestable', type: 'Identifier', line: 3, column: 35, endLine: 3, endColumn: 44 }],
237+
},
200238
{
201239
// Reports suggestions, hasSuggestions property set to false (as variable), violation should be on variable
202240
code: `

tests/lib/rules/require-meta-schema.js

+10
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,16 @@ schema: [] },
129129
output: null,
130130
errors: [{ messageId: 'wrongType', type: 'Literal' }],
131131
},
132+
{
133+
code: `
134+
module.exports = {
135+
meta: { schema: undefined },
136+
create(context) {}
137+
};
138+
`,
139+
output: null,
140+
errors: [{ messageId: 'wrongType', type: 'Identifier' }],
141+
},
132142
{
133143
code: `
134144
const schema = null;

0 commit comments

Comments
 (0)