Skip to content

Commit

Permalink
fix(eslint-plugin): [naming-convention] ignore properties inside obje…
Browse files Browse the repository at this point in the history
…ct patterns (#2566)
  • Loading branch information
Josh Goldberg committed Sep 21, 2020
1 parent 1329294 commit 53a3cbc
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
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',
},
],
},
],
});

0 comments on commit 53a3cbc

Please sign in to comment.