You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Fixestypescript-eslint#2761Fixestypescript-eslint#1483
This modifier simply matches any member name that requires quotes.
To clarify: this does not match names that have quotes - only names that ***require*** quotes.
Copy file name to clipboardExpand all lines: packages/eslint-plugin/docs/rules/naming-convention.md
+45-16Lines changed: 45 additions & 16 deletions
Original file line number
Diff line number
Diff line change
@@ -183,6 +183,7 @@ If these are provided, the identifier must start with one of the provided values
183
183
-`global` - matches a variable/function declared in the top-level scope.
184
184
-`exported` - matches anything that is exported from the module.
185
185
-`unused` - matches anything that is not used.
186
+
-`requiresQuotes` - matches any name that requires quotes as it is not a valid identifier (i.e. has a space, a dash, etc in it).
186
187
-`public` - matches any member that is either explicitly declared as `public`, or has no visibility modifier (i.e. implicitly public).
187
188
-`readonly`, `static`, `abstract`, `protected`, `private` - matches any member explicitly declared with the given modifier.
188
189
-`types` allows you to specify which types to match. This option supports simple, primitive types only (`boolean`, `string`, `number`, `array`, `function`).
@@ -229,31 +230,31 @@ Individual Selectors match specific, well-defined sets. There is no overlap betw
-`objectLiteralProperty` - matches any object literal property. Does not match properties that have direct function expression or arrow function expression values.
-`typeProperty` - matches any object type property. Does not match properties that have direct function expression or arrow function expression values.
-`classMethod` - matches any class method. Also matches properties that have direct function expression or arrow function expression values. Does not match accessors.
-`objectLiteralMethod` - matches any object literal method. Also matches properties that have direct function expression or arrow function expression values. Does not match accessors.
-`typeMethod` - matches any object type method. Also matches properties that have direct function expression or arrow function expression values. Does not match accessors.
@@ -424,12 +425,36 @@ This allows you to lint multiple type with same pattern.
424
425
}
425
426
```
426
427
427
-
### Ignore properties that require quotes
428
+
### Ignore properties that **_require_** quotes
428
429
429
430
Sometimes you have to use a quoted name that breaks the convention (for example, HTTP headers).
430
-
If this is a common thing in your codebase, then you can use the `filter` option in one of two ways:
431
+
If this is a common thing in your codebase, then you have a few options.
431
432
432
-
You can use the `filter` option to ignore specific names only:
433
+
If you simply want to allow all property names that require quotes, you can use the `requiresQuotes` modifier to match any property name that _requires_ quoting, and use `format: null` to ignore the name.
434
+
435
+
```jsonc
436
+
{
437
+
"@typescript-eslint/naming-convention": [
438
+
"error",
439
+
{
440
+
"selector": [
441
+
"classProperty",
442
+
"objectLiteralProperty",
443
+
"typeProperty",
444
+
"classMethod",
445
+
"objectLiteralMethod",
446
+
"typeMethod",
447
+
"accessor",
448
+
"enumMember"
449
+
],
450
+
"format":null,
451
+
"modifiers": ["requiresQuotes"]
452
+
}
453
+
]
454
+
}
455
+
```
456
+
457
+
If you have a small and known list of exceptions, you can use the `filter` option to ignore these specific names only:
433
458
434
459
```jsonc
435
460
{
@@ -448,7 +473,7 @@ You can use the `filter` option to ignore specific names only:
448
473
}
449
474
```
450
475
451
-
You can use the `filter` option to ignore names that require quoting:
476
+
You can use the `filter` option to ignore names with specific characters:
452
477
453
478
```jsonc
454
479
{
@@ -467,6 +492,10 @@ You can use the `filter` option to ignore names that require quoting:
467
492
}
468
493
```
469
494
495
+
Note that there is no way to ignore any name that is quoted - only names that are required to be quoted.
496
+
This is intentional - adding quotes around a name is not an escape hatch for proper naming.
497
+
If you want an escape hatch for a specific name - you should can use an [`eslint-disable` comment](https://eslint.org/docs/user-guide/configuring#disabling-rules-with-inline-comments).
498
+
470
499
### Ignore destructured names
471
500
472
501
Sometimes you might want to allow destructured properties to retain their original name, even if it breaks your naming convention.
0 commit comments