html-indent.js 2.1 KB

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