Skip to content
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

feat: false negative with onlyDeclarations + properties in id-match #15431

Merged
merged 5 commits into from Dec 21, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 7 additions & 0 deletions lib/rules/id-match.js
Expand Up @@ -238,6 +238,13 @@ module.exports = {
}
}

// For https://github.com/eslint/eslint/issues/15123
if (parent.parent && parent.parent.type === "ObjectExpression") {
if (checkProperties && parent.key === node && isInvalid(name)) {
report(node);
}
}
snitin315 marked this conversation as resolved.
Show resolved Hide resolved

// never check properties or always ignore destructuring
if (!checkProperties || (ignoreDestructuring && isInsideObjectPattern(node))) {
return;
Expand Down
91 changes: 90 additions & 1 deletion tests/lib/rules/id-match.js
Expand Up @@ -197,6 +197,46 @@ ruleTester.run("id-match", rule, {
}],
parserOptions: { ecmaVersion: 2022 }
},
{
code: `
const foo = {
foo_one: 1,
bar_one: 2,
fooBar: 3
};
`,
options: ["^[^_]+$", {
properties: false
}],
parserOptions: { ecmaVersion: 2022 }
},
{
code: `
const foo = {
foo_one: 1,
bar_one: 2,
fooBar: 3
};
`,
options: ["^[^_]+$", {
onlyDeclarations: true
}],
parserOptions: { ecmaVersion: 2022 }
},
{
code: `
const foo = {
foo_one: 1,
bar_one: 2,
fooBar: 3
};
`,
options: ["^[^_]+$", {
properties: false,
onlyDeclarations: false
}],
parserOptions: { ecmaVersion: 2022 }
},

// Class Methods
{
Expand Down Expand Up @@ -774,7 +814,56 @@ ruleTester.run("id-match", rule, {
type: "PrivateIdentifier"
}
]
}
},

// https://github.com/eslint/eslint/issues/15123
{
code: `
const foo = {
foo_one: 1,
bar_one: 2,
fooBar: 3
};
`,
options: ["^[^_]+$", {
properties: true,
onlyDeclarations: true
}],
parserOptions: { ecmaVersion: 2022 },
errors: [
{
message: "Identifier 'foo_one' does not match the pattern '^[^_]+$'.",
type: "Identifier"
},
{
message: "Identifier 'bar_one' does not match the pattern '^[^_]+$'.",
type: "Identifier"
}
]
},
{
code: `
const foo = {
foo_one: 1,
bar_one: 2,
fooBar: 3
};
`,
options: ["^[^_]+$", {
properties: true,
onlyDeclarations: false
}],
parserOptions: { ecmaVersion: 2022 },
errors: [
{
message: "Identifier 'foo_one' does not match the pattern '^[^_]+$'.",
type: "Identifier"
},
{
message: "Identifier 'bar_one' does not match the pattern '^[^_]+$'.",
type: "Identifier"
}
]
}
]
});