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