Skip to content

Commit c8caa1c

Browse files
feat: feat-eslint-vscode-settings (#241)
1 parent 464ba03 commit c8caa1c

File tree

7 files changed

+22
-12
lines changed

7 files changed

+22
-12
lines changed

Diff for: index.ts

+3
Original file line numberDiff line numberDiff line change
@@ -484,7 +484,10 @@ async function init() {
484484

485485
// Render ESLint config
486486
// By default ESLint, Prettier and Husky will be added
487+
// if (needsEslint) {
487488
renderEslint(root, { needsTypeScript, needsCypress, needsCypressCT, needsPlaywright })
489+
render('config/eslint')
490+
// }
488491
render('config/husky')
489492

490493
// if (needsPrettier) {

Diff for: scripts/snapshot.mjs

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ function fullCombination(arr) {
5252
}
5353

5454
let flagCombinations = fullCombination(featureFlags)
55-
flagCombinations.push(['default'])
55+
flagCombinations.push(['default'], ['eslint'], ['eslint-with-prettier'])
5656

5757
// `--with-tests` are equivalent of `--vitest --cypress`
5858
// Previously it means `--cypress` without `--vitest`.

Diff for: template/base/.vscode/settings.json

+1-5
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,5 @@
44
"files.trimTrailingWhitespace": true,
55
"files.eol": "\n",
66
"files.insertFinalNewline": true,
7-
"files.trimFinalNewlines": true,
8-
"editor.codeActionsOnSave": {
9-
"source.fixAll.eslint": true,
10-
"source.fixAll.stylelint": true
11-
}
7+
"files.trimFinalNewlines": true
128
}

Diff for: template/config/eslint/.vscode/extensions.json

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"recommendations": ["dbaeumer.vscode-eslint"]
3+
}

Diff for: template/config/eslint/.vscode/settings.json

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"editor.codeActionsOnSave": {
3+
"source.fixAll": "explicit"
4+
}
5+
}

Diff for: utils/renderEslint.ts

-6
Original file line numberDiff line numberDiff line change
@@ -106,10 +106,4 @@ export default function renderEslint(
106106
const fullPath = path.resolve(rootDir, fileName)
107107
fs.writeFileSync(fullPath, content as string, 'utf-8')
108108
}
109-
110-
// update .vscode/extensions.json
111-
const extensionsJsonPath = path.resolve(rootDir, '.vscode/extensions.json')
112-
const existingExtensions = JSON.parse(fs.readFileSync(extensionsJsonPath, 'utf8'))
113-
existingExtensions.recommendations.push('dbaeumer.vscode-eslint')
114-
fs.writeFileSync(extensionsJsonPath, JSON.stringify(existingExtensions, null, 2) + '\n', 'utf-8')
115109
}

Diff for: utils/renderTemplate.ts

+9
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,15 @@ function renderTemplate(src, dest, callbacks) {
5151
return
5252
}
5353

54+
if (filename === 'settings.json' && fs.existsSync(dest)) {
55+
// merge instead of overwriting
56+
const settings = JSON.parse(fs.readFileSync(dest, 'utf8'))
57+
const newSettings = JSON.parse(fs.readFileSync(src, 'utf8'))
58+
const extensions = deepMerge(settings, newSettings)
59+
fs.writeFileSync(dest, JSON.stringify(settings, null, 2) + '\n')
60+
return
61+
}
62+
5463
if (filename.startsWith('_')) {
5564
// rename `_file` to `.file`
5665
dest = path.resolve(path.dirname(dest), filename.replace(/^_/, '.'))

0 commit comments

Comments
 (0)