html-indent.js 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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. type: 'layout',
  25. docs: {
  26. description: 'enforce consistent indentation in `<template>`',
  27. category: 'strongly-recommended',
  28. url: 'https://eslint.vuejs.org/rules/html-indent.html'
  29. },
  30. fixable: 'whitespace',
  31. schema: [
  32. {
  33. anyOf: [
  34. { type: 'integer', minimum: 1 },
  35. { enum: ['tab'] }
  36. ]
  37. },
  38. {
  39. type: 'object',
  40. properties: {
  41. 'attribute': { type: 'integer', minimum: 0 },
  42. 'baseIndent': { type: 'integer', minimum: 0 },
  43. 'closeBracket': { type: 'integer', minimum: 0 },
  44. 'switchCase': { type: 'integer', minimum: 0 },
  45. 'alignAttributesVertically': { type: 'boolean' },
  46. 'ignores': {
  47. type: 'array',
  48. items: {
  49. allOf: [
  50. { type: 'string' },
  51. { not: { type: 'string', pattern: ':exit$' }},
  52. { not: { type: 'string', pattern: '^\\s*$' }}
  53. ]
  54. },
  55. uniqueItems: true,
  56. additionalItems: false
  57. }
  58. },
  59. additionalProperties: false
  60. }
  61. ]
  62. }
  63. }