]> git.ipfire.org Git - thirdparty/vuejs/create-vue.git/commitdiff
feat: add experimental Oxlint integration (#601)
authorHaoqun Jiang <haoqunjiang@gmail.com>
Tue, 5 Nov 2024 08:31:42 +0000 (16:31 +0800)
committerGitHub <noreply@github.com>
Tue, 5 Nov 2024 08:31:42 +0000 (16:31 +0800)
index.ts
locales/en-US.json
locales/fr-FR.json
locales/tr-TR.json
locales/zh-Hans.json
locales/zh-Hant.json
package.json
pnpm-lock.yaml
utils/renderEslint.ts

index 35bd3cd486f00564232eb0a5a0eb9c57c913807b..aea4f3b94d496266d3ac12b27826c736edca8fdb 100755 (executable)
--- 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,23 @@ async function init() {
         },
         {
           name: 'needsEslint',
-          type: () => (isFeatureFlagsUsed ? null : 'toggle'),
+          type: () => (isFeatureFlagsUsed ? null : 'select'),
           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 +337,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 +474,7 @@ async function init() {
   if (needsEslint) {
     renderEslint(root, {
       needsTypeScript,
+      needsOxlint,
       needsVitest,
       needsCypress,
       needsCypressCT,
index 8dc45e43e2ee9993f271b2044816e06af3725959..2f55f9720578afcd38f746c7dcb58e1f631c3d33 100644 (file)
     }
   },
   "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?"
index 6815e7668c3f74c56a879a85dc02b0ed145cd680..1b61b56187dbc965998c2180507dd14f1e078ba2 100644 (file)
     }
   },
   "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érer avec Oxlint (expérimental)"
+      }
+    }
   },
   "needsPrettier": {
     "message": "Ajouter Prettier pour le formatage du code\u00a0?"
index 26ea693f5f3c94c04155b3f78741e1072db3d48f..3700fbecefe34a7ec18ba5d7966eed6be108093a 100644 (file)
     }
   },
   "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?"
index 1e9a0fc071f509f4c2440166e85c21d7d8cd7e06..b27f1c02dc30ef3e5abf4393d1815b66297ebcd5 100644 (file)
     }
   },
   "needsEslint": {
-    "message": "是否引入 ESLint 用于代码质量检测?"
+    "message": "是否引入 ESLint 用于代码质量检测?",
+    "selectOptions": {
+      "negative": { "title": "否" },
+      "eslintOnly": {
+        "title": "是"
+      },
+      "speedUpWithOxlint": {
+        "title": "是,并同时引入 Oxlint 以加快检测(试验阶段)"
+      }
+    }
   },
   "needsPrettier": {
     "message": "是否引入 Prettier 用于代码格式化?"
index cab9ca2199524ddf5beb247a8e18a094e0b40a36..a22be42690ca670dfcad8e8ebe274be4665b6afd 100644 (file)
     }
   },
   "needsEslint": {
-    "message": "是否引入 ESLint 用於程式碼品質檢測?"
+    "message": "是否引入 ESLint 用於程式碼品質檢測?",
+    "selectOptions": {
+      "negative": { "title": "否" },
+      "eslintOnly": {
+        "title": "是"
+      },
+      "speedUpWithOxlint": {
+        "title": "是,並同時引入 Oxlint 以加快檢測(試驗性功能)"
+      }
+    }
   },
   "needsPrettier": {
     "message": "是否引入 Prettier 用於程式碼格式化?"
index c04397efb109df1f62b2bc00698fce5f369b907a..c56a2eb52285991aae286f38e029cca93f6818f6 100644 (file)
@@ -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",
index 2839be86502b61dd2acad03e5bd1c946bba4b62c..8f9bd3b426bb892c9adcc7597fe6e939c686515c 100644 (file)
@@ -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
index e677c064607405cc4a4c077bfac8d0a72705f074..a22a222ecd20f183f040a9a1d5611fa45284c518 100644 (file)
@@ -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<string, string> = {
-    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')