html-indent.js 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. /**
  2. * @author Toru Nagashima
  3. * @copyright 2016 Toru Nagashima. All rights reserved.
  4. * See LICENSE file in root directory for full license.
  5. */
  6. 'use strict'
  7. // ------------------------------------------------------------------------------
  8. // Requirements
  9. // ------------------------------------------------------------------------------
  10. const indentCommon = require('../utils/indent-common')
  11. const utils = require('../utils')
  12. // ------------------------------------------------------------------------------
  13. // Rule Definition
  14. // ------------------------------------------------------------------------------
  15. module.exports = {
  16. create (context) {
  17. const tokenStore =
  18. context.parserServices.getTemplateBodyTokenStore &&
  19. context.parserServices.getTemplateBodyTokenStore()
  20. const visitor = indentCommon.defineVisitor(context, tokenStore, { baseIndent: 1 })
  21. return utils.defineTemplateBodyVisitor(context, visitor)
  22. },
  23. meta: {
  24. docs: {
  25. description: 'enforce consistent indentation in `<template>`',
  26. category: 'strongly-recommended',
  27. url: 'https://github.com/vuejs/eslint-plugin-vue/blob/v4.7.1/docs/rules/html-indent.md'
  28. },
  29. fixable: 'whitespace',
  30. schema: [
  31. {
  32. anyOf: [
  33. { type: 'integer', minimum: 1 },
  34. { enum: ['tab'] }
  35. ]
  36. },
  37. {
  38. type: 'object',
  39. properties: {
  40. 'attribute': { type: 'integer', minimum: 0 },
  41. 'closeBracket': { type: 'integer', minimum: 0 },
  42. 'switchCase': { type: 'integer', minimum: 0 },
  43. 'alignAttributesVertically': { type: 'boolean' },
  44. 'ignores': {
  45. type: 'array',
  46. items: {
  47. allOf: [
  48. { type: 'string' },
  49. { not: { type: 'string', pattern: ':exit$' }},
  50. { not: { type: 'string', pattern: '^\\s*$' }}
  51. ]
  52. },
  53. uniqueItems: true,
  54. additionalItems: false
  55. }
  56. },
  57. additionalProperties: false
  58. }
  59. ]
  60. }
  61. }