index.js 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. const configDescriptor = require('./configDescriptor')
  2. const taskDescriptor = require('./taskDescriptor')
  3. const CONFIG = 'org.vue.eslintrc'
  4. const OPEN_ESLINTRC = 'org.vue.eslint.open-eslintrc'
  5. module.exports = api => {
  6. api.describeConfig(configDescriptor.config)
  7. api.describeTask(taskDescriptor.task)
  8. api.onViewOpen(({ view }) => {
  9. if (view.id !== 'vue-project-configurations') {
  10. removeSuggestions()
  11. }
  12. })
  13. api.onConfigRead(({ config }) => {
  14. if (config.id === CONFIG) {
  15. api.addSuggestion({
  16. id: OPEN_ESLINTRC,
  17. type: 'action',
  18. label: 'org.vue.eslint.suggestions.open-eslintrc.label',
  19. handler () {
  20. const file = config.foundFiles.eslint.path
  21. const { launch } = require('@vue/cli-shared-utils')
  22. launch(file)
  23. return {
  24. keep: true
  25. }
  26. }
  27. })
  28. } else {
  29. removeSuggestions()
  30. }
  31. })
  32. function removeSuggestions () {
  33. [OPEN_ESLINTRC].forEach(id => api.removeSuggestion(id))
  34. }
  35. }