Skip to content

Commit

Permalink
Fix: Ensure require-meta-* rules test null/undefined property values (
Browse files Browse the repository at this point in the history
#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.
  • Loading branch information
bmish authored Jul 12, 2021
1 parent cb9276e commit 990f8f6
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 1 deletion.
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

3 comments on commit 990f8f6

@aladdin-add
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

seems all the ready PRs have been merged. do you think we need to release a new version? 😄 @bmish

@bmish
Copy link
Member Author

@bmish bmish commented on 990f8f6 Jul 12, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@aladdin-add yes I think now is a good time for a minor version. Thanks!

@aladdin-add
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Released v3.4.0. Thanks for your awesome working! 👍

Please sign in to comment.