Skip to content

feat: add vscode config for ESLint #467

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

Merged
merged 3 commits into from
Mar 19, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
5 changes: 4 additions & 1 deletion scripts/snapshot.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,12 @@ const featureFlags = [
'vitest',
'cypress',
'playwright',
'nightwatch'
'nightwatch',
'eslint',
'eslint-with-prettier'
]
const featureFlagsDenylist = [
['eslint', '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.

I think the changes to this file should be removed, as this is going to generate a lot of new snapshots (that's why they aren't generated at the moment).

Copy link
Contributor Author

@yoshi-pi yoshi-pi Mar 15, 2024

Choose a reason for hiding this comment

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

Moved eslint and eslint-with-prettier as separate features based on #460 (comment).

['cypress', 'playwright'],
['playwright', 'nightwatch'],
['cypress', 'nightwatch'],
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