-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patheslint.config.mjs
More file actions
293 lines (288 loc) · 11 KB
/
eslint.config.mjs
File metadata and controls
293 lines (288 loc) · 11 KB
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
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
import tseslint from 'typescript-eslint';
import importPlugin from 'eslint-plugin-import';
import prettierPlugin from 'eslint-plugin-prettier';
import boundariesPlugin from 'eslint-plugin-boundaries';
import tsdocPlugin from 'eslint-plugin-tsdoc';
import securityPlugin from 'eslint-plugin-security';
import unicornPlugin from 'eslint-plugin-unicorn';
import sonarjs from 'eslint-plugin-sonarjs';
export default [
...tseslint.configs.strict,
...tseslint.configs.stylistic,
{
ignores: ['**/generated/**', 'dist/**', '.next/**', 'node_modules/**', 'out/**'],
},
{
files: ['**/*.{ts,tsx,js,jsx}'],
languageOptions: {
ecmaVersion: 'latest',
parser: tseslint.parser,
parserOptions: {
projectService: true,
tsconfigRootDir: import.meta.dirname,
},
},
plugins: {
import: importPlugin,
prettier: prettierPlugin,
tsdoc: tsdocPlugin,
security: securityPlugin,
unicorn: unicornPlugin,
sonarjs: sonarjs,
},
rules: {
/* ==================
* PRETTIER
* ================== */
/**
* Force l'utilisation de guillemets simples pour les chaînes de caractères.
*/
quotes: ['error', 'single', { avoidEscape: true }],
/* ==================
* TYPESCRIPT
* ================== */
/**
* Ruleset strict pour TypeScript. Contient le set recommandé et ajoute
* quelques règles supplémentaires.
* 43 règles recommandées, 23 règles strictes.
* Voir liste et explications ici : https://typescript-eslint.io/rules/
*/
...tseslint.configs.strict.rules,
/**
* Autorisation des variables non-utilisées si elles sont préfixées par '_'
*/
'@typescript-eslint/naming-convention': [
'error',
{
selector: 'parameter',
modifiers: ['unused'],
format: ['strictCamelCase'],
leadingUnderscore: 'require',
},
],
'@typescript-eslint/no-unused-vars': [
'error',
{
argsIgnorePattern: '^_',
varsIgnorePattern: '^_',
caughtErrorsIgnorePattern: '^_',
},
],
/**
* Interdiction de console.log en autorisant les autres instructions console
* pour le suivi d'exécution (console.info, console.time, ...)
*/
'no-console': [
'error',
{
allow: ['warn', 'error', 'info', 'time', 'timeEnd'],
},
],
/**
* Autorisation d'utiliser des classes comme namespace (i.e. Logger).
* Il s'agit d'une règle du set 'strict' de tseslint s'opposant à une
* approche OOP commune.
*/
'@typescript-eslint/no-extraneous-class': 'off',
/**
* Oblige à utiliser un type de retour pour les fonctions.
*/
'@typescript-eslint/explicit-function-return-type': 'error',
/**
* Oblige à utiliser la syntaxe raccourcie pour les propriétés d'objet.
*/
'object-shorthand': ['error', 'always'],
/* ==================
* STYLISTIC
* ================== */
/**
* Ruleset orienté sur le style et la lisibilité du code.
* 21 règles.
* Voir liste et explications ici : https://typescript-eslint.io/rules/
*/
...tseslint.configs.stylistic.rules,
/**
* Cette règle oblige à utiliser des interfaces au lieu de types.
* Ce monorepo suit la règle inverse : uniquement des types sauf
* si une interface est nécessaire.
*/
'@typescript-eslint/consistent-type-definitions': 'off',
/* ==================
* UNICORN
* ================== */
/**
* Unicorn recommended set enables 125 linter rules targeting good practices.
* Those rules are quite restrictive thus enforce a good code quality.
* See https://github.com/sindresorhus/eslint-plugin-unicorn
* for the list of rules and explanations.
*/
...unicornPlugin.configs.recommended.rules,
/**
* Abreviations can be useful to improve code readability.
* For instance for naming elements in array methods like `map`
* or for known abbreviations (ex: `ctx`, `ref`, `err`, ...).
*/
'unicorn/prevent-abbreviations': 'off',
/**
* `null` cannot always be replaced by `undefined`. `undefined` means
* a value is not defined, while `null` means a value is defined but is "nothing".
* Moreover, JSON treats `undefined` as "skip this property"
* while `null` means "this property has a non-value".
* This rule is debated (see: https://github.com/sindresorhus/meta/discussions/7)
*/
'unicorn/no-null': 'off',
'unicorn/filename-case' : [
'error',
{
cases: {
kebabCase: true,
pascalCase: true
}
}
],
/* ==================
* SECURITY
* ================== */
/**
* The security plugin helps detect potential security issues.
* Finds a lot of false positives that need to be manually checked.
* 14 rules.
* See: https://github.com/nodesecurity/eslint-plugin-security
*/
...securityPlugin.configs.recommended.rules,
/**
* Detects a lot a false positives by forbidding any square bracket access
* to an object.
*/
'security/detect-object-injection': 'off',
/* ==================
* SONARJS
* ================== */
/**
* Ruleset to detect code smells and bugs.
* 32 rules.
* See list and explanations here: https://github.com/SonarSource/eslint-plugin-sonarjs
*/
...sonarjs.configs.recommended.rules,
/**
* Redundant with typescript-eslint/no-unused-vars and no configurable
* to accept variables prefixed with '_'.
*/
'sonarjs/no-unused-vars': 'off',
},
},
{
files: ['**/*.{ts,tsx,js,jsx}'],
plugins: {
boundaries: boundariesPlugin,
},
settings: {
'boundaries/dependency-nodes': ['import', 'export'],
'boundaries/elements': [
{
type: 'module',
mode: 'full',
pattern: 'apps/*/*/**',
capture: ['appName', 'moduleName'],
},
{
type: 'app-index',
mode: 'full',
pattern: 'apps/*/index.ts',
capture: ['appName'],
},
{
type: 'common',
mode: 'full',
pattern: 'common/**',
},
],
'boundaries/include': ['apps/**/*.ts', 'common/**/*.ts'],
'import/resolver': {
typescript: {
alwaysTryTypes: true,
},
},
},
rules: {
/* ==================
* BOUNDARIES
* ================== */
/**
* Boundaries permet de créer des règles pour séparer les différentes modules
* d'un projet et leur affecter des permissions.
* Voir : https://github.com/javierbrea/eslint-plugin-boundaries/blob/master/docs/rules/external.md
*/
...boundariesPlugin.configs.recommended.rules,
/**
* Interdit les importations de modules inconnus.
*/
'boundaries/no-unknown': ['error'],
/**
* Interdit les importations de fichiers inconnus.
*/
'boundaries/no-unknown-files': ['error'],
/**
* Interdit les importations d'une app à une autre ainsi que d'un module
* à un autre au sein d'une même app.
* Les seules importations autorisées sont les importations relatives au
* même module, les importations d'un module nommé `shared` ou `generated`
* et les importations relatives au package `common`.
*/
'boundaries/no-private': 'off',
'boundaries/element-types': [
'error',
{
default: 'disallow',
rules: [
{
from: 'module',
allow: [
[
'module',
{
appName: '${from.appName}',
moduleName: '${from.moduleName}',
},
],
],
},
{
from: 'module',
allow: [
[
'module',
{
appName: '${from.appName}',
moduleName: '{shared,generated}',
},
],
],
},
{ from: 'module', allow: ['common'] },
{ from: 'common', allow: ['common'] },
{
from: 'app-index',
allow: [['module', { appName: '${from.appName}' }]],
},
],
},
],
},
},
{
/**
* Interdiction des importations `@urmet/common` dans le package `common`.
* Les imports au sein d'un package doivent être relatifs.
*/
files: ['common/**/*.{ts,tsx,js,jsx}'],
rules: {
'no-restricted-imports': [
'error',
{
patterns: ['@urmet/common/*'],
},
],
},
},
]