Skip to content

Commit db14381

Browse files
committed
fix: review suggestions
1 parent cd750b8 commit db14381

14 files changed

+135
-25
lines changed

lib/config-generator.js

Lines changed: 30 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ export class ConfigGenerator {
8181
let exportContent = "";
8282
let needCompatHelper = false;
8383
const languages = this.answers.languages;
84+
const purpose = this.answers.purpose;
8485

8586
if (languages?.includes("javascript")) {
8687
if (this.answers.moduleType === "commonjs" || this.answers.moduleType === "script") {
@@ -99,10 +100,10 @@ export class ConfigGenerator {
99100
exportContent += ` {languageOptions: { ${envContent[this.answers.env.join(",")]} }},\n`;
100101
}
101102

102-
if (this.answers.purpose === "syntax") {
103+
if (purpose === "syntax") {
103104

104105
// no need to install any plugin
105-
} else if (this.answers.purpose === "problems") {
106+
} else if (purpose === "problems") {
106107
this.result.devDependencies.push("@eslint/js");
107108
importContent += "import pluginJs from \"@eslint/js\";\n";
108109
exportContent += " pluginJs.configs.recommended,\n";
@@ -145,23 +146,43 @@ export class ConfigGenerator {
145146
importContent += "import json from \"@eslint/json\";\n";
146147
}
147148
if (languages?.includes("json")) {
148-
exportContent += " {files: [\"**/*.json\"], language: \"json/json\", ...json.configs.recommended},\n";
149+
const config = purpose === "syntax"
150+
? " {files: [\"**/*.json\"], language: \"json/json\"},\n"
151+
: " {files: [\"**/*.json\"], language: \"json/json\", ...json.configs.recommended},\n";
152+
153+
exportContent += config;
149154
}
150155
if (languages?.includes("jsonc")) {
151-
exportContent += " {files: [\"**/*.jsonc\"], language: \"json/jsonc\", ...json.configs.recommended},\n";
156+
const config = purpose === "syntax"
157+
? " {files: [\"**/*.jsonc\"], language: \"json/jsonc\"},\n"
158+
: " {files: [\"**/*.jsonc\"], language: \"json/jsonc\", ...json.configs.recommended},\n";
159+
160+
exportContent += config;
152161
}
153162
if (languages?.includes("json5")) {
154-
exportContent += " {files: [\"**/*.json5\"], language: \"json/json5\", ...json.configs.recommended},\n";
163+
const config = purpose === "syntax"
164+
? " {files: [\"**/*.json5\"], language: \"json/json5\"},\n"
165+
: " {files: [\"**/*.json5\"], language: \"json/json5\", ...json.configs.recommended},\n";
166+
167+
exportContent += config;
155168
}
156169

157170
if (languages?.includes("md")) {
158171
this.result.devDependencies.push("@eslint/markdown");
159172
importContent += "import markdown from \"@eslint/markdown\";\n";
160-
exportContent += " ...markdown.configs.recommended,\n";
161-
if (this.answers.mdType === "gfm") {
162173

163-
// the default is commonmark
164-
exportContent += " {files: [\"**/*.md\"], language: \"markdown/gfm\"},\n";
174+
if (purpose === "syntax") {
175+
const config = this.answers.mdType === "commonmark" ? " {files: [\"**/*.md\"], language: \"markdown/commonmark\"},\n" : " {files: [\"**/*.md\"], language: \"markdown/gfm\"},\n";
176+
177+
exportContent += config;
178+
} else if (purpose === "problems") {
179+
exportContent += " ...markdown.configs.recommended,\n";
180+
181+
if (this.answers.mdType === "gfm") {
182+
183+
// the default is commonmark
184+
exportContent += " {files: [\"**/*.md\"], language: \"markdown/gfm\"},\n";
185+
}
165186
}
166187
}
167188

lib/questions.js

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,18 @@ export const langQuestions = [{
1515
{ message: "Markdown", name: "md" }
1616
],
1717
initial: 0
18+
}, {
19+
type: "select",
20+
name: "purpose",
21+
message: "How would you like to use ESLint?",
22+
initial: 1,
23+
choices: [
24+
{ message: "To check syntax only", name: "syntax" },
25+
{ message: "To check syntax and find problems", name: "problems" }
26+
]
1827
}];
1928

2029
export const jsQuestions = [
21-
{
22-
type: "select",
23-
name: "purpose",
24-
message: "How would you like to use ESLint?",
25-
initial: 1,
26-
choices: [
27-
{ message: "To check syntax only", name: "syntax" },
28-
{ message: "To check syntax and find problems", name: "problems" }
29-
]
30-
},
3130
{
3231
type: "select",
3332
name: "moduleType",
File renamed without changes.
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"configContent": "import json from "@eslint/json";
3+
4+
5+
/** @type {import('eslint').Linter.Config[]} */
6+
export default [
7+
{files: ["**/*.json"], language: "json/json"},
8+
];",
9+
"configFilename": "eslint.config.js",
10+
"devDependencies": [
11+
"eslint",
12+
"@eslint/json",
13+
],
14+
"installFlags": [
15+
"-D",
16+
],
17+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"configContent": "import json from "@eslint/json";
3+
4+
5+
/** @type {import('eslint').Linter.Config[]} */
6+
export default [
7+
{files: ["**/*.json5"], language: "json/json5"},
8+
];",
9+
"configFilename": "eslint.config.js",
10+
"devDependencies": [
11+
"eslint",
12+
"@eslint/json",
13+
],
14+
"installFlags": [
15+
"-D",
16+
],
17+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"configContent": "import json from "@eslint/json";
3+
4+
5+
/** @type {import('eslint').Linter.Config[]} */
6+
export default [
7+
{files: ["**/*.jsonc"], language: "json/jsonc"},
8+
];",
9+
"configFilename": "eslint.config.js",
10+
"devDependencies": [
11+
"eslint",
12+
"@eslint/json",
13+
],
14+
"installFlags": [
15+
"-D",
16+
],
17+
}
File renamed without changes.

0 commit comments

Comments
 (0)