-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy patheslint.config.js
140 lines (131 loc) · 4.3 KB
/
eslint.config.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
import {
baseConfig,
configFilesConfig,
typescriptConfig,
typescriptDefinitionsConfig,
} from '@arabasta/eslint-config';
// import/no-unresolved doesn't support node "exports" field. https://github.com/import-js/eslint-plugin-import/issues/1810
// eslint-disable-next-line import/no-unresolved
import playwright from 'eslint-plugin-playwright';
// import/no-unresolved doesn't support node "exports" field. https://github.com/import-js/eslint-plugin-import/issues/1810
// eslint-disable-next-line import/no-unresolved
import tseslint from 'typescript-eslint';
const typeScriptExtensions = ['ts', 'cts', 'mts', 'tsx'];
const typeScriptDefinitionExtensions = typeScriptExtensions
.filter((x) => x !== 'tsx')
.map((x) => `d.${x}`);
const allExtensions = ['js', 'cjs', 'mjs', 'jsx', ...typeScriptExtensions];
export default [
// We use a tseslint helper function here so that we get easy "extends"
// functionality that eslint flat config makes hard to achieve.
// You can use this for the convenience, without using TypeScript.
// Ideally this helper function should be provided by eslint.
// For more information: https://typescript-eslint.io/packages/typescript-eslint/#flat-config-extends
...tseslint.config({
name: 'All files',
files: [`**/*.+(${allExtensions.join('|')})`],
extends: [...baseConfig],
settings: {
'import/extensions': allExtensions.map((ext) => `.${ext}`),
'import/resolver': {
node: {
extensions: allExtensions.map((ext) => `.${ext}`),
},
},
},
rules: {
'import/no-restricted-paths': [
'error',
{
zones: [
{
target: './',
from: `./src/**/*.+(spec|test).+(${allExtensions.join('|')})`,
message: 'Importing test files in non-test files is not allowed.',
},
{
target: './',
from: `./__mocks__`,
message:
'Importing mock modules in non-test files is not allowed.',
},
{
target: './',
from: './src/testing',
message:
'Importing testing utilities in non-test files is not allowed.',
},
],
},
],
},
}),
...tseslint.config({
name: 'TypeScript files',
files: [`**/*.+(${typeScriptExtensions.join('|')})`],
extends: [...typescriptConfig],
rules: {
// Put your rules here.
},
}),
...tseslint.config({
name: 'TypeScript definition files',
files: [`**/*.+(${typeScriptDefinitionExtensions.join('|')})`],
extends: [...typescriptDefinitionsConfig],
rules: {
// Put your rules here.
},
}),
...tseslint.config({
name: 'Test files and test related infrastructure',
files: [
`src/**/*.+(spec|test).+(${allExtensions.join('|')})`,
`src/testing/**/*.+(${allExtensions.join('|')})`,
`__mocks__/**/*.+(${allExtensions.join('|')})`,
'setupTests.ts',
],
extends: [playwright.configs['flat/recommended']],
rules: {
'playwright/no-page-pause': 'off',
'playwright/max-nested-describe': ['error', { max: 2 }],
'playwright/no-raw-locators': 'error',
'playwright/prefer-to-be': 'error',
'playwright/prefer-to-contain': 'error',
'playwright/prefer-to-have-count': 'error',
'playwright/prefer-to-have-length': 'error',
'playwright/no-skipped-test': 'error',
'playwright/expect-expect': 'error',
'playwright/no-conditional-in-test': 'error',
'playwright/no-element-handle': 'error',
'playwright/no-eval': 'error',
'playwright/no-force-option': 'error',
'playwright/no-nested-step': 'error',
'playwright/no-useless-await': 'error',
'playwright/no-useless-not': 'error',
'playwright/no-wait-for-selector': 'error',
'playwright/no-wait-for-timeout': 'error',
},
}),
...tseslint.config({
name: 'Root level configuration files',
files: [
`*.+(${allExtensions.join('|')})`,
`__mocks__/**/*.+(${allExtensions.join('|')})`,
],
extends: [...configFilesConfig],
rules: {
// Put your rules here.
},
}),
{
ignores: [
'dist',
'coverage',
'mock-app',
'tests-out',
'tests-results',
'playwright',
'playwright-report',
],
},
];