Skip to content

Commit a26669c

Browse files
author
Guillaume Chau
committed
feat(ui): open eslintrc suggestion
1 parent d1480e3 commit a26669c

File tree

3 files changed

+43
-2
lines changed

3 files changed

+43
-2
lines changed

packages/@vue/cli-plugin-eslint/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
"babel-eslint": "^8.2.3",
2727
"eslint": "^4.19.1",
2828
"eslint-loader": "^2.0.0",
29-
"eslint-plugin-vue": "^4.5.0"
29+
"eslint-plugin-vue": "^4.5.0",
30+
"launch-editor": "^2.2.1"
3031
}
3132
}

packages/@vue/cli-plugin-eslint/ui.js

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
module.exports = api => {
2+
const CONFIG = 'eslintrc'
3+
24
// Config file
35
api.describeConfig({
4-
id: 'eslintrc',
6+
id: CONFIG,
57
name: 'ESLint configuration',
68
description: 'eslint.config.eslint.description',
79
link: 'https://github.com/vuejs/eslint-plugin-vue',
@@ -226,4 +228,37 @@ module.exports = api => {
226228
if (answers.noFix) args.push('--no-fix')
227229
}
228230
})
231+
232+
const OPEN_ESLINTRC = 'vue-eslint-open-eslintrc'
233+
234+
api.onViewOpen(({ view }) => {
235+
if (view.id !== 'vue-project-configurations') {
236+
removeSuggestions()
237+
}
238+
})
239+
240+
api.onConfigRead(({ config }) => {
241+
if (config.id === CONFIG) {
242+
api.addSuggestion({
243+
id: OPEN_ESLINTRC,
244+
type: 'action',
245+
label: 'eslint.suggestions.open-eslintrc.label',
246+
handler () {
247+
const file = config.foundFiles.eslint.path
248+
console.log('open', file)
249+
const launch = require('launch-editor')
250+
launch(file)
251+
return {
252+
keep: true
253+
}
254+
}
255+
})
256+
} else {
257+
removeSuggestions()
258+
}
259+
})
260+
261+
function removeSuggestions () {
262+
[OPEN_ESLINTRC].forEach(id => api.removeSuggestion(id))
263+
}
229264
}

packages/@vue/cli-ui/locales/en.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -461,6 +461,11 @@
461461
"description": "Lints and fixes files",
462462
"noFix": "Do not fix errors"
463463
}
464+
},
465+
"suggestions": {
466+
"open-eslintrc": {
467+
"label": "Open eslintrc"
468+
}
464469
}
465470
},
466471
"pwa": {

0 commit comments

Comments
 (0)