-
Notifications
You must be signed in to change notification settings - Fork 7
/
.eslintrc.js
229 lines (224 loc) · 6.85 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
/*
* simple-import-sort default grouping, but with type imports last as a separate
* group, sorting that group like non-type imports are grouped.
*/
const importGroups = [
// Side effect imports.
['^\\u0000'],
// Packages.
// Things that start with a letter (or digit or underscore), or `@` followed by a letter.
['^@?\\w'],
// Absolute imports and other imports such as Vue-style `@/foo`.
// Anything not matched in another group.
['^'],
// Relative imports.
// Anything that starts with a dot
['^\\.'],
// Typings
['^@?\\w.*\\u0000$', '^[^.].*\\u0000$', '^\\..*\\u0000$']
];
/*
* Configuration for simple-import-sort plugin to detect
* the different namespaces defined in the application.
* This matches the "paths" property of the tsconfig.json file.
*/
const { compilerOptions } = require('get-tsconfig').getTsconfig('./tsconfig.json')['config'];
if ('paths' in compilerOptions) {
const namespaces = Object.keys(compilerOptions.paths).map(path => path.replace('/*', ''));
if (namespaces && namespaces.length > 0) {
// Anything that is defined in tsconfig.json with a little trick in order to resolve paths
const pathAliasRegex = [`^(${namespaces.join('|')})(/.*|$)`];
importGroups.splice(2, 0, pathAliasRegex);
}
}
/*
* Although many of the extended configurations already automatically
* import the plugins, we have chosen to add them explicitly in case
* the recommended configurations are dispensed with in the future.
* In this way the rules could be added directly in the "rules" section.
*/
module.exports = {
root: true,
ignorePatterns: ['projects/**/*'],
env: {
node: true,
jest: true,
'jest/globals': true,
'cypress/globals': true
},
parserOptions: {
ecmaVersion: 12,
sourceType: 'module'
},
overrides: [
{
files: '*.js',
extends: ['eslint:recommended']
},
{
files: ['*.ts'],
parser: '@typescript-eslint/parser',
parserOptions: {
project: ['./tsconfig.json', './tsconfig.app.json', './tsconfig.server.json', './tsconfig.spec.json'],
createDefaultProgram: true
},
extends: [
'plugin:@angular-eslint/recommended',
'plugin:@angular-eslint/recommended--extra',
'plugin:@angular-eslint/template/process-inline-templates',
'plugin:eslint-comments/recommended',
'plugin:sonarjs/recommended',
'plugin:import/recommended',
'plugin:import/typescript',
'plugin:prettier/recommended'
],
plugins: [
'@typescript-eslint',
'prefer-arrow',
'eslint-comments',
'sonarjs',
'import',
'prettier',
'simple-import-sort',
'unused-imports',
'deprecation'
],
settings: {
// Define import resolver for import plugin
'import/resolver': {
typescript: {
alwaysTryTypes: true
}
}
},
rules: {
// For faster development
'no-process-exit': 'off',
'no-useless-constructor': 'off',
'class-methods-use-this': 'off',
'@typescript-eslint/no-explicit-any': 'off',
'@typescript-eslint/explicit-function-return-type': 'off',
'@typescript-eslint/no-non-null-assertion': 'off',
'sonarjs/cognitive-complexity': ['error', 18],
// Angular specific
'@angular-eslint/directive-selector': [
'error',
{
type: 'attribute',
prefix: 'app',
style: 'camelCase'
}
],
'@angular-eslint/component-selector': [
'error',
{
type: 'element',
prefix: 'app',
style: 'kebab-case'
}
],
// Import and order style
'simple-import-sort/imports': [
'error',
{
groups: importGroups
}
],
'no-restricted-imports': [
'error',
{
patterns: [
{
group: ['../*', './../*'],
message: 'For imports of parent elements use better path aliases. For example, @domain/shared.'
}
]
}
],
'import/no-named-as-default': 'off',
'import/no-named-as-default-member': 'off',
'simple-import-sort/exports': 'error',
'import/prefer-default-export': 'off',
'import/no-default-export': 'off',
'import/first': 'error',
'import/newline-after-import': 'error',
'import/no-duplicates': 'error',
'import/no-deprecated': 'error',
'import/group-exports': 'error',
'import/exports-last': 'error',
'padding-line-between-statements': [
'error',
{ blankLine: 'always', prev: '*', next: 'export' },
{ blankLine: 'any', prev: 'export', next: 'export' }
],
quotes: [
'error',
'single',
{
allowTemplateLiterals: true
}
],
'@typescript-eslint/member-ordering': 'error',
'@typescript-eslint/no-unused-vars': 'off',
'no-unused-vars': 'off',
'unused-imports/no-unused-imports': 'error',
'unused-imports/no-unused-vars': [
'error',
{ vars: 'all', varsIgnorePattern: '^_', args: 'after-used', argsIgnorePattern: '^_' }
],
// General rules
'deprecation/deprecation': 'warn',
'eslint-comments/disable-enable-pair': ['error', { allowWholeFile: true }],
'lines-between-class-members': 'off',
'@typescript-eslint/lines-between-class-members': 'error',
'prefer-arrow/prefer-arrow-functions': [
'warn',
{
disallowPrototype: true,
singleReturnOnly: false,
classPropertiesAllowed: false
}
]
},
overrides: [
{
files: ['*.unit.ts', '*.int.ts', '*.spec.ts', '*.test.ts'],
env: {
jest: true,
'jest/globals': true
},
extends: ['plugin:jest/recommended', 'plugin:jest/style'],
plugins: ['jest'],
rules: {
'jest/expect-expect': ['error', { assertFunctionNames: ['expect', 'request.**.expect'] }]
}
},
{
files: ['*.e2e.ts', '*.cy.ts'],
env: {
'cypress/globals': true
},
parserOptions: {
project: './cypress/tsconfig.json'
},
extends: ['plugin:cypress/recommended'],
plugins: ['cypress'],
rules: {}
}
]
},
{
files: ['*.html'],
extends: ['plugin:@angular-eslint/template/recommended'],
rules: {}
},
{
files: ['*.html'],
excludedFiles: ['*inline-template-*.component.html'],
extends: ['plugin:prettier/recommended'],
rules: {
'prettier/prettier': ['error', { parser: 'angular' }]
}
}
]
};