Skip to content

Commit e51048c

Browse files
fix(eslint-plugin): [quotes] ignore backticks for Enum members (#1355)
* fix(eslint-plugin): [quotes] ignore backticks for Enum members * feat(eslint-plugin): [quotes] handle more TypeScript node types Co-authored-by: Brad Zacher <brad.zacher@gmail.com>
1 parent 2aa696c commit e51048c

File tree

2 files changed

+514
-8
lines changed

2 files changed

+514
-8
lines changed

packages/eslint-plugin/src/rules/quotes.ts

+28-8
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
import { AST_NODE_TYPES } from '@typescript-eslint/experimental-utils';
1+
import {
2+
AST_NODE_TYPES,
3+
TSESTree,
4+
} from '@typescript-eslint/experimental-utils';
25
import baseRule from 'eslint/lib/rules/quotes';
36
import * as util from '../util';
47

@@ -29,15 +32,32 @@ export default util.createRule<Options, MessageIds>({
2932
create(context, [option]) {
3033
const rules = baseRule.create(context);
3134

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+
3258
return {
3359
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)) {
4161
return;
4262
}
4363

0 commit comments

Comments
 (0)