|
1 |
| -import { AST_NODE_TYPES } from '@typescript-eslint/experimental-utils'; |
| 1 | +import { |
| 2 | + AST_NODE_TYPES, |
| 3 | + TSESTree, |
| 4 | +} from '@typescript-eslint/experimental-utils'; |
2 | 5 | import baseRule from 'eslint/lib/rules/quotes';
|
3 | 6 | import * as util from '../util';
|
4 | 7 |
|
@@ -29,15 +32,32 @@ export default util.createRule<Options, MessageIds>({
|
29 | 32 | create(context, [option]) {
|
30 | 33 | const rules = baseRule.create(context);
|
31 | 34 |
|
| 35 | + function isAllowedAsNonBacktick(node: TSESTree.Literal): boolean { |
| 36 | + const parent = node.parent; |
| 37 | + |
| 38 | + switch (parent?.type) { |
| 39 | + case AST_NODE_TYPES.TSAbstractMethodDefinition: |
| 40 | + case AST_NODE_TYPES.TSMethodSignature: |
| 41 | + case AST_NODE_TYPES.TSPropertySignature: |
| 42 | + case AST_NODE_TYPES.TSModuleDeclaration: |
| 43 | + case AST_NODE_TYPES.TSLiteralType: |
| 44 | + return true; |
| 45 | + |
| 46 | + case AST_NODE_TYPES.TSEnumMember: |
| 47 | + return node === parent.id; |
| 48 | + |
| 49 | + case AST_NODE_TYPES.TSAbstractClassProperty: |
| 50 | + case AST_NODE_TYPES.ClassProperty: |
| 51 | + return node === parent.key; |
| 52 | + |
| 53 | + default: |
| 54 | + return false; |
| 55 | + } |
| 56 | + } |
| 57 | + |
32 | 58 | return {
|
33 | 59 | Literal(node): void {
|
34 |
| - const parent = node.parent; |
35 |
| - if ( |
36 |
| - option === 'backtick' && |
37 |
| - (parent?.type === AST_NODE_TYPES.TSModuleDeclaration || |
38 |
| - parent?.type === AST_NODE_TYPES.TSLiteralType || |
39 |
| - parent?.type === AST_NODE_TYPES.TSPropertySignature) |
40 |
| - ) { |
| 60 | + if (option === 'backtick' && isAllowedAsNonBacktick(node)) { |
41 | 61 | return;
|
42 | 62 | }
|
43 | 63 |
|
|
0 commit comments