From e5384d08b738dd99841814d8c194c10dfedb0167 Mon Sep 17 00:00:00 2001 From: Haoqun Jiang Date: Tue, 5 Nov 2024 02:46:21 +0800 Subject: [PATCH 1/4] feat: add experimental Oxlint integration Bumped @vue/create-eslint-config to 0.6.0 to support the new feature. Note: The `scripts` field generated in package.json for ESLint/Oxlint/Prettier is now handled by `@vue/create-eslint-config` instead of here. TODO: need to update the French and Turkish translations. --- index.ts | 29 +++++++++++++++++++++++------ locales/en-US.json | 11 ++++++++++- locales/zh-Hans.json | 11 ++++++++++- locales/zh-Hant.json | 11 ++++++++++- package.json | 2 +- pnpm-lock.yaml | 20 ++++++-------------- utils/renderEslint.ts | 32 ++++++++++++++------------------ 7 files changed, 74 insertions(+), 42 deletions(-) diff --git a/index.ts b/index.ts index 35bd3cd4..a2a86ca5 100755 --- a/index.ts +++ b/index.ts @@ -141,7 +141,8 @@ async function init() { needsPinia?: boolean needsVitest?: boolean needsE2eTesting?: false | 'cypress' | 'nightwatch' | 'playwright' - needsEslint?: boolean + needsEslint?: false | 'eslintOnly' | 'speedUpWithOxlint' + needsOxlint?: boolean needsPrettier?: boolean needsDevTools?: boolean } = {} @@ -274,11 +275,24 @@ async function init() { }, { name: 'needsEslint', - type: () => (isFeatureFlagsUsed ? null : 'toggle'), + type: () => (isFeatureFlagsUsed ? null : 'select'), + // FIXME: message: language.needsEslint.message, - initial: false, - active: language.defaultToggleOptions.active, - inactive: language.defaultToggleOptions.inactive, + initial: 0, + choices: [ + { + title: language.needsEslint.selectOptions.negative.title, + value: false, + }, + { + title: language.needsEslint.selectOptions.eslintOnly.title, + value: 'eslintOnly', + }, + { + title: language.needsEslint.selectOptions.speedUpWithOxlint.title, + value: 'speedUpWithOxlint', + }, + ], }, { name: 'needsPrettier', @@ -324,11 +338,13 @@ async function init() { needsRouter = argv.router || argv['vue-router'], needsPinia = argv.pinia, needsVitest = argv.vitest || argv.tests, - needsEslint = argv.eslint || argv['eslint-with-prettier'], needsPrettier = argv['eslint-with-prettier'], needsDevTools = argv.devtools || argv['vue-devtools'], } = result + const needsEslint = Boolean(argv.eslint || argv['eslint-with-prettier'] || result.needsEslint) + const needsOxlint = result.needsEslint === 'speedUpWithOxlint' + const { needsE2eTesting } = result const needsCypress = argv.cypress || argv.tests || needsE2eTesting === 'cypress' const needsCypressCT = needsCypress && !needsVitest @@ -459,6 +475,7 @@ async function init() { if (needsEslint) { renderEslint(root, { needsTypeScript, + needsOxlint, needsVitest, needsCypress, needsCypressCT, diff --git a/locales/en-US.json b/locales/en-US.json index 8dc45e43..2f55f972 100644 --- a/locales/en-US.json +++ b/locales/en-US.json @@ -45,7 +45,16 @@ } }, "needsEslint": { - "message": "Add ESLint for code quality?" + "message": "Add ESLint for code quality?", + "selectOptions": { + "negative": { "title": "No" }, + "eslintOnly": { + "title": "Yes" + }, + "speedUpWithOxlint": { + "title": "Yes, and speed up with Oxlint (experimental)" + } + } }, "needsPrettier": { "message": "Add Prettier for code formatting?" diff --git a/locales/zh-Hans.json b/locales/zh-Hans.json index 1e9a0fc0..b27f1c02 100644 --- a/locales/zh-Hans.json +++ b/locales/zh-Hans.json @@ -45,7 +45,16 @@ } }, "needsEslint": { - "message": "是否引入 ESLint 用于代码质量检测?" + "message": "是否引入 ESLint 用于代码质量检测?", + "selectOptions": { + "negative": { "title": "否" }, + "eslintOnly": { + "title": "是" + }, + "speedUpWithOxlint": { + "title": "是,并同时引入 Oxlint 以加快检测(试验阶段)" + } + } }, "needsPrettier": { "message": "是否引入 Prettier 用于代码格式化?" diff --git a/locales/zh-Hant.json b/locales/zh-Hant.json index cab9ca21..a22be426 100644 --- a/locales/zh-Hant.json +++ b/locales/zh-Hant.json @@ -49,7 +49,16 @@ } }, "needsEslint": { - "message": "是否引入 ESLint 用於程式碼品質檢測?" + "message": "是否引入 ESLint 用於程式碼品質檢測?", + "selectOptions": { + "negative": { "title": "否" }, + "eslintOnly": { + "title": "是" + }, + "speedUpWithOxlint": { + "title": "是,並同時引入 Oxlint 以加快檢測(試驗性功能)" + } + } }, "needsPrettier": { "message": "是否引入 Prettier 用於程式碼格式化?" diff --git a/package.json b/package.json index c04397ef..c56a2eb5 100644 --- a/package.json +++ b/package.json @@ -41,7 +41,7 @@ "@types/eslint": "^9.6.1", "@types/node": "^20.17.6", "@types/prompts": "^2.4.9", - "@vue/create-eslint-config": "0.5.0", + "@vue/create-eslint-config": "^0.6.0", "@vue/tsconfig": "^0.5.1", "ejs": "^3.1.10", "esbuild": "^0.24.0", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 2839be86..8f9bd3b4 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -21,8 +21,8 @@ importers: specifier: ^2.4.9 version: 2.4.9 '@vue/create-eslint-config': - specifier: 0.5.0 - version: 0.5.0 + specifier: ^0.6.0 + version: 0.6.0 '@vue/tsconfig': specifier: ^0.5.1 version: 0.5.1 @@ -1267,8 +1267,8 @@ packages: '@vue/compiler-vue2@2.7.16': resolution: {integrity: sha512-qYC3Psj9S/mfu9uVi5WvNZIzq+xnXMhOwbTFKKDD7b1lhpnn71jXSFdTQ+WsIEk0ONCd7VV2IMm7ONl6tbQ86A==} - '@vue/create-eslint-config@0.5.0': - resolution: {integrity: sha512-wXmFEDiuntXbNEtVtuBzhXXiIT5/M00gB9J3Io0tY9x4wznti64Xwj0//gA/f+cdp6kK8OmjYPeVTYZRLooimg==} + '@vue/create-eslint-config@0.6.0': + resolution: {integrity: sha512-IueSBgOXI+NzsG1ScPfGf1abU+cVNZ7i+nVLwTNanPkwt/Ocvj7qQWaDTLNb1TByRi1EIs9xJ81rbnDe8zY09g==} engines: {node: ^16.14.0 || >= 18.0.0} hasBin: true @@ -4839,14 +4839,6 @@ snapshots: optionalDependencies: vite: 5.4.10(@types/node@20.17.6) - '@vitest/mocker@2.1.4(vite@5.4.10(@types/node@22.7.5))': - dependencies: - '@vitest/spy': 2.1.4 - estree-walker: 3.0.3 - magic-string: 0.30.12 - optionalDependencies: - vite: 5.4.10(@types/node@22.7.5) - '@vitest/pretty-format@2.1.4': dependencies: tinyrainbow: 1.2.0 @@ -4979,7 +4971,7 @@ snapshots: de-indent: 1.0.2 he: 1.2.0 - '@vue/create-eslint-config@0.5.0': + '@vue/create-eslint-config@0.6.0': dependencies: ejs: 3.1.10 enquirer: 2.4.1 @@ -7741,7 +7733,7 @@ snapshots: vitest@2.1.4(@types/node@22.7.5)(jsdom@25.0.1): dependencies: '@vitest/expect': 2.1.4 - '@vitest/mocker': 2.1.4(vite@5.4.10(@types/node@22.7.5)) + '@vitest/mocker': 2.1.4(vite@5.4.10(@types/node@20.17.6)) '@vitest/pretty-format': 2.1.4 '@vitest/runner': 2.1.4 '@vitest/snapshot': 2.1.4 diff --git a/utils/renderEslint.ts b/utils/renderEslint.ts index e677c064..a22a222e 100644 --- a/utils/renderEslint.ts +++ b/utils/renderEslint.ts @@ -11,7 +11,15 @@ const eslintDeps = eslintTemplatePackage.devDependencies export default function renderEslint( rootDir, - { needsTypeScript, needsVitest, needsCypress, needsCypressCT, needsPrettier, needsPlaywright }, + { + needsTypeScript, + needsVitest, + needsCypress, + needsCypressCT, + needsOxlint, + needsPrettier, + needsPlaywright, + }, ) { const additionalConfigs = getAdditionalConfigs({ needsVitest, @@ -23,32 +31,20 @@ export default function renderEslint( const { pkg, files } = createESLintConfig({ styleGuide: 'default', hasTypeScript: needsTypeScript, + needsOxlint, + // Theoretically, we could add Prettier without requring ESLint. + // But it doesn't seem to be a good practice, so we just let createESLintConfig handle it. needsPrettier, - additionalConfigs, }) - const scripts: Record = { - lint: 'eslint . --fix', - } - - // Theoretically, we could add Prettier without requring ESLint. - // But it doesn't seem to be a good practice, so we just leave it here. - if (needsPrettier) { - // Default to only format the `src/` directory to avoid too much noise, and - // the need for a `.prettierignore` file. - // Users can still append any paths they'd like to format to the command, - // e.g. `npm run format cypress/`. - scripts.format = 'prettier --write src/' - } - // update package.json const packageJsonPath = path.resolve(rootDir, 'package.json') const existingPkg = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8')) - const updatedPkg = sortDependencies(deepMerge(deepMerge(existingPkg, pkg), { scripts })) + const updatedPkg = sortDependencies(deepMerge(existingPkg, pkg)) fs.writeFileSync(packageJsonPath, JSON.stringify(updatedPkg, null, 2) + '\n', 'utf8') - // write to eslint.config.mjs, .prettierrc.json, .editorconfig, etc. + // write to eslint.config.js, .prettierrc.json, .editorconfig, etc. for (const [fileName, content] of Object.entries(files)) { const fullPath = path.resolve(rootDir, fileName) fs.writeFileSync(fullPath, content as string, 'utf8') From 4f62d693abbf7a3c33203e654833f818bec2680f Mon Sep 17 00:00:00 2001 From: Haoqun Jiang Date: Tue, 5 Nov 2024 02:52:14 +0800 Subject: [PATCH 2/4] chore: add French and Turkish translations for the new Oxlint integration --- locales/fr-FR.json | 11 ++++++++++- locales/tr-TR.json | 11 ++++++++++- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/locales/fr-FR.json b/locales/fr-FR.json index 6815e766..88532d21 100644 --- a/locales/fr-FR.json +++ b/locales/fr-FR.json @@ -45,7 +45,16 @@ } }, "needsEslint": { - "message": "Ajouter ESLint pour la qualité du code\u00a0?" + "message": "Ajouter ESLint pour la qualité du code\u00a0?", + "selectOptions": { + "negative": { "title": "Non" }, + "eslintOnly": { + "title": "Oui" + }, + "speedUpWithOxlint": { + "title": "Oui, et accélérez avec Oxlint (expérimental)" + } + } }, "needsPrettier": { "message": "Ajouter Prettier pour le formatage du code\u00a0?" diff --git a/locales/tr-TR.json b/locales/tr-TR.json index 26ea693f..3700fbec 100644 --- a/locales/tr-TR.json +++ b/locales/tr-TR.json @@ -45,7 +45,16 @@ } }, "needsEslint": { - "message": "Kod kalitesi için ESLint eklensin mi?" + "message": "Kod kalitesi için ESLint eklensin mi?", + "selectOptions": { + "negative": { "title": "Hayır" }, + "eslintOnly": { + "title": "Evet" + }, + "speedUpWithOxlint": { + "title": "Evet ve Oxlint ile hızlanın (deneysel)" + } + } }, "needsPrettier": { "message": "Kod formatlama için Prettier eklensin mi?" From a9843ebe88e5d8997c5972f541084ed0eb14b1b6 Mon Sep 17 00:00:00 2001 From: Haoqun Jiang Date: Tue, 5 Nov 2024 13:58:24 +0800 Subject: [PATCH 3/4] chore: remove redundant FIXME comment [skip ci] --- index.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/index.ts b/index.ts index a2a86ca5..aea4f3b9 100755 --- a/index.ts +++ b/index.ts @@ -276,7 +276,6 @@ async function init() { { name: 'needsEslint', type: () => (isFeatureFlagsUsed ? null : 'select'), - // FIXME: message: language.needsEslint.message, initial: 0, choices: [ From 26804fe99a9d8f7326f156c405d2602df6277139 Mon Sep 17 00:00:00 2001 From: Haoqun Jiang Date: Tue, 5 Nov 2024 16:30:29 +0800 Subject: [PATCH 4/4] =?UTF-8?q?fix(fr-FR):=20acc=C3=A9l=C3=A9rez=20->=20ac?= =?UTF-8?q?c=C3=A9l=C3=A9rer=20[skip=20ci]?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- locales/fr-FR.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/locales/fr-FR.json b/locales/fr-FR.json index 88532d21..1b61b561 100644 --- a/locales/fr-FR.json +++ b/locales/fr-FR.json @@ -52,7 +52,7 @@ "title": "Oui" }, "speedUpWithOxlint": { - "title": "Oui, et accélérez avec Oxlint (expérimental)" + "title": "Oui, et accélérer avec Oxlint (expérimental)" } } },