html-indent.js 2.2 KB

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