feat(ui): open eslintrc suggestion

This commit is contained in:
Guillaume Chau
2018-06-11 21:05:32 +02:00
parent d1480e32e8
commit a26669c25f
3 changed files with 43 additions and 2 deletions

View File

@@ -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"
}
}

View File

@@ -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',
@@ -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))
}
}

View File

@@ -461,6 +461,11 @@
"description": "Lints and fixes files",
"noFix": "Do not fix errors"
}
},
"suggestions": {
"open-eslintrc": {
"label": "Open eslintrc"
}
}
},
"pwa": {