Skip to content

Commit

Permalink
feat: support json/md
Browse files Browse the repository at this point in the history
fixes #148
  • Loading branch information
aladdin-add committed Nov 4, 2024
1 parent bbb24ef commit 77337f8
Showing 1 changed file with 28 additions and 1 deletion.
29 changes: 28 additions & 1 deletion lib/config-generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,9 @@ export class ConfigGenerator {
let importContent = "";
let exportContent = "";
let needCompatHelper = false;
const languages = this.answers.languages;

if (this.answers.languages?.includes("javascript")) {
if (languages?.includes("javascript")) {
if (this.answers.moduleType === "commonjs" || this.answers.moduleType === "script") {
exportContent += ` {files: ["**/*.js"], languageOptions: {sourceType: "${this.answers.moduleType}"}},\n`;
}
Expand Down Expand Up @@ -138,6 +139,32 @@ export class ConfigGenerator {
exportContent += " pluginReact.configs.flat.recommended,\n";
}
}

if (languages?.some(item => item.startsWith("json"))) {
this.result.devDependencies.push("@eslint/json");
importContent += "import json from \"@eslint/json\";\n";
}
if (languages?.includes("json")) {
exportContent += " {files: [\"**/*.json\"], language: \"json/json\", ...json.configs.recommended},\n";
}
if (languages?.includes("jsonc")) {
exportContent += " {files: [\"**/*.jsonc\"], language: \"json/jsonc\", ...json.configs.recommended},\n";
}
if (languages?.includes("json5")) {
exportContent += " {files: [\"**/*.json5\"], language: \"json/json5\", ...json.configs.recommended},\n";
}

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

// the default is commonmark
exportContent += " {files: [\"**/*.md\"], language: \"markdown/gfm\"},\n";
}
}

if (this.answers.config) {
const config = this.answers.config;

Expand Down

0 comments on commit 77337f8

Please sign in to comment.