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

fix(eslint-plugin): [naming-convention] ignore properties inside object patterns #2566

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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/eslint-plugin/src/rules/naming-convention.ts
Expand Up @@ -579,7 +579,7 @@ export default util.createRule<Options, MessageIds>({

// #region property

'Property[computed = false][kind = "init"][value.type != "ArrowFunctionExpression"][value.type != "FunctionExpression"][value.type != "TSEmptyBodyFunctionExpression"]'(
':not(ObjectPattern) > Property[computed = false][kind = "init"][value.type != "ArrowFunctionExpression"][value.type != "FunctionExpression"][value.type != "TSEmptyBodyFunctionExpression"]'(
node: TSESTree.PropertyNonComputedName,
): void {
const modifiers = new Set<Modifiers>([Modifiers.public]);
Expand Down
34 changes: 34 additions & 0 deletions packages/eslint-plugin/tests/rules/naming-convention.test.ts
Expand Up @@ -906,6 +906,20 @@ ruleTester.run('naming-convention', rule, {
},
],
},
{
code: `
class SomeClass {
static OtherConstant = 'hello';
}

export const { OtherConstant: otherConstant } = SomeClass;
`,
parserOptions,
options: [
{ selector: 'property', format: ['PascalCase'] },
{ selector: 'variable', format: ['camelCase'] },
],
},
],
invalid: [
{
Expand Down Expand Up @@ -1282,5 +1296,25 @@ ruleTester.run('naming-convention', rule, {
],
errors: [{ messageId: 'doesNotMatchFormatTrimmed' }],
},
{
code: `
class SomeClass {
static otherConstant = 'hello';
}

export const { otherConstant } = SomeClass;
`,
parserOptions,
options: [
{ selector: 'property', format: ['PascalCase'] },
{ selector: 'variable', format: ['camelCase'] },
],
errors: [
{
line: 3,
messageId: 'doesNotMatchFormat',
},
],
},
],
});