Skip to content

Commit 990f8f6

Browse files
authored
Fix: Ensure require-meta-* rules test null/undefined property values (#164)
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 cb9276e commit 990f8f6

File tree

4 files changed

+49
-1
lines changed

4 files changed

+49
-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
@@ -134,6 +134,26 @@ ruleTester.run('require-meta-docs-description', rule, {
134134
output: null,
135135
errors: [{ messageId: 'wrongType', type: 'Literal' }],
136136
},
137+
{
138+
code: `
139+
module.exports = {
140+
meta: { docs: { description: null } },
141+
create(context) {}
142+
};
143+
`,
144+
output: null,
145+
errors: [{ messageId: 'wrongType', type: 'Literal' }],
146+
},
147+
{
148+
code: `
149+
module.exports = {
150+
meta: { docs: { description: undefined } },
151+
create(context) {}
152+
};
153+
`,
154+
output: null,
155+
errors: [{ messageId: 'wrongType', type: 'Identifier' }],
156+
},
137157
{
138158
code: `
139159
const DESCRIPTION = true;

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

+18
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;

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)