-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patheslint.config.mjs
91 lines (83 loc) · 2.7 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
import pluginJavascript from '@eslint/js'
import pluginStylistic from '@stylistic/eslint-plugin'
import globals from 'globals'
import { config, configs as typescriptConfigs } from 'typescript-eslint'
const javascriptPluginConfig = config(
pluginJavascript.configs.recommended,
normalizeRules({
'no-useless-rename': 'error',
'object-shorthand': 'error',
'no-useless-concat': 'error',
'prefer-template': 'error',
eqeqeq: 'smart',
}),
)
const stylisticPluginConfig = config(
pluginStylistic.configs.customize({
indent: 2,
semi: false,
arrowParens: true,
quoteProps: 'as-needed',
braceStyle: '1tbs',
}),
normalizeRules('@stylistic', {
quotes: 'single',
'linebreak-style': 'unix',
'no-extra-parens': 'all',
'no-extra-semi': 'error',
'no-floating-decimal': 'off',
'padded-blocks': 'off',
}),
)
const typescriptPluginConfig = config(
typescriptConfigs.strictTypeChecked,
typescriptConfigs.stylisticTypeChecked,
{ languageOptions: { parserOptions: { projectService: true, tsconfigRootDir: process.cwd() } } },
normalizeRules('@typescript-eslint', {
'array-type': { default: 'array-simple', readonly: 'array-simple' },
'restrict-template-expressions': {
allowNumber: true,
allowNever: true,
allowBoolean: false,
allowAny: false,
allowNullish: false,
allowRegExp: false,
allowArray: false,
},
}),
{
files: ['**/*.{js,mjs,cjs}'],
...typescriptConfigs.disableTypeChecked,
},
)
export default config(
{ ignores: ['dist', 'coverage'] },
{ files: ['**/*.{js,mjs,cjs,ts}'] },
{ languageOptions: { globals: { ...globals.node, ...globals.browser } } },
javascriptPluginConfig,
stylisticPluginConfig,
typescriptPluginConfig,
)
function normalizeRules(pluginName, rules) {
if (!rules && pluginName) return normalizeRules(null, pluginName)
const normalizeEntry = createEntryNormalizer(pluginName)
const entries = Object.entries(rules).map(normalizeEntry)
return { rules: Object.fromEntries(entries) }
}
function createEntryNormalizer(pluginName) {
if (!pluginName) return ([ruleName, ruleEntry]) => [ruleName, normalizeRuleEntry(ruleEntry)]
const normalizeRuleName = createPluginRuleNameNormalizer(pluginName)
return ([ruleName, ruleEntry]) => [normalizeRuleName(ruleName), normalizeRuleEntry(ruleEntry)]
}
function createPluginRuleNameNormalizer(pluginName) {
const pluginPrefix = `${pluginName}/`
return (ruleName) => {
if (ruleName.startsWith(pluginPrefix)) return ruleName
return `${pluginPrefix}${ruleName}`
}
}
function normalizeRuleEntry(entry) {
if (Array.isArray(entry)) return entry
if (['error', 'off', 'warn'].includes(entry)) return entry
return ['error', entry]
}