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