-
-
Notifications
You must be signed in to change notification settings - Fork 24
/
eslint.config.mjs
128 lines (110 loc) · 3.72 KB
/
eslint.config.mjs
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
import fs from 'node:fs'
import ts_eslint from '@typescript-eslint/eslint-plugin'
import ts_parser from '@typescript-eslint/parser'
// @ts-expect-error no types for package
import no_only_tests from 'eslint-plugin-no-only-tests'
// @ts-expect-error no types for package
import eslint_comments from '@eslint-community/eslint-plugin-eslint-comments'
import nb_eslint from '@nothing-but/eslint-plugin'
/**
@param {string} gitignore
@returns {string[]} */
function gitignore_to_glob_patterns(gitignore) {
const patterns = []
for (let pattern of gitignore.split('\n')) {
pattern = pattern.trim()
if (pattern === '' || pattern.startsWith('#')) {
continue
}
let negated = false
if (pattern[0] === '!') {
negated = true
pattern = pattern.slice(1)
}
if (pattern[0] === '/') {
pattern = pattern.slice(1)
} else if (!pattern.startsWith('**/')) {
pattern = '**/'+pattern
}
if (negated) {
pattern = '!'+pattern
}
if (pattern.indexOf('.') > 0) {
patterns.push(pattern)
} else {
patterns.push(pattern)
if (pattern.endsWith('/')) {
patterns.push(pattern+'**/*')
} else {
patterns.push(pattern+'/**/*')
}
}
}
return patterns
}
const git_ignored_paths = gitignore_to_glob_patterns(fs.readFileSync('.gitignore', 'utf-8'))
/** @type {import('eslint').Linter.Config[]} */
export default [{
files: ['**/*.{js,mjs,jsx,ts,tsx}'],
plugins: {
'@typescript-eslint': /** @type {*} */(ts_eslint),
'@no-only-tests': no_only_tests,
'@eslint-comments': eslint_comments,
'@nothing-but': /** @type {*} */(nb_eslint),
},
languageOptions: {
parser: ts_parser,
ecmaVersion: 5,
sourceType: 'module',
parserOptions: {
project: './tsconfig.json',
tsconfigRootDir: '.',
},
},
rules: {
/*
forgot to remove/implement
*/
'no-console' : 'warn',
'no-debugger' : 'warn',
// 'prefer-const' : 'warn',
'require-await' : 'warn',
'no-empty' : 'warn',
'@typescript-eslint/no-unused-vars': ['warn', {
'argsIgnorePattern' : '^_',
'varsIgnorePattern' : '^_',
'caughtErrorsIgnorePattern': '^_'
}],
'@typescript-eslint/no-unnecessary-boolean-literal-compare': 'warn',
'@typescript-eslint/no-unnecessary-condition' : 'warn',
'@typescript-eslint/no-unnecessary-qualifier' : 'warn',
'@typescript-eslint/no-unnecessary-type-arguments' : 'warn',
'@typescript-eslint/no-unnecessary-type-assertion' : 'warn',
'@typescript-eslint/no-unnecessary-type-constraint' : 'warn',
'@typescript-eslint/no-useless-empty-export' : 'warn',
'@typescript-eslint/no-empty-function' : 'warn',
'@typescript-eslint/no-unused-expressions' : ['warn', {
'allowShortCircuit': true,
'allowTernary' : true,
}],
'@eslint-comments/no-unused-disable': 'warn',
/*
prevent unexpected behavior
*/
'@typescript-eslint/no-empty-object-type' : 'warn',
'@typescript-eslint/no-unsafe-function-type' : 'warn',
'@typescript-eslint/no-wrapper-object-types' : 'warn',
'@typescript-eslint/switch-exhaustiveness-check': 'warn',
'no-fallthrough' : ['warn', {'allowEmptyCase': true}],
// '@nothing-but/no-ignored-return': 'warn',
// '@nothing-but/no-return-to-void': 'warn',
/*
tests
*/
'@no-only-tests/no-only-tests': 'warn',
},
}, {
// ignores need to be in a separate config for some reason
// https://github.com/eslint/eslint/issues/17400
ignores: ['examples/**/*', ...git_ignored_paths],
}]