From 53a3cbc6f002e55135efbdf4982a3ad308ac708b Mon Sep 17 00:00:00 2001 From: Josh Goldberg Date: Mon, 21 Sep 2020 12:18:03 -0400 Subject: [PATCH] fix(eslint-plugin): [naming-convention] ignore properties inside object patterns (#2566) --- .../src/rules/naming-convention.ts | 2 +- .../tests/rules/naming-convention.test.ts | 34 +++++++++++++++++++ 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/packages/eslint-plugin/src/rules/naming-convention.ts b/packages/eslint-plugin/src/rules/naming-convention.ts index fb814e17e04..3acfa116b8f 100644 --- a/packages/eslint-plugin/src/rules/naming-convention.ts +++ b/packages/eslint-plugin/src/rules/naming-convention.ts @@ -579,7 +579,7 @@ export default util.createRule({ // #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.public]); diff --git a/packages/eslint-plugin/tests/rules/naming-convention.test.ts b/packages/eslint-plugin/tests/rules/naming-convention.test.ts index 8c855b3a8a5..634ad424559 100644 --- a/packages/eslint-plugin/tests/rules/naming-convention.test.ts +++ b/packages/eslint-plugin/tests/rules/naming-convention.test.ts @@ -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: [ { @@ -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', + }, + ], + }, ], });