Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add vscode config for ESLint #467

Merged
merged 3 commits into from
Mar 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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'] ??
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch 👍

(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