@ivanmaxlogiudice/eslint-config 1.0.0-beta.8 → 1.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +20 -20
- package/README.md +282 -25
- package/bin/index.js +3 -0
- package/dist/cli.cjs +283 -0
- package/dist/cli.d.cts +2 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +254 -0
- package/dist/index.cjs +1944 -0
- package/dist/index.d.cts +267 -0
- package/dist/index.d.ts +267 -0
- package/dist/index.js +1840 -0
- package/package.json +75 -33
- package/index.cjs +0 -1
- package/index.js +0 -9
- package/src/eslint-comments.js +0 -17
- package/src/js.js +0 -539
- package/src/jsonc.js +0 -116
- package/src/markdown.js +0 -43
- package/src/presets.js +0 -69
- package/src/shared.js +0 -67
- package/src/typescript.js +0 -155
- package/src/unocss.js +0 -13
- package/src/vue.js +0 -198
- package/src/yml.js +0 -26
package/dist/cli.d.ts
ADDED
package/dist/cli.js
ADDED
|
@@ -0,0 +1,254 @@
|
|
|
1
|
+
// src/cli/index.ts
|
|
2
|
+
import { cac } from "cac";
|
|
3
|
+
import c4 from "picocolors";
|
|
4
|
+
|
|
5
|
+
// src/cli/constants.ts
|
|
6
|
+
import c from "picocolors";
|
|
7
|
+
|
|
8
|
+
// package.json
|
|
9
|
+
var version = "1.0.6";
|
|
10
|
+
var devDependencies = {
|
|
11
|
+
"@stylistic/eslint-plugin-migrate": "^1.2.0",
|
|
12
|
+
"@types/eslint": "^8.44.7",
|
|
13
|
+
"@types/fs-extra": "^11.0.4",
|
|
14
|
+
"@types/node": "^20.9.0",
|
|
15
|
+
"@types/prompts": "^2.4.8",
|
|
16
|
+
bumpp: "^9.2.0",
|
|
17
|
+
eslint: "^8.53.0",
|
|
18
|
+
"eslint-flat-config-viewer": "^0.1.1",
|
|
19
|
+
execa: "^8.0.1",
|
|
20
|
+
"fast-glob": "^3.3.2",
|
|
21
|
+
"fs-extra": "^11.1.1",
|
|
22
|
+
"lint-staged": "^15.1.0",
|
|
23
|
+
"simple-git-hooks": "^2.9.0",
|
|
24
|
+
tsup: "^7.2.0",
|
|
25
|
+
typescript: "^5.2.2",
|
|
26
|
+
vitest: "^0.34.6"
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
// src/cli/constants.ts
|
|
30
|
+
var ARROW = c.cyan("\u2192");
|
|
31
|
+
var CHECK = c.green("\u2714");
|
|
32
|
+
var CROSS = c.red("\u2718");
|
|
33
|
+
var WARN = c.yellow("\u2139");
|
|
34
|
+
var vscodeSettingsString = `
|
|
35
|
+
// Enable the ESlint flat config support
|
|
36
|
+
"eslint.experimental.useFlatConfig": true,
|
|
37
|
+
|
|
38
|
+
// Disable the default formatter, use eslint instead
|
|
39
|
+
"prettier.enable": false,
|
|
40
|
+
"editor.formatOnSave": false,
|
|
41
|
+
|
|
42
|
+
// Auto fix
|
|
43
|
+
"editor.codeActionsOnSave": {
|
|
44
|
+
"source.fixAll.eslint": "explicit",
|
|
45
|
+
"source.organizeImports": "never"
|
|
46
|
+
},
|
|
47
|
+
|
|
48
|
+
// Silent the stylistic rules in you IDE, but still auto fix them
|
|
49
|
+
"eslint.rules.customizations": [
|
|
50
|
+
{ "rule": "style/*", "severity": "off" },
|
|
51
|
+
{ "rule": "*-indent", "severity": "off" },
|
|
52
|
+
{ "rule": "*-spacing", "severity": "off" },
|
|
53
|
+
{ "rule": "*-spaces", "severity": "off" },
|
|
54
|
+
{ "rule": "*-order", "severity": "off" },
|
|
55
|
+
{ "rule": "*-dangle", "severity": "off" },
|
|
56
|
+
{ "rule": "*-newline", "severity": "off" },
|
|
57
|
+
{ "rule": "*quotes", "severity": "off" },
|
|
58
|
+
{ "rule": "*semi", "severity": "off" }
|
|
59
|
+
],
|
|
60
|
+
|
|
61
|
+
// Enable eslint for all supported languages
|
|
62
|
+
"eslint.validate": [
|
|
63
|
+
"javascript",
|
|
64
|
+
"javascriptreact",
|
|
65
|
+
"typescript",
|
|
66
|
+
"typescriptreact",
|
|
67
|
+
"vue",
|
|
68
|
+
"html",
|
|
69
|
+
"markdown",
|
|
70
|
+
"json",
|
|
71
|
+
"jsonc",
|
|
72
|
+
"yaml"
|
|
73
|
+
]
|
|
74
|
+
`;
|
|
75
|
+
|
|
76
|
+
// src/cli/migrate.ts
|
|
77
|
+
import fs from "node:fs";
|
|
78
|
+
import fsp from "node:fs/promises";
|
|
79
|
+
import path from "node:path";
|
|
80
|
+
import process2 from "node:process";
|
|
81
|
+
import detectIndent from "detect-indent";
|
|
82
|
+
import parse from "parse-gitignore";
|
|
83
|
+
import c3 from "picocolors";
|
|
84
|
+
import prompts from "prompts";
|
|
85
|
+
|
|
86
|
+
// src/cli/utils.ts
|
|
87
|
+
import { execSync } from "node:child_process";
|
|
88
|
+
import process from "node:process";
|
|
89
|
+
import c2 from "picocolors";
|
|
90
|
+
function throwError(level, message) {
|
|
91
|
+
console.error(`
|
|
92
|
+
${c2.inverse(c2.red(` Failed to migrate `))}`);
|
|
93
|
+
console.error(level, message);
|
|
94
|
+
process.exit(1);
|
|
95
|
+
}
|
|
96
|
+
function isGitClean() {
|
|
97
|
+
try {
|
|
98
|
+
execSync("git diff-index --quiet HEAD --");
|
|
99
|
+
return true;
|
|
100
|
+
} catch {
|
|
101
|
+
return false;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
// src/cli/migrate.ts
|
|
106
|
+
var SKIP_PROMPT = !!process2.env.SKIP_PROMPT;
|
|
107
|
+
var SKIP_GIT_CHECK = !!process2.env.SKIP_GIT_CHECK;
|
|
108
|
+
async function migrate() {
|
|
109
|
+
const cwd = process2.cwd();
|
|
110
|
+
const pathPackageJSON = path.join(process2.cwd(), "package.json");
|
|
111
|
+
const pathESLintConfig = path.join(process2.cwd(), "eslint.config.js");
|
|
112
|
+
const pathESLintIngore = path.join(process2.cwd(), ".eslintignore");
|
|
113
|
+
if (fs.existsSync(pathESLintConfig))
|
|
114
|
+
throwError(WARN, "eslint.config.js already exists, migration wizard exited.");
|
|
115
|
+
if (!SKIP_GIT_CHECK && !isGitClean())
|
|
116
|
+
throwError(CROSS, "There are uncommitted changes in the current repository, please commit them and try again.");
|
|
117
|
+
console.log(`
|
|
118
|
+
${ARROW} Installing ${c3.green("@ivanmaxlogiudice/eslint-config")} to v${c3.yellow(version)}.
|
|
119
|
+
`);
|
|
120
|
+
const pkgContent = await fsp.readFile(pathPackageJSON, "utf-8");
|
|
121
|
+
const pkgIndent = detectIndent(pkgContent).indent || 2;
|
|
122
|
+
const pkg = JSON.parse(pkgContent);
|
|
123
|
+
pkg.devDependencies ??= {};
|
|
124
|
+
pkg.devDependencies["@ivanmaxlogiudice/eslint-config"] = `^${version}`;
|
|
125
|
+
await fsp.writeFile(pathPackageJSON, JSON.stringify(pkg, null, pkgIndent));
|
|
126
|
+
console.log(`${CHECK} Changes wrote to package.json`);
|
|
127
|
+
const eslintIgnores = [];
|
|
128
|
+
if (fs.existsSync(pathESLintIngore)) {
|
|
129
|
+
console.log(`${ARROW} Migrating existing .eslintignore.`);
|
|
130
|
+
const content = await fsp.readFile(pathESLintIngore, "utf-8");
|
|
131
|
+
const parsed = parse(content);
|
|
132
|
+
const globs = parsed.globs();
|
|
133
|
+
for (const glob of globs) {
|
|
134
|
+
if (glob.type === "ignore")
|
|
135
|
+
eslintIgnores.push(...glob.patterns);
|
|
136
|
+
else if (glob.type === "unignore")
|
|
137
|
+
eslintIgnores.push(...glob.patterns.map((pattern) => `!${pattern}`));
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
let configContent = `${eslintIgnores.length > 0 ? `ignores: ${JSON.stringify(eslintIgnores)}` : ""}`;
|
|
141
|
+
if (pkg.type === "module") {
|
|
142
|
+
configContent = `
|
|
143
|
+
import config from '@ivanmaxlogiudice/eslint-config'
|
|
144
|
+
|
|
145
|
+
export default config({
|
|
146
|
+
${configContent}
|
|
147
|
+
})
|
|
148
|
+
`.trimStart();
|
|
149
|
+
} else {
|
|
150
|
+
configContent = `
|
|
151
|
+
const config = require('@ivanmaxlogiudice/eslint-config').default
|
|
152
|
+
|
|
153
|
+
module.exports = config({
|
|
154
|
+
${configContent}
|
|
155
|
+
})
|
|
156
|
+
`.trimStart();
|
|
157
|
+
}
|
|
158
|
+
await fsp.writeFile(pathESLintConfig, configContent);
|
|
159
|
+
console.log(`${CHECK} Created ${c3.green("eslint.config.js")} successfully.`);
|
|
160
|
+
const files = fs.readdirSync(cwd);
|
|
161
|
+
const legacyFiles = [];
|
|
162
|
+
files.forEach((file) => {
|
|
163
|
+
if (file !== "eslint.config.js" && (file.includes("eslint") || file.includes("prettier")))
|
|
164
|
+
legacyFiles.push(file);
|
|
165
|
+
});
|
|
166
|
+
if (legacyFiles.length > 0) {
|
|
167
|
+
console.log(`
|
|
168
|
+
${WARN} You can now remove those files manually: `);
|
|
169
|
+
console.log(` ${c3.red("-")} ${c3.dim(legacyFiles.join(", "))}`);
|
|
170
|
+
}
|
|
171
|
+
const dependencies = { ...pkg.devDependencies, ...pkg?.dependencies };
|
|
172
|
+
const legacyDependencies = [];
|
|
173
|
+
Object.keys(dependencies).forEach((dep) => {
|
|
174
|
+
if (dep.includes("prettier"))
|
|
175
|
+
legacyDependencies.push(dep);
|
|
176
|
+
});
|
|
177
|
+
if (legacyDependencies.length > 0) {
|
|
178
|
+
console.log(`
|
|
179
|
+
${WARN} You can now remove those dependencies: `);
|
|
180
|
+
console.log(` ${c3.red("-")} ${c3.dim(legacyDependencies.join(", "))}`);
|
|
181
|
+
}
|
|
182
|
+
const updateESLintVersion = pkg.devDependencies?.eslint ? pkg.devDependencies.eslint !== "latest" && pkg.devDependencies.eslint.match(/\d+/)?.[0] < 8 : true;
|
|
183
|
+
let prompResult = {
|
|
184
|
+
updateESLintVersion,
|
|
185
|
+
updateVscodeSettings: true
|
|
186
|
+
};
|
|
187
|
+
if (!SKIP_PROMPT) {
|
|
188
|
+
console.log();
|
|
189
|
+
try {
|
|
190
|
+
prompResult = await prompts([
|
|
191
|
+
{
|
|
192
|
+
initial: true,
|
|
193
|
+
message: "Update .vscode/settings.json for better VSCode experience?",
|
|
194
|
+
name: "updateVscodeSettings",
|
|
195
|
+
type: "confirm"
|
|
196
|
+
},
|
|
197
|
+
{
|
|
198
|
+
initial: true,
|
|
199
|
+
message: "Update ESLint to the latest version?",
|
|
200
|
+
name: "updateESLintVersion",
|
|
201
|
+
type: "confirm"
|
|
202
|
+
}
|
|
203
|
+
], {
|
|
204
|
+
onCancel() {
|
|
205
|
+
throw new Error("Cancelled");
|
|
206
|
+
}
|
|
207
|
+
});
|
|
208
|
+
} catch (error) {
|
|
209
|
+
console.log(error.message);
|
|
210
|
+
return;
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
if (prompResult.updateVscodeSettings ?? true) {
|
|
214
|
+
const dotVSCodePath = path.join(cwd, ".vscode");
|
|
215
|
+
const settingsPath = path.join(dotVSCodePath, "settings.json");
|
|
216
|
+
if (!fs.existsSync(dotVSCodePath))
|
|
217
|
+
await fsp.mkdir(dotVSCodePath, { recursive: true });
|
|
218
|
+
if (!fs.existsSync(settingsPath)) {
|
|
219
|
+
await fsp.writeFile(settingsPath, `{${vscodeSettingsString}}
|
|
220
|
+
`);
|
|
221
|
+
console.log(`${CHECK} Created ${c3.green(".vscode/settings.json")} successfully.`);
|
|
222
|
+
} else {
|
|
223
|
+
let settingsContent = await fsp.readFile(settingsPath, "utf-8");
|
|
224
|
+
settingsContent = settingsContent.trim().replace(/\s*}$/, "");
|
|
225
|
+
settingsContent += settingsContent.endsWith(",") || settingsContent.endsWith("{") ? "" : ",";
|
|
226
|
+
settingsContent += `${vscodeSettingsString}}
|
|
227
|
+
`;
|
|
228
|
+
await fsp.writeFile(settingsPath, settingsContent, "utf-8");
|
|
229
|
+
console.log(`${CHECK} Updated ${c3.green(".vscode/settings.json")} successfully.`);
|
|
230
|
+
console.log(`${WARN} You need to check if there is any conflict between duplicate keys.
|
|
231
|
+
`);
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
if (prompResult.updateESLintVersion) {
|
|
235
|
+
pkg.devDependencies.eslint = devDependencies.eslint;
|
|
236
|
+
await fsp.writeFile(pathPackageJSON, JSON.stringify(pkg, null, pkgIndent));
|
|
237
|
+
console.log(`${CHECK} Updated ${c3.green("eslint")} to the version ${c3.yellow(devDependencies.eslint)}.
|
|
238
|
+
`);
|
|
239
|
+
}
|
|
240
|
+
console.log(`${CHECK} Migration completed!`);
|
|
241
|
+
console.log(`${c3.green("-")} Now you can update the dependencies and run ${c3.blue("eslint . --fix")}
|
|
242
|
+
`);
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
// src/cli/index.ts
|
|
246
|
+
var cli = cac(
|
|
247
|
+
c4.green("@ivanmaxlogiudice/eslint-config")
|
|
248
|
+
);
|
|
249
|
+
cli.command("migrate", "Migrate from legacy config to new flat config").action(migrate);
|
|
250
|
+
cli.help();
|
|
251
|
+
cli.version(`${c4.bold(version)}`);
|
|
252
|
+
cli.parse();
|
|
253
|
+
if (!cli.matchedCommand)
|
|
254
|
+
cli.outputHelp();
|