processor.js 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. /**
  2. * @author Toru Nagashima <https://github.com/mysticatea>
  3. */
  4. 'use strict'
  5. module.exports = {
  6. preprocess (code) {
  7. return [code]
  8. },
  9. postprocess (messages) {
  10. const state = {
  11. block: {
  12. disableAll: false,
  13. disableRules: new Set()
  14. },
  15. line: {
  16. disableAll: false,
  17. disableRules: new Set()
  18. }
  19. }
  20. // Filter messages which are in disabled area.
  21. return messages[0].filter(message => {
  22. if (message.ruleId === 'vue/comment-directive') {
  23. const rules = message.message.split(' ')
  24. const type = rules.shift()
  25. const group = rules.shift()
  26. switch (type) {
  27. case '--':
  28. state[group].disableAll = true
  29. break
  30. case '++':
  31. state[group].disableAll = false
  32. break
  33. case '-':
  34. for (const rule of rules) {
  35. state[group].disableRules.add(rule)
  36. }
  37. break
  38. case '+':
  39. for (const rule of rules) {
  40. state[group].disableRules.delete(rule)
  41. }
  42. break
  43. case 'clear':
  44. state.block.disableAll = false
  45. state.block.disableRules.clear()
  46. state.line.disableAll = false
  47. state.line.disableRules.clear()
  48. break
  49. }
  50. return false
  51. } else {
  52. return !(
  53. state.block.disableAll ||
  54. state.line.disableAll ||
  55. state.block.disableRules.has(message.ruleId) ||
  56. state.line.disableRules.has(message.ruleId)
  57. )
  58. }
  59. })
  60. },
  61. supportsAutofix: true
  62. }