@herb-tools/linter 0.4.1 → 0.4.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (147) hide show
  1. package/README.md +16 -4
  2. package/dist/herb-lint.js +557 -122
  3. package/dist/herb-lint.js.map +1 -1
  4. package/dist/index.cjs +454 -67
  5. package/dist/index.cjs.map +1 -1
  6. package/dist/index.js +448 -69
  7. package/dist/index.js.map +1 -1
  8. package/dist/package.json +4 -4
  9. package/dist/src/cli/file-processor.js +2 -4
  10. package/dist/src/cli/file-processor.js.map +1 -1
  11. package/dist/src/default-rules.js +8 -0
  12. package/dist/src/default-rules.js.map +1 -1
  13. package/dist/src/linter.js +37 -6
  14. package/dist/src/linter.js.map +1 -1
  15. package/dist/src/rules/erb-no-empty-tags.js +4 -3
  16. package/dist/src/rules/erb-no-empty-tags.js.map +1 -1
  17. package/dist/src/rules/erb-no-output-control-flow.js +4 -3
  18. package/dist/src/rules/erb-no-output-control-flow.js.map +1 -1
  19. package/dist/src/rules/erb-prefer-image-tag-helper.js +93 -0
  20. package/dist/src/rules/erb-prefer-image-tag-helper.js.map +1 -0
  21. package/dist/src/rules/erb-require-whitespace-inside-tags.js +22 -5
  22. package/dist/src/rules/erb-require-whitespace-inside-tags.js.map +1 -1
  23. package/dist/src/rules/erb-requires-trailing-newline.js +22 -0
  24. package/dist/src/rules/erb-requires-trailing-newline.js.map +1 -0
  25. package/dist/src/rules/html-anchor-require-href.js +4 -3
  26. package/dist/src/rules/html-anchor-require-href.js.map +1 -1
  27. package/dist/src/rules/html-aria-attribute-must-be-valid.js +4 -3
  28. package/dist/src/rules/html-aria-attribute-must-be-valid.js.map +1 -1
  29. package/dist/src/rules/html-aria-level-must-be-valid.js +27 -0
  30. package/dist/src/rules/html-aria-level-must-be-valid.js.map +1 -0
  31. package/dist/src/rules/html-aria-role-heading-requires-level.js +4 -3
  32. package/dist/src/rules/html-aria-role-heading-requires-level.js.map +1 -1
  33. package/dist/src/rules/html-aria-role-must-be-valid.js +4 -3
  34. package/dist/src/rules/html-aria-role-must-be-valid.js.map +1 -1
  35. package/dist/src/rules/html-attribute-double-quotes.js +4 -3
  36. package/dist/src/rules/html-attribute-double-quotes.js.map +1 -1
  37. package/dist/src/rules/html-attribute-values-require-quotes.js +4 -3
  38. package/dist/src/rules/html-attribute-values-require-quotes.js.map +1 -1
  39. package/dist/src/rules/html-boolean-attributes-no-value.js +4 -3
  40. package/dist/src/rules/html-boolean-attributes-no-value.js.map +1 -1
  41. package/dist/src/rules/html-img-require-alt.js +4 -3
  42. package/dist/src/rules/html-img-require-alt.js.map +1 -1
  43. package/dist/src/rules/html-no-block-inside-inline.js +4 -3
  44. package/dist/src/rules/html-no-block-inside-inline.js.map +1 -1
  45. package/dist/src/rules/html-no-duplicate-attributes.js +4 -3
  46. package/dist/src/rules/html-no-duplicate-attributes.js.map +1 -1
  47. package/dist/src/rules/html-no-duplicate-ids.js +4 -3
  48. package/dist/src/rules/html-no-duplicate-ids.js.map +1 -1
  49. package/dist/src/rules/html-no-empty-headings.js +4 -3
  50. package/dist/src/rules/html-no-empty-headings.js.map +1 -1
  51. package/dist/src/rules/html-no-nested-links.js +4 -3
  52. package/dist/src/rules/html-no-nested-links.js.map +1 -1
  53. package/dist/src/rules/html-tag-name-lowercase.js +21 -11
  54. package/dist/src/rules/html-tag-name-lowercase.js.map +1 -1
  55. package/dist/src/rules/index.js +4 -0
  56. package/dist/src/rules/index.js.map +1 -1
  57. package/dist/src/rules/rule-utils.js +168 -2
  58. package/dist/src/rules/rule-utils.js.map +1 -1
  59. package/dist/src/rules/svg-tag-name-capitalization.js +58 -0
  60. package/dist/src/rules/svg-tag-name-capitalization.js.map +1 -0
  61. package/dist/src/types.js +15 -1
  62. package/dist/src/types.js.map +1 -1
  63. package/dist/tsconfig.tsbuildinfo +1 -1
  64. package/dist/types/linter.d.ts +20 -5
  65. package/dist/types/rules/erb-no-empty-tags.d.ts +4 -3
  66. package/dist/types/rules/erb-no-output-control-flow.d.ts +4 -3
  67. package/dist/types/rules/erb-prefer-image-tag-helper.d.ts +7 -0
  68. package/dist/types/rules/erb-require-whitespace-inside-tags.d.ts +4 -3
  69. package/dist/types/rules/erb-requires-trailing-newline.d.ts +6 -0
  70. package/dist/types/rules/html-anchor-require-href.d.ts +4 -3
  71. package/dist/types/rules/html-aria-attribute-must-be-valid.d.ts +4 -3
  72. package/dist/types/rules/html-aria-level-must-be-valid.d.ts +7 -0
  73. package/dist/types/rules/html-aria-role-heading-requires-level.d.ts +4 -3
  74. package/dist/types/rules/html-aria-role-must-be-valid.d.ts +4 -3
  75. package/dist/types/rules/html-attribute-double-quotes.d.ts +4 -3
  76. package/dist/types/rules/html-attribute-values-require-quotes.d.ts +4 -3
  77. package/dist/types/rules/html-boolean-attributes-no-value.d.ts +4 -3
  78. package/dist/types/rules/html-img-require-alt.d.ts +4 -3
  79. package/dist/types/rules/html-no-block-inside-inline.d.ts +4 -3
  80. package/dist/types/rules/html-no-duplicate-attributes.d.ts +4 -3
  81. package/dist/types/rules/html-no-duplicate-ids.d.ts +4 -3
  82. package/dist/types/rules/html-no-empty-headings.d.ts +4 -3
  83. package/dist/types/rules/html-no-nested-links.d.ts +4 -3
  84. package/dist/types/rules/html-tag-name-lowercase.d.ts +4 -3
  85. package/dist/types/rules/index.d.ts +4 -0
  86. package/dist/types/rules/rule-utils.d.ts +82 -4
  87. package/dist/types/rules/svg-tag-name-capitalization.d.ts +7 -0
  88. package/dist/types/src/linter.d.ts +20 -5
  89. package/dist/types/src/rules/erb-no-empty-tags.d.ts +4 -3
  90. package/dist/types/src/rules/erb-no-output-control-flow.d.ts +4 -3
  91. package/dist/types/src/rules/erb-prefer-image-tag-helper.d.ts +7 -0
  92. package/dist/types/src/rules/erb-require-whitespace-inside-tags.d.ts +4 -3
  93. package/dist/types/src/rules/erb-requires-trailing-newline.d.ts +6 -0
  94. package/dist/types/src/rules/html-anchor-require-href.d.ts +4 -3
  95. package/dist/types/src/rules/html-aria-attribute-must-be-valid.d.ts +4 -3
  96. package/dist/types/src/rules/html-aria-level-must-be-valid.d.ts +7 -0
  97. package/dist/types/src/rules/html-aria-role-heading-requires-level.d.ts +4 -3
  98. package/dist/types/src/rules/html-aria-role-must-be-valid.d.ts +4 -3
  99. package/dist/types/src/rules/html-attribute-double-quotes.d.ts +4 -3
  100. package/dist/types/src/rules/html-attribute-values-require-quotes.d.ts +4 -3
  101. package/dist/types/src/rules/html-boolean-attributes-no-value.d.ts +4 -3
  102. package/dist/types/src/rules/html-img-require-alt.d.ts +4 -3
  103. package/dist/types/src/rules/html-no-block-inside-inline.d.ts +4 -3
  104. package/dist/types/src/rules/html-no-duplicate-attributes.d.ts +4 -3
  105. package/dist/types/src/rules/html-no-duplicate-ids.d.ts +4 -3
  106. package/dist/types/src/rules/html-no-empty-headings.d.ts +4 -3
  107. package/dist/types/src/rules/html-no-nested-links.d.ts +4 -3
  108. package/dist/types/src/rules/html-tag-name-lowercase.d.ts +4 -3
  109. package/dist/types/src/rules/index.d.ts +4 -0
  110. package/dist/types/src/rules/rule-utils.d.ts +82 -4
  111. package/dist/types/src/rules/svg-tag-name-capitalization.d.ts +7 -0
  112. package/dist/types/src/types.d.ts +49 -6
  113. package/dist/types/types.d.ts +49 -6
  114. package/docs/rules/README.md +5 -1
  115. package/docs/rules/erb-prefer-image-tag-helper.md +65 -0
  116. package/docs/rules/erb-requires-trailing-newline.md +37 -0
  117. package/docs/rules/html-anchor-require-href.md +1 -1
  118. package/docs/rules/html-aria-level-must-be-valid.md +37 -0
  119. package/docs/rules/svg-tag-name-capitalization.md +57 -0
  120. package/package.json +4 -4
  121. package/src/cli/file-processor.ts +2 -4
  122. package/src/default-rules.ts +8 -0
  123. package/src/linter.ts +42 -8
  124. package/src/rules/erb-no-empty-tags.ts +5 -4
  125. package/src/rules/erb-no-output-control-flow.ts +6 -4
  126. package/src/rules/erb-prefer-image-tag-helper.ts +124 -0
  127. package/src/rules/erb-require-whitespace-inside-tags.ts +38 -6
  128. package/src/rules/erb-requires-trailing-newline.ts +27 -0
  129. package/src/rules/html-anchor-require-href.ts +5 -4
  130. package/src/rules/html-aria-attribute-must-be-valid.ts +5 -5
  131. package/src/rules/html-aria-level-must-be-valid.ts +42 -0
  132. package/src/rules/html-aria-role-heading-requires-level.ts +5 -4
  133. package/src/rules/html-aria-role-must-be-valid.ts +5 -4
  134. package/src/rules/html-attribute-double-quotes.ts +5 -4
  135. package/src/rules/html-attribute-values-require-quotes.ts +5 -4
  136. package/src/rules/html-boolean-attributes-no-value.ts +5 -4
  137. package/src/rules/html-img-require-alt.ts +5 -4
  138. package/src/rules/html-no-block-inside-inline.ts +5 -4
  139. package/src/rules/html-no-duplicate-attributes.ts +5 -4
  140. package/src/rules/html-no-duplicate-ids.ts +5 -5
  141. package/src/rules/html-no-empty-headings.ts +5 -4
  142. package/src/rules/html-no-nested-links.ts +5 -4
  143. package/src/rules/html-tag-name-lowercase.ts +29 -13
  144. package/src/rules/index.ts +4 -0
  145. package/src/rules/rule-utils.ts +203 -4
  146. package/src/rules/svg-tag-name-capitalization.ts +74 -0
  147. package/src/types.ts +60 -6
@@ -1,6 +1,7 @@
1
1
  import type { Node, Token } from "@herb-tools/core"
2
2
  import { isERBNode } from "@herb-tools/core";
3
- import type { LintOffense, Rule } from "../types.js"
3
+ import { ParserRule } from "../types.js"
4
+ import type { LintOffense, LintContext } from "../types.js"
4
5
  import { BaseRuleVisitor } from "./rule-utils.js"
5
6
 
6
7
  class RequireWhitespaceInsideTags extends BaseRuleVisitor {
@@ -24,14 +25,43 @@ class RequireWhitespaceInsideTags extends BaseRuleVisitor {
24
25
 
25
26
  const value = content.value
26
27
 
27
- this.checkOpenTagWhitespace(openTag, value)
28
- this.checkCloseTagWhitespace(closeTag, value)
28
+ if (openTag.value === "<%#") {
29
+ this.checkCommentTagWhitespace(openTag, closeTag, value)
30
+ } else {
31
+ this.checkOpenTagWhitespace(openTag, value)
32
+ this.checkCloseTagWhitespace(closeTag, value)
33
+ }
34
+ }
35
+
36
+ private checkCommentTagWhitespace(openTag: Token, closeTag: Token, content: string): void {
37
+ if (!content.startsWith(" ") && !content.startsWith("\n") && !content.startsWith("=")) {
38
+ this.addOffense(
39
+ `Add whitespace after \`${openTag.value}\`.`,
40
+ openTag.location,
41
+ "error"
42
+ )
43
+ } else if (content.startsWith("=") && content.length > 1 && !content[1].match(/\s/)) {
44
+ this.addOffense(
45
+ `Add whitespace after \`<%#=\`.`,
46
+ openTag.location,
47
+ "error"
48
+ )
49
+ }
50
+
51
+ if (!content.endsWith(" ") && !content.endsWith("\n")) {
52
+ this.addOffense(
53
+ `Add whitespace before \`${closeTag.value}\`.`,
54
+ closeTag.location,
55
+ "error"
56
+ )
57
+ }
29
58
  }
30
59
 
31
60
  private checkOpenTagWhitespace(openTag: Token, content:string):void {
32
61
  if (content.startsWith(" ") || content.startsWith("\n")) {
33
62
  return
34
63
  }
64
+
35
65
  this.addOffense(
36
66
  `Add whitespace after \`${openTag.value}\`.`,
37
67
  openTag.location,
@@ -43,6 +73,7 @@ class RequireWhitespaceInsideTags extends BaseRuleVisitor {
43
73
  if (content.endsWith(" ") || content.endsWith("\n")) {
44
74
  return
45
75
  }
76
+
46
77
  this.addOffense(
47
78
  `Add whitespace before \`${closeTag.value}\`.`,
48
79
  closeTag.location,
@@ -51,10 +82,11 @@ class RequireWhitespaceInsideTags extends BaseRuleVisitor {
51
82
  }
52
83
  }
53
84
 
54
- export class ERBRequireWhitespaceRule implements Rule {
85
+ export class ERBRequireWhitespaceRule extends ParserRule {
55
86
  name = "erb-require-whitespace-inside-tags"
56
- check(node: Node): LintOffense[] {
57
- const visitor = new RequireWhitespaceInsideTags(this.name)
87
+
88
+ check(node: Node, context?: Partial<LintContext>): LintOffense[] {
89
+ const visitor = new RequireWhitespaceInsideTags(this.name, context)
58
90
  visitor.visit(node)
59
91
  return visitor.offenses
60
92
  }
@@ -0,0 +1,27 @@
1
+ import { BaseSourceRuleVisitor, createEndOfFileLocation } from "./rule-utils.js"
2
+ import { SourceRule } from "../types.js"
3
+ import type { LintOffense, LintContext } from "../types.js"
4
+
5
+ class ERBRequiresTrailingNewlineVisitor extends BaseSourceRuleVisitor {
6
+ protected visitSource(source: string): void {
7
+ if (source.length === 0) return
8
+ if (source.endsWith('\n')) return
9
+ if (!this.context.fileName) return
10
+
11
+ this.addOffense(
12
+ "File must end with trailing newline",
13
+ createEndOfFileLocation(source),
14
+ "error"
15
+ )
16
+ }
17
+ }
18
+
19
+ export class ERBRequiresTrailingNewlineRule extends SourceRule {
20
+ name = "erb-requires-trailing-newline"
21
+
22
+ check(source: string, context?: Partial<LintContext>): LintOffense[] {
23
+ const visitor = new ERBRequiresTrailingNewlineVisitor(this.name, context)
24
+ visitor.visit(source)
25
+ return visitor.offenses
26
+ }
27
+ }
@@ -1,6 +1,7 @@
1
1
  import { BaseRuleVisitor, getTagName, hasAttribute } from "./rule-utils.js"
2
2
 
3
- import { Rule, LintOffense } from "../types.js"
3
+ import { ParserRule } from "../types.js"
4
+ import type { LintOffense, LintContext } from "../types.js"
4
5
  import type { HTMLOpenTagNode, Node } from "@herb-tools/core"
5
6
 
6
7
  class AnchorRechireHrefVisitor extends BaseRuleVisitor {
@@ -26,11 +27,11 @@ class AnchorRechireHrefVisitor extends BaseRuleVisitor {
26
27
  }
27
28
  }
28
29
 
29
- export class HTMLAnchorRequireHrefRule implements Rule {
30
+ export class HTMLAnchorRequireHrefRule extends ParserRule {
30
31
  name = "html-anchor-require-href"
31
32
 
32
- check(node: Node): LintOffense[] {
33
- const visitor = new AnchorRechireHrefVisitor(this.name)
33
+ check(node: Node, context?: Partial<LintContext>): LintOffense[] {
34
+ const visitor = new AnchorRechireHrefVisitor(this.name, context)
34
35
 
35
36
  visitor.visit(node)
36
37
 
@@ -2,8 +2,8 @@ import {
2
2
  ARIA_ATTRIBUTES,
3
3
  AttributeVisitorMixin,
4
4
  } from "./rule-utils.js";
5
-
6
- import type { LintOffense, Rule } from "../types.js";
5
+ import { ParserRule } from "../types.js";
6
+ import type { LintOffense, LintContext } from "../types.js";
7
7
  import type {
8
8
  HTMLAttributeNode,
9
9
  HTMLOpenTagNode,
@@ -31,11 +31,11 @@ class AriaAttributeMustBeValid extends AttributeVisitorMixin {
31
31
  }
32
32
  }
33
33
 
34
- export class HTMLAriaAttributeMustBeValid implements Rule {
34
+ export class HTMLAriaAttributeMustBeValid extends ParserRule {
35
35
  name = "html-aria-attribute-must-be-valid";
36
36
 
37
- check(node: Node): LintOffense[] {
38
- const visitor = new AriaAttributeMustBeValid(this.name);
37
+ check(node: Node, context?: Partial<LintContext>): LintOffense[] {
38
+ const visitor = new AriaAttributeMustBeValid(this.name, context);
39
39
  visitor.visit(node);
40
40
  return visitor.offenses;
41
41
  }
@@ -0,0 +1,42 @@
1
+ import { AttributeVisitorMixin } from "./rule-utils.js"
2
+ import { ParserRule } from "../types.js"
3
+
4
+ import type { LintOffense, LintContext } from "../types.js"
5
+ import type { Node, HTMLAttributeNode, HTMLOpenTagNode, HTMLSelfCloseTagNode } from "@herb-tools/core"
6
+
7
+ class HTMLAriaLevelMustBeValidVisitor extends AttributeVisitorMixin {
8
+ protected checkAttribute(attributeName: string, attributeValue: string | null, attributeNode: HTMLAttributeNode, _parentNode: HTMLOpenTagNode | HTMLSelfCloseTagNode): void {
9
+ if (attributeName !== "aria-level") return
10
+ if (attributeValue !== null && attributeValue.includes("<%")) return
11
+
12
+ if (attributeValue === null || attributeValue === "") {
13
+ this.addOffense(
14
+ `The \`aria-level\` attribute must be an integer between 1 and 6, got an empty value.`,
15
+ attributeNode.location,
16
+ )
17
+
18
+ return
19
+ }
20
+
21
+ const number = parseInt(attributeValue)
22
+
23
+ if (isNaN(number) || number < 1 || number > 6 || attributeValue !== number.toString()) {
24
+ this.addOffense(
25
+ `The \`aria-level\` attribute must be an integer between 1 and 6, got \`${attributeValue}\`.`,
26
+ attributeNode.location,
27
+ )
28
+ }
29
+ }
30
+ }
31
+
32
+ export class HTMLAriaLevelMustBeValidRule extends ParserRule {
33
+ name = "html-aria-level-must-be-valid"
34
+
35
+ check(node: Node, context?: Partial<LintContext>): LintOffense[] {
36
+ const visitor = new HTMLAriaLevelMustBeValidVisitor(this.name, context)
37
+
38
+ visitor.visit(node)
39
+
40
+ return visitor.offenses
41
+ }
42
+ }
@@ -1,6 +1,7 @@
1
1
  import { AttributeVisitorMixin, getAttributeName, getAttributes } from "./rule-utils.js"
2
2
 
3
- import type { Rule, LintOffense } from "../types.js"
3
+ import { ParserRule } from "../types.js"
4
+ import type { LintOffense, LintContext } from "../types.js"
4
5
  import type { Node, HTMLAttributeNode, HTMLOpenTagNode, HTMLSelfCloseTagNode } from "@herb-tools/core"
5
6
 
6
7
  class AriaRoleHeadingRequiresLevel extends AttributeVisitorMixin {
@@ -33,11 +34,11 @@ class AriaRoleHeadingRequiresLevel extends AttributeVisitorMixin {
33
34
  }
34
35
  }
35
36
 
36
- export class HTMLAriaRoleHeadingRequiresLevelRule implements Rule {
37
+ export class HTMLAriaRoleHeadingRequiresLevelRule extends ParserRule {
37
38
  name = "html-aria-role-heading-requires-level"
38
39
 
39
- check(node: Node): LintOffense[] {
40
- const visitor = new AriaRoleHeadingRequiresLevel(this.name)
40
+ check(node: Node, context?: Partial<LintContext>): LintOffense[] {
41
+ const visitor = new AriaRoleHeadingRequiresLevel(this.name, context)
41
42
  visitor.visit(node)
42
43
  return visitor.offenses
43
44
  }
@@ -1,6 +1,7 @@
1
1
  import { AttributeVisitorMixin, VALID_ARIA_ROLES } from "./rule-utils.js"
2
2
 
3
- import type { Rule, LintOffense } from "../types.js"
3
+ import { ParserRule } from "../types.js"
4
+ import type { LintOffense, LintContext } from "../types.js"
4
5
  import type { Node, HTMLAttributeNode } from "@herb-tools/core"
5
6
 
6
7
  class AriaRoleMustBeValid extends AttributeVisitorMixin {
@@ -17,11 +18,11 @@ class AriaRoleMustBeValid extends AttributeVisitorMixin {
17
18
  }
18
19
  }
19
20
 
20
- export class HTMLAriaRoleMustBeValidRule implements Rule {
21
+ export class HTMLAriaRoleMustBeValidRule extends ParserRule {
21
22
  name = "html-aria-role-must-be-valid"
22
23
 
23
- check(node: Node): LintOffense[] {
24
- const visitor = new AriaRoleMustBeValid(this.name)
24
+ check(node: Node, context?: Partial<LintContext>): LintOffense[] {
25
+ const visitor = new AriaRoleMustBeValid(this.name, context)
25
26
 
26
27
  visitor.visit(node)
27
28
 
@@ -1,6 +1,7 @@
1
1
  import { AttributeVisitorMixin, getAttributeValueQuoteType, hasAttributeValue } from "./rule-utils.js"
2
2
 
3
- import type { Rule, LintOffense } from "../types.js"
3
+ import { ParserRule } from "../types.js"
4
+ import type { LintOffense, LintContext } from "../types.js"
4
5
  import type { Node, HTMLAttributeNode } from "@herb-tools/core"
5
6
 
6
7
  class AttributeDoubleQuotesVisitor extends AttributeVisitorMixin {
@@ -17,11 +18,11 @@ class AttributeDoubleQuotesVisitor extends AttributeVisitorMixin {
17
18
  }
18
19
  }
19
20
 
20
- export class HTMLAttributeDoubleQuotesRule implements Rule {
21
+ export class HTMLAttributeDoubleQuotesRule extends ParserRule {
21
22
  name = "html-attribute-double-quotes"
22
23
 
23
- check(node: Node): LintOffense[] {
24
- const visitor = new AttributeDoubleQuotesVisitor(this.name)
24
+ check(node: Node, context?: Partial<LintContext>): LintOffense[] {
25
+ const visitor = new AttributeDoubleQuotesVisitor(this.name, context)
25
26
  visitor.visit(node)
26
27
  return visitor.offenses
27
28
  }
@@ -1,6 +1,7 @@
1
1
  import { AttributeVisitorMixin } from "./rule-utils.js"
2
2
 
3
- import type { Rule, LintOffense } from "../types.js"
3
+ import { ParserRule } from "../types.js"
4
+ import type { LintOffense, LintContext } from "../types.js"
4
5
  import type { HTMLAttributeNode, HTMLAttributeValueNode, Node } from "@herb-tools/core"
5
6
 
6
7
  class AttributeValuesRequireQuotesVisitor extends AttributeVisitorMixin {
@@ -19,11 +20,11 @@ class AttributeValuesRequireQuotesVisitor extends AttributeVisitorMixin {
19
20
  }
20
21
  }
21
22
 
22
- export class HTMLAttributeValuesRequireQuotesRule implements Rule {
23
+ export class HTMLAttributeValuesRequireQuotesRule extends ParserRule {
23
24
  name = "html-attribute-values-require-quotes"
24
25
 
25
- check(node: Node): LintOffense[] {
26
- const visitor = new AttributeValuesRequireQuotesVisitor(this.name)
26
+ check(node: Node, context?: Partial<LintContext>): LintOffense[] {
27
+ const visitor = new AttributeValuesRequireQuotesVisitor(this.name, context)
27
28
  visitor.visit(node)
28
29
  return visitor.offenses
29
30
  }
@@ -1,6 +1,7 @@
1
1
  import { AttributeVisitorMixin, isBooleanAttribute, hasAttributeValue } from "./rule-utils.js"
2
2
 
3
- import type { Rule, LintOffense } from "../types.js"
3
+ import { ParserRule } from "../types.js"
4
+ import type { LintOffense, LintContext } from "../types.js"
4
5
  import type { HTMLAttributeNode, Node } from "@herb-tools/core"
5
6
 
6
7
  class BooleanAttributesNoValueVisitor extends AttributeVisitorMixin {
@@ -16,11 +17,11 @@ class BooleanAttributesNoValueVisitor extends AttributeVisitorMixin {
16
17
  }
17
18
  }
18
19
 
19
- export class HTMLBooleanAttributesNoValueRule implements Rule {
20
+ export class HTMLBooleanAttributesNoValueRule extends ParserRule {
20
21
  name = "html-boolean-attributes-no-value"
21
22
 
22
- check(node: Node): LintOffense[] {
23
- const visitor = new BooleanAttributesNoValueVisitor(this.name)
23
+ check(node: Node, context?: Partial<LintContext>): LintOffense[] {
24
+ const visitor = new BooleanAttributesNoValueVisitor(this.name, context)
24
25
  visitor.visit(node)
25
26
  return visitor.offenses
26
27
  }
@@ -1,6 +1,7 @@
1
1
  import { BaseRuleVisitor, getTagName, hasAttribute } from "./rule-utils.js"
2
2
 
3
- import type { Rule, LintOffense } from "../types.js"
3
+ import { ParserRule } from "../types.js"
4
+ import type { LintOffense, LintContext } from "../types.js"
4
5
  import type { HTMLOpenTagNode, HTMLSelfCloseTagNode, Node } from "@herb-tools/core"
5
6
 
6
7
  class ImgRequireAltVisitor extends BaseRuleVisitor {
@@ -31,11 +32,11 @@ class ImgRequireAltVisitor extends BaseRuleVisitor {
31
32
  }
32
33
  }
33
34
 
34
- export class HTMLImgRequireAltRule implements Rule {
35
+ export class HTMLImgRequireAltRule extends ParserRule {
35
36
  name = "html-img-require-alt"
36
37
 
37
- check(node: Node): LintOffense[] {
38
- const visitor = new ImgRequireAltVisitor(this.name)
38
+ check(node: Node, context?: Partial<LintContext>): LintOffense[] {
39
+ const visitor = new ImgRequireAltVisitor(this.name, context)
39
40
  visitor.visit(node)
40
41
  return visitor.offenses
41
42
  }
@@ -1,6 +1,7 @@
1
1
  import { BaseRuleVisitor, isInlineElement, isBlockElement } from "./rule-utils.js"
2
2
 
3
- import type { Rule, LintOffense } from "../types.js"
3
+ import { ParserRule } from "../types.js"
4
+ import type { LintOffense, LintContext } from "../types.js"
4
5
  import type { HTMLOpenTagNode, HTMLElementNode, Node } from "@herb-tools/core"
5
6
 
6
7
  class BlockInsideInlineVisitor extends BaseRuleVisitor {
@@ -73,11 +74,11 @@ class BlockInsideInlineVisitor extends BaseRuleVisitor {
73
74
  }
74
75
  }
75
76
 
76
- export class HTMLNoBlockInsideInlineRule implements Rule {
77
+ export class HTMLNoBlockInsideInlineRule extends ParserRule {
77
78
  name = "html-no-block-inside-inline"
78
79
 
79
- check(node: Node): LintOffense[] {
80
- const visitor = new BlockInsideInlineVisitor(this.name)
80
+ check(node: Node, context?: Partial<LintContext>): LintOffense[] {
81
+ const visitor = new BlockInsideInlineVisitor(this.name, context)
81
82
  visitor.visit(node)
82
83
  return visitor.offenses
83
84
  }
@@ -1,6 +1,7 @@
1
1
  import { BaseRuleVisitor, forEachAttribute } from "./rule-utils.js"
2
2
 
3
- import type { Rule, LintOffense } from "../types.js"
3
+ import { ParserRule } from "../types.js"
4
+ import type { LintOffense, LintContext } from "../types.js"
4
5
  import type { HTMLOpenTagNode, HTMLSelfCloseTagNode, HTMLAttributeNameNode, Node } from "@herb-tools/core"
5
6
 
6
7
  class NoDuplicateAttributesVisitor extends BaseRuleVisitor {
@@ -48,11 +49,11 @@ class NoDuplicateAttributesVisitor extends BaseRuleVisitor {
48
49
  }
49
50
  }
50
51
 
51
- export class HTMLNoDuplicateAttributesRule implements Rule {
52
+ export class HTMLNoDuplicateAttributesRule extends ParserRule {
52
53
  name = "html-no-duplicate-attributes"
53
54
 
54
- check(node: Node): LintOffense[] {
55
- const visitor = new NoDuplicateAttributesVisitor(this.name)
55
+ check(node: Node, context?: Partial<LintContext>): LintOffense[] {
56
+ const visitor = new NoDuplicateAttributesVisitor(this.name, context)
56
57
  visitor.visit(node)
57
58
  return visitor.offenses
58
59
  }
@@ -1,7 +1,7 @@
1
1
  import { AttributeVisitorMixin } from "./rule-utils"
2
-
2
+ import { ParserRule } from "../types"
3
3
  import type { Node } from "@herb-tools/core"
4
- import type { LintOffense, Rule } from "../types"
4
+ import type { LintOffense, LintContext } from "../types"
5
5
 
6
6
  class NoDuplicateIdsVisitor extends AttributeVisitorMixin {
7
7
  private documentIds: Set<string> = new Set<string>()
@@ -26,11 +26,11 @@ class NoDuplicateIdsVisitor extends AttributeVisitorMixin {
26
26
  }
27
27
  }
28
28
 
29
- export class HTMLNoDuplicateIdsRule implements Rule {
29
+ export class HTMLNoDuplicateIdsRule extends ParserRule {
30
30
  name = "html-no-duplicate-ids"
31
31
 
32
- check(node: Node): LintOffense[] {
33
- const visitor = new NoDuplicateIdsVisitor(this.name)
32
+ check(node: Node, context?: Partial<LintContext>): LintOffense[] {
33
+ const visitor = new NoDuplicateIdsVisitor(this.name, context)
34
34
 
35
35
  visitor.visit(node)
36
36
 
@@ -1,6 +1,7 @@
1
1
  import { BaseRuleVisitor, getTagName, getAttributes, findAttributeByName, getAttributeValue, HEADING_TAGS } from "./rule-utils.js"
2
2
 
3
- import type { Rule, LintOffense } from "../types.js"
3
+ import { ParserRule } from "../types.js"
4
+ import type { LintOffense, LintContext } from "../types.js"
4
5
  import type { HTMLElementNode, HTMLOpenTagNode, HTMLSelfCloseTagNode, Node, LiteralNode, HTMLTextNode } from "@herb-tools/core"
5
6
 
6
7
  class NoEmptyHeadingsVisitor extends BaseRuleVisitor {
@@ -174,11 +175,11 @@ class NoEmptyHeadingsVisitor extends BaseRuleVisitor {
174
175
  }
175
176
  }
176
177
 
177
- export class HTMLNoEmptyHeadingsRule implements Rule {
178
+ export class HTMLNoEmptyHeadingsRule extends ParserRule {
178
179
  name = "html-no-empty-headings"
179
180
 
180
- check(node: Node): LintOffense[] {
181
- const visitor = new NoEmptyHeadingsVisitor(this.name)
181
+ check(node: Node, context?: Partial<LintContext>): LintOffense[] {
182
+ const visitor = new NoEmptyHeadingsVisitor(this.name, context)
182
183
  visitor.visit(node)
183
184
  return visitor.offenses
184
185
  }
@@ -1,6 +1,7 @@
1
1
  import { BaseRuleVisitor, getTagName } from "./rule-utils.js"
2
2
 
3
- import type { Rule, LintOffense } from "../types.js"
3
+ import { ParserRule } from "../types.js"
4
+ import type { LintOffense, LintContext } from "../types.js"
4
5
  import type { HTMLOpenTagNode, HTMLElementNode, Node } from "@herb-tools/core"
5
6
 
6
7
  class NestedLinkVisitor extends BaseRuleVisitor {
@@ -54,11 +55,11 @@ class NestedLinkVisitor extends BaseRuleVisitor {
54
55
  }
55
56
  }
56
57
 
57
- export class HTMLNoNestedLinksRule implements Rule {
58
+ export class HTMLNoNestedLinksRule extends ParserRule {
58
59
  name = "html-no-nested-links"
59
60
 
60
- check(node: Node): LintOffense[] {
61
- const visitor = new NestedLinkVisitor(this.name)
61
+ check(node: Node, context?: Partial<LintContext>): LintOffense[] {
62
+ const visitor = new NestedLinkVisitor(this.name, context)
62
63
  visitor.visit(node)
63
64
  return visitor.offenses
64
65
  }
@@ -1,17 +1,30 @@
1
1
  import { BaseRuleVisitor } from "./rule-utils.js"
2
2
 
3
- import type { Rule, LintOffense } from "../types.js"
4
- import type { HTMLOpenTagNode, HTMLCloseTagNode, HTMLSelfCloseTagNode, Node } from "@herb-tools/core"
3
+ import { ParserRule } from "../types.js"
4
+ import type { LintOffense, LintContext } from "../types.js"
5
+ import type { HTMLElementNode, HTMLOpenTagNode, HTMLCloseTagNode, HTMLSelfCloseTagNode, Node } from "@herb-tools/core"
5
6
 
6
7
  class TagNameLowercaseVisitor extends BaseRuleVisitor {
7
- visitHTMLOpenTagNode(node: HTMLOpenTagNode): void {
8
- this.checkTagName(node)
9
- this.visitChildNodes(node)
10
- }
8
+ visitHTMLElementNode(node: HTMLElementNode): void {
9
+ const tagName = node.tag_name?.value
10
+
11
+ if (node.open_tag) {
12
+ this.checkTagName(node.open_tag as HTMLOpenTagNode)
13
+ }
14
+
15
+ if (tagName && ["svg"].includes(tagName.toLowerCase())) {
16
+ if (node.close_tag) {
17
+ this.checkTagName(node.close_tag as HTMLCloseTagNode)
18
+ }
19
+
20
+ return
21
+ }
11
22
 
12
- visitHTMLCloseTagNode(node: HTMLCloseTagNode): void {
13
- this.checkTagName(node)
14
23
  this.visitChildNodes(node)
24
+
25
+ if (node.close_tag) {
26
+ this.checkTagName(node.close_tag as HTMLCloseTagNode)
27
+ }
15
28
  }
16
29
 
17
30
  visitHTMLSelfCloseTagNode(node: HTMLSelfCloseTagNode): void {
@@ -21,9 +34,12 @@ class TagNameLowercaseVisitor extends BaseRuleVisitor {
21
34
 
22
35
  private checkTagName(node: HTMLOpenTagNode | HTMLCloseTagNode | HTMLSelfCloseTagNode): void {
23
36
  const tagName = node.tag_name?.value
37
+
24
38
  if (!tagName) return
25
39
 
26
- if (tagName !== tagName.toLowerCase()) {
40
+ const lowercaseTagName = tagName.toLowerCase()
41
+
42
+ if (tagName !== lowercaseTagName) {
27
43
  let type: string = node.type
28
44
 
29
45
  if (node.type == "AST_HTML_OPEN_TAG_NODE") type = "Opening"
@@ -31,7 +47,7 @@ class TagNameLowercaseVisitor extends BaseRuleVisitor {
31
47
  if (node.type == "AST_HTML_SELF_CLOSE_TAG_NODE") type = "Self-closing"
32
48
 
33
49
  this.addOffense(
34
- `${type} tag name \`${tagName}\` should be lowercase. Use \`${tagName.toLowerCase()}\` instead.`,
50
+ `${type} tag name \`${tagName}\` should be lowercase. Use \`${lowercaseTagName}\` instead.`,
35
51
  node.tag_name!.location,
36
52
  "error"
37
53
  )
@@ -39,11 +55,11 @@ class TagNameLowercaseVisitor extends BaseRuleVisitor {
39
55
  }
40
56
  }
41
57
 
42
- export class HTMLTagNameLowercaseRule implements Rule {
58
+ export class HTMLTagNameLowercaseRule extends ParserRule {
43
59
  name = "html-tag-name-lowercase"
44
60
 
45
- check(node: Node): LintOffense[] {
46
- const visitor = new TagNameLowercaseVisitor(this.name)
61
+ check(node: Node, context?: Partial<LintContext>): LintOffense[] {
62
+ const visitor = new TagNameLowercaseVisitor(this.name, context)
47
63
  visitor.visit(node)
48
64
  return visitor.offenses
49
65
  }
@@ -1,6 +1,9 @@
1
1
  export * from "./erb-no-empty-tags.js"
2
2
  export * from "./erb-no-output-control-flow.js"
3
+ export * from "./erb-prefer-image-tag-helper.js"
4
+ export * from "./erb-requires-trailing-newline.js"
3
5
  export * from "./html-anchor-require-href.js"
6
+ export * from "./html-aria-level-must-be-valid.js"
4
7
  export * from "./html-aria-role-heading-requires-level.js"
5
8
  export * from "./html-aria-role-must-be-valid.js"
6
9
  export * from "./html-attribute-double-quotes.js"
@@ -13,3 +16,4 @@ export * from "./html-no-duplicate-ids.js"
13
16
  export * from "./html-no-empty-headings.js"
14
17
  export * from "./html-no-nested-links.js"
15
18
  export * from "./html-tag-name-lowercase.js"
19
+ export * from "./svg-tag-name-capitalization.js"