From 116da9ce23d980461c317dba64d2107d681f5c0d Mon Sep 17 00:00:00 2001 From: lonyele Date: Tue, 22 Feb 2022 09:03:28 +0900 Subject: [PATCH 1/5] fix: cover case that requires quotes --- .../rules/naming-convention-utils/validator.ts | 15 ++++++++++----- .../tests/rules/naming-convention.test.ts | 12 ++++++++++++ 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/packages/eslint-plugin/src/rules/naming-convention-utils/validator.ts b/packages/eslint-plugin/src/rules/naming-convention-utils/validator.ts index 8e8c8711a59f..43550b681c00 100644 --- a/packages/eslint-plugin/src/rules/naming-convention-utils/validator.ts +++ b/packages/eslint-plugin/src/rules/naming-convention-utils/validator.ts @@ -127,7 +127,9 @@ function createValidator( return; } - if (!validatePredefinedFormat(config, name, node, originalName)) { + if ( + !validatePredefinedFormat(config, name, node, originalName, modifiers) + ) { // fail return; } @@ -376,16 +378,19 @@ function createValidator( name: string, node: TSESTree.Identifier | TSESTree.PrivateIdentifier | TSESTree.Literal, originalName: string, + modifiers: Set, ): boolean { const formats = config.format; if (formats === null || formats.length === 0) { return true; } - for (const format of formats) { - const checker = PredefinedFormatToCheckFunction[format]; - if (checker(name)) { - return true; + if (!modifiers.has(Modifiers.requiresQuotes)) { + for (const format of formats) { + const checker = PredefinedFormatToCheckFunction[format]; + if (checker(name)) { + return true; + } } } diff --git a/packages/eslint-plugin/tests/rules/naming-convention.test.ts b/packages/eslint-plugin/tests/rules/naming-convention.test.ts index ef1235008809..f974690e3fa0 100644 --- a/packages/eslint-plugin/tests/rules/naming-convention.test.ts +++ b/packages/eslint-plugin/tests/rules/naming-convention.test.ts @@ -2224,5 +2224,17 @@ ruleTester.run('naming-convention', rule, { ], errors: Array(13).fill({ messageId: 'doesNotMatchFormat' }), }, + { + code: ` + type Foo = { + 'foo Bar': string; + }; + + interface Bar { + 'boo-----foo': string; + } + `, + errors: Array(2).fill({ messageId: 'doesNotMatchFormat' }), + }, ], }); From db21512cb9716c967df2884c2ef2e5f76ccde856 Mon Sep 17 00:00:00 2001 From: lonyele Date: Sun, 27 Feb 2022 14:05:08 +0900 Subject: [PATCH 2/5] test: cover more cases --- .../eslint-plugin/tests/rules/naming-convention.test.ts | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/packages/eslint-plugin/tests/rules/naming-convention.test.ts b/packages/eslint-plugin/tests/rules/naming-convention.test.ts index f974690e3fa0..d5f003d5dcc0 100644 --- a/packages/eslint-plugin/tests/rules/naming-convention.test.ts +++ b/packages/eslint-plugin/tests/rules/naming-convention.test.ts @@ -2228,13 +2228,20 @@ ruleTester.run('naming-convention', rule, { code: ` type Foo = { 'foo Bar': string; + '': string; + '0': string; + 'foo': string; + 'foo-bar': string; + '#foo-bar': string; }; interface Bar { 'boo-----foo': string; } + + `, - errors: Array(2).fill({ messageId: 'doesNotMatchFormat' }), + errors: Array(6).fill({ messageId: 'doesNotMatchFormat' }), }, ], }); From 6da7dd0d4b3fd89df08b98b99abbe452166c0d1f Mon Sep 17 00:00:00 2001 From: lonyele Date: Sun, 27 Feb 2022 14:32:35 +0900 Subject: [PATCH 3/5] chore: fix lint style --- .../eslint-plugin/tests/rules/naming-convention.test.ts | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/packages/eslint-plugin/tests/rules/naming-convention.test.ts b/packages/eslint-plugin/tests/rules/naming-convention.test.ts index d5f003d5dcc0..37bbbfd20761 100644 --- a/packages/eslint-plugin/tests/rules/naming-convention.test.ts +++ b/packages/eslint-plugin/tests/rules/naming-convention.test.ts @@ -2230,16 +2230,14 @@ ruleTester.run('naming-convention', rule, { 'foo Bar': string; '': string; '0': string; - 'foo': string; + foo: string; 'foo-bar': string; '#foo-bar': string; }; - + interface Bar { 'boo-----foo': string; } - - `, errors: Array(6).fill({ messageId: 'doesNotMatchFormat' }), }, From 9d12d86065db2e8b0e94c81aeb58e5087b431a8a Mon Sep 17 00:00:00 2001 From: lonyele Date: Tue, 1 Mar 2022 13:26:26 +0900 Subject: [PATCH 4/5] test: use noFormat for better testing case --- .../eslint-plugin/tests/rules/naming-convention.test.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/eslint-plugin/tests/rules/naming-convention.test.ts b/packages/eslint-plugin/tests/rules/naming-convention.test.ts index 37bbbfd20761..078171a97b84 100644 --- a/packages/eslint-plugin/tests/rules/naming-convention.test.ts +++ b/packages/eslint-plugin/tests/rules/naming-convention.test.ts @@ -6,7 +6,7 @@ import { Selector, selectorTypeToMessageString, } from '../../src/rules/naming-convention-utils'; -import { getFixturesRootDir, RuleTester } from '../RuleTester'; +import { getFixturesRootDir, noFormat, RuleTester } from '../RuleTester'; const ruleTester = new RuleTester({ parser: '@typescript-eslint/parser', @@ -2225,16 +2225,16 @@ ruleTester.run('naming-convention', rule, { errors: Array(13).fill({ messageId: 'doesNotMatchFormat' }), }, { - code: ` + code: noFormat` type Foo = { 'foo Bar': string; '': string; '0': string; - foo: string; + 'foo': string; 'foo-bar': string; '#foo-bar': string; }; - + interface Bar { 'boo-----foo': string; } From 524960324e95a7f1246552cfc1cf04fc946f1397 Mon Sep 17 00:00:00 2001 From: Brad Zacher Date: Mon, 28 Feb 2022 20:32:30 -0800 Subject: [PATCH 5/5] nit add comment to test --- packages/eslint-plugin/tests/rules/naming-convention.test.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/eslint-plugin/tests/rules/naming-convention.test.ts b/packages/eslint-plugin/tests/rules/naming-convention.test.ts index 078171a97b84..656dade01d73 100644 --- a/packages/eslint-plugin/tests/rules/naming-convention.test.ts +++ b/packages/eslint-plugin/tests/rules/naming-convention.test.ts @@ -2239,6 +2239,7 @@ ruleTester.run('naming-convention', rule, { 'boo-----foo': string; } `, + // 6, not 7 because 'foo' is valid errors: Array(6).fill({ messageId: 'doesNotMatchFormat' }), }, ], pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy