html-indent.js 2.3 KB

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