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..656dade01d73 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', @@ -2224,5 +2224,23 @@ ruleTester.run('naming-convention', rule, { ], errors: Array(13).fill({ messageId: 'doesNotMatchFormat' }), }, + { + code: noFormat` + type Foo = { + 'foo Bar': string; + '': string; + '0': string; + 'foo': string; + 'foo-bar': string; + '#foo-bar': string; + }; + + interface Bar { + '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