Skip to content

Commit 2b37a6c

Browse files
committed
refactor: language = js
1 parent 61c9c30 commit 2b37a6c

File tree

55 files changed

+124
-183
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+124
-183
lines changed

lib/config-generator.js

Lines changed: 56 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,16 @@ export class ConfigGenerator {
123123
const purpose = this.answers.purpose;
124124
const useTs = this.answers.useTs;
125125

126+
if (purpose === "syntax") {
127+
128+
// no need to install any plugin
129+
} else if (purpose === "problems") {
130+
this.result.devDependencies.push("@eslint/js");
131+
importContent += "import js from \"@eslint/js\";\n";
132+
exportContent += ` { files: ["${extensions}"], plugins: { js }, extends: ["js/recommended"] },\n`;
133+
}
134+
135+
// language = javascript/typescript
126136
if (languages.includes("javascript")) {
127137
if (this.answers.moduleType === "commonjs" || this.answers.moduleType === "script") {
128138
exportContent += ` { files: ["**/*.js"], languageOptions: { sourceType: "${this.answers.moduleType}" } },\n`;
@@ -139,74 +149,71 @@ export class ConfigGenerator {
139149

140150
exportContent += ` { files: ["${extensions}"], languageOptions: { ${envContent[this.answers.env.join(",")]} } },\n`;
141151
}
142-
}
143-
144-
if (purpose === "syntax") {
152+
if (useTs) {
153+
this.result.devDependencies.push("typescript-eslint");
154+
importContent += "import tseslint from \"typescript-eslint\";\n";
155+
exportContent += " tseslint.configs.recommended,\n";
156+
}
145157

146-
// no need to install any plugin
147-
} else if (purpose === "problems") {
148-
this.result.devDependencies.push("@eslint/js");
149-
importContent += "import js from \"@eslint/js\";\n";
150-
exportContent += ` { files: ["${extensions}"], plugins: { js }, extends: ["js/recommended"] },\n`;
151-
}
158+
if (this.answers.framework === "vue") {
159+
this.result.devDependencies.push("eslint-plugin-vue");
160+
importContent += "import pluginVue from \"eslint-plugin-vue\";\n";
161+
exportContent += " pluginVue.configs[\"flat/essential\"],\n";
152162

153-
if (useTs) {
154-
this.result.devDependencies.push("typescript-eslint");
155-
importContent += "import tseslint from \"typescript-eslint\";\n";
156-
exportContent += " tseslint.configs.recommended,\n";
157-
}
158-
159-
if (this.answers.framework === "vue") {
160-
this.result.devDependencies.push("eslint-plugin-vue");
161-
importContent += "import pluginVue from \"eslint-plugin-vue\";\n";
162-
exportContent += " pluginVue.configs[\"flat/essential\"],\n";
163+
// https://eslint.vuejs.org/user-guide/#how-to-use-a-custom-parser
164+
if (this.answers.language === "typescript") {
165+
exportContent += " { files: [\"**/*.vue\"], languageOptions: { parserOptions: { parser: tseslint.parser } } },\n";
166+
}
167+
}
163168

164-
// https://eslint.vuejs.org/user-guide/#how-to-use-a-custom-parser
165-
if (this.answers.language === "typescript") {
166-
exportContent += " { files: [\"**/*.vue\"], languageOptions: { parserOptions: { parser: tseslint.parser } } },\n";
169+
if (this.answers.framework === "react") {
170+
this.result.devDependencies.push("eslint-plugin-react");
171+
importContent += "import pluginReact from \"eslint-plugin-react\";\n";
172+
exportContent += " pluginReact.configs.flat.recommended,\n";
167173
}
168-
}
169174

170-
if (this.answers.framework === "react") {
171-
this.result.devDependencies.push("eslint-plugin-react");
172-
importContent += "import pluginReact from \"eslint-plugin-react\";\n";
173-
exportContent += " pluginReact.configs.flat.recommended,\n";
175+
if (needCompatHelper) {
176+
this.result.devDependencies.push("@eslint/eslintrc", "@eslint/js");
177+
}
174178
}
175179

180+
// language = json/jsonc/json5
176181
if (languages.some(item => item.startsWith("json"))) {
177182
this.result.devDependencies.push("@eslint/json");
178183
importContent += "import json from \"@eslint/json\";\n";
179-
}
180-
if (languages.includes("json")) {
181-
const config = purpose === "syntax"
182-
? " {files: [\"**/*.json\"], plugins: {json}, language: \"json/json\"},\n"
183-
: " {files: [\"**/*.json\"], language: \"json/json\", ...json.configs.recommended},\n";
184184

185-
exportContent += config;
186-
}
187-
if (languages.includes("jsonc")) {
188-
const config = purpose === "syntax"
189-
? " {files: [\"**/*.jsonc\"], plugins: {json}, language: \"json/jsonc\"},\n"
190-
: " {files: [\"**/*.jsonc\"], language: \"json/jsonc\", ...json.configs.recommended},\n";
185+
if (languages.includes("json")) {
186+
const config = purpose === "syntax"
187+
? " { files: [\"**/*.json\"], plugins: { json }, language: \"json/json\" },\n"
188+
: " { files: [\"**/*.json\"], language: \"json/json\", ...json.configs.recommended},\n";
191189

192-
exportContent += config;
193-
}
194-
if (languages.includes("json5")) {
195-
const config = purpose === "syntax"
196-
? " {files: [\"**/*.json5\"], plugins: {json}, language: \"json/json5\"},\n"
197-
: " {files: [\"**/*.json5\"], language: \"json/json5\", ...json.configs.recommended},\n";
190+
exportContent += config;
191+
}
192+
if (languages.includes("jsonc")) {
193+
const config = purpose === "syntax"
194+
? " { files: [\"**/*.jsonc\"], plugins: { json }, language: \"json/jsonc\" },\n"
195+
: " { files: [\"**/*.jsonc\"], language: \"json/jsonc\", ...json.configs.recommended },\n";
198196

199-
exportContent += config;
197+
exportContent += config;
198+
}
199+
if (languages.includes("json5")) {
200+
const config = purpose === "syntax"
201+
? " { files: [\"**/*.json5\"], plugins: { json }, language: \"json/json5\" },\n"
202+
: " { files: [\"**/*.json5\"], language: \"json/json5\", ...json.configs.recommended },\n";
203+
204+
exportContent += config;
205+
}
200206
}
201207

208+
// language = markdown
202209
if (languages.includes("md")) {
203210
this.result.devDependencies.push("@eslint/markdown");
204211
importContent += "import markdown from \"@eslint/markdown\";\n";
205212

206213
if (purpose === "syntax") {
207214
const config = this.answers.mdType === "commonmark"
208-
? " {files: [\"**/*.md\"], plugins: {markdown}, language: \"markdown/commonmark\"},\n"
209-
: " {files: [\"**/*.md\"], plugins: {markdown}, language: \"markdown/gfm\"},\n";
215+
? " { files: [\"**/*.md\"], plugins: {markdown}, language: \"markdown/commonmark\" },\n"
216+
: " { files: [\"**/*.md\"], plugins: {markdown}, language: \"markdown/gfm\" },\n";
210217

211218
exportContent += config;
212219
} else if (purpose === "problems") {
@@ -215,11 +222,12 @@ export class ConfigGenerator {
215222
if (this.answers.mdType === "gfm") {
216223

217224
// the default is commonmark
218-
exportContent += " {files: [\"**/*.md\"], language: \"markdown/gfm\"},\n";
225+
exportContent += " { files: [\"**/*.md\"], language: \"markdown/gfm\" },\n";
219226
}
220227
}
221228
}
222229

230+
// passed `--config`
223231
if (this.answers.config) {
224232
const config = this.answers.config;
225233

@@ -256,14 +264,6 @@ export class ConfigGenerator {
256264
}
257265
}
258266

259-
if (needCompatHelper) {
260-
this.result.devDependencies.push("@eslint/eslintrc", "@eslint/js");
261-
}
262-
263-
const lintFilesConfig = ` { files: ["${extensions}"] },\n`;
264-
265-
exportContent = `${lintFilesConfig}${exportContent}`;
266-
267267
this.result.configContent = `${importContent}
268268
${needCompatHelper ? helperContent : ""}
269269
export default defineConfig([\n${exportContent || " {}\n"}]);`; // defaults to `[{}]` to avoid empty config warning

tests/__snapshots__/config@eslint-config-airbnb

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ const __dirname = path.dirname(__filename);
1212
const compat = new FlatCompat({baseDirectory: __dirname, recommendedConfig: js.configs.recommended});
1313

1414
export default defineConfig([
15-
{ files: ["**/*.{js,mjs,cjs}"] },
1615
compat.extends("airbnb"),
1716
]);",
1817
"configFilename": "eslint.config.mjs",
@@ -23,8 +22,6 @@ export default defineConfig([
2322
"eslint-plugin-import@^2.25.3",
2423
"eslint-plugin-jsx-a11y@^6.5.1",
2524
"eslint-plugin-react-hooks@^4.3.0",
26-
"@eslint/eslintrc",
27-
"@eslint/js",
2825
],
2926
"installFlags": [
3027
"-D",

tests/__snapshots__/config@eslint-config-airbnb-base

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,13 @@ const __dirname = path.dirname(__filename);
1212
const compat = new FlatCompat({baseDirectory: __dirname, recommendedConfig: js.configs.recommended});
1313

1414
export default defineConfig([
15-
{ files: ["**/*.{js,mjs,cjs}"] },
1615
compat.extends("airbnb-base"),
1716
]);",
1817
"configFilename": "eslint.config.mjs",
1918
"devDependencies": [
2019
"eslint@^7.32.0 || ^8.2.0",
2120
"eslint-config-airbnb-base",
2221
"eslint-plugin-import@^2.25.2",
23-
"@eslint/eslintrc",
24-
"@eslint/js",
2522
],
2623
"installFlags": [
2724
"-D",

tests/__snapshots__/config@eslint-config-standard

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ const __dirname = path.dirname(__filename);
1212
const compat = new FlatCompat({baseDirectory: __dirname, recommendedConfig: js.configs.recommended});
1313

1414
export default defineConfig([
15-
{ files: ["**/*.{js,mjs,cjs}"] },
1615
compat.extends("standard"),
1716
]);",
1817
"configFilename": "eslint.config.mjs",
@@ -22,8 +21,6 @@ export default defineConfig([
2221
"eslint-plugin-import@^2.25.2",
2322
"eslint-plugin-n@^15.0.0 || ^16.0.0 ",
2423
"eslint-plugin-promise@^6.0.0",
25-
"@eslint/eslintrc",
26-
"@eslint/js",
2724
],
2825
"installFlags": [
2926
"-D",

tests/__snapshots__/config@eslint-config-standard-flat

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import config from "eslint-config-standard";
44

55

66
export default defineConfig([
7-
{ files: ["**/*.{js,mjs,cjs}"] },
87
config,
98
]);",
109
"configFilename": "eslint.config.mjs",

tests/__snapshots__/config@eslint-config-standard-flat2

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import config from "eslint-config-standard";
44

55

66
export default defineConfig([
7-
{ files: ["**/*.{js,mjs,cjs}"] },
87
config,
98
]);",
109
"configFilename": "eslint.config.mjs",

tests/__snapshots__/config@eslint-config-xo

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import config from "eslint-config-xo";
44

55

66
export default defineConfig([
7-
{ files: ["**/*.{js,mjs,cjs}"] },
87
config,
98
]);",
109
"configFilename": "eslint.config.mjs",

tests/__snapshots__/empty

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44

55
export default defineConfig([
6-
{ files: ["**/*.{js,mjs,cjs}"] },
6+
{}
77
]);",
88
"configFilename": "eslint.config.js",
99
"devDependencies": [

tests/__snapshots__/esm-javascript-json-problems

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,20 @@
11
{
22
"configContent": "import { defineConfig } from "eslint/config";
3-
import globals from "globals";
43
import js from "@eslint/js";
4+
import globals from "globals";
55
import json from "@eslint/json";
66

77

88
export default defineConfig([
9-
{ files: ["**/*.{js,mjs,cjs}"] },
10-
{ files: ["**/*.{js,mjs,cjs}"], languageOptions: { globals: globals.node } },
119
{ files: ["**/*.{js,mjs,cjs}"], plugins: { js }, extends: ["js/recommended"] },
12-
{files: ["**/*.json"], language: "json/json", ...json.configs.recommended},
10+
{ files: ["**/*.{js,mjs,cjs}"], languageOptions: { globals: globals.node } },
11+
{ files: ["**/*.json"], language: "json/json", ...json.configs.recommended},
1312
]);",
1413
"configFilename": "eslint.config.js",
1514
"devDependencies": [
1615
"eslint",
17-
"globals",
1816
"@eslint/js",
17+
"globals",
1918
"@eslint/json",
2019
],
2120
"installFlags": [

tests/__snapshots__/esm-json-problems

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,8 @@ import json from "@eslint/json";
55

66

77
export default defineConfig([
8-
{ files: ["**/*.{js,mjs,cjs}"] },
98
{ files: ["**/*.{js,mjs,cjs}"], plugins: { js }, extends: ["js/recommended"] },
10-
{files: ["**/*.json"], language: "json/json", ...json.configs.recommended},
9+
{ files: ["**/*.json"], language: "json/json", ...json.configs.recommended},
1110
]);",
1211
"configFilename": "eslint.config.js",
1312
"devDependencies": [

0 commit comments

Comments
 (0)