Skip to content

Commit

Permalink
feat: add vscode config for ESLint (#467)
Browse files Browse the repository at this point in the history
  • Loading branch information
yoshi-pi authored Mar 19, 2024
1 parent 8ef4e48 commit bebba95
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 7 deletions.
2 changes: 2 additions & 0 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ async function init() {
argv.nightwatch ??
argv.playwright ??
argv.eslint ??
argv['eslint-with-prettier'] ??
(argv.devtools || argv['vue-devtools'])
) === 'boolean'

Expand Down Expand Up @@ -463,6 +464,7 @@ async function init() {
needsPrettier,
needsPlaywright
})
render('config/eslint')
}

if (needsPrettier) {
Expand Down
2 changes: 1 addition & 1 deletion scripts/snapshot.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
Expand Down
3 changes: 3 additions & 0 deletions template/config/eslint/.vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"recommendations": ["dbaeumer.vscode-eslint"]
}
5 changes: 5 additions & 0 deletions template/config/eslint/.vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"editor.codeActionsOnSave": {
"source.fixAll": "explicit"
}
}
6 changes: 0 additions & 6 deletions utils/renderEslint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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')
}
9 changes: 9 additions & 0 deletions utils/renderTemplate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(/^_/, '.'))
Expand Down

0 comments on commit bebba95

Please sign in to comment.