-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy patheslint.config.mjs
135 lines (126 loc) · 3.59 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
129
130
131
132
133
134
135
import path from "node:path";
import { includeIgnoreFile } from "@eslint/compat";
import eslint from "@eslint/js";
import alloy from "eslint-config-alloy/base.js";
import alloyts from "eslint-config-alloy/typescript.js";
import importPlugin from "eslint-plugin-import";
import noAutoFix from "eslint-plugin-no-autofix";
import unusedImports from "eslint-plugin-unused-imports";
import tseslint from "typescript-eslint";
function main() {
const setting = Object.values(SettingConfig).flat();
const main = Object.values(MainConfig).flat();
const linting = Object.values(LintingConfig)
.flat()
.map((config) => unfixable(config));
return tseslint.config(...setting, ...main, ...linting);
}
function unfixable(config) {
if (!config.rules) {
return config;
}
const newRules = Object.fromEntries(
Object.entries(config.rules).flatMap(([key, value]) => [
[key, "off"],
[`noAutoFix/` + key, value],
]),
);
return {
...config,
plugins: {
...config.plugins,
noAutoFix: noAutoFix,
},
rules: newRules,
};
}
class SettingConfig {
static ignore = [includeIgnoreFile(path.resolve(import.meta.dirname, ".gitignore"))];
}
class MainConfig {
static js = [eslint.configs.recommended, { rules: alloy.rules }];
static ts = [
tseslint.configs.strictTypeChecked,
tseslint.configs.stylisticTypeChecked,
{ rules: alloyts.rules },
];
static typecheckRulesSettings = [
// Linting with Type Information https://typescript-eslint.io/getting-started/typed-linting/
{
languageOptions: {
parserOptions: {
projectService: true,
tsconfigRootDir: import.meta.dirname,
},
},
},
// type-checked rules for files outscoped of tsconfig
// cause Error: `Parsing error: was not found by the project service`.
// avoid the error with disabling typechecked rules for the files
{
files: ["**/*.{js,cjs,mjs,jsx}"],
...tseslint.configs.disableTypeChecked,
},
];
static removingTsRulesFromJs = {
files: ["**/*.{js,cjs,mjs,jsx}"],
rules: {
"@typescript-eslint/explicit-member-accessibility": "off",
"@typescript-eslint/consistent-type-imports": "off",
"@typescript-eslint/no-unused-expressions": "off",
},
};
static tuning = {
rules: {
"max-params": ["off", { max: 3 }],
"@typescript-eslint/no-unused-vars": ["off"],
"@typescript-eslint/member-ordering": ["off"],
"@typescript-eslint/dot-notation": ["off"],
},
};
static sortImport = {
plugins: {
importPlugin,
},
rules: {
"importPlugin/consistent-type-specifier-style": ["warn", "prefer-top-level"],
"importPlugin/first": ["warn"],
"importPlugin/newline-after-import": ["warn", { considerComments: true }],
"importPlugin/no-duplicates": ["warn"],
"importPlugin/no-namespace": ["warn"],
"importPlugin/order": [
"warn",
{
"newlines-between": "always",
named: true,
alphabetize: {
order: "asc",
orderImportKind: "desc",
},
groups: ["builtin", "external", ["internal", "parent", "sibling"], "index", "object"],
},
],
},
settings: {
"import/parsers": {
"@typescript-eslint/parser": [".ts", ".tsx"],
},
"import/resolver": {
typescript: {
project: ["**/tsconfig.json"],
},
},
},
};
}
class LintingConfig {
static unusedImports = {
plugins: {
unusedImports,
},
rules: {
"unused-imports/no-unused-imports": ["warn"],
},
};
}
export default main();