-
Notifications
You must be signed in to change notification settings - Fork 0
/
eslint.config.mjs
74 lines (66 loc) · 2.16 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
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',
'prefer-template': 'error',
'no-useless-concat': 'error',
});
const stylisticRules = normalizeRules('@stylistic', {
quotes: 'single',
'linebreak-style': 'unix',
'no-extra-parens': 'all',
'no-extra-semi': 'error',
'padded-blocks': 'off',
});
const stylisticPluginConfig = stylistic.configs.customize({
indent: 2,
semi: true,
arrowParens: true,
quoteProps: 'as-needed',
braceStyle: '1tbs',
});
const typescriptPluginConfig = 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.node } },
js.configs.recommended,
...typescriptPluginConfig,
stylisticPluginConfig,
{ rules: { ...eslintRules, ...stylisticRules } },
);
function normalizeRuleEntry(entry) {
if (Array.isArray(entry)) return entry;
if (['off', 'warn', 'error'].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(pluginOrRules, rules) {
if (!rules) return normalizeRulesObject(pluginOrRules);
return normalizeRulesObject(rules, pluginOrRules);
}