no-unused-vars.js 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. /**
  2. * @fileoverview disallow unused variable definitions of v-for directives or scope attributes.
  3. * @author 薛定谔的猫<hh_2013@foxmail.com>
  4. */
  5. 'use strict'
  6. const utils = require('../utils')
  7. // ------------------------------------------------------------------------------
  8. // Rule Definition
  9. // ------------------------------------------------------------------------------
  10. module.exports = {
  11. meta: {
  12. type: 'suggestion',
  13. docs: {
  14. description: 'disallow unused variable definitions of v-for directives or scope attributes',
  15. category: 'essential',
  16. url: 'https://eslint.vuejs.org/rules/no-unused-vars.html'
  17. },
  18. fixable: null,
  19. schema: []
  20. },
  21. create (context) {
  22. return utils.defineTemplateBodyVisitor(context, {
  23. VElement (node) {
  24. const variables = node.variables
  25. for (
  26. let i = variables.length - 1;
  27. i >= 0 && !variables[i].references.length;
  28. i--
  29. ) {
  30. const variable = variables[i]
  31. context.report({
  32. node: variable.id,
  33. loc: variable.id.loc,
  34. message: `'{{name}}' is defined but never used.`,
  35. data: variable.id
  36. })
  37. }
  38. }
  39. })
  40. }
  41. }