From ed9946da591dc91b4b8734d43c143bb797ce1e9f Mon Sep 17 00:00:00 2001 From: hyperz111 Date: Fri, 18 Jul 2025 17:35:31 +0700 Subject: [PATCH 1/9] fix: remove double blank lines when not use eslintrc style --- lib/config-generator.js | 2 +- tests/__snapshots__/cjs-configfile-js | 1 - tests/__snapshots__/cjs-configfile-ts | 1 - tests/__snapshots__/cjs-configfile-ts-jiti | 1 - tests/__snapshots__/config@eslint-config-standard-flat | 1 - tests/__snapshots__/config@eslint-config-standard-flat2 | 1 - tests/__snapshots__/config@eslint-config-xo | 1 - tests/__snapshots__/empty | 1 - tests/__snapshots__/esm-configfile-js | 1 - tests/__snapshots__/esm-configfile-ts | 1 - tests/__snapshots__/esm-configfile-ts-jiti | 1 - tests/__snapshots__/esm-css-problems | 1 - tests/__snapshots__/esm-css-syntax | 1 - tests/__snapshots__/esm-javascript-json-problems | 1 - tests/__snapshots__/esm-json-problems | 1 - tests/__snapshots__/esm-json-syntax | 1 - tests/__snapshots__/esm-json5-problems | 1 - tests/__snapshots__/esm-json5-syntax | 1 - tests/__snapshots__/esm-jsonc-problems | 1 - tests/__snapshots__/esm-jsonc-syntax | 1 - tests/__snapshots__/esm-markdown-commonmark-problems | 1 - tests/__snapshots__/esm-markdown-commonmark-syntax | 1 - tests/__snapshots__/esm-markdown-gfm-problems | 1 - tests/__snapshots__/esm-markdown-gfm-syntax | 1 - tests/__snapshots__/problems-commonjs-none-javascript | 1 - tests/__snapshots__/problems-commonjs-none-typescript | 1 - tests/__snapshots__/problems-commonjs-react-javascript | 1 - tests/__snapshots__/problems-commonjs-react-typescript | 1 - tests/__snapshots__/problems-commonjs-vue-javascript | 1 - tests/__snapshots__/problems-commonjs-vue-typescript | 1 - tests/__snapshots__/problems-esm-none-javascript | 1 - tests/__snapshots__/problems-esm-none-typescript | 1 - tests/__snapshots__/problems-esm-react-javascript | 1 - tests/__snapshots__/problems-esm-react-typescript | 1 - tests/__snapshots__/problems-esm-vue-javascript | 1 - tests/__snapshots__/problems-esm-vue-typescript | 1 - tests/__snapshots__/problems-script-none-javascript | 1 - tests/__snapshots__/problems-script-none-typescript | 1 - tests/__snapshots__/problems-script-react-javascript | 1 - tests/__snapshots__/problems-script-react-typescript | 1 - tests/__snapshots__/problems-script-vue-javascript | 1 - tests/__snapshots__/problems-script-vue-typescript | 1 - tests/__snapshots__/syntax-commonjs-none-javascript | 1 - tests/__snapshots__/syntax-commonjs-none-typescript | 1 - tests/__snapshots__/syntax-commonjs-react-javascript | 1 - tests/__snapshots__/syntax-commonjs-react-typescript | 1 - tests/__snapshots__/syntax-commonjs-vue-javascript | 1 - tests/__snapshots__/syntax-commonjs-vue-typescript | 1 - tests/__snapshots__/syntax-esm-none-javascript | 1 - tests/__snapshots__/syntax-esm-none-typescript | 1 - tests/__snapshots__/syntax-esm-react-javascript | 1 - tests/__snapshots__/syntax-esm-react-typescript | 1 - tests/__snapshots__/syntax-esm-vue-javascript | 1 - tests/__snapshots__/syntax-esm-vue-typescript | 1 - tests/__snapshots__/syntax-script-none-javascript | 1 - tests/__snapshots__/syntax-script-none-typescript | 1 - tests/__snapshots__/syntax-script-react-javascript | 1 - tests/__snapshots__/syntax-script-react-typescript | 1 - tests/__snapshots__/syntax-script-vue-javascript | 1 - tests/__snapshots__/syntax-script-vue-typescript | 1 - 60 files changed, 1 insertion(+), 60 deletions(-) diff --git a/lib/config-generator.js b/lib/config-generator.js index 6ce67a4d..a9c86ba5 100644 --- a/lib/config-generator.js +++ b/lib/config-generator.js @@ -343,7 +343,7 @@ export class ConfigGenerator { this.result.devDependencies.push("jiti"); } - this.result.configContent = `${importContent} + this.result.configContent = `${needCompatHelper ? importContent : importContent.slice(0, -1)} ${needCompatHelper ? helperContent : ""} export default defineConfig([\n${exportContent || " {}\n"}]);\n`; // defaults to `[{}]` to avoid empty config warning } diff --git a/tests/__snapshots__/cjs-configfile-js b/tests/__snapshots__/cjs-configfile-js index 962004f0..c0d61ff8 100644 --- a/tests/__snapshots__/cjs-configfile-js +++ b/tests/__snapshots__/cjs-configfile-js @@ -4,7 +4,6 @@ import globals from "globals"; import tseslint from "typescript-eslint"; import { defineConfig } from "eslint/config"; - export default defineConfig([ { files: ["**/*.{js,mjs,cjs,ts,mts,cts}"], plugins: { js }, extends: ["js/recommended"], languageOptions: { globals: globals.node } }, { files: ["**/*.js"], languageOptions: { sourceType: "commonjs" } }, diff --git a/tests/__snapshots__/cjs-configfile-ts b/tests/__snapshots__/cjs-configfile-ts index 7cb46b7f..5e8cd02f 100644 --- a/tests/__snapshots__/cjs-configfile-ts +++ b/tests/__snapshots__/cjs-configfile-ts @@ -4,7 +4,6 @@ import globals from "globals"; import tseslint from "typescript-eslint"; import { defineConfig } from "eslint/config"; - export default defineConfig([ { files: ["**/*.{js,mjs,cjs,ts,mts,cts}"], plugins: { js }, extends: ["js/recommended"], languageOptions: { globals: globals.node } }, { files: ["**/*.js"], languageOptions: { sourceType: "commonjs" } }, diff --git a/tests/__snapshots__/cjs-configfile-ts-jiti b/tests/__snapshots__/cjs-configfile-ts-jiti index d4a800f3..9bf7f0ce 100644 --- a/tests/__snapshots__/cjs-configfile-ts-jiti +++ b/tests/__snapshots__/cjs-configfile-ts-jiti @@ -4,7 +4,6 @@ import globals from "globals"; import tseslint from "typescript-eslint"; import { defineConfig } from "eslint/config"; - export default defineConfig([ { files: ["**/*.{js,mjs,cjs,ts,mts,cts}"], plugins: { js }, extends: ["js/recommended"], languageOptions: { globals: globals.node } }, { files: ["**/*.js"], languageOptions: { sourceType: "commonjs" } }, diff --git a/tests/__snapshots__/config@eslint-config-standard-flat b/tests/__snapshots__/config@eslint-config-standard-flat index d56d9305..c728c9cd 100644 --- a/tests/__snapshots__/config@eslint-config-standard-flat +++ b/tests/__snapshots__/config@eslint-config-standard-flat @@ -2,7 +2,6 @@ "configContent": "import config from "eslint-config-standard"; import { defineConfig } from "@eslint/config-helpers"; - export default defineConfig([ config, ]); diff --git a/tests/__snapshots__/config@eslint-config-standard-flat2 b/tests/__snapshots__/config@eslint-config-standard-flat2 index d56d9305..c728c9cd 100644 --- a/tests/__snapshots__/config@eslint-config-standard-flat2 +++ b/tests/__snapshots__/config@eslint-config-standard-flat2 @@ -2,7 +2,6 @@ "configContent": "import config from "eslint-config-standard"; import { defineConfig } from "@eslint/config-helpers"; - export default defineConfig([ config, ]); diff --git a/tests/__snapshots__/config@eslint-config-xo b/tests/__snapshots__/config@eslint-config-xo index 6d174613..056c9c3f 100644 --- a/tests/__snapshots__/config@eslint-config-xo +++ b/tests/__snapshots__/config@eslint-config-xo @@ -2,7 +2,6 @@ "configContent": "import config from "eslint-config-xo"; import { defineConfig } from "eslint/config"; - export default defineConfig([ config, ]); diff --git a/tests/__snapshots__/empty b/tests/__snapshots__/empty index ec245a24..a6e1e7f6 100644 --- a/tests/__snapshots__/empty +++ b/tests/__snapshots__/empty @@ -1,7 +1,6 @@ { "configContent": "import { defineConfig } from "eslint/config"; - export default defineConfig([ {} ]); diff --git a/tests/__snapshots__/esm-configfile-js b/tests/__snapshots__/esm-configfile-js index 4e3dda6a..a504e660 100644 --- a/tests/__snapshots__/esm-configfile-js +++ b/tests/__snapshots__/esm-configfile-js @@ -4,7 +4,6 @@ import globals from "globals"; import tseslint from "typescript-eslint"; import { defineConfig } from "eslint/config"; - export default defineConfig([ { files: ["**/*.{js,mjs,cjs,ts,mts,cts}"], plugins: { js }, extends: ["js/recommended"], languageOptions: { globals: globals.node } }, tseslint.configs.recommended, diff --git a/tests/__snapshots__/esm-configfile-ts b/tests/__snapshots__/esm-configfile-ts index c03a049d..d0ad7e83 100644 --- a/tests/__snapshots__/esm-configfile-ts +++ b/tests/__snapshots__/esm-configfile-ts @@ -4,7 +4,6 @@ import globals from "globals"; import tseslint from "typescript-eslint"; import { defineConfig } from "eslint/config"; - export default defineConfig([ { files: ["**/*.{js,mjs,cjs,ts,mts,cts}"], plugins: { js }, extends: ["js/recommended"], languageOptions: { globals: globals.node } }, tseslint.configs.recommended, diff --git a/tests/__snapshots__/esm-configfile-ts-jiti b/tests/__snapshots__/esm-configfile-ts-jiti index 68d793d5..666107ba 100644 --- a/tests/__snapshots__/esm-configfile-ts-jiti +++ b/tests/__snapshots__/esm-configfile-ts-jiti @@ -4,7 +4,6 @@ import globals from "globals"; import tseslint from "typescript-eslint"; import { defineConfig } from "eslint/config"; - export default defineConfig([ { files: ["**/*.{js,mjs,cjs,ts,mts,cts}"], plugins: { js }, extends: ["js/recommended"], languageOptions: { globals: globals.node } }, tseslint.configs.recommended, diff --git a/tests/__snapshots__/esm-css-problems b/tests/__snapshots__/esm-css-problems index f0a27fe1..1a658b3e 100644 --- a/tests/__snapshots__/esm-css-problems +++ b/tests/__snapshots__/esm-css-problems @@ -2,7 +2,6 @@ "configContent": "import css from "@eslint/css"; import { defineConfig } from "eslint/config"; - export default defineConfig([ { ignores: ["**/*.js", "**/*.cjs", "**/*.mjs"] }, { files: ["**/*.css"], plugins: { css }, language: "css/css", extends: ["css/recommended"] }, diff --git a/tests/__snapshots__/esm-css-syntax b/tests/__snapshots__/esm-css-syntax index c69760d0..66f070a4 100644 --- a/tests/__snapshots__/esm-css-syntax +++ b/tests/__snapshots__/esm-css-syntax @@ -2,7 +2,6 @@ "configContent": "import css from "@eslint/css"; import { defineConfig } from "eslint/config"; - export default defineConfig([ { ignores: ["**/*.js", "**/*.cjs", "**/*.mjs"] }, { files: ["**/*.css"], plugins: { css }, language: "css/css" }, diff --git a/tests/__snapshots__/esm-javascript-json-problems b/tests/__snapshots__/esm-javascript-json-problems index 6691dae2..da7a36b4 100644 --- a/tests/__snapshots__/esm-javascript-json-problems +++ b/tests/__snapshots__/esm-javascript-json-problems @@ -4,7 +4,6 @@ import globals from "globals"; import json from "@eslint/json"; import { defineConfig } from "eslint/config"; - export default defineConfig([ { files: ["**/*.{js,mjs,cjs}"], plugins: { js }, extends: ["js/recommended"], languageOptions: { globals: globals.node } }, { files: ["**/*.json"], plugins: { json }, language: "json/json", extends: ["json/recommended"] }, diff --git a/tests/__snapshots__/esm-json-problems b/tests/__snapshots__/esm-json-problems index bb154fb3..f769a23d 100644 --- a/tests/__snapshots__/esm-json-problems +++ b/tests/__snapshots__/esm-json-problems @@ -2,7 +2,6 @@ "configContent": "import json from "@eslint/json"; import { defineConfig } from "eslint/config"; - export default defineConfig([ { ignores: ["**/*.js", "**/*.cjs", "**/*.mjs"] }, { files: ["**/*.json"], plugins: { json }, language: "json/json", extends: ["json/recommended"] }, diff --git a/tests/__snapshots__/esm-json-syntax b/tests/__snapshots__/esm-json-syntax index bd94f20f..f03393f7 100644 --- a/tests/__snapshots__/esm-json-syntax +++ b/tests/__snapshots__/esm-json-syntax @@ -2,7 +2,6 @@ "configContent": "import json from "@eslint/json"; import { defineConfig } from "eslint/config"; - export default defineConfig([ { ignores: ["**/*.js", "**/*.cjs", "**/*.mjs"] }, { files: ["**/*.json"], plugins: { json }, language: "json/json" }, diff --git a/tests/__snapshots__/esm-json5-problems b/tests/__snapshots__/esm-json5-problems index 6755ce48..453f7fdf 100644 --- a/tests/__snapshots__/esm-json5-problems +++ b/tests/__snapshots__/esm-json5-problems @@ -2,7 +2,6 @@ "configContent": "import json from "@eslint/json"; import { defineConfig } from "eslint/config"; - export default defineConfig([ { ignores: ["**/*.js", "**/*.cjs", "**/*.mjs"] }, { files: ["**/*.json5"], plugins: { json }, language: "json/json5", extends: ["json/recommended"] }, diff --git a/tests/__snapshots__/esm-json5-syntax b/tests/__snapshots__/esm-json5-syntax index 59a7c2b9..c46ff5c3 100644 --- a/tests/__snapshots__/esm-json5-syntax +++ b/tests/__snapshots__/esm-json5-syntax @@ -2,7 +2,6 @@ "configContent": "import json from "@eslint/json"; import { defineConfig } from "eslint/config"; - export default defineConfig([ { ignores: ["**/*.js", "**/*.cjs", "**/*.mjs"] }, { files: ["**/*.json5"], plugins: { json }, language: "json/json5" }, diff --git a/tests/__snapshots__/esm-jsonc-problems b/tests/__snapshots__/esm-jsonc-problems index 3a47d768..e46942d4 100644 --- a/tests/__snapshots__/esm-jsonc-problems +++ b/tests/__snapshots__/esm-jsonc-problems @@ -2,7 +2,6 @@ "configContent": "import json from "@eslint/json"; import { defineConfig } from "eslint/config"; - export default defineConfig([ { ignores: ["**/*.js", "**/*.cjs", "**/*.mjs"] }, { files: ["**/*.jsonc"], plugins: { json }, language: "json/jsonc", extends: ["json/recommended"] }, diff --git a/tests/__snapshots__/esm-jsonc-syntax b/tests/__snapshots__/esm-jsonc-syntax index abfbf410..dd93ae62 100644 --- a/tests/__snapshots__/esm-jsonc-syntax +++ b/tests/__snapshots__/esm-jsonc-syntax @@ -2,7 +2,6 @@ "configContent": "import json from "@eslint/json"; import { defineConfig } from "eslint/config"; - export default defineConfig([ { ignores: ["**/*.js", "**/*.cjs", "**/*.mjs"] }, { files: ["**/*.jsonc"], plugins: { json }, language: "json/jsonc" }, diff --git a/tests/__snapshots__/esm-markdown-commonmark-problems b/tests/__snapshots__/esm-markdown-commonmark-problems index 74e7aec5..e28e76c0 100644 --- a/tests/__snapshots__/esm-markdown-commonmark-problems +++ b/tests/__snapshots__/esm-markdown-commonmark-problems @@ -2,7 +2,6 @@ "configContent": "import markdown from "@eslint/markdown"; import { defineConfig } from "eslint/config"; - export default defineConfig([ { ignores: ["**/*.js", "**/*.cjs", "**/*.mjs"] }, { files: ["**/*.md"], plugins: { markdown }, language: "markdown/commonmark", extends: ["markdown/recommended"] }, diff --git a/tests/__snapshots__/esm-markdown-commonmark-syntax b/tests/__snapshots__/esm-markdown-commonmark-syntax index 54545b40..09b39785 100644 --- a/tests/__snapshots__/esm-markdown-commonmark-syntax +++ b/tests/__snapshots__/esm-markdown-commonmark-syntax @@ -2,7 +2,6 @@ "configContent": "import markdown from "@eslint/markdown"; import { defineConfig } from "eslint/config"; - export default defineConfig([ { ignores: ["**/*.js", "**/*.cjs", "**/*.mjs"] }, { files: ["**/*.md"], plugins: { markdown }, language: "markdown/commonmark" }, diff --git a/tests/__snapshots__/esm-markdown-gfm-problems b/tests/__snapshots__/esm-markdown-gfm-problems index 859b8473..5f97d97c 100644 --- a/tests/__snapshots__/esm-markdown-gfm-problems +++ b/tests/__snapshots__/esm-markdown-gfm-problems @@ -2,7 +2,6 @@ "configContent": "import markdown from "@eslint/markdown"; import { defineConfig } from "eslint/config"; - export default defineConfig([ { ignores: ["**/*.js", "**/*.cjs", "**/*.mjs"] }, { files: ["**/*.md"], plugins: { markdown }, language: "markdown/gfm", extends: ["markdown/recommended"] }, diff --git a/tests/__snapshots__/esm-markdown-gfm-syntax b/tests/__snapshots__/esm-markdown-gfm-syntax index 9d3e01c9..5723b9dc 100644 --- a/tests/__snapshots__/esm-markdown-gfm-syntax +++ b/tests/__snapshots__/esm-markdown-gfm-syntax @@ -2,7 +2,6 @@ "configContent": "import markdown from "@eslint/markdown"; import { defineConfig } from "eslint/config"; - export default defineConfig([ { ignores: ["**/*.js", "**/*.cjs", "**/*.mjs"] }, { files: ["**/*.md"], plugins: { markdown }, language: "markdown/gfm" }, diff --git a/tests/__snapshots__/problems-commonjs-none-javascript b/tests/__snapshots__/problems-commonjs-none-javascript index c3b2fe01..5660b0a1 100644 --- a/tests/__snapshots__/problems-commonjs-none-javascript +++ b/tests/__snapshots__/problems-commonjs-none-javascript @@ -3,7 +3,6 @@ import globals from "globals"; import { defineConfig } from "eslint/config"; - export default defineConfig([ { files: ["**/*.{js,mjs,cjs}"], plugins: { js }, extends: ["js/recommended"], languageOptions: { globals: {...globals.browser, ...globals.node} } }, { files: ["**/*.js"], languageOptions: { sourceType: "commonjs" } }, diff --git a/tests/__snapshots__/problems-commonjs-none-typescript b/tests/__snapshots__/problems-commonjs-none-typescript index c15f9dbb..43ead2df 100644 --- a/tests/__snapshots__/problems-commonjs-none-typescript +++ b/tests/__snapshots__/problems-commonjs-none-typescript @@ -4,7 +4,6 @@ import globals from "globals"; import tseslint from "typescript-eslint"; import { defineConfig } from "eslint/config"; - export default defineConfig([ { files: ["**/*.{js,mjs,cjs,ts,mts,cts}"], plugins: { js }, extends: ["js/recommended"], languageOptions: { globals: {...globals.browser, ...globals.node} } }, { files: ["**/*.js"], languageOptions: { sourceType: "commonjs" } }, diff --git a/tests/__snapshots__/problems-commonjs-react-javascript b/tests/__snapshots__/problems-commonjs-react-javascript index 4b3f3a30..23c1f496 100644 --- a/tests/__snapshots__/problems-commonjs-react-javascript +++ b/tests/__snapshots__/problems-commonjs-react-javascript @@ -4,7 +4,6 @@ import globals from "globals"; import pluginReact from "eslint-plugin-react"; import { defineConfig } from "eslint/config"; - export default defineConfig([ { files: ["**/*.{js,mjs,cjs,jsx}"], plugins: { js }, extends: ["js/recommended"], languageOptions: { globals: {...globals.browser, ...globals.node} } }, { files: ["**/*.js"], languageOptions: { sourceType: "commonjs" } }, diff --git a/tests/__snapshots__/problems-commonjs-react-typescript b/tests/__snapshots__/problems-commonjs-react-typescript index 0784cdec..2fe997c1 100644 --- a/tests/__snapshots__/problems-commonjs-react-typescript +++ b/tests/__snapshots__/problems-commonjs-react-typescript @@ -5,7 +5,6 @@ import tseslint from "typescript-eslint"; import pluginReact from "eslint-plugin-react"; import { defineConfig } from "eslint/config"; - export default defineConfig([ { files: ["**/*.{js,mjs,cjs,ts,mts,cts,jsx,tsx}"], plugins: { js }, extends: ["js/recommended"], languageOptions: { globals: {...globals.browser, ...globals.node} } }, { files: ["**/*.js"], languageOptions: { sourceType: "commonjs" } }, diff --git a/tests/__snapshots__/problems-commonjs-vue-javascript b/tests/__snapshots__/problems-commonjs-vue-javascript index 7a246a38..390f3e8b 100644 --- a/tests/__snapshots__/problems-commonjs-vue-javascript +++ b/tests/__snapshots__/problems-commonjs-vue-javascript @@ -4,7 +4,6 @@ import globals from "globals"; import pluginVue from "eslint-plugin-vue"; import { defineConfig } from "eslint/config"; - export default defineConfig([ { files: ["**/*.{js,mjs,cjs,vue}"], plugins: { js }, extends: ["js/recommended"], languageOptions: { globals: {...globals.browser, ...globals.node} } }, { files: ["**/*.js"], languageOptions: { sourceType: "commonjs" } }, diff --git a/tests/__snapshots__/problems-commonjs-vue-typescript b/tests/__snapshots__/problems-commonjs-vue-typescript index 20168676..d67de869 100644 --- a/tests/__snapshots__/problems-commonjs-vue-typescript +++ b/tests/__snapshots__/problems-commonjs-vue-typescript @@ -5,7 +5,6 @@ import tseslint from "typescript-eslint"; import pluginVue from "eslint-plugin-vue"; import { defineConfig } from "eslint/config"; - export default defineConfig([ { files: ["**/*.{js,mjs,cjs,ts,mts,cts,vue}"], plugins: { js }, extends: ["js/recommended"], languageOptions: { globals: {...globals.browser, ...globals.node} } }, { files: ["**/*.js"], languageOptions: { sourceType: "commonjs" } }, diff --git a/tests/__snapshots__/problems-esm-none-javascript b/tests/__snapshots__/problems-esm-none-javascript index 7bd6cec0..08de2787 100644 --- a/tests/__snapshots__/problems-esm-none-javascript +++ b/tests/__snapshots__/problems-esm-none-javascript @@ -3,7 +3,6 @@ import globals from "globals"; import { defineConfig } from "eslint/config"; - export default defineConfig([ { files: ["**/*.{js,mjs,cjs}"], plugins: { js }, extends: ["js/recommended"], languageOptions: { globals: {...globals.browser, ...globals.node} } }, ]); diff --git a/tests/__snapshots__/problems-esm-none-typescript b/tests/__snapshots__/problems-esm-none-typescript index 3600e89a..4006a15d 100644 --- a/tests/__snapshots__/problems-esm-none-typescript +++ b/tests/__snapshots__/problems-esm-none-typescript @@ -4,7 +4,6 @@ import globals from "globals"; import tseslint from "typescript-eslint"; import { defineConfig } from "eslint/config"; - export default defineConfig([ { files: ["**/*.{js,mjs,cjs,ts,mts,cts}"], plugins: { js }, extends: ["js/recommended"], languageOptions: { globals: {...globals.browser, ...globals.node} } }, tseslint.configs.recommended, diff --git a/tests/__snapshots__/problems-esm-react-javascript b/tests/__snapshots__/problems-esm-react-javascript index 1b9b6f9c..23dc6b8c 100644 --- a/tests/__snapshots__/problems-esm-react-javascript +++ b/tests/__snapshots__/problems-esm-react-javascript @@ -4,7 +4,6 @@ import globals from "globals"; import pluginReact from "eslint-plugin-react"; import { defineConfig } from "eslint/config"; - export default defineConfig([ { files: ["**/*.{js,mjs,cjs,jsx}"], plugins: { js }, extends: ["js/recommended"], languageOptions: { globals: {...globals.browser, ...globals.node} } }, pluginReact.configs.flat.recommended, diff --git a/tests/__snapshots__/problems-esm-react-typescript b/tests/__snapshots__/problems-esm-react-typescript index 27dca16f..0d1c32cc 100644 --- a/tests/__snapshots__/problems-esm-react-typescript +++ b/tests/__snapshots__/problems-esm-react-typescript @@ -5,7 +5,6 @@ import tseslint from "typescript-eslint"; import pluginReact from "eslint-plugin-react"; import { defineConfig } from "eslint/config"; - export default defineConfig([ { files: ["**/*.{js,mjs,cjs,ts,mts,cts,jsx,tsx}"], plugins: { js }, extends: ["js/recommended"], languageOptions: { globals: {...globals.browser, ...globals.node} } }, tseslint.configs.recommended, diff --git a/tests/__snapshots__/problems-esm-vue-javascript b/tests/__snapshots__/problems-esm-vue-javascript index e92b1237..2f05bb54 100644 --- a/tests/__snapshots__/problems-esm-vue-javascript +++ b/tests/__snapshots__/problems-esm-vue-javascript @@ -4,7 +4,6 @@ import globals from "globals"; import pluginVue from "eslint-plugin-vue"; import { defineConfig } from "eslint/config"; - export default defineConfig([ { files: ["**/*.{js,mjs,cjs,vue}"], plugins: { js }, extends: ["js/recommended"], languageOptions: { globals: {...globals.browser, ...globals.node} } }, pluginVue.configs["flat/essential"], diff --git a/tests/__snapshots__/problems-esm-vue-typescript b/tests/__snapshots__/problems-esm-vue-typescript index c3d45eb8..cc092273 100644 --- a/tests/__snapshots__/problems-esm-vue-typescript +++ b/tests/__snapshots__/problems-esm-vue-typescript @@ -5,7 +5,6 @@ import tseslint from "typescript-eslint"; import pluginVue from "eslint-plugin-vue"; import { defineConfig } from "eslint/config"; - export default defineConfig([ { files: ["**/*.{js,mjs,cjs,ts,mts,cts,vue}"], plugins: { js }, extends: ["js/recommended"], languageOptions: { globals: {...globals.browser, ...globals.node} } }, tseslint.configs.recommended, diff --git a/tests/__snapshots__/problems-script-none-javascript b/tests/__snapshots__/problems-script-none-javascript index 12801c65..dab54471 100644 --- a/tests/__snapshots__/problems-script-none-javascript +++ b/tests/__snapshots__/problems-script-none-javascript @@ -3,7 +3,6 @@ import globals from "globals"; import { defineConfig } from "eslint/config"; - export default defineConfig([ { files: ["**/*.{js,mjs,cjs}"], plugins: { js }, extends: ["js/recommended"], languageOptions: { globals: {...globals.browser, ...globals.node} } }, { files: ["**/*.js"], languageOptions: { sourceType: "script" } }, diff --git a/tests/__snapshots__/problems-script-none-typescript b/tests/__snapshots__/problems-script-none-typescript index 0b15107c..3f1c93d1 100644 --- a/tests/__snapshots__/problems-script-none-typescript +++ b/tests/__snapshots__/problems-script-none-typescript @@ -4,7 +4,6 @@ import globals from "globals"; import tseslint from "typescript-eslint"; import { defineConfig } from "eslint/config"; - export default defineConfig([ { files: ["**/*.{js,mjs,cjs,ts,mts,cts}"], plugins: { js }, extends: ["js/recommended"], languageOptions: { globals: {...globals.browser, ...globals.node} } }, { files: ["**/*.js"], languageOptions: { sourceType: "script" } }, diff --git a/tests/__snapshots__/problems-script-react-javascript b/tests/__snapshots__/problems-script-react-javascript index d15df70b..27b319d4 100644 --- a/tests/__snapshots__/problems-script-react-javascript +++ b/tests/__snapshots__/problems-script-react-javascript @@ -4,7 +4,6 @@ import globals from "globals"; import pluginReact from "eslint-plugin-react"; import { defineConfig } from "eslint/config"; - export default defineConfig([ { files: ["**/*.{js,mjs,cjs,jsx}"], plugins: { js }, extends: ["js/recommended"], languageOptions: { globals: {...globals.browser, ...globals.node} } }, { files: ["**/*.js"], languageOptions: { sourceType: "script" } }, diff --git a/tests/__snapshots__/problems-script-react-typescript b/tests/__snapshots__/problems-script-react-typescript index f65090f1..80a34dcf 100644 --- a/tests/__snapshots__/problems-script-react-typescript +++ b/tests/__snapshots__/problems-script-react-typescript @@ -5,7 +5,6 @@ import tseslint from "typescript-eslint"; import pluginReact from "eslint-plugin-react"; import { defineConfig } from "eslint/config"; - export default defineConfig([ { files: ["**/*.{js,mjs,cjs,ts,mts,cts,jsx,tsx}"], plugins: { js }, extends: ["js/recommended"], languageOptions: { globals: {...globals.browser, ...globals.node} } }, { files: ["**/*.js"], languageOptions: { sourceType: "script" } }, diff --git a/tests/__snapshots__/problems-script-vue-javascript b/tests/__snapshots__/problems-script-vue-javascript index c971fc95..183f39df 100644 --- a/tests/__snapshots__/problems-script-vue-javascript +++ b/tests/__snapshots__/problems-script-vue-javascript @@ -4,7 +4,6 @@ import globals from "globals"; import pluginVue from "eslint-plugin-vue"; import { defineConfig } from "eslint/config"; - export default defineConfig([ { files: ["**/*.{js,mjs,cjs,vue}"], plugins: { js }, extends: ["js/recommended"], languageOptions: { globals: {...globals.browser, ...globals.node} } }, { files: ["**/*.js"], languageOptions: { sourceType: "script" } }, diff --git a/tests/__snapshots__/problems-script-vue-typescript b/tests/__snapshots__/problems-script-vue-typescript index 7e72d431..4ca1cb3e 100644 --- a/tests/__snapshots__/problems-script-vue-typescript +++ b/tests/__snapshots__/problems-script-vue-typescript @@ -5,7 +5,6 @@ import tseslint from "typescript-eslint"; import pluginVue from "eslint-plugin-vue"; import { defineConfig } from "eslint/config"; - export default defineConfig([ { files: ["**/*.{js,mjs,cjs,ts,mts,cts,vue}"], plugins: { js }, extends: ["js/recommended"], languageOptions: { globals: {...globals.browser, ...globals.node} } }, { files: ["**/*.js"], languageOptions: { sourceType: "script" } }, diff --git a/tests/__snapshots__/syntax-commonjs-none-javascript b/tests/__snapshots__/syntax-commonjs-none-javascript index 26b26dac..f74bf514 100644 --- a/tests/__snapshots__/syntax-commonjs-none-javascript +++ b/tests/__snapshots__/syntax-commonjs-none-javascript @@ -2,7 +2,6 @@ "configContent": "import globals from "globals"; import { defineConfig } from "eslint/config"; - export default defineConfig([ { files: ["**/*.js"], languageOptions: { sourceType: "commonjs" } }, { files: ["**/*.{js,mjs,cjs}"], languageOptions: { globals: {...globals.browser, ...globals.node} } }, diff --git a/tests/__snapshots__/syntax-commonjs-none-typescript b/tests/__snapshots__/syntax-commonjs-none-typescript index 094b2764..948d0dc9 100644 --- a/tests/__snapshots__/syntax-commonjs-none-typescript +++ b/tests/__snapshots__/syntax-commonjs-none-typescript @@ -3,7 +3,6 @@ import tseslint from "typescript-eslint"; import { defineConfig } from "eslint/config"; - export default defineConfig([ { files: ["**/*.js"], languageOptions: { sourceType: "commonjs" } }, { files: ["**/*.{js,mjs,cjs,ts,mts,cts}"], languageOptions: { globals: {...globals.browser, ...globals.node} } }, diff --git a/tests/__snapshots__/syntax-commonjs-react-javascript b/tests/__snapshots__/syntax-commonjs-react-javascript index f08781a9..7b0984fa 100644 --- a/tests/__snapshots__/syntax-commonjs-react-javascript +++ b/tests/__snapshots__/syntax-commonjs-react-javascript @@ -3,7 +3,6 @@ import pluginReact from "eslint-plugin-react"; import { defineConfig } from "eslint/config"; - export default defineConfig([ { files: ["**/*.js"], languageOptions: { sourceType: "commonjs" } }, { files: ["**/*.{js,mjs,cjs,jsx}"], languageOptions: { globals: {...globals.browser, ...globals.node} } }, diff --git a/tests/__snapshots__/syntax-commonjs-react-typescript b/tests/__snapshots__/syntax-commonjs-react-typescript index 6ef776ca..0d4f0f2f 100644 --- a/tests/__snapshots__/syntax-commonjs-react-typescript +++ b/tests/__snapshots__/syntax-commonjs-react-typescript @@ -4,7 +4,6 @@ import tseslint from "typescript-eslint"; import pluginReact from "eslint-plugin-react"; import { defineConfig } from "eslint/config"; - export default defineConfig([ { files: ["**/*.js"], languageOptions: { sourceType: "commonjs" } }, { files: ["**/*.{js,mjs,cjs,ts,mts,cts,jsx,tsx}"], languageOptions: { globals: {...globals.browser, ...globals.node} } }, diff --git a/tests/__snapshots__/syntax-commonjs-vue-javascript b/tests/__snapshots__/syntax-commonjs-vue-javascript index e88a6a50..069f4d8d 100644 --- a/tests/__snapshots__/syntax-commonjs-vue-javascript +++ b/tests/__snapshots__/syntax-commonjs-vue-javascript @@ -3,7 +3,6 @@ import pluginVue from "eslint-plugin-vue"; import { defineConfig } from "eslint/config"; - export default defineConfig([ { files: ["**/*.js"], languageOptions: { sourceType: "commonjs" } }, { files: ["**/*.{js,mjs,cjs,vue}"], languageOptions: { globals: {...globals.browser, ...globals.node} } }, diff --git a/tests/__snapshots__/syntax-commonjs-vue-typescript b/tests/__snapshots__/syntax-commonjs-vue-typescript index a07a86ee..5d63baa5 100644 --- a/tests/__snapshots__/syntax-commonjs-vue-typescript +++ b/tests/__snapshots__/syntax-commonjs-vue-typescript @@ -4,7 +4,6 @@ import tseslint from "typescript-eslint"; import pluginVue from "eslint-plugin-vue"; import { defineConfig } from "eslint/config"; - export default defineConfig([ { files: ["**/*.js"], languageOptions: { sourceType: "commonjs" } }, { files: ["**/*.{js,mjs,cjs,ts,mts,cts,vue}"], languageOptions: { globals: {...globals.browser, ...globals.node} } }, diff --git a/tests/__snapshots__/syntax-esm-none-javascript b/tests/__snapshots__/syntax-esm-none-javascript index d4a59f76..943558d3 100644 --- a/tests/__snapshots__/syntax-esm-none-javascript +++ b/tests/__snapshots__/syntax-esm-none-javascript @@ -2,7 +2,6 @@ "configContent": "import globals from "globals"; import { defineConfig } from "eslint/config"; - export default defineConfig([ { files: ["**/*.{js,mjs,cjs}"], languageOptions: { globals: {...globals.browser, ...globals.node} } }, ]); diff --git a/tests/__snapshots__/syntax-esm-none-typescript b/tests/__snapshots__/syntax-esm-none-typescript index 343335ab..f69113ea 100644 --- a/tests/__snapshots__/syntax-esm-none-typescript +++ b/tests/__snapshots__/syntax-esm-none-typescript @@ -3,7 +3,6 @@ import tseslint from "typescript-eslint"; import { defineConfig } from "eslint/config"; - export default defineConfig([ { files: ["**/*.{js,mjs,cjs,ts,mts,cts}"], languageOptions: { globals: {...globals.browser, ...globals.node} } }, tseslint.configs.recommended, diff --git a/tests/__snapshots__/syntax-esm-react-javascript b/tests/__snapshots__/syntax-esm-react-javascript index 6275ec53..85e33b83 100644 --- a/tests/__snapshots__/syntax-esm-react-javascript +++ b/tests/__snapshots__/syntax-esm-react-javascript @@ -3,7 +3,6 @@ import pluginReact from "eslint-plugin-react"; import { defineConfig } from "eslint/config"; - export default defineConfig([ { files: ["**/*.{js,mjs,cjs,jsx}"], languageOptions: { globals: {...globals.browser, ...globals.node} } }, pluginReact.configs.flat.recommended, diff --git a/tests/__snapshots__/syntax-esm-react-typescript b/tests/__snapshots__/syntax-esm-react-typescript index 0fe80163..64dc51c6 100644 --- a/tests/__snapshots__/syntax-esm-react-typescript +++ b/tests/__snapshots__/syntax-esm-react-typescript @@ -4,7 +4,6 @@ import tseslint from "typescript-eslint"; import pluginReact from "eslint-plugin-react"; import { defineConfig } from "eslint/config"; - export default defineConfig([ { files: ["**/*.{js,mjs,cjs,ts,mts,cts,jsx,tsx}"], languageOptions: { globals: {...globals.browser, ...globals.node} } }, tseslint.configs.recommended, diff --git a/tests/__snapshots__/syntax-esm-vue-javascript b/tests/__snapshots__/syntax-esm-vue-javascript index 649043a3..f9c4a2c3 100644 --- a/tests/__snapshots__/syntax-esm-vue-javascript +++ b/tests/__snapshots__/syntax-esm-vue-javascript @@ -3,7 +3,6 @@ import pluginVue from "eslint-plugin-vue"; import { defineConfig } from "eslint/config"; - export default defineConfig([ { files: ["**/*.{js,mjs,cjs,vue}"], languageOptions: { globals: {...globals.browser, ...globals.node} } }, pluginVue.configs["flat/essential"], diff --git a/tests/__snapshots__/syntax-esm-vue-typescript b/tests/__snapshots__/syntax-esm-vue-typescript index d904f8db..5b073380 100644 --- a/tests/__snapshots__/syntax-esm-vue-typescript +++ b/tests/__snapshots__/syntax-esm-vue-typescript @@ -4,7 +4,6 @@ import tseslint from "typescript-eslint"; import pluginVue from "eslint-plugin-vue"; import { defineConfig } from "eslint/config"; - export default defineConfig([ { files: ["**/*.{js,mjs,cjs,ts,mts,cts,vue}"], languageOptions: { globals: {...globals.browser, ...globals.node} } }, tseslint.configs.recommended, diff --git a/tests/__snapshots__/syntax-script-none-javascript b/tests/__snapshots__/syntax-script-none-javascript index b4f3ec18..7e118f97 100644 --- a/tests/__snapshots__/syntax-script-none-javascript +++ b/tests/__snapshots__/syntax-script-none-javascript @@ -2,7 +2,6 @@ "configContent": "import globals from "globals"; import { defineConfig } from "eslint/config"; - export default defineConfig([ { files: ["**/*.js"], languageOptions: { sourceType: "script" } }, { files: ["**/*.{js,mjs,cjs}"], languageOptions: { globals: {...globals.browser, ...globals.node} } }, diff --git a/tests/__snapshots__/syntax-script-none-typescript b/tests/__snapshots__/syntax-script-none-typescript index c3447020..2dea5f97 100644 --- a/tests/__snapshots__/syntax-script-none-typescript +++ b/tests/__snapshots__/syntax-script-none-typescript @@ -3,7 +3,6 @@ import tseslint from "typescript-eslint"; import { defineConfig } from "eslint/config"; - export default defineConfig([ { files: ["**/*.js"], languageOptions: { sourceType: "script" } }, { files: ["**/*.{js,mjs,cjs,ts,mts,cts}"], languageOptions: { globals: {...globals.browser, ...globals.node} } }, diff --git a/tests/__snapshots__/syntax-script-react-javascript b/tests/__snapshots__/syntax-script-react-javascript index 0317395b..9170867d 100644 --- a/tests/__snapshots__/syntax-script-react-javascript +++ b/tests/__snapshots__/syntax-script-react-javascript @@ -3,7 +3,6 @@ import pluginReact from "eslint-plugin-react"; import { defineConfig } from "eslint/config"; - export default defineConfig([ { files: ["**/*.js"], languageOptions: { sourceType: "script" } }, { files: ["**/*.{js,mjs,cjs,jsx}"], languageOptions: { globals: {...globals.browser, ...globals.node} } }, diff --git a/tests/__snapshots__/syntax-script-react-typescript b/tests/__snapshots__/syntax-script-react-typescript index 810481f1..7f841dda 100644 --- a/tests/__snapshots__/syntax-script-react-typescript +++ b/tests/__snapshots__/syntax-script-react-typescript @@ -4,7 +4,6 @@ import tseslint from "typescript-eslint"; import pluginReact from "eslint-plugin-react"; import { defineConfig } from "eslint/config"; - export default defineConfig([ { files: ["**/*.js"], languageOptions: { sourceType: "script" } }, { files: ["**/*.{js,mjs,cjs,ts,mts,cts,jsx,tsx}"], languageOptions: { globals: {...globals.browser, ...globals.node} } }, diff --git a/tests/__snapshots__/syntax-script-vue-javascript b/tests/__snapshots__/syntax-script-vue-javascript index c415abe6..d8027496 100644 --- a/tests/__snapshots__/syntax-script-vue-javascript +++ b/tests/__snapshots__/syntax-script-vue-javascript @@ -3,7 +3,6 @@ import pluginVue from "eslint-plugin-vue"; import { defineConfig } from "eslint/config"; - export default defineConfig([ { files: ["**/*.js"], languageOptions: { sourceType: "script" } }, { files: ["**/*.{js,mjs,cjs,vue}"], languageOptions: { globals: {...globals.browser, ...globals.node} } }, diff --git a/tests/__snapshots__/syntax-script-vue-typescript b/tests/__snapshots__/syntax-script-vue-typescript index 0fadc28f..31f47e76 100644 --- a/tests/__snapshots__/syntax-script-vue-typescript +++ b/tests/__snapshots__/syntax-script-vue-typescript @@ -4,7 +4,6 @@ import tseslint from "typescript-eslint"; import pluginVue from "eslint-plugin-vue"; import { defineConfig } from "eslint/config"; - export default defineConfig([ { files: ["**/*.js"], languageOptions: { sourceType: "script" } }, { files: ["**/*.{js,mjs,cjs,ts,mts,cts,vue}"], languageOptions: { globals: {...globals.browser, ...globals.node} } }, From f3f1aa46429b50b55e9c6d69c6d6fbe3d3ed64da Mon Sep 17 00:00:00 2001 From: hyperz111 Date: Mon, 22 Sep 2025 11:28:00 +0700 Subject: [PATCH 2/9] add ansi-colors --- package.json | 1 + 1 file changed, 1 insertion(+) diff --git a/package.json b/package.json index 569c7fab..a36f98dc 100644 --- a/package.json +++ b/package.json @@ -35,6 +35,7 @@ "test:snapshots:update": "vitest -u run snapshots" }, "dependencies": { + "ansi-colors": "^4.1.3", "cross-spawn": "^7.0.2", "enquirer": "^2.3.5", "semver": "^7.7.1" From 3140a2115be8b9b747362429ce91cf7206a7e85c Mon Sep 17 00:00:00 2001 From: hyperz111 Date: Mon, 22 Sep 2025 11:41:00 +0700 Subject: [PATCH 3/9] add style for questions --- lib/questions.js | 62 ++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 52 insertions(+), 10 deletions(-) diff --git a/lib/questions.js b/lib/questions.js index 9e3bb8fa..7b9c1f7e 100644 --- a/lib/questions.js +++ b/lib/questions.js @@ -3,7 +3,49 @@ * @author 唯然 */ -export const langQuestions = [{ +// ------------------------------------------------------------------------------ +// Imports +// ------------------------------------------------------------------------------ + +import colors from "ansi-colors"; + +// ------------------------------------------------------------------------------ +// Helpers +// ------------------------------------------------------------------------------ + +/** + * Set questions prompt style options in here. + * @param {Array} questionsPromptArray Array of questions prompt. + * @returns {Array} Questions prompt with style options. + */ +function setQuestionsPromptStyle(questionsPromptArray) { + return questionsPromptArray.map(opts => ({ + ...opts, + styles: { + danger: colors.red, + strong: colors.reset + }, + symbols: { + prefix(state) { + return ({ + pending: colors.cyan(colors.symbols.question), + cancelled: colors.red(colors.symbols.cross), + submitted: colors.green(colors.symbols.check) + })[state.status]; + }, + indicator: { + on: colors.cyan(colors.symbols.radioOn), + off: colors.gray(colors.symbols.radioOff) + } + } + })); +} + +// ------------------------------------------------------------------------------ +// Export contents +// ------------------------------------------------------------------------------ + +export const langQuestions = setQuestionsPromptStyle([{ type: "multiselect", name: "languages", message: "What do you want to lint?", @@ -25,9 +67,9 @@ export const langQuestions = [{ { message: "To check syntax only", name: "syntax" }, { message: "To check syntax and find problems", name: "problems" } ] -}]; +}]); -export const jsQuestions = [ +export const jsQuestions = setQuestionsPromptStyle([ { type: "select", name: "moduleType", @@ -82,9 +124,9 @@ export const jsQuestions = [ return !this.state.answers.useTs; } } -]; +]); -export const mdQuestions = [{ +export const mdQuestions = setQuestionsPromptStyle([{ type: "select", name: "mdType", message: "What flavor of Markdown do you want to lint?", @@ -93,9 +135,9 @@ export const mdQuestions = [{ { message: "CommonMark", name: "commonmark" }, { message: "GitHub Flavored Markdown", name: "gfm" } ] -}]; +}]); -export const installationQuestions = [ +export const installationQuestions = setQuestionsPromptStyle([ { type: "toggle", name: "executeInstallation", @@ -113,13 +155,13 @@ export const installationQuestions = [ return this.state.answers.executeInstallation === false; } } -]; +]); -export const addJitiQuestion = { +export const addJitiQuestion = setQuestionsPromptStyle([{ type: "toggle", name: "addJiti", message: "Would you like to add Jiti as a devDependency?", disabled: "No", enabled: "Yes", initial: 1 -}; +}]); From c186f700e46c405c6cbeb597229a44edbf299c4e Mon Sep 17 00:00:00 2001 From: hyperz111 Date: Mon, 22 Sep 2025 12:55:19 +0700 Subject: [PATCH 4/9] add style for logg util --- bin/create-config.js | 12 ++++++------ lib/config-generator.js | 8 ++++---- lib/questions.js | 6 +++++- lib/utils/logging.js | 29 ++++++++++++++++++++++++----- lib/utils/npm-utils.js | 4 ++-- 5 files changed, 41 insertions(+), 18 deletions(-) diff --git a/bin/create-config.js b/bin/create-config.js index 534284fa..fa8620f6 100755 --- a/bin/create-config.js +++ b/bin/create-config.js @@ -7,21 +7,21 @@ import { ConfigGenerator } from "../lib/config-generator.js"; import { findPackageJson } from "../lib/utils/npm-utils.js"; -import { info } from "../lib/utils/logging.js"; +import { log, error } from "../lib/utils/logging.js"; import process from "node:process"; import fs from "node:fs/promises"; const pkg = JSON.parse(await fs.readFile(new URL("../package.json", import.meta.url), "utf8")); -info(`${pkg.name}: v${pkg.version}\n`); +log(`${pkg.name}: v${pkg.version}\n`); -process.on("uncaughtException", error => { - if (error instanceof Error && error.code === "ERR_USE_AFTER_CLOSE") { - info("Operation canceled"); +process.on("uncaughtException", err => { + if (err instanceof Error && err.code === "ERR_USE_AFTER_CLOSE") { + error("Operation canceled"); // eslint-disable-next-line n/no-process-exit -- exit gracefully on Ctrl+C process.exit(1); } else { - throw error; + throw err; } }); diff --git a/lib/config-generator.js b/lib/config-generator.js index a9c86ba5..b1145104 100644 --- a/lib/config-generator.js +++ b/lib/config-generator.js @@ -355,14 +355,14 @@ export default defineConfig([\n${exportContent || " {}\n"}]);\n`; // defaults t async output() { log.info("The config that you've selected requires the following dependencies:\n"); - log.info(this.result.devDependencies.join(", ")); + log.log(this.result.devDependencies.join(", ")); const { executeInstallation, packageManager } = (await enquirer.prompt(installationQuestions)); const configPath = path.join(this.cwd, this.result.configFilename); if (executeInstallation === true) { - log.info("☕️Installing..."); + log.log("☕️Installing..."); installSyncSaveDev(this.result.devDependencies, packageManager, this.result.installFlags); await writeFile(configPath, this.result.configContent); @@ -374,12 +374,12 @@ export default defineConfig([\n${exportContent || " {}\n"}]);\n`; // defaults t if (result.error || result.status !== 0) { log.error("A config file was generated, but the config file itself may not follow your linting rules."); } else { - log.info(`Successfully created ${configPath} file.`); + log.success(`Successfully created ${configPath} file.`); } } else { await writeFile(configPath, this.result.configContent); - log.info(`Successfully created ${configPath} file.`); + log.success(`Successfully created ${configPath} file.`); log.warn("You will need to install the dependencies yourself."); } } diff --git a/lib/questions.js b/lib/questions.js index 7b9c1f7e..e05c3c3a 100644 --- a/lib/questions.js +++ b/lib/questions.js @@ -23,9 +23,11 @@ function setQuestionsPromptStyle(questionsPromptArray) { ...opts, styles: { danger: colors.red, - strong: colors.reset + strong: str => str }, symbols: { + + // For symbol in the start of question text prefix(state) { return ({ pending: colors.cyan(colors.symbols.question), @@ -33,6 +35,8 @@ function setQuestionsPromptStyle(questionsPromptArray) { submitted: colors.green(colors.symbols.check) })[state.status]; }, + + // For option symbol in select and multiselect indicator: { on: colors.cyan(colors.symbols.radioOn), off: colors.gray(colors.symbols.radioOff) diff --git a/lib/utils/logging.js b/lib/utils/logging.js index 39576e10..9b9a63ee 100644 --- a/lib/utils/logging.js +++ b/lib/utils/logging.js @@ -3,6 +3,7 @@ * @author Gyandeep Singh */ +import colors from "ansi-colors"; /* eslint no-console: "off" -- Logging util */ @@ -11,24 +12,42 @@ * @param {...any} args The elements to log. * @returns {void} */ -export function info(...args) { +export function log(...args) { console.log(...args); } /** - * Cover for console.warn + * Cover for console.log with check symbol + * @param {...any} args The elements to log. + * @returns {void} + */ +export function success(...args) { + console.log(colors.green(colors.symbols.check), ...args); +} + +/** + * Cover for console.log with info symbol + * @param {...any} args The elements to log. + * @returns {void} + */ +export function info(...args) { + console.log(colors.blue(colors.symbols.info), ...args); +} + +/** + * Cover for console.warn with warn symbol * @param {...any} args The elements to log. * @returns {void} */ export function warn(...args) { - console.warn(...args); + console.warn(colors.yellow(colors.symbols.warning), ...args); } /** - * Cover for console.error + * Cover for console.error with cross symbol * @param {...any} args The elements to log. * @returns {void} */ export function error(...args) { - console.error(...args); + console.error(colors.red(colors.symbols.cross), ...args); } diff --git a/lib/utils/npm-utils.js b/lib/utils/npm-utils.js index 1f97db99..5b55ab20 100644 --- a/lib/utils/npm-utils.js +++ b/lib/utils/npm-utils.js @@ -11,7 +11,7 @@ import fs from "node:fs"; import spawn from "cross-spawn"; import path from "node:path"; -import * as log from "./logging.js"; +import { error as logError } from "./logging.js"; //------------------------------------------------------------------------------ // Helpers @@ -58,7 +58,7 @@ function installSyncSaveDev(packages, packageManager = "npm", installFlags = ["- if (error && error.code === "ENOENT") { const pluralS = packageList.length > 1 ? "s" : ""; - log.error(`Could not execute ${packageManager}. Please install the following package${pluralS} with a package manager of your choice: ${packageList.join(", ")}`); + logError(`Could not execute ${packageManager}. Please install the following package${pluralS} with a package manager of your choice: ${packageList.join(", ")}`); } } From 21525d416da7928d05e95654cc0068a4199acd18 Mon Sep 17 00:00:00 2001 From: hyperz111 Date: Mon, 22 Sep 2025 12:57:45 +0700 Subject: [PATCH 5/9] change error color back to magenta --- lib/questions.js | 10 ---------- lib/utils/logging.js | 2 +- 2 files changed, 1 insertion(+), 11 deletions(-) diff --git a/lib/questions.js b/lib/questions.js index e05c3c3a..9cc25d9b 100644 --- a/lib/questions.js +++ b/lib/questions.js @@ -22,20 +22,10 @@ function setQuestionsPromptStyle(questionsPromptArray) { return questionsPromptArray.map(opts => ({ ...opts, styles: { - danger: colors.red, strong: str => str }, symbols: { - // For symbol in the start of question text - prefix(state) { - return ({ - pending: colors.cyan(colors.symbols.question), - cancelled: colors.red(colors.symbols.cross), - submitted: colors.green(colors.symbols.check) - })[state.status]; - }, - // For option symbol in select and multiselect indicator: { on: colors.cyan(colors.symbols.radioOn), diff --git a/lib/utils/logging.js b/lib/utils/logging.js index 9b9a63ee..d1897732 100644 --- a/lib/utils/logging.js +++ b/lib/utils/logging.js @@ -49,5 +49,5 @@ export function warn(...args) { * @returns {void} */ export function error(...args) { - console.error(colors.red(colors.symbols.cross), ...args); + console.error(colors.magenta(colors.symbols.cross), ...args); } From 40d05e330423b958356d5e0d13b6705015048e9c Mon Sep 17 00:00:00 2001 From: hyperz111 Date: Wed, 24 Sep 2025 05:24:34 +0700 Subject: [PATCH 6/9] update console --- lib/utils/logging.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/utils/logging.js b/lib/utils/logging.js index d1897732..cfeb16f3 100644 --- a/lib/utils/logging.js +++ b/lib/utils/logging.js @@ -26,12 +26,12 @@ export function success(...args) { } /** - * Cover for console.log with info symbol + * Cover for console.info with info symbol * @param {...any} args The elements to log. * @returns {void} */ export function info(...args) { - console.log(colors.blue(colors.symbols.info), ...args); + console.info(colors.blue(colors.symbols.info), ...args); } /** From da3ab41718e41583e225761705ad3fd2f5604665 Mon Sep 17 00:00:00 2001 From: hyperz111 Date: Fri, 26 Sep 2025 02:23:34 +0700 Subject: [PATCH 7/9] some changes --- bin/create-config.js | 12 ++++++------ lib/questions.js | 3 --- lib/utils/logging.js | 10 +++++----- lib/utils/npm-utils.js | 4 ++-- 4 files changed, 13 insertions(+), 16 deletions(-) diff --git a/bin/create-config.js b/bin/create-config.js index fa8620f6..7808a24c 100755 --- a/bin/create-config.js +++ b/bin/create-config.js @@ -7,21 +7,21 @@ import { ConfigGenerator } from "../lib/config-generator.js"; import { findPackageJson } from "../lib/utils/npm-utils.js"; -import { log, error } from "../lib/utils/logging.js"; +import * as log from "../lib/utils/logging.js"; import process from "node:process"; import fs from "node:fs/promises"; const pkg = JSON.parse(await fs.readFile(new URL("../package.json", import.meta.url), "utf8")); -log(`${pkg.name}: v${pkg.version}\n`); +log.log(`${pkg.name}: v${pkg.version}\n`); -process.on("uncaughtException", err => { - if (err instanceof Error && err.code === "ERR_USE_AFTER_CLOSE") { - error("Operation canceled"); +process.on("uncaughtException", error => { + if (error instanceof Error && error.code === "ERR_USE_AFTER_CLOSE") { + log.error("Operation canceled"); // eslint-disable-next-line n/no-process-exit -- exit gracefully on Ctrl+C process.exit(1); } else { - throw err; + throw error; } }); diff --git a/lib/questions.js b/lib/questions.js index 9cc25d9b..9b821311 100644 --- a/lib/questions.js +++ b/lib/questions.js @@ -21,9 +21,6 @@ import colors from "ansi-colors"; function setQuestionsPromptStyle(questionsPromptArray) { return questionsPromptArray.map(opts => ({ ...opts, - styles: { - strong: str => str - }, symbols: { // For option symbol in select and multiselect diff --git a/lib/utils/logging.js b/lib/utils/logging.js index cfeb16f3..e848db5b 100644 --- a/lib/utils/logging.js +++ b/lib/utils/logging.js @@ -13,7 +13,7 @@ import colors from "ansi-colors"; * @returns {void} */ export function log(...args) { - console.log(...args); + console.log(colors.bold(args.join(" "))); } /** @@ -22,7 +22,7 @@ export function log(...args) { * @returns {void} */ export function success(...args) { - console.log(colors.green(colors.symbols.check), ...args); + console.log(colors.green(colors.symbols.check), colors.bold(args.join(" "))); } /** @@ -31,7 +31,7 @@ export function success(...args) { * @returns {void} */ export function info(...args) { - console.info(colors.blue(colors.symbols.info), ...args); + console.info(colors.blue(colors.symbols.info), colors.bold(args.join(" "))); } /** @@ -40,7 +40,7 @@ export function info(...args) { * @returns {void} */ export function warn(...args) { - console.warn(colors.yellow(colors.symbols.warning), ...args); + console.warn(colors.yellow(colors.symbols.warning), colors.bold(args.join(" "))); } /** @@ -49,5 +49,5 @@ export function warn(...args) { * @returns {void} */ export function error(...args) { - console.error(colors.magenta(colors.symbols.cross), ...args); + console.error(colors.magenta(colors.symbols.cross), colors.bold(args.join(" "))); } diff --git a/lib/utils/npm-utils.js b/lib/utils/npm-utils.js index 5b55ab20..1f97db99 100644 --- a/lib/utils/npm-utils.js +++ b/lib/utils/npm-utils.js @@ -11,7 +11,7 @@ import fs from "node:fs"; import spawn from "cross-spawn"; import path from "node:path"; -import { error as logError } from "./logging.js"; +import * as log from "./logging.js"; //------------------------------------------------------------------------------ // Helpers @@ -58,7 +58,7 @@ function installSyncSaveDev(packages, packageManager = "npm", installFlags = ["- if (error && error.code === "ENOENT") { const pluralS = packageList.length > 1 ? "s" : ""; - logError(`Could not execute ${packageManager}. Please install the following package${pluralS} with a package manager of your choice: ${packageList.join(", ")}`); + log.error(`Could not execute ${packageManager}. Please install the following package${pluralS} with a package manager of your choice: ${packageList.join(", ")}`); } } From bb4832347e5efe670831c3274a6be10946276413 Mon Sep 17 00:00:00 2001 From: hyperz111 Date: Fri, 26 Sep 2025 18:00:59 +0700 Subject: [PATCH 8/9] some changes --- lib/questions.js | 10 +++++++--- lib/utils/logging.js | 31 ++++++++++++++++++++++++++----- 2 files changed, 33 insertions(+), 8 deletions(-) diff --git a/lib/questions.js b/lib/questions.js index 9b821311..29ee596b 100644 --- a/lib/questions.js +++ b/lib/questions.js @@ -3,6 +3,10 @@ * @author 唯然 */ +/** + * @typedef {Object} PlainObject + */ + // ------------------------------------------------------------------------------ // Imports // ------------------------------------------------------------------------------ @@ -15,8 +19,8 @@ import colors from "ansi-colors"; /** * Set questions prompt style options in here. - * @param {Array} questionsPromptArray Array of questions prompt. - * @returns {Array} Questions prompt with style options. + * @param {PlainObject[]} questionsPromptArray Array of questions prompt. + * @returns {PlainObject[]} Questions prompt with style options. */ function setQuestionsPromptStyle(questionsPromptArray) { return questionsPromptArray.map(opts => ({ @@ -33,7 +37,7 @@ function setQuestionsPromptStyle(questionsPromptArray) { } // ------------------------------------------------------------------------------ -// Export contents +// Exports // ------------------------------------------------------------------------------ export const langQuestions = setQuestionsPromptStyle([{ diff --git a/lib/utils/logging.js b/lib/utils/logging.js index e848db5b..7cd72c92 100644 --- a/lib/utils/logging.js +++ b/lib/utils/logging.js @@ -3,8 +3,29 @@ * @author Gyandeep Singh */ +// ------------------------------------------------------------------------------ +// Imports +// ------------------------------------------------------------------------------ + import colors from "ansi-colors"; +// ------------------------------------------------------------------------------ +// Helpers +// ------------------------------------------------------------------------------ + +/** + * Used for joining and add bold style to an array of arguments. + * @param {any[]} args Array of arguments. + * @returns {string} Joined and bolded string. + */ +function boldArgs(args) { + return colors.bold(args.join(" ")); +} + +// ------------------------------------------------------------------------------ +// Exports +// ------------------------------------------------------------------------------ + /* eslint no-console: "off" -- Logging util */ /** @@ -13,7 +34,7 @@ import colors from "ansi-colors"; * @returns {void} */ export function log(...args) { - console.log(colors.bold(args.join(" "))); + console.log(boldArgs(args)); } /** @@ -22,7 +43,7 @@ export function log(...args) { * @returns {void} */ export function success(...args) { - console.log(colors.green(colors.symbols.check), colors.bold(args.join(" "))); + console.log(colors.green(colors.symbols.check), boldArgs(args)); } /** @@ -31,7 +52,7 @@ export function success(...args) { * @returns {void} */ export function info(...args) { - console.info(colors.blue(colors.symbols.info), colors.bold(args.join(" "))); + console.info(colors.blue(colors.symbols.info), boldArgs(args)); } /** @@ -40,7 +61,7 @@ export function info(...args) { * @returns {void} */ export function warn(...args) { - console.warn(colors.yellow(colors.symbols.warning), colors.bold(args.join(" "))); + console.warn(colors.yellow(colors.symbols.warning), boldArgs(args)); } /** @@ -49,5 +70,5 @@ export function warn(...args) { * @returns {void} */ export function error(...args) { - console.error(colors.magenta(colors.symbols.cross), colors.bold(args.join(" "))); + console.error(colors.magenta(colors.symbols.cross), boldArgs(args)); } From 5c1edf1fecfac7fc37e4bd494fffe3c43ab1fba2 Mon Sep 17 00:00:00 2001 From: hyperz111 Date: Mon, 29 Sep 2025 15:49:13 +0700 Subject: [PATCH 9/9] change jsdoc type --- lib/questions.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/questions.js b/lib/questions.js index 29ee596b..1e27f32f 100644 --- a/lib/questions.js +++ b/lib/questions.js @@ -4,7 +4,7 @@ */ /** - * @typedef {Object} PlainObject + * @typedef {Record} PlainObject */ // ------------------------------------------------------------------------------