-
Notifications
You must be signed in to change notification settings - Fork 3
/
.eslintrc.js
251 lines (250 loc) · 7.3 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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
/**
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
// https://eslint.org/docs/developer-guide/shareable-configs#publishing-a-shareable-config
module.exports = {
parser: "@typescript-eslint/parser",
parserOptions: {
ecmaVersion: 6,
sourceType: "module",
ecmaFeatures: {
jsx: true,
},
project: "./tsconfig.json",
},
env: {
node: true,
es6: true,
jest: true,
jasmine: true,
browser: true,
commonjs: true,
},
ignorePatterns: [
// same as exclude in tsconfig.json
"/build",
"/coverage",
"/dist",
"/doc",
"/node_modules",
"/tmp",
],
plugins: [
"@typescript-eslint",
"flowtype",
"import",
"jsx-a11y",
"react",
"react-hooks",
"sonarjs",
],
extends: [
// Base recommended set of rules
"eslint:recommended",
// https://github.com/typescript-eslint/typescript-eslint/tree/master/packages/eslint-plugin/src/configs
// recommended extends @typescript-eslint/eslint-recommended which disables some of eslint:recommended
"plugin:@typescript-eslint/recommended",
// Additional recommended react rules
"plugin:react/recommended",
// Additional recommended react-hooks rules
"plugin:react-hooks/recommended",
// SonarJS recommended set
"plugin:sonarjs/recommended",
// Prettier config comes last as it disables conflicting ESLint rules enabled by other sets
"prettier",
],
settings: {
react: {
version: "detect",
},
},
rules: {
//************************************************************************
// Enforced
//
curly: "warn",
// Force import first
"import/first": "warn",
"import/order": [
"warn",
{
groups: ["builtin", "external"],
pathGroups: [
{
pattern: "@epconnect/**",
group: "external",
position: "after",
},
],
"newlines-between": "always-and-inside-groups",
},
],
// Set console calls to emit warnings as not enabled by eslint:recommended
"no-console": "warn",
// enforce types
"@typescript-eslint/no-explicit-any": "warn",
// Bans specific types from being used (e.g. builtin types)
"@typescript-eslint/ban-types": "warn",
// enforce typed exports
"@typescript-eslint/explicit-module-boundary-types": "warn",
// enforce clean code
"@typescript-eslint/no-unused-vars": [
"warn",
{
argsIgnorePattern: "^_",
varsIgnorePattern: "^_",
},
],
// Keep naming convention for later
// enforce interface naming convention
// "@typescript-eslint/naming-convention": [
// "warn",
// {
// selector: "interface",
// format: ["PascalCase"],
// custom: {
// regex: "^I[A-Z]",
// match: true,
// },
// },
// {
// selector: "typeAlias",
// format: ["PascalCase"],
// custom: {
// regex: "^T[A-Z]",
// match: true,
// },
// },
// ],
// enforce import ordering
"sort-imports": [
"warn",
{
allowSeparatedGroups: true,
memberSyntaxSortOrder: ["none", "all", "single", "multiple"],
ignoreCase: false,
},
],
"no-restricted-imports": [
"warn",
{
paths: [
{
name: "@mui/material",
importNames: [
"Table",
"Dialog",
"Tooltip",
"Button",
"TextField",
"Select",
"Switch",
"Tab",
"Tabs",
],
message: "Please import from '@epconnect/mui-components' instead.",
},
{
name: "@mui/material/Table",
importNames: ["default"],
message:
"Please import Table from '@epconnect/mui-components' instead.",
},
{
name: "@mui/material/Dialog",
importNames: ["default"],
message:
"Please import ResponsiveDialog from '@epconnect/mui-components' instead.",
},
{
name: "@mui/material/Tooltip",
importNames: ["default"],
message:
"Please import Tooltip from '@epconnect/mui-components' instead.",
},
{
name: "@mui/material/Button",
importNames: ["default"],
message:
"Please import Button from '@epconnect/mui-components' instead.",
},
{
name: "@mui/material/TextField",
importNames: ["default"],
message:
"Please import TextField from '@epconnect/mui-components' instead.",
},
{
name: "@mui/material/Select",
importNames: ["default"],
message:
"Please import SmartSelector from '@epconnect/mui-components' instead.",
},
{
name: "@mui/material/Switch",
importNames: ["default"],
message:
"Please import SwitchControl from '@epconnect/mui-components' instead.",
},
{
name: "@mui/material/Tab",
importNames: ["default"],
message:
"Please import TabsBar from '@epconnect/mui-components' instead.",
},
{
name: "@mui/material/Tabs",
importNames: ["default"],
message:
"Please import TabsBar from '@epconnect/mui-components' instead.",
},
],
},
],
},
overrides: [
// Typescript overrides
{
files: ["**/*.ts?(x)"],
rules: {
"react/prop-types": "off", // Not necessary in Typescript
},
},
// Test overrides
{
files: ["**/*.test.{j,t}s?(x)", "**/__*tests__/*"],
rules: {
// Allow assertion operator in unit tests because TS does not recognize
// jest expects such as toBeDefined() or not.toBeNull() as type-validating
"@typescript-eslint/no-non-null-assertion": "off",
},
},
// Storybook overrides
{
files: ["**/*.stories.{j,t}s?(x)"],
rules: {
"import/no-anonymous-default-export": "off", // Not helpful
},
},
// Cypress overrides
{
files: ["cypress/**/*.{j,t}s?(x)"],
plugins: ["cypress"],
extends: ["plugin:cypress/recommended"],
rules: {
//https://github.com/SonarSource/eslint-plugin-sonarjs/issues/176
//https://github.com/SonarSource/eslint-plugin-sonarjs/blob/master/src/rules/no-duplicate-string.ts
//not compatible with asserts like should("be.visible")
// > 10 chars and contains a separator "." so it would have to follow the no-duplicate-string rule
"sonarjs/no-duplicate-string": "off",
// Default complexity is 15 but since cypress test have some before and after hooks, let's increase a little bit
"sonarjs/cognitive-complexity": ["warn", 20],
// Allow assertion operator in unit tests because TS does not recognize
// jest expects such as toBeDefined() or not.toBeNull() as type-validating
"@typescript-eslint/no-non-null-assertion": "off",
},
},
],
reportUnusedDisableDirectives: true,
};