Skip to content

Commit 77337f8

Browse files
committed
feat: support json/md
fixes #148
1 parent bbb24ef commit 77337f8

File tree

1 file changed

+28
-1
lines changed

1 file changed

+28
-1
lines changed

lib/config-generator.js

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,9 @@ export class ConfigGenerator {
8080
let importContent = "";
8181
let exportContent = "";
8282
let needCompatHelper = false;
83+
const languages = this.answers.languages;
8384

84-
if (this.answers.languages?.includes("javascript")) {
85+
if (languages?.includes("javascript")) {
8586
if (this.answers.moduleType === "commonjs" || this.answers.moduleType === "script") {
8687
exportContent += ` {files: ["**/*.js"], languageOptions: {sourceType: "${this.answers.moduleType}"}},\n`;
8788
}
@@ -138,6 +139,32 @@ export class ConfigGenerator {
138139
exportContent += " pluginReact.configs.flat.recommended,\n";
139140
}
140141
}
142+
143+
if (languages?.some(item => item.startsWith("json"))) {
144+
this.result.devDependencies.push("@eslint/json");
145+
importContent += "import json from \"@eslint/json\";\n";
146+
}
147+
if (languages?.includes("json")) {
148+
exportContent += " {files: [\"**/*.json\"], language: \"json/json\", ...json.configs.recommended},\n";
149+
}
150+
if (languages?.includes("jsonc")) {
151+
exportContent += " {files: [\"**/*.jsonc\"], language: \"json/jsonc\", ...json.configs.recommended},\n";
152+
}
153+
if (languages?.includes("json5")) {
154+
exportContent += " {files: [\"**/*.json5\"], language: \"json/json5\", ...json.configs.recommended},\n";
155+
}
156+
157+
if (languages?.includes("md")) {
158+
this.result.devDependencies.push("@eslint/markdown");
159+
importContent += "import markdown from \"@eslint/markdown\";\n";
160+
exportContent += " ...markdown.configs.recommended,\n";
161+
if (this.answers.mdType === "gfm") {
162+
163+
// the default is commonmark
164+
exportContent += " {files: [\"**/*.md\"], language: \"markdown/gfm\"},\n";
165+
}
166+
}
167+
141168
if (this.answers.config) {
142169
const config = this.answers.config;
143170

0 commit comments

Comments
 (0)