Skip to content

Commit

Permalink
feat(ui): open eslintrc suggestion
Browse files Browse the repository at this point in the history
  • Loading branch information
Guillaume Chau committed Jun 11, 2018
1 parent d1480e3 commit a26669c
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 2 deletions.
3 changes: 2 additions & 1 deletion packages/@vue/cli-plugin-eslint/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"babel-eslint": "^8.2.3",
"eslint": "^4.19.1",
"eslint-loader": "^2.0.0",
"eslint-plugin-vue": "^4.5.0"
"eslint-plugin-vue": "^4.5.0",
"launch-editor": "^2.2.1"
}
}
37 changes: 36 additions & 1 deletion packages/@vue/cli-plugin-eslint/ui.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
module.exports = api => {
const CONFIG = 'eslintrc'

// Config file
api.describeConfig({
id: 'eslintrc',
id: CONFIG,
name: 'ESLint configuration',
description: 'eslint.config.eslint.description',
link: 'https://github.com/vuejs/eslint-plugin-vue',
Expand Down Expand Up @@ -226,4 +228,37 @@ module.exports = api => {
if (answers.noFix) args.push('--no-fix')
}
})

const OPEN_ESLINTRC = 'vue-eslint-open-eslintrc'

api.onViewOpen(({ view }) => {
if (view.id !== 'vue-project-configurations') {
removeSuggestions()
}
})

api.onConfigRead(({ config }) => {
if (config.id === CONFIG) {
api.addSuggestion({
id: OPEN_ESLINTRC,
type: 'action',
label: 'eslint.suggestions.open-eslintrc.label',
handler () {
const file = config.foundFiles.eslint.path
console.log('open', file)
const launch = require('launch-editor')
launch(file)
return {
keep: true
}
}
})
} else {
removeSuggestions()
}
})

function removeSuggestions () {
[OPEN_ESLINTRC].forEach(id => api.removeSuggestion(id))
}
}
5 changes: 5 additions & 0 deletions packages/@vue/cli-ui/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -461,6 +461,11 @@
"description": "Lints and fixes files",
"noFix": "Do not fix errors"
}
},
"suggestions": {
"open-eslintrc": {
"label": "Open eslintrc"
}
}
},
"pwa": {
Expand Down

0 comments on commit a26669c

Please sign in to comment.