html-indent.js 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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. /** @param {RuleContext} context */
  17. create(context) {
  18. const tokenStore =
  19. context.parserServices.getTemplateBodyTokenStore &&
  20. context.parserServices.getTemplateBodyTokenStore()
  21. const visitor = indentCommon.defineVisitor(context, tokenStore, {
  22. baseIndent: 1
  23. })
  24. return utils.defineTemplateBodyVisitor(context, visitor)
  25. },
  26. meta: {
  27. type: 'layout',
  28. docs: {
  29. description: 'enforce consistent indentation in `<template>`',
  30. categories: ['vue3-strongly-recommended', 'strongly-recommended'],
  31. url: 'https://eslint.vuejs.org/rules/html-indent.html'
  32. },
  33. fixable: 'whitespace',
  34. schema: [
  35. {
  36. anyOf: [{ type: 'integer', minimum: 1 }, { enum: ['tab'] }]
  37. },
  38. {
  39. type: 'object',
  40. properties: {
  41. attribute: { type: 'integer', minimum: 0 },
  42. baseIndent: { type: 'integer', minimum: 0 },
  43. closeBracket: {
  44. anyOf: [
  45. { type: 'integer', minimum: 0 },
  46. {
  47. type: 'object',
  48. properties: {
  49. startTag: { type: 'integer', minimum: 0 },
  50. endTag: { type: 'integer', minimum: 0 },
  51. selfClosingTag: { type: 'integer', minimum: 0 }
  52. },
  53. additionalProperties: false
  54. }
  55. ]
  56. },
  57. switchCase: { type: 'integer', minimum: 0 },
  58. alignAttributesVertically: { type: 'boolean' },
  59. ignores: {
  60. type: 'array',
  61. items: {
  62. allOf: [
  63. { type: 'string' },
  64. { not: { type: 'string', pattern: ':exit$' } },
  65. { not: { type: 'string', pattern: '^\\s*$' } }
  66. ]
  67. },
  68. uniqueItems: true,
  69. additionalItems: false
  70. }
  71. },
  72. additionalProperties: false
  73. }
  74. ]
  75. }
  76. }