-
-
Notifications
You must be signed in to change notification settings - Fork 62
Expand file tree
/
Copy patheslint.config.mjs
More file actions
92 lines (89 loc) · 3.71 KB
/
eslint.config.mjs
File metadata and controls
92 lines (89 loc) · 3.71 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
import wdioEslint from '@wdio/eslint'
export default wdioEslint.config([
{
ignores: [
'lib',
'**/*/dist',
'playgrounds/**'
]
},
/**
* custom test configuration
*/
{
files: [
'test/**/*',
'__mocks__/**/*'
],
languageOptions: {
globals: {
beforeAll: true,
afterAll: true,
afterEach: true,
beforeEach: true
}
},
rules: {
'@typescript-eslint/no-require-imports': 'off',
'@typescript-eslint/no-explicit-any': 'off'
}
},
{
files: ['src/**/*.ts'],
plugins: {
local: {
rules: {
'enforce-options-list': {
create(context) {
const fileName = context.filename || context.getFilename()
const isConstantsFile = fileName.endsWith('src/constants.ts')
const definedOptions = new Set()
let listNode = null
const listElements = new Set()
return {
VariableDeclarator(node) {
if (node.id.type === 'Identifier') {
if (node.id.name.includes('DEFAULT_OPTIONS')) {
if (isConstantsFile) {
definedOptions.add(node.id.name)
} else {
context.report({
node: node.id,
message: `Option '${node.id.name}' must be included in 'src/constants.ts#defaultOptionsList', so it can be globally overridden.`
})
}
}
if (isConstantsFile && node.id.name === 'defaultOptionsList' && node.init && node.init.type === 'ArrayExpression') {
listNode = node
node.init.elements.forEach(el => {
if (el && el.type === 'Identifier') {
listElements.add(el.name)
}
})
}
}
},
'Program:exit'() {
if (!listNode) {
return
}
definedOptions.forEach(opt => {
if (!listElements.has(opt)) {
context.report({
node: listNode,
message: `Option '${opt}' must be included in 'defaultOptionsList', so it can be globally overridden in 'src/constants.ts'.`
})
}
})
}
}
}
}
}
}
},
rules: {
'local/enforce-options-list': 'error'
}
}
])