-
Notifications
You must be signed in to change notification settings - Fork 2
/
.eslintrc.js
102 lines (99 loc) · 3.43 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
/**
* Steps to configure ESLint:
* 1. Set environment
* 1.1. Add Node.js global variables and Node.js scoping
* 1.2. Support the ES2022 ES syntax + predefined global variables
* 2. Set the parser's `sourceType` to `module` to allow imports of code placed in ECMAScript modules
* 3. Extensions
* 3.1. Add recommended ESLint rules ["eslint"]
* 3.2. Add recommended errors and warnings rules for imports ["eslint-plugin-import"]
* 3.3. Add recommended best practices for JavaScript promises ["eslint-plugin-promise"]
* 3.4. Add prettier rules. This will display prettier errors as ESLint errors. Make sure this is always the last configuration in the extends array. ["prettier", "eslint-plugin-prettier", "eslint-config-prettier"]
* 4. Add TypeScript configuration just to TypeScript files
* 4.1. Specify the TS file extensions that should be linted
* 4.2. Set the parser to TypeScript ["@typescript-eslint/parser"]
* 4.3. Set the parser options to Linting with Type Information. Docs: https://typescript-eslint.io/docs/linting/typed-linting
* 4.4. TS Extensions
* 4.1. Add recommended TypeScript rules ["@typescript-eslint/eslint-plugin"]
* 4.2. Add TypeScript rules for Linting with Type Information ["@typescript-eslint/eslint-plugin"]
* 4.3. Add recommended Typescript rules for imports ["eslint-plugin-import"]
* 5. Ignore files and folders from linting based on the exclude property in `tsconfig.json`
* 6. Add specific rules
*/
module.exports = {
env: {
node: true,
es2022: true,
},
parserOptions: {
sourceType: 'module',
},
extends: [
'eslint:recommended',
'plugin:import/errors',
'plugin:import/warnings',
'plugin:promise/recommended',
'plugin:prettier/recommended',
],
overrides: [
{
files: ['*.ts', '*.d.ts'],
parser: '@typescript-eslint/parser',
parserOptions: {
tsconfigRootDir: __dirname,
project: ['./tsconfig.eslint.json'],
},
extends: [
'plugin:@typescript-eslint/recommended',
'plugin:@typescript-eslint/recommended-requiring-type-checking',
'plugin:import/typescript',
],
},
],
// TODO: Can we use the `exclude` property from `tsconfig.eslint.json`? (`require('./tsconfig.eslint.json').exclude`)
ignorePatterns: ['node_modules', 'build'],
rules: {
/**
* Define extensions that shouldn't be specified on import
* https://github.com/import-js/eslint-plugin-import/blob/main/docs/rules/extensions.md
*/
'import/extensions': [
'error',
'ignorePackages',
{
ts: 'never',
'd.ts': 'never',
},
],
/**
* Define the order of imports
* https://github.com/un-es/eslint-plugin-i/blob/fork-release/docs/rules/order.md
*/
'import/order': [
'error',
{
groups: [
'builtin',
'external',
'internal',
'parent',
'sibling',
'index',
'object',
'type',
],
'newlines-between': 'always',
alphabetize: {
order: 'asc',
},
},
],
/**
* Force the `type` keyword for type imports
* https://github.com/typescript-eslint/typescript-eslint/blob/main/packages/eslint-plugin/docs/rules/consistent-type-imports.md
*/
'@typescript-eslint/consistent-type-imports': 'error',
// Disable in favor of the errors Typescript provides
'import/no-unresolved': 0,
},
};