-
Notifications
You must be signed in to change notification settings - Fork 0
/
.eslintrc.js
156 lines (142 loc) · 4.99 KB
/
.eslintrc.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
module.exports = {
parserOptions: {
ecmaVersion: 2020,
sourceType: 'module',
project: './tsconfig.json',
tsconfigRootDir: __dirname,
createDefaultProgram: true,
},
plugins: ['unicorn'],
settings: {
'import/resolver': {
// See https://github.com/benmosher/eslint-plugin-import/issues/1396#issuecomment-575727774 for line below
node: {},
webpack: {
config: require.resolve('./.erb/configs/webpack.config.eslint.ts'),
},
typescript: {},
},
'import/parsers': {
'@typescript-eslint/parser': ['.ts', '.tsx'],
},
},
rules: {
// A temporary hack related to IDE not resolving correct package.json
'import/no-extraneous-dependencies': 'off',
'import/no-unresolved': 'error',
// Since React 17 and typescript 4.1 you can safely disable the rule
'react/react-in-jsx-scope': 'off',
/*
* Custom CSS rules :)
*/
// https://reactjs.org/docs/hooks-rules.html
// allows placing the hooks logic in a different file for better code management
'react-hooks/rules-of-hooks': 'off',
// https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/require-default-props.md
'react/require-default-props': 'off',
// https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/no-unused-prop-types.md
'react/no-unused-prop-types': 'off',
// https://eslint.org/docs/latest/rules/no-restricted-syntax
// remove the for-of usage restriction from airbnb-base rules
'no-restricted-syntax': [
'error',
{
selector: 'ForInStatement',
message:
'for..in loops iterate over the entire prototype chain, which is virtually never what you want. Use Object.{keys,values,entries}, and iterate over the resulting array.',
},
{
selector: 'LabeledStatement',
message:
'Labels are a form of GOTO; using them makes code confusing and hard to maintain and understand.',
},
{
selector: 'WithStatement',
message:
'`with` is disallowed in strict mode because it makes code impossible to predict and optimize.',
},
],
// https://typescript-eslint.io/rules/no-use-before-define/
'no-use-before-define': 'off',
'@typescript-eslint/no-use-before-define': [
'error',
{
functions: false,
classes: false,
},
],
// https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/jsx-props-no-spreading.md
'react/jsx-props-no-spreading': 'off',
// https://eslint.org/docs/latest/rules/no-plusplus
'no-plusplus': 'off',
// https://github.com/import-js/eslint-plugin-import/blob/main/docs/rules/prefer-default-export.md
'import/prefer-default-export': 'off',
// https://github.com/typescript-eslint/typescript-eslint/blob/main/packages/eslint-plugin/docs/rules/no-non-null-assertion.md
'@typescript-eslint/no-non-null-assertion': 'off',
// https://typescript-eslint.io/rules/ban-types/
'@typescript-eslint/ban-types': 'off',
// https://eslint.org/docs/latest/rules/no-nested-ternary
'no-nested-ternary': 'off',
// https://github.com/sindresorhus/eslint-plugin-unicorn/blob/main/docs/rules/filename-case.md
'unicorn/filename-case': ['error', { case: 'kebabCase' }],
// https://github.com/typescript-eslint/typescript-eslint/blob/main/packages/eslint-plugin/docs/rules/naming-convention.md
'@typescript-eslint/naming-convention': [
'error',
{
selector: 'default',
format: ['camelCase'],
},
// destructured variables come from other places so no format is enforced
{
selector: 'variable',
modifiers: ['destructured'],
format: null,
},
// Constants can also be camelCase apart from UPPER_CASE
{
selector: 'variable',
modifiers: ['const'],
format: ['UPPER_CASE', 'camelCase'],
},
// functions defined as constants should have the same format as functions
{
selector: 'variable',
types: ['function'],
format: ['camelCase', 'PascalCase'],
},
// functions can be:
// - regular functions (camelCase)
// - functional components (PascalCase)
{
selector: 'function',
format: ['camelCase', 'PascalCase'],
},
// type definitions (class, interface, typeAlias, enum, typeParameter)
// should be PascalCase
{
selector: 'typeLike',
format: ['PascalCase'],
},
// each member of an enum (const-like) should be UPPER_CASE
{
selector: 'enumMember',
format: ['UPPER_CASE'],
},
{
// Ignore properties that require quotes
selector: [
'classProperty',
'objectLiteralProperty',
'typeProperty',
'classMethod',
'objectLiteralMethod',
'typeMethod',
'accessor',
'enumMember',
],
format: null,
modifiers: ['requiresQuotes'],
},
],
},
};