Skip to content

Fix: Ensure require-meta-* rules test null / undefined property values #164

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/rules/require-meta-schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ module.exports = {
}

let { value } = schemaNode;
if (value.type === 'Identifier') {
if (value.type === 'Identifier' && value.name !== 'undefined') {
const variable = findVariable(
scopeManager.acquire(value) || scopeManager.globalScope,
value
Expand Down
20 changes: 20 additions & 0 deletions tests/lib/rules/require-meta-docs-description.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,26 @@ ruleTester.run('require-meta-docs-description', rule, {
output: null,
errors: [{ messageId: 'wrongType', type: 'Literal' }],
},
{
code: `
module.exports = {
meta: { docs: { description: null } },
create(context) {}
};
`,
output: null,
errors: [{ messageId: 'wrongType', type: 'Literal' }],
},
{
code: `
module.exports = {
meta: { docs: { description: undefined } },
create(context) {}
};
`,
output: null,
errors: [{ messageId: 'wrongType', type: 'Identifier' }],
},
{
code: `
const DESCRIPTION = true;
Expand Down
18 changes: 18 additions & 0 deletions tests/lib/rules/require-meta-has-suggestions.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,24 @@ ruleTester.run('require-meta-has-suggestions', rule, {
}
};
`,
// No suggestions reported, hasSuggestions property set to `null`.
`
module.exports = {
meta: { hasSuggestions: null },
create(context) {
context.report({node, message});
}
};
`,
// No suggestions reported, hasSuggestions property set to `undefined`.
`
module.exports = {
meta: { hasSuggestions: undefined },
create(context) {
context.report({node, message});
}
};
`,
// No suggestions reported, hasSuggestions property set to false (as variable).
`
const hasSuggestions = false;
Expand Down
10 changes: 10 additions & 0 deletions tests/lib/rules/require-meta-schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,16 @@ schema: [] },
output: null,
errors: [{ messageId: 'wrongType', type: 'Literal' }],
},
{
code: `
module.exports = {
meta: { schema: undefined },
create(context) {}
};
`,
output: null,
errors: [{ messageId: 'wrongType', type: 'Identifier' }],
},
{
code: `
const schema = null;
Expand Down