]> git.ipfire.org Git - thirdparty/vuejs/create-vue.git/commitdiff
feat: add vscode config for ESLint (#467)
authoryoshipi <yoshipyft@gmail.com>
Tue, 19 Mar 2024 07:39:55 +0000 (16:39 +0900)
committerGitHub <noreply@github.com>
Tue, 19 Mar 2024 07:39:55 +0000 (15:39 +0800)
index.ts
scripts/snapshot.mjs
template/config/eslint/.vscode/extensions.json [new file with mode: 0644]
template/config/eslint/.vscode/settings.json [new file with mode: 0644]
utils/renderEslint.ts
utils/renderTemplate.ts

index 611fec77dbcebef2c5e17f12371d9c69e731c353..45a1cb6743eb2c41abc188377c28b876fd229ae3 100755 (executable)
--- a/index.ts
+++ b/index.ts
@@ -120,6 +120,7 @@ async function init() {
       argv.nightwatch ??
       argv.playwright ??
       argv.eslint ??
+      argv['eslint-with-prettier'] ??
       (argv.devtools || argv['vue-devtools'])
     ) === 'boolean'
 
@@ -463,6 +464,7 @@ async function init() {
       needsPrettier,
       needsPlaywright
     })
+    render('config/eslint')
   }
 
   if (needsPrettier) {
index 01b909fa9b5bd863d3c1acb4535194e70f98e3a8..932432289d9dede17ddd05e5adef7e837905cf83 100644 (file)
@@ -54,7 +54,7 @@ function fullCombination(arr) {
 }
 
 let flagCombinations = fullCombination(featureFlags)
-flagCombinations.push(['default'], ['devtools'])
+flagCombinations.push(['default'], ['devtools'], ['eslint'], ['eslint-with-prettier'])
 
 // `--with-tests` are equivalent of `--vitest --cypress`
 // Previously it means `--cypress` without `--vitest`.
diff --git a/template/config/eslint/.vscode/extensions.json b/template/config/eslint/.vscode/extensions.json
new file mode 100644 (file)
index 0000000..940260d
--- /dev/null
@@ -0,0 +1,3 @@
+{
+  "recommendations": ["dbaeumer.vscode-eslint"]
+}
diff --git a/template/config/eslint/.vscode/settings.json b/template/config/eslint/.vscode/settings.json
new file mode 100644 (file)
index 0000000..c8e04de
--- /dev/null
@@ -0,0 +1,5 @@
+{
+  "editor.codeActionsOnSave": {
+    "source.fixAll": "explicit"
+  }
+}
index f92f1ed42683979482385b1270c570ea6e148969..ecb74ae6768b171351216e09a39be212dbecf9b5 100644 (file)
@@ -85,10 +85,4 @@ export default function renderEslint(
     const fullPath = path.resolve(rootDir, fileName)
     fs.writeFileSync(fullPath, content as string, 'utf-8')
   }
-
-  // update .vscode/extensions.json
-  const extensionsJsonPath = path.resolve(rootDir, '.vscode/extensions.json')
-  const existingExtensions = JSON.parse(fs.readFileSync(extensionsJsonPath, 'utf8'))
-  existingExtensions.recommendations.push('dbaeumer.vscode-eslint')
-  fs.writeFileSync(extensionsJsonPath, JSON.stringify(existingExtensions, null, 2) + '\n', 'utf-8')
 }
index 2588dc3f3d5ad3173e5e58cdfaa019bee221c844..f2b869e8ce12b854bb9ec6acee30a73b7a3cf95d 100644 (file)
@@ -51,6 +51,15 @@ function renderTemplate(src, dest, callbacks) {
     return
   }
 
+  if (filename === 'settings.json' && fs.existsSync(dest)) {
+    // merge instead of overwriting
+    const settings = JSON.parse(fs.readFileSync(dest, 'utf8'))
+    const newSettings = JSON.parse(fs.readFileSync(src, 'utf8'))
+    const extensions = deepMerge(settings, newSettings)
+    fs.writeFileSync(dest, JSON.stringify(settings, null, 2) + '\n')
+    return
+  }
+
   if (filename.startsWith('_')) {
     // rename `_file` to `.file`
     dest = path.resolve(path.dirname(dest), filename.replace(/^_/, '.'))