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', + }, + ], + }, ], });