@herb-tools/linter 0.5.0 → 0.6.1
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.
- package/dist/herb-lint.js +6627 -1937
- package/dist/herb-lint.js.map +1 -1
- package/dist/index.cjs +1574 -210
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +1566 -212
- package/dist/index.js.map +1 -1
- package/dist/package.json +5 -4
- package/dist/src/cli/argument-parser.js +0 -4
- package/dist/src/cli/argument-parser.js.map +1 -1
- package/dist/src/default-rules.js +20 -0
- package/dist/src/default-rules.js.map +1 -1
- package/dist/src/linter.js +29 -4
- package/dist/src/linter.js.map +1 -1
- package/dist/src/rules/erb-no-silent-tag-in-attribute-name.js +26 -0
- package/dist/src/rules/erb-no-silent-tag-in-attribute-name.js.map +1 -0
- package/dist/src/rules/erb-prefer-image-tag-helper.js +50 -64
- package/dist/src/rules/erb-prefer-image-tag-helper.js.map +1 -1
- package/dist/src/rules/html-aria-attribute-must-be-valid.js +11 -10
- package/dist/src/rules/html-aria-attribute-must-be-valid.js.map +1 -1
- package/dist/src/rules/html-aria-label-is-well-formatted.js +33 -0
- package/dist/src/rules/html-aria-label-is-well-formatted.js.map +1 -0
- package/dist/src/rules/html-aria-level-must-be-valid.js +26 -4
- package/dist/src/rules/html-aria-level-must-be-valid.js.map +1 -1
- package/dist/src/rules/html-aria-role-heading-requires-level.js +7 -13
- package/dist/src/rules/html-aria-role-heading-requires-level.js.map +1 -1
- package/dist/src/rules/html-aria-role-must-be-valid.js +3 -3
- package/dist/src/rules/html-aria-role-must-be-valid.js.map +1 -1
- package/dist/src/rules/html-attribute-double-quotes.js +14 -4
- package/dist/src/rules/html-attribute-double-quotes.js.map +1 -1
- package/dist/src/rules/html-attribute-equals-spacing.js +24 -0
- package/dist/src/rules/html-attribute-equals-spacing.js.map +1 -0
- package/dist/src/rules/html-attribute-values-require-quotes.js +19 -8
- package/dist/src/rules/html-attribute-values-require-quotes.js.map +1 -1
- package/dist/src/rules/html-avoid-both-disabled-and-aria-disabled.js +47 -0
- package/dist/src/rules/html-avoid-both-disabled-and-aria-disabled.js.map +1 -0
- package/dist/src/rules/html-boolean-attributes-no-value.js +9 -2
- package/dist/src/rules/html-boolean-attributes-no-value.js.map +1 -1
- package/dist/src/rules/html-iframe-has-title.js +39 -0
- package/dist/src/rules/html-iframe-has-title.js.map +1 -0
- package/dist/src/rules/html-img-require-alt.js +0 -4
- package/dist/src/rules/html-img-require-alt.js.map +1 -1
- package/dist/src/rules/html-navigation-has-label.js +43 -0
- package/dist/src/rules/html-navigation-has-label.js.map +1 -0
- package/dist/src/rules/html-no-aria-hidden-on-focusable.js +67 -0
- package/dist/src/rules/html-no-aria-hidden-on-focusable.js.map +1 -0
- package/dist/src/rules/html-no-duplicate-attributes.js +22 -25
- package/dist/src/rules/html-no-duplicate-attributes.js.map +1 -1
- package/dist/src/rules/html-no-duplicate-ids.js +134 -9
- package/dist/src/rules/html-no-duplicate-ids.js.map +1 -1
- package/dist/src/rules/html-no-empty-headings.js +0 -21
- package/dist/src/rules/html-no-empty-headings.js.map +1 -1
- package/dist/src/rules/html-no-positive-tab-index.js +21 -0
- package/dist/src/rules/html-no-positive-tab-index.js.map +1 -0
- package/dist/src/rules/html-no-self-closing.js +29 -0
- package/dist/src/rules/html-no-self-closing.js.map +1 -0
- package/dist/src/rules/html-no-title-attribute.js +27 -0
- package/dist/src/rules/html-no-title-attribute.js.map +1 -0
- package/dist/src/rules/html-tag-name-lowercase.js +35 -23
- package/dist/src/rules/html-tag-name-lowercase.js.map +1 -1
- package/dist/src/rules/index.js +10 -0
- package/dist/src/rules/index.js.map +1 -1
- package/dist/src/rules/rule-utils.js +245 -22
- package/dist/src/rules/rule-utils.js.map +1 -1
- package/dist/src/rules/svg-tag-name-capitalization.js +0 -8
- package/dist/src/rules/svg-tag-name-capitalization.js.map +1 -1
- package/dist/src/types.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/types/cli/index.d.ts +4 -0
- package/dist/types/rules/erb-no-silent-tag-in-attribute-name.d.ts +7 -0
- package/dist/types/rules/html-aria-label-is-well-formatted.d.ts +7 -0
- package/dist/types/rules/html-attribute-equals-spacing.d.ts +7 -0
- package/dist/types/rules/html-avoid-both-disabled-and-aria-disabled.d.ts +7 -0
- package/dist/types/rules/html-iframe-has-title.d.ts +7 -0
- package/dist/types/rules/html-navigation-has-label.d.ts +7 -0
- package/dist/types/rules/html-no-aria-hidden-on-focusable.d.ts +7 -0
- package/dist/types/rules/html-no-positive-tab-index.d.ts +7 -0
- package/dist/types/rules/html-no-self-closing.d.ts +7 -0
- package/dist/types/rules/html-no-title-attribute.d.ts +7 -0
- package/dist/types/rules/html-tag-name-lowercase.d.ts +2 -1
- package/dist/types/rules/index.d.ts +10 -0
- package/dist/types/rules/rule-utils.d.ts +146 -13
- package/dist/types/src/rules/erb-no-silent-tag-in-attribute-name.d.ts +7 -0
- package/dist/types/src/rules/html-aria-label-is-well-formatted.d.ts +7 -0
- package/dist/types/src/rules/html-attribute-equals-spacing.d.ts +7 -0
- package/dist/types/src/rules/html-avoid-both-disabled-and-aria-disabled.d.ts +7 -0
- package/dist/types/src/rules/html-iframe-has-title.d.ts +7 -0
- package/dist/types/src/rules/html-navigation-has-label.d.ts +7 -0
- package/dist/types/src/rules/html-no-aria-hidden-on-focusable.d.ts +7 -0
- package/dist/types/src/rules/html-no-positive-tab-index.d.ts +7 -0
- package/dist/types/src/rules/html-no-self-closing.d.ts +7 -0
- package/dist/types/src/rules/html-no-title-attribute.d.ts +7 -0
- package/dist/types/src/rules/html-tag-name-lowercase.d.ts +2 -1
- package/dist/types/src/rules/index.d.ts +10 -0
- package/dist/types/src/rules/rule-utils.d.ts +146 -13
- package/dist/types/src/types.d.ts +24 -0
- package/dist/types/types.d.ts +24 -0
- package/docs/rules/README.md +12 -2
- package/docs/rules/erb-no-silent-tag-in-attribute-name.md +34 -0
- package/docs/rules/html-aria-label-is-well-formatted.md +49 -0
- package/docs/rules/html-attribute-equals-spacing.md +35 -0
- package/docs/rules/html-avoid-both-disabled-and-aria-disabled.md +48 -0
- package/docs/rules/html-iframe-has-title.md +43 -0
- package/docs/rules/html-navigation-has-label.md +61 -0
- package/docs/rules/html-no-aria-hidden-on-focusable.md +54 -0
- package/docs/rules/html-no-positive-tab-index.md +55 -0
- package/docs/rules/html-no-self-closing.md +65 -0
- package/docs/rules/html-no-title-attribute.md +69 -0
- package/docs/rules/html-tag-name-lowercase.md +16 -3
- package/package.json +5 -4
- package/src/cli/argument-parser.ts +0 -5
- package/src/default-rules.ts +20 -0
- package/src/linter.ts +30 -4
- package/src/rules/erb-no-silent-tag-in-attribute-name.ts +40 -0
- package/src/rules/erb-prefer-image-tag-helper.ts +53 -76
- package/src/rules/html-aria-attribute-must-be-valid.ts +28 -32
- package/src/rules/html-aria-label-is-well-formatted.ts +59 -0
- package/src/rules/html-aria-level-must-be-valid.ts +38 -5
- package/src/rules/html-aria-role-heading-requires-level.ts +16 -28
- package/src/rules/html-aria-role-must-be-valid.ts +5 -5
- package/src/rules/html-attribute-double-quotes.ts +21 -6
- package/src/rules/html-attribute-equals-spacing.ts +41 -0
- package/src/rules/html-attribute-values-require-quotes.ts +29 -9
- package/src/rules/html-avoid-both-disabled-and-aria-disabled.ts +66 -0
- package/src/rules/html-boolean-attributes-no-value.ts +17 -4
- package/src/rules/html-iframe-has-title.ts +62 -0
- package/src/rules/html-img-require-alt.ts +2 -7
- package/src/rules/html-navigation-has-label.ts +64 -0
- package/src/rules/html-no-aria-hidden-on-focusable.ts +90 -0
- package/src/rules/html-no-duplicate-attributes.ts +28 -28
- package/src/rules/html-no-duplicate-ids.ts +189 -14
- package/src/rules/html-no-empty-headings.ts +2 -31
- package/src/rules/html-no-positive-tab-index.ts +33 -0
- package/src/rules/html-no-self-closing.ts +41 -0
- package/src/rules/html-no-title-attribute.ts +42 -0
- package/src/rules/html-tag-name-lowercase.ts +42 -29
- package/src/rules/index.ts +10 -0
- package/src/rules/rule-utils.ts +357 -39
- package/src/rules/svg-tag-name-capitalization.ts +2 -9
- package/src/types.ts +27 -0
|
@@ -1,85 +1,71 @@
|
|
|
1
|
-
import { BaseRuleVisitor, getTagName, findAttributeByName, getAttributes } from "./rule-utils.js";
|
|
2
1
|
import { ParserRule } from "../types.js";
|
|
2
|
+
import { BaseRuleVisitor, getTagName, findAttributeByName, getAttributes } from "./rule-utils.js";
|
|
3
|
+
import { ERBToRubyStringPrinter } from "@herb-tools/printer";
|
|
4
|
+
import { filterNodes, ERBContentNode, LiteralNode, isNode } from "@herb-tools/core";
|
|
3
5
|
class ERBPreferImageTagHelperVisitor extends BaseRuleVisitor {
|
|
4
6
|
visitHTMLOpenTagNode(node) {
|
|
5
7
|
this.checkImgTag(node);
|
|
6
8
|
super.visitHTMLOpenTagNode(node);
|
|
7
9
|
}
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
}
|
|
12
|
-
checkImgTag(node) {
|
|
13
|
-
const tagName = getTagName(node);
|
|
14
|
-
if (tagName !== "img") {
|
|
10
|
+
checkImgTag(openTag) {
|
|
11
|
+
const tagName = getTagName(openTag);
|
|
12
|
+
if (tagName !== "img")
|
|
15
13
|
return;
|
|
16
|
-
|
|
17
|
-
const attributes = getAttributes(node);
|
|
14
|
+
const attributes = getAttributes(openTag);
|
|
18
15
|
const srcAttribute = findAttributeByName(attributes, "src");
|
|
19
|
-
if (!srcAttribute)
|
|
16
|
+
if (!srcAttribute)
|
|
20
17
|
return;
|
|
21
|
-
|
|
22
|
-
if (!srcAttribute.value) {
|
|
18
|
+
if (!srcAttribute.value)
|
|
23
19
|
return;
|
|
24
|
-
|
|
25
|
-
const
|
|
26
|
-
const hasERBContent = this.containsERBContent(valueNode);
|
|
20
|
+
const node = srcAttribute.value;
|
|
21
|
+
const hasERBContent = this.containsERBContent(node);
|
|
27
22
|
if (hasERBContent) {
|
|
28
|
-
|
|
29
|
-
|
|
23
|
+
if (this.isDataUri(node))
|
|
24
|
+
return;
|
|
25
|
+
if (this.shouldFlagAsImageTagCandidate(node)) {
|
|
26
|
+
const suggestedExpression = this.buildSuggestedExpression(node);
|
|
27
|
+
this.addOffense(`Prefer \`image_tag\` helper over manual \`<img>\` with dynamic ERB expressions. Use \`<%= image_tag ${suggestedExpression}, alt: "..." %>\` instead.`, srcAttribute.location, "warning");
|
|
28
|
+
}
|
|
30
29
|
}
|
|
31
30
|
}
|
|
32
|
-
containsERBContent(
|
|
33
|
-
|
|
31
|
+
containsERBContent(node) {
|
|
32
|
+
return filterNodes(node.children, ERBContentNode).length > 0;
|
|
33
|
+
}
|
|
34
|
+
isOnlyERBContent(node) {
|
|
35
|
+
return node.children.length > 0 && node.children.length === filterNodes(node.children, ERBContentNode).length;
|
|
36
|
+
}
|
|
37
|
+
getContentofFirstChild(node) {
|
|
38
|
+
if (!node.children || node.children.length === 0)
|
|
39
|
+
return "";
|
|
40
|
+
const firstChild = node.children[0];
|
|
41
|
+
if (isNode(firstChild, LiteralNode)) {
|
|
42
|
+
return (firstChild.content || "").trim();
|
|
43
|
+
}
|
|
44
|
+
return "";
|
|
45
|
+
}
|
|
46
|
+
isDataUri(node) {
|
|
47
|
+
return this.getContentofFirstChild(node).startsWith("data:");
|
|
48
|
+
}
|
|
49
|
+
isFullUrl(node) {
|
|
50
|
+
const content = this.getContentofFirstChild(node);
|
|
51
|
+
return content.startsWith("http://") || content.startsWith("https://");
|
|
52
|
+
}
|
|
53
|
+
shouldFlagAsImageTagCandidate(node) {
|
|
54
|
+
if (this.isOnlyERBContent(node))
|
|
55
|
+
return true;
|
|
56
|
+
if (this.isFullUrl(node))
|
|
34
57
|
return false;
|
|
35
|
-
return
|
|
58
|
+
return true;
|
|
36
59
|
}
|
|
37
|
-
buildSuggestedExpression(
|
|
38
|
-
if (!
|
|
60
|
+
buildSuggestedExpression(node) {
|
|
61
|
+
if (!node.children)
|
|
39
62
|
return "expression";
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
for (const child of valueNode.children) {
|
|
43
|
-
if (child.type === "AST_ERB_CONTENT_NODE") {
|
|
44
|
-
hasERB = true;
|
|
45
|
-
}
|
|
46
|
-
else if (child.type === "AST_LITERAL_NODE") {
|
|
47
|
-
const literalNode = child;
|
|
48
|
-
if (literalNode.content && literalNode.content.trim()) {
|
|
49
|
-
hasText = true;
|
|
50
|
-
}
|
|
51
|
-
}
|
|
63
|
+
try {
|
|
64
|
+
return ERBToRubyStringPrinter.print(node, { ignoreErrors: false });
|
|
52
65
|
}
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
for (const child of valueNode.children) {
|
|
56
|
-
if (child.type === "AST_ERB_CONTENT_NODE") {
|
|
57
|
-
const erbNode = child;
|
|
58
|
-
result += `#{${(erbNode.content?.value || "").trim()}}`;
|
|
59
|
-
}
|
|
60
|
-
else if (child.type === "AST_LITERAL_NODE") {
|
|
61
|
-
const literalNode = child;
|
|
62
|
-
result += literalNode.content || "";
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
result += '"';
|
|
66
|
-
return result;
|
|
67
|
-
}
|
|
68
|
-
if (hasERB && !hasText) {
|
|
69
|
-
const erbNodes = valueNode.children.filter(child => child.type === "AST_ERB_CONTENT_NODE");
|
|
70
|
-
if (erbNodes.length === 1) {
|
|
71
|
-
return (erbNodes[0].content?.value || "").trim();
|
|
72
|
-
}
|
|
73
|
-
else if (erbNodes.length > 1) {
|
|
74
|
-
let result = '"';
|
|
75
|
-
for (const erbNode of erbNodes) {
|
|
76
|
-
result += `#{${(erbNode.content?.value || "").trim()}}`;
|
|
77
|
-
}
|
|
78
|
-
result += '"';
|
|
79
|
-
return result;
|
|
80
|
-
}
|
|
66
|
+
catch (error) {
|
|
67
|
+
return "expression";
|
|
81
68
|
}
|
|
82
|
-
return "expression";
|
|
83
69
|
}
|
|
84
70
|
}
|
|
85
71
|
export class ERBPreferImageTagHelperRule extends ParserRule {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"erb-prefer-image-tag-helper.js","sourceRoot":"","sources":["../../../src/rules/erb-prefer-image-tag-helper.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,UAAU,EAAE,mBAAmB,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAA;AAEjG,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"erb-prefer-image-tag-helper.js","sourceRoot":"","sources":["../../../src/rules/erb-prefer-image-tag-helper.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AACxC,OAAO,EAAE,eAAe,EAAE,UAAU,EAAE,mBAAmB,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAA;AAEjG,OAAO,EAAE,sBAAsB,EAAE,MAAM,qBAAqB,CAAA;AAC5D,OAAO,EAAE,WAAW,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAA;AAKnF,MAAM,8BAA+B,SAAQ,eAAe;IAC1D,oBAAoB,CAAC,IAAqB;QACxC,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,CAAA;QACtB,KAAK,CAAC,oBAAoB,CAAC,IAAI,CAAC,CAAA;IAClC,CAAC;IAEO,WAAW,CAAC,OAAwB;QAC1C,MAAM,OAAO,GAAG,UAAU,CAAC,OAAO,CAAC,CAAA;QAEnC,IAAI,OAAO,KAAK,KAAK;YAAE,OAAM;QAE7B,MAAM,UAAU,GAAG,aAAa,CAAC,OAAO,CAAC,CAAA;QACzC,MAAM,YAAY,GAAG,mBAAmB,CAAC,UAAU,EAAE,KAAK,CAAC,CAAA;QAE3D,IAAI,CAAC,YAAY;YAAE,OAAM;QACzB,IAAI,CAAC,YAAY,CAAC,KAAK;YAAE,OAAM;QAE/B,MAAM,IAAI,GAAG,YAAY,CAAC,KAAK,CAAA;QAC/B,MAAM,aAAa,GAAG,IAAI,CAAC,kBAAkB,CAAC,IAAI,CAAC,CAAA;QAEnD,IAAI,aAAa,EAAE,CAAC;YAClB,IAAI,IAAI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AI,CAAC,sBAAsB,CAAC,IAAI,CAAC,CAAA;QAEjD,OAAO,OAAO,CAAC,UAAU,CAAC,SAAS,CAAC,IAAI,OAAO,CAAC,UAAU,CAAC,UAAU,CAAC,CAAA;IACxE,CAAC;IAEO,6BAA6B,CAAC,IAA4B;QAChE,IAAI,IAAI,CAAC,gBAAgB,CAAC,IAAI,CAAC;YAAE,OAAO,IAAI,CAAA;QAC5C,IAAI,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC;YAAE,OAAO,KAAK,CAAA;QAEtC,OAAO,IAAI,CAAA;IACb,CAAC;IAEO,wBAAwB,CAAC,IAA4B;QAC3D,IAAI,CAAC,IAAI,CAAC,QAAQ;YAAE,OAAO,YAAY,CAAA;QAEvC,IAAI,CAAC;YACH,OAAO,sBAAsB,CAAC,KAAK,CAAC,IAAI,EAAE,EAAE,YAAY,EAAE,KAAK,EAAE,CAAC,CAAA;QACpE,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,OAAO,YAAY,CAAA;QACrB,CAAC;IACH,CAAC;CACF;AAED,MAAM,OAAO,2BAA4B,SAAQ,UAAU;IACzD,IAAI,GAAG,6BAA6B,CAAA;IAEpC,KAAK,CAAC,MAAmB,EAAE,OAA8B;QACvD,MAAM,OAAO,GAAG,IAAI,8BAA8B,CAAC,IAAI,CAAC,IAAI,EAAE,OAAO,CAAC,CAAA;QACtE,OAAO,CAAC,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,CAAA;QAC3B,OAAO,OAAO,CAAC,QAAQ,CAAA;IACzB,CAAC;CACF"}
|
|
@@ -1,17 +1,18 @@
|
|
|
1
|
-
import { ARIA_ATTRIBUTES, AttributeVisitorMixin, } from "./rule-utils.js";
|
|
2
1
|
import { ParserRule } from "../types.js";
|
|
2
|
+
import { ARIA_ATTRIBUTES, AttributeVisitorMixin } from "./rule-utils.js";
|
|
3
3
|
class AriaAttributeMustBeValid extends AttributeVisitorMixin {
|
|
4
|
-
|
|
4
|
+
checkStaticAttributeStaticValue({ attributeName, attributeNode }) {
|
|
5
|
+
this.check(attributeName, attributeNode);
|
|
6
|
+
}
|
|
7
|
+
checkStaticAttributeDynamicValue({ attributeName, attributeNode }) {
|
|
8
|
+
this.check(attributeName, attributeNode);
|
|
9
|
+
}
|
|
10
|
+
check(attributeName, attributeNode) {
|
|
5
11
|
if (!attributeName.startsWith("aria-"))
|
|
6
12
|
return;
|
|
7
|
-
if (
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
severity: "error",
|
|
11
|
-
location: attributeNode.location,
|
|
12
|
-
rule: this.ruleName,
|
|
13
|
-
});
|
|
14
|
-
}
|
|
13
|
+
if (ARIA_ATTRIBUTES.has(attributeName))
|
|
14
|
+
return;
|
|
15
|
+
this.addOffense(`The attribute \`${attributeName}\` is not a valid ARIA attribute. ARIA attributes must match the WAI-ARIA specification.`, attributeNode.location, "error");
|
|
15
16
|
}
|
|
16
17
|
}
|
|
17
18
|
export class HTMLAriaAttributeMustBeValid extends ParserRule {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"html-aria-attribute-must-be-valid.js","sourceRoot":"","sources":["../../../src/rules/html-aria-attribute-must-be-valid.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"html-aria-attribute-must-be-valid.js","sourceRoot":"","sources":["../../../src/rules/html-aria-attribute-must-be-valid.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AACxC,OAAO,EAAE,eAAe,EAAE,qBAAqB,EAAuE,MAAM,iBAAiB,CAAA;AAK7I,MAAM,wBAAyB,SAAQ,qBAAqB;IAChD,+BAA+B,CAAC,EAAE,aAAa,EAAE,aAAa,EAAoC;QAC1G,IAAI,CAAC,KAAK,CAAC,aAAa,EAAE,aAAa,CAAC,CAAA;IAC1C,CAAC;IAES,gCAAgC,CAAC,EAAE,aAAa,EAAE,aAAa,EAAqC;QAC5G,IAAI,CAAC,KAAK,CAAC,aAAa,EAAE,aAAa,CAAC,CAAA;IAC1C,CAAC;IAEO,KAAK,CAAC,aAAqB,EAAE,aAAgC;QACnE,IAAI,CAAC,aAAa,CAAC,UAAU,CAAC,OAAO,CAAC;YAAE,OAAM;QAC9C,IAAI,eAAe,CAAC,GAAG,CAAC,aAAa,CAAC;YAAE,OAAM;QAE9C,IAAI,CAAC,UAAU,CACb,mBAAmB,aAAa,0FAA0F,EAC1H,aAAa,CAAC,QAAQ,EACtB,OAAO,CACR,CAAA;IACH,CAAC;CACF;AAED,MAAM,OAAO,4BAA6B,SAAQ,UAAU;IAC1D,IAAI,GAAG,mCAAmC,CAAA;IAE1C,KAAK,CAAC,MAAmB,EAAE,OAA8B;QACvD,MAAM,OAAO,GAAG,IAAI,wBAAwB,CAAC,IAAI,CAAC,IAAI,EAAE,OAAO,CAAC,CAAA;QAEhE,OAAO,CAAC,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,CAAA;QAE3B,OAAO,OAAO,CAAC,QAAQ,CAAA;IACzB,CAAC;CACF"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { ParserRule } from "../types.js";
|
|
2
|
+
import { AttributeVisitorMixin } from "./rule-utils.js";
|
|
3
|
+
class AriaLabelIsWellFormattedVisitor extends AttributeVisitorMixin {
|
|
4
|
+
checkStaticAttributeStaticValue({ attributeName, attributeValue, attributeNode }) {
|
|
5
|
+
if (attributeName !== "aria-label")
|
|
6
|
+
return;
|
|
7
|
+
if (attributeValue.match(/[\r\n]+/) || attributeValue.match(/ | |
|
/i)) {
|
|
8
|
+
this.addOffense("The `aria-label` attribute value text should not contain line breaks. Use concise, single-line descriptions.", attributeNode.location, "error");
|
|
9
|
+
return;
|
|
10
|
+
}
|
|
11
|
+
if (this.looksLikeId(attributeValue)) {
|
|
12
|
+
this.addOffense("The `aria-label` attribute value should not be formatted like an ID. Use natural, sentence-case text instead.", attributeNode.location, "error");
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
15
|
+
if (attributeValue.match(/^[a-z]/)) {
|
|
16
|
+
this.addOffense("The `aria-label` attribute value text should be formatted like visual text. Use sentence case (capitalize the first letter).", attributeNode.location, "error");
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
looksLikeId(text) {
|
|
20
|
+
return (text.includes('_') ||
|
|
21
|
+
text.includes('-') ||
|
|
22
|
+
/^[a-z]+([A-Z][a-z]*)*$/.test(text)) && !text.includes(' ');
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
export class HTMLAriaLabelIsWellFormattedRule extends ParserRule {
|
|
26
|
+
name = "html-aria-label-is-well-formatted";
|
|
27
|
+
check(result, context) {
|
|
28
|
+
const visitor = new AriaLabelIsWellFormattedVisitor(this.name, context);
|
|
29
|
+
visitor.visit(result.value);
|
|
30
|
+
return visitor.offenses;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
//# sourceMappingURL=html-aria-label-is-well-formatted.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"html-aria-label-is-well-formatted.js","sourceRoot":"","sources":["../../../src/rules/html-aria-label-is-well-formatted.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AACxC,OAAO,EAAE,qBAAqB,EAAoC,MAAM,iBAAiB,CAAA;AAKzF,MAAM,+BAAgC,SAAQ,qBAAqB;IACvD,+BAA+B,CAAC,EAAE,aAAa,EAAE,cAAc,EAAE,aAAa,EAAoC;QAC1H,IAAI,aAAa,KAAK,YAAY;YAAE,OAAM;QAE1C,IAAI,cAAc,CAAC,KAAK,CAAC,SAAS,CAAC,IAAI,cAAc,CAAC,KAAK,CAAC,4BAA4B,CAAC,EAAE,CAAC;YAC1F,IAAI,CAAC,UAAU,CACb,8GAA8G,EAC9G,aAAa,CAAC,QAAQ,EACtB,OAAO,CACR,CAAA;YAED,OAAM;QACR,CAAC;QAED,IAAI,IAAI,CAAC,WAAW,CAAC,cAAc,CAAC,EAAE,CAAC;YACrC,IAAI,CAAC,UAAU,CACb,+GAA+G,EAC/G,aAAa,CAAC,QAAQ,EACtB,OAAO,CACR,CAAA;YAED,OAAM;QACR,CAAC;QAED,IAAI,cAAc,CAAC,KAAK,CAAC,QAAQ,CAAC,EAAE,CAAC;YACnC,IAAI,CAAC,UAAU,CACb,8HAA8H,EAC9H,aAAa,CAAC,QAAQ,EACtB,OAAO,CACR,CAAA;QACH,CAAC;IACH,CAAC;IAEO,WAAW,CAAC,IAAY;QAC9B,OAAO,CACL,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC;YAClB,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC;YAClB,wBAAwB,CAAC,IAAI,CAAC,IAAI,CAAC,CACpC,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAA;IAC1B,CAAC;CACF;AAED,MAAM,OAAO,gCAAiC,SAAQ,UAAU;IAC9D,IAAI,GAAG,mCAAmC,CAAA;IAE1C,KAAK,CAAC,MAAmB,EAAE,OAA8B;QACvD,MAAM,OAAO,GAAG,IAAI,+BAA+B,CAAC,IAAI,CAAC,IAAI,EAAE,OAAO,CAAC,CAAA;QAEvE,OAAO,CAAC,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,CAAA;QAE3B,OAAO,OAAO,CAAC,QAAQ,CAAA;IACzB,CAAC;CACF"}
|
|
@@ -1,12 +1,34 @@
|
|
|
1
|
-
import { AttributeVisitorMixin } from "./rule-utils.js";
|
|
2
1
|
import { ParserRule } from "../types.js";
|
|
2
|
+
import { AttributeVisitorMixin } from "./rule-utils.js";
|
|
3
|
+
import { getValidatableStaticContent, hasERBOutput, filterLiteralNodes, filterERBContentNodes, isERBOutputNode } from "@herb-tools/core";
|
|
3
4
|
class HTMLAriaLevelMustBeValidVisitor extends AttributeVisitorMixin {
|
|
4
|
-
|
|
5
|
+
checkStaticAttributeStaticValue({ attributeName, attributeValue, attributeNode }) {
|
|
6
|
+
if (attributeName !== "aria-level")
|
|
7
|
+
return;
|
|
8
|
+
this.validateAriaLevel(attributeValue, attributeNode);
|
|
9
|
+
}
|
|
10
|
+
checkStaticAttributeDynamicValue({ attributeName, valueNodes, attributeNode }) {
|
|
5
11
|
if (attributeName !== "aria-level")
|
|
6
12
|
return;
|
|
7
|
-
|
|
13
|
+
const validatableContent = getValidatableStaticContent(valueNodes);
|
|
14
|
+
if (validatableContent !== null) {
|
|
15
|
+
this.validateAriaLevel(validatableContent, attributeNode);
|
|
8
16
|
return;
|
|
9
|
-
|
|
17
|
+
}
|
|
18
|
+
if (!hasERBOutput(valueNodes))
|
|
19
|
+
return;
|
|
20
|
+
const literalNodes = filterLiteralNodes(valueNodes);
|
|
21
|
+
const erbOutputNodes = filterERBContentNodes(valueNodes).filter(isERBOutputNode);
|
|
22
|
+
if (literalNodes.length > 0 && erbOutputNodes.length > 0) {
|
|
23
|
+
const staticPart = literalNodes.map(node => node.content).join("");
|
|
24
|
+
// TODO: this can be cleaned up using @herb-tools/printer
|
|
25
|
+
const erbPart = erbOutputNodes[0];
|
|
26
|
+
const erbText = `${erbPart.tag_opening?.value || ""}${erbPart.content?.value || ""}${erbPart.tag_closing?.value || ""}`;
|
|
27
|
+
this.addOffense(`The \`aria-level\` attribute must be an integer between 1 and 6, got \`${staticPart}\` and the ERB expression \`${erbText}\`.`, attributeNode.location);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
validateAriaLevel(attributeValue, attributeNode) {
|
|
31
|
+
if (!attributeValue || attributeValue === "") {
|
|
10
32
|
this.addOffense(`The \`aria-level\` attribute must be an integer between 1 and 6, got an empty value.`, attributeNode.location);
|
|
11
33
|
return;
|
|
12
34
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"html-aria-level-must-be-valid.js","sourceRoot":"","sources":["../../../src/rules/html-aria-level-must-be-valid.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"html-aria-level-must-be-valid.js","sourceRoot":"","sources":["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./rule-utils.js";
|
|
2
1
|
import { ParserRule } from "../types.js";
|
|
2
|
+
import { AttributeVisitorMixin, getAttributeName, getAttributes } from "./rule-utils.js";
|
|
3
3
|
class AriaRoleHeadingRequiresLevel extends AttributeVisitorMixin {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
if (
|
|
4
|
+
checkStaticAttributeStaticValue({ attributeName, attributeValue, attributeNode, parentNode }) {
|
|
5
|
+
if (!(attributeName === "role" && attributeValue === "heading"))
|
|
6
|
+
return;
|
|
7
|
+
const ariaLevelAttributes = getAttributes(parentNode).find(attribute => getAttributeName(attribute) === "aria-level");
|
|
8
|
+
if (ariaLevelAttributes)
|
|
9
9
|
return;
|
|
10
|
-
|
|
11
|
-
const allAttributes = getAttributes(parentNode);
|
|
12
|
-
// If we have a role="heading", we must check for aria-level
|
|
13
|
-
const ariaLevelAttr = allAttributes.find(attr => getAttributeName(attr) === "aria-level");
|
|
14
|
-
if (!ariaLevelAttr) {
|
|
15
|
-
this.addOffense(`Element with \`role="heading"\` must have an \`aria-level\` attribute.`, attributeNode.location, "error");
|
|
16
|
-
}
|
|
10
|
+
this.addOffense(`Element with \`role="heading"\` must have an \`aria-level\` attribute.`, attributeNode.location, "error");
|
|
17
11
|
}
|
|
18
12
|
}
|
|
19
13
|
export class HTMLAriaRoleHeadingRequiresLevelRule extends ParserRule {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"html-aria-role-heading-requires-level.js","sourceRoot":"","sources":["../../../src/rules/html-aria-role-heading-requires-level.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"html-aria-role-heading-requires-level.js","sourceRoot":"","sources":["../../../src/rules/html-aria-role-heading-requires-level.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AACxC,OAAO,EAAE,qBAAqB,EAAE,gBAAgB,EAAE,aAAa,EAAoC,MAAM,iBAAiB,CAAA;AAK1H,MAAM,4BAA6B,SAAQ,qBAAqB;IACpD,+BAA+B,CAAC,EAAE,aAAa,EAAE,cAAc,EAAE,aAAa,EAAE,UAAU,EAAoC;QACtI,IAAI,CAAC,CAAC,aAAa,KAAK,MAAM,IAAI,cAAc,KAAK,SAAS,CAAC;YAAE,OAAM;QAEvE,MAAM,mBAAmB,GAAG,aAAa,CAAC,UAAU,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,EAAE,CAAC,gBAAgB,CAAC,SAAS,CAAC,KAAK,YAAY,CAAC,CAAA;QAErH,IAAI,mBAAmB;YAAE,OAAM;QAE/B,IAAI,CAAC,UAAU,CACb,wEAAwE,EACxE,aAAa,CAAC,QAAQ,EACtB,OAAO,CACR,CAAA;IACH,CAAC;CACF;AAED,MAAM,OAAO,oCAAqC,SAAQ,UAAU;IAClE,IAAI,GAAG,uCAAuC,CAAA;IAE9C,KAAK,CAAC,MAAmB,EAAE,OAA8B;QACvD,MAAM,OAAO,GAAG,IAAI,4BAA4B,CAAC,IAAI,CAAC,IAAI,EAAE,OAAO,CAAC,CAAA;QAEpE,OAAO,CAAC,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,CAAA;QAE3B,OAAO,OAAO,CAAC,QAAQ,CAAA;IACzB,CAAC;CACF"}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { AttributeVisitorMixin, VALID_ARIA_ROLES } from "./rule-utils.js";
|
|
2
1
|
import { ParserRule } from "../types.js";
|
|
2
|
+
import { AttributeVisitorMixin, VALID_ARIA_ROLES } from "./rule-utils.js";
|
|
3
3
|
class AriaRoleMustBeValid extends AttributeVisitorMixin {
|
|
4
|
-
|
|
4
|
+
checkStaticAttributeStaticValue({ attributeName, attributeValue, attributeNode }) {
|
|
5
5
|
if (attributeName !== "role")
|
|
6
6
|
return;
|
|
7
|
-
if (attributeValue
|
|
7
|
+
if (!attributeValue)
|
|
8
8
|
return;
|
|
9
9
|
if (VALID_ARIA_ROLES.has(attributeValue))
|
|
10
10
|
return;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"html-aria-role-must-be-valid.js","sourceRoot":"","sources":["../../../src/rules/html-aria-role-must-be-valid.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"html-aria-role-must-be-valid.js","sourceRoot":"","sources":["../../../src/rules/html-aria-role-must-be-valid.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AACxC,OAAO,EAAE,qBAAqB,EAAE,gBAAgB,EAAoC,MAAM,iBAAiB,CAAA;AAK3G,MAAM,mBAAoB,SAAQ,qBAAqB;IAC3C,+BAA+B,CAAC,EAAE,aAAa,EAAE,cAAc,EAAE,aAAa,EAAoC;QAC1H,IAAI,aAAa,KAAK,MAAM;YAAE,OAAM;QACpC,IAAI,CAAC,cAAc;YAAE,OAAM;QAC3B,IAAI,gBAAgB,CAAC,GAAG,CAAC,cAAc,CAAC;YAAE,OAAM;QAEhD,IAAI,CAAC,UAAU,CACb,4DAA4D,cAAc,uBAAuB,EACjG,aAAa,CAAC,QAAQ,EACtB,OAAO,CACR,CAAA;IACH,CAAC;CACF;AAED,MAAM,OAAO,2BAA4B,SAAQ,UAAU;IACzD,IAAI,GAAG,8BAA8B,CAAA;IAErC,KAAK,CAAC,MAAmB,EAAE,OAA8B;QACvD,MAAM,OAAO,GAAG,IAAI,mBAAmB,CAAC,IAAI,CAAC,IAAI,EAAE,OAAO,CAAC,CAAA;QAE3D,OAAO,CAAC,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,CAAA;QAE3B,OAAO,OAAO,CAAC,QAAQ,CAAA;IACzB,CAAC;CACF"}
|
|
@@ -1,14 +1,24 @@
|
|
|
1
|
-
import { AttributeVisitorMixin, getAttributeValueQuoteType, hasAttributeValue } from "./rule-utils.js";
|
|
2
1
|
import { ParserRule } from "../types.js";
|
|
2
|
+
import { AttributeVisitorMixin, getAttributeValueQuoteType, hasAttributeValue } from "./rule-utils.js";
|
|
3
|
+
import { filterLiteralNodes } from "@herb-tools/core";
|
|
3
4
|
class AttributeDoubleQuotesVisitor extends AttributeVisitorMixin {
|
|
4
|
-
|
|
5
|
+
checkStaticAttributeStaticValue({ attributeName, attributeValue, attributeNode }) {
|
|
5
6
|
if (!hasAttributeValue(attributeNode))
|
|
6
7
|
return;
|
|
7
8
|
if (getAttributeValueQuoteType(attributeNode) !== "single")
|
|
8
9
|
return;
|
|
9
10
|
if (attributeValue?.includes('"'))
|
|
10
|
-
return;
|
|
11
|
-
this.addOffense(`Attribute \`${attributeName}\` uses single quotes. Prefer double quotes for HTML attribute values: \`${attributeName}="
|
|
11
|
+
return;
|
|
12
|
+
this.addOffense(`Attribute \`${attributeName}\` uses single quotes. Prefer double quotes for HTML attribute values: \`${attributeName}="${attributeValue}"\`.`, attributeNode.value.location, "warning");
|
|
13
|
+
}
|
|
14
|
+
checkStaticAttributeDynamicValue({ attributeName, valueNodes, attributeNode, combinedValue }) {
|
|
15
|
+
if (!hasAttributeValue(attributeNode))
|
|
16
|
+
return;
|
|
17
|
+
if (getAttributeValueQuoteType(attributeNode) !== "single")
|
|
18
|
+
return;
|
|
19
|
+
if (filterLiteralNodes(valueNodes).some(node => node.content?.includes('"')))
|
|
20
|
+
return;
|
|
21
|
+
this.addOffense(`Attribute \`${attributeName}\` uses single quotes. Prefer double quotes for HTML attribute values: \`${attributeName}="${combinedValue}"\`.`, attributeNode.value.location, "warning");
|
|
12
22
|
}
|
|
13
23
|
}
|
|
14
24
|
export class HTMLAttributeDoubleQuotesRule extends ParserRule {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"html-attribute-double-quotes.js","sourceRoot":"","sources":["../../../src/rules/html-attribute-double-quotes.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"html-attribute-double-quotes.js","sourceRoot":"","sources":["../../../src/rules/html-attribute-double-quotes.ts"],"names":[],"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QACvD,MAAM,OAAO,GAAG,IAAI,4BAA4B,CAAC,IAAI,CAAC,IAAI,EAAE,OAAO,CAAC,CAAA;QAEpE,OAAO,CAAC,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,CAAA;QAE3B,OAAO,OAAO,CAAC,QAAQ,CAAA;IACzB,CAAC;CACF"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { BaseRuleVisitor } from "./rule-utils.js";
|
|
2
|
+
import { ParserRule } from "../types.js";
|
|
3
|
+
class HTMLAttributeEqualsSpacingVisitor extends BaseRuleVisitor {
|
|
4
|
+
visitHTMLAttributeNode(attribute) {
|
|
5
|
+
if (!attribute.equals || !attribute.name || !attribute.value) {
|
|
6
|
+
return;
|
|
7
|
+
}
|
|
8
|
+
if (attribute.equals.value.startsWith(" ")) {
|
|
9
|
+
this.addOffense("Remove whitespace before `=` in HTML attribute", attribute.equals.location, "error");
|
|
10
|
+
}
|
|
11
|
+
if (attribute.equals.value.endsWith(" ")) {
|
|
12
|
+
this.addOffense("Remove whitespace after `=` in HTML attribute", attribute.equals.location, "error");
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
export class HTMLAttributeEqualsSpacingRule extends ParserRule {
|
|
17
|
+
name = "html-attribute-equals-spacing";
|
|
18
|
+
check(result, context) {
|
|
19
|
+
const visitor = new HTMLAttributeEqualsSpacingVisitor(this.name, context);
|
|
20
|
+
visitor.visit(result.value);
|
|
21
|
+
return visitor.offenses;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
//# sourceMappingURL=html-attribute-equals-spacing.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"html-attribute-equals-spacing.js","sourceRoot":"","sources":["../../../src/rules/html-attribute-equals-spacing.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAA;AACjD,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AAKxC,MAAM,iCAAkC,SAAQ,eAAe;IAC7D,sBAAsB,CAAC,SAA4B;QACjD,IAAI,CAAC,SAAS,CAAC,MAAM,IAAI,CAAC,SAAS,CAAC,IAAI,IAAI,CAAC,SAAS,CAAC,KAAK,EAAE,CAAC;YAC7D,OAAM;QACR,CAAC;QAED,IAAI,SAAS,CAAC,MAAM,CAAC,KAAK,CAAC,UAAU,CAAC,GAAG,CAAC,EAAE,CAAC;YAC3C,IAAI,CAAC,UAAU,CACb,gDAAgD,EAChD,SAAS,CAAC,MAAM,CAAC,QAAQ,EACzB,OAAO,CACR,CAAA;QACH,CAAC;QAED,IAAI,SAAS,CAAC,MAAM,CAAC,KAAK,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,CAAC;YACzC,IAAI,CAAC,UAAU,CACb,+CAA+C,EAC/C,SAAS,CAAC,MAAM,CAAC,QAAQ,EACzB,OAAO,CACR,CAAA;QACH,CAAC;IACH,CAAC;CACF;AAED,MAAM,OAAO,8BAA+B,SAAQ,UAAU;IAC5D,IAAI,GAAG,+BAA+B,CAAA;IAEtC,KAAK,CAAC,MAAmB,EAAE,OAA8B;QACvD,MAAM,OAAO,GAAG,IAAI,iCAAiC,CAAC,IAAI,CAAC,IAAI,EAAE,OAAO,CAAC,CAAA;QAEzE,OAAO,CAAC,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,CAAA;QAE3B,OAAO,OAAO,CAAC,QAAQ,CAAA;IACzB,CAAC;CACF"}
|
|
@@ -1,15 +1,26 @@
|
|
|
1
|
-
import { AttributeVisitorMixin } from "./rule-utils.js";
|
|
2
1
|
import { ParserRule } from "../types.js";
|
|
2
|
+
import { AttributeVisitorMixin } from "./rule-utils.js";
|
|
3
3
|
class AttributeValuesRequireQuotesVisitor extends AttributeVisitorMixin {
|
|
4
|
-
|
|
5
|
-
if (attributeNode
|
|
4
|
+
checkStaticAttributeStaticValue({ attributeName, attributeValue, attributeNode }) {
|
|
5
|
+
if (this.hasAttributeValue(attributeNode))
|
|
6
6
|
return;
|
|
7
|
-
|
|
8
|
-
|
|
7
|
+
if (this.isQuoted(attributeNode))
|
|
8
|
+
return;
|
|
9
|
+
this.addOffense(`Attribute value should be quoted: \`${attributeName}="${attributeValue}"\`. Always wrap attribute values in quotes.`, attributeNode.value.location, "error");
|
|
10
|
+
}
|
|
11
|
+
checkStaticAttributeDynamicValue({ attributeName, attributeNode, combinedValue }) {
|
|
12
|
+
if (this.hasAttributeValue(attributeNode))
|
|
9
13
|
return;
|
|
10
|
-
this.
|
|
11
|
-
|
|
12
|
-
`Attribute value should be quoted: \`${attributeName}="
|
|
14
|
+
if (this.isQuoted(attributeNode))
|
|
15
|
+
return;
|
|
16
|
+
this.addOffense(`Attribute value should be quoted: \`${attributeName}="${combinedValue}"\`. Always wrap attribute values in quotes.`, attributeNode.value.location, "error");
|
|
17
|
+
}
|
|
18
|
+
hasAttributeValue(attributeNode) {
|
|
19
|
+
return attributeNode.value?.type !== "AST_HTML_ATTRIBUTE_VALUE_NODE";
|
|
20
|
+
}
|
|
21
|
+
isQuoted(attributeNode) {
|
|
22
|
+
const valueNode = attributeNode.value;
|
|
23
|
+
return valueNode.quoted;
|
|
13
24
|
}
|
|
14
25
|
}
|
|
15
26
|
export class HTMLAttributeValuesRequireQuotesRule extends ParserRule {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"html-attribute-values-require-quotes.js","sourceRoot":"","sources":["../../../src/rules/html-attribute-values-require-quotes.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"html-attribute-values-require-quotes.js","sourceRoot":"","sources":["../../../src/rules/html-attribute-values-require-quotes.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AACxC,OAAO,EAAE,qBAAqB,EAAuE,MAAM,iBAAiB,CAAA;AAK5H,MAAM,mCAAoC,SAAQ,qBAAqB;IAC3D,+BAA+B,CAAC,EAAE,aAAa,EAAE,cAAc,E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Visitor, getTagName, hasAttribute, getAttributes, findAttributeByName } from "./rule-utils.js";
|
|
3
|
+
const ELEMENTS_WITH_NATIVE_DISABLED_ATTRIBUTE_SUPPORT = new Set([
|
|
4
|
+
"button", "fieldset", "input", "optgroup", "option", "select", "textarea"
|
|
5
|
+
]);
|
|
6
|
+
class AvoidBothDisabledAndAriaDisabledVisitor extends BaseRuleVisitor {
|
|
7
|
+
visitHTMLOpenTagNode(node) {
|
|
8
|
+
this.checkElement(node);
|
|
9
|
+
super.visitHTMLOpenTagNode(node);
|
|
10
|
+
}
|
|
11
|
+
checkElement(node) {
|
|
12
|
+
const tagName = getTagName(node);
|
|
13
|
+
if (!tagName || !ELEMENTS_WITH_NATIVE_DISABLED_ATTRIBUTE_SUPPORT.has(tagName)) {
|
|
14
|
+
return;
|
|
15
|
+
}
|
|
16
|
+
const hasDisabled = hasAttribute(node, "disabled");
|
|
17
|
+
const hasAriaDisabled = hasAttribute(node, "aria-disabled");
|
|
18
|
+
if ((hasDisabled && this.hasERBContent(node, "disabled")) || (hasAriaDisabled && this.hasERBContent(node, "aria-disabled"))) {
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
if (hasDisabled && hasAriaDisabled) {
|
|
22
|
+
this.addOffense("aria-disabled may be used in place of native HTML disabled to allow tab-focus on an otherwise ignored element. Setting both attributes is contradictory and confusing. Choose either disabled or aria-disabled, not both.", node.tag_name.location, "error");
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
hasERBContent(node, attributeName) {
|
|
26
|
+
const attributes = getAttributes(node);
|
|
27
|
+
const attribute = findAttributeByName(attributes, attributeName);
|
|
28
|
+
if (!attribute)
|
|
29
|
+
return false;
|
|
30
|
+
const valueNode = attribute.value;
|
|
31
|
+
if (!valueNode || valueNode.type !== "AST_HTML_ATTRIBUTE_VALUE_NODE")
|
|
32
|
+
return false;
|
|
33
|
+
const htmlValueNode = valueNode;
|
|
34
|
+
if (!htmlValueNode.children)
|
|
35
|
+
return false;
|
|
36
|
+
return htmlValueNode.children.some((child) => child.type === "AST_ERB_CONTENT_NODE");
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
export class HTMLAvoidBothDisabledAndAriaDisabledRule extends ParserRule {
|
|
40
|
+
name = "html-avoid-both-disabled-and-aria-disabled";
|
|
41
|
+
check(result, context) {
|
|
42
|
+
const visitor = new AvoidBothDisabledAndAriaDisabledVisitor(this.name, context);
|
|
43
|
+
visitor.visit(result.value);
|
|
44
|
+
return visitor.offenses;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
//# sourceMappingURL=html-avoid-both-disabled-and-aria-disabled.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"html-avoid-both-disabled-and-aria-disabled.js","sourceRoot":"","sources":["../../../src/rules/html-avoid-both-disabled-and-aria-disabled.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AACxC,OAAO,EAAE,eAAe,EAAE,UAAU,EAAE,YAAY,EAAE,aAAa,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAA;AAK/G,MAAM,+CAA+C,GAAG,IAAI,GAAG,CAAC;IAC9D,QAAQ,EAAE,UAAU,EAAE,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,QAAQ,EAAE,UAAU;CAC1E,CAAC,CAAA;AAEF,MAAM,uCAAwC,SAAQ,eAAe;IACnE,oBAAoB,CAAC,IAAqB;QACxC,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC,CAAA;QACvB,KAAK,CAAC,oBAAoB,CAAC,IAAI,CAAC,CAAA;IAClC,CAAC;IAEO,YAAY,CAAC,IAAqB;QACxC,MAAM,OAAO,GAAG,UAAU,CAAC,IAAI,CAAC,CAAA;QAEhC,IAAI,CAAC,OAAO,IAAI,CAAC,+CAA+C,CAAC,GAAG,CAAC,OAAO,CAAC,EAAE,CAAC;YAC9E,OAAM;QACR,CAAC;QAED,MAAM,WAAW,GAAG,YA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E,OAAO,CAAC,CAAA;QAE/E,OAAO,CAAC,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,CAAA;QAE3B,OAAO,OAAO,CAAC,QAAQ,CAAA;IACzB,CAAC;CACF"}
|
|
@@ -1,13 +1,20 @@
|
|
|
1
|
-
import { AttributeVisitorMixin, isBooleanAttribute, hasAttributeValue } from "./rule-utils.js";
|
|
2
1
|
import { ParserRule } from "../types.js";
|
|
2
|
+
import { AttributeVisitorMixin, isBooleanAttribute, hasAttributeValue } from "./rule-utils.js";
|
|
3
3
|
class BooleanAttributesNoValueVisitor extends AttributeVisitorMixin {
|
|
4
|
-
|
|
4
|
+
checkStaticAttributeStaticValue({ attributeName, attributeNode }) {
|
|
5
5
|
if (!isBooleanAttribute(attributeName))
|
|
6
6
|
return;
|
|
7
7
|
if (!hasAttributeValue(attributeNode))
|
|
8
8
|
return;
|
|
9
9
|
this.addOffense(`Boolean attribute \`${attributeName}\` should not have a value. Use \`${attributeName}\` instead of \`${attributeName}="${attributeName}"\`.`, attributeNode.value.location, "error");
|
|
10
10
|
}
|
|
11
|
+
checkStaticAttributeDynamicValue({ attributeName, attributeNode, combinedValue }) {
|
|
12
|
+
if (!isBooleanAttribute(attributeName))
|
|
13
|
+
return;
|
|
14
|
+
if (!hasAttributeValue(attributeNode))
|
|
15
|
+
return;
|
|
16
|
+
this.addOffense(`Boolean attribute \`${attributeName}\` should not have a value. Use \`${attributeName}\` instead of \`${attributeName}="${combinedValue}"\`.`, attributeNode.value.location, "error");
|
|
17
|
+
}
|
|
11
18
|
}
|
|
12
19
|
export class HTMLBooleanAttributesNoValueRule extends ParserRule {
|
|
13
20
|
name = "html-boolean-attributes-no-value";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"html-boolean-attributes-no-value.js","sourceRoot":"","sources":["../../../src/rules/html-boolean-attributes-no-value.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"html-boolean-attributes-no-value.js","s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 -0,0 +1,39 @@
|
|
|
1
|
+
import { ParserRule } from "../types.js";
|
|
2
|
+
import { BaseRuleVisitor, getTagName, getAttribute, getAttributeValue } from "./rule-utils.js";
|
|
3
|
+
class IframeHasTitleVisitor extends BaseRuleVisitor {
|
|
4
|
+
visitHTMLOpenTagNode(node) {
|
|
5
|
+
this.checkIframeElement(node);
|
|
6
|
+
super.visitHTMLOpenTagNode(node);
|
|
7
|
+
}
|
|
8
|
+
checkIframeElement(node) {
|
|
9
|
+
const tagName = getTagName(node);
|
|
10
|
+
if (tagName !== "iframe") {
|
|
11
|
+
return;
|
|
12
|
+
}
|
|
13
|
+
const ariaHiddenAttribute = getAttribute(node, "aria-hidden");
|
|
14
|
+
if (ariaHiddenAttribute) {
|
|
15
|
+
const ariaHiddenValue = getAttributeValue(ariaHiddenAttribute);
|
|
16
|
+
if (ariaHiddenValue === "true") {
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
const attribute = getAttribute(node, "title");
|
|
21
|
+
if (!attribute) {
|
|
22
|
+
this.addOffense("`<iframe>` elements must have a `title` attribute that describes the content of the frame for screen reader users.", node.location, "error");
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
const value = getAttributeValue(attribute);
|
|
26
|
+
if (!value || value.trim() === "") {
|
|
27
|
+
this.addOffense("`<iframe>` elements must have a `title` attribute that describes the content of the frame for screen reader users.", node.location, "error");
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
export class HTMLIframeHasTitleRule extends ParserRule {
|
|
32
|
+
name = "html-iframe-has-title";
|
|
33
|
+
check(result, context) {
|
|
34
|
+
const visitor = new IframeHasTitleVisitor(this.name, context);
|
|
35
|
+
visitor.visit(result.value);
|
|
36
|
+
return visitor.offenses;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
//# sourceMappingURL=html-iframe-has-title.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"html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AM,OAAO,sBAAuB,SAAQ,UAAU;IACpD,IAAI,GAAG,uBAAuB,CAAA;IAE9B,KAAK,CAAC,MAAmB,EAAE,OAA8B;QACvD,MAAM,OAAO,GAAG,IAAI,qBAAqB,CAAC,IAAI,CAAC,IAAI,EAAE,OAAO,CAAC,CAAA;QAE7D,OAAO,CAAC,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,CAAA;QAE3B,OAAO,OAAO,CAAC,QAAQ,CAAA;IACzB,CAAC;CACF"}
|
|
@@ -5,10 +5,6 @@ class ImgRequireAltVisitor extends BaseRuleVisitor {
|
|
|
5
5
|
this.checkImgTag(node);
|
|
6
6
|
super.visitHTMLOpenTagNode(node);
|
|
7
7
|
}
|
|
8
|
-
visitHTMLSelfCloseTagNode(node) {
|
|
9
|
-
this.checkImgTag(node);
|
|
10
|
-
super.visitHTMLSelfCloseTagNode(node);
|
|
11
|
-
}
|
|
12
8
|
checkImgTag(node) {
|
|
13
9
|
const tagName = getTagName(node);
|
|
14
10
|
if (tagName !== "img") {
|