@herb-tools/linter 0.7.4 → 0.7.5
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/README.md +2 -2
- package/dist/herb-lint.js +116 -42
- package/dist/herb-lint.js.map +1 -1
- package/dist/index.cjs +47 -8
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +47 -10
- package/dist/index.js.map +1 -1
- package/dist/package.json +5 -5
- package/dist/src/cli/argument-parser.js +4 -2
- package/dist/src/cli/argument-parser.js.map +1 -1
- package/dist/src/cli.js +2 -1
- package/dist/src/cli.js.map +1 -1
- package/dist/src/default-rules.js +4 -0
- package/dist/src/default-rules.js.map +1 -1
- package/dist/src/rules/erb-comment-syntax.js +19 -0
- package/dist/src/rules/erb-comment-syntax.js.map +1 -0
- package/dist/src/rules/erb-require-whitespace-inside-tags.js +1 -9
- package/dist/src/rules/erb-require-whitespace-inside-tags.js.map +1 -1
- package/dist/src/rules/erb-right-trim.js +28 -0
- package/dist/src/rules/erb-right-trim.js.map +1 -0
- package/dist/src/rules/index.js +2 -0
- package/dist/src/rules/index.js.map +1 -1
- package/dist/src/rules/rule-utils.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/types/rules/erb-comment-syntax.d.ts +7 -0
- package/dist/types/rules/erb-require-whitespace-inside-tags.d.ts +1 -1
- package/dist/types/rules/erb-right-trim.d.ts +7 -0
- package/dist/types/rules/index.d.ts +2 -0
- package/dist/types/src/rules/erb-comment-syntax.d.ts +7 -0
- package/dist/types/src/rules/erb-require-whitespace-inside-tags.d.ts +1 -1
- package/dist/types/src/rules/erb-right-trim.d.ts +7 -0
- package/dist/types/src/rules/index.d.ts +2 -0
- package/docs/rules/README.md +3 -1
- package/docs/rules/erb-comment-syntax.md +44 -0
- package/docs/rules/erb-right-trim.md +57 -0
- package/package.json +5 -5
- package/src/cli/argument-parser.ts +4 -2
- package/src/cli.ts +3 -1
- package/src/default-rules.ts +4 -0
- package/src/rules/erb-comment-syntax.ts +30 -0
- package/src/rules/erb-require-whitespace-inside-tags.ts +4 -12
- package/src/rules/erb-right-trim.ts +44 -0
- package/src/rules/index.ts +2 -0
- package/src/rules/rule-utils.ts +2 -2
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Visitor, getStaticAttributeName, hasDynamicAttributeName as hasDynamicAttributeName$1, getCombinedAttributeName, hasStaticContent, getStaticContentFromNodes, Position, Location, hasERBOutput, isEffectivelyStatic, getValidatableStaticContent, filterERBContentNodes, filterNodes, ERBContentNode, isERBOutputNode, getNodesBeforePosition, getNodesAfterPosition, isToken, isParseResult, isNode, LiteralNode,
|
|
1
|
+
import { Visitor, getStaticAttributeName, hasDynamicAttributeName as hasDynamicAttributeName$1, getCombinedAttributeName, hasStaticContent, getStaticContentFromNodes, Position, Location, hasERBOutput, isEffectivelyStatic, getValidatableStaticContent, filterERBContentNodes, filterNodes, ERBContentNode, isERBOutputNode, getNodesBeforePosition, getNodesAfterPosition, isToken, isParseResult, isNode, LiteralNode, filterLiteralNodes, getTagName as getTagName$1, HTMLOpenTagNode } from '@herb-tools/core';
|
|
2
2
|
|
|
3
3
|
class ParserRule {
|
|
4
4
|
static type = "parser";
|
|
@@ -680,6 +680,23 @@ class BaseSourceRuleVisitor {
|
|
|
680
680
|
}
|
|
681
681
|
}
|
|
682
682
|
|
|
683
|
+
class ERBCommentSyntaxVisitor extends BaseRuleVisitor {
|
|
684
|
+
visitERBContentNode(node) {
|
|
685
|
+
if (node.content?.value.startsWith(" #")) {
|
|
686
|
+
const openingTag = node.tag_opening?.value;
|
|
687
|
+
this.addOffense(`Use \`<%#\` instead of \`${openingTag} #\`. Ruby comments immediately after ERB tags can cause parsing issues.`, node.location);
|
|
688
|
+
}
|
|
689
|
+
}
|
|
690
|
+
}
|
|
691
|
+
class ERBCommentSyntax extends ParserRule {
|
|
692
|
+
name = "erb-comment-syntax";
|
|
693
|
+
check(result, context) {
|
|
694
|
+
const visitor = new ERBCommentSyntaxVisitor(this.name, context);
|
|
695
|
+
visitor.visit(result.value);
|
|
696
|
+
return visitor.offenses;
|
|
697
|
+
}
|
|
698
|
+
}
|
|
699
|
+
|
|
683
700
|
class ERBNoEmptyTagsVisitor extends BaseRuleVisitor {
|
|
684
701
|
visitERBContentNode(node) {
|
|
685
702
|
this.visitChildNodes(node);
|
|
@@ -1531,14 +1548,7 @@ class ERBRequiresTrailingNewlineRule extends SourceRule {
|
|
|
1531
1548
|
}
|
|
1532
1549
|
|
|
1533
1550
|
class RequireWhitespaceInsideTags extends BaseRuleVisitor {
|
|
1534
|
-
|
|
1535
|
-
this.checkWhitespace(node);
|
|
1536
|
-
super.visitChildNodes(node);
|
|
1537
|
-
}
|
|
1538
|
-
checkWhitespace(node) {
|
|
1539
|
-
if (!isERBNode(node)) {
|
|
1540
|
-
return;
|
|
1541
|
-
}
|
|
1551
|
+
visitERBNode(node) {
|
|
1542
1552
|
const openTag = node.tag_opening;
|
|
1543
1553
|
const closeTag = node.tag_closing;
|
|
1544
1554
|
const content = node.content;
|
|
@@ -2647,7 +2657,33 @@ class HTMLNoUnderscoresInAttributeNamesRule extends ParserRule {
|
|
|
2647
2657
|
}
|
|
2648
2658
|
}
|
|
2649
2659
|
|
|
2660
|
+
class ERBRightTrimVisitor extends BaseRuleVisitor {
|
|
2661
|
+
visitERBNode(node) {
|
|
2662
|
+
if (!node.tag_closing)
|
|
2663
|
+
return;
|
|
2664
|
+
const trimClosing = node.tag_closing.value;
|
|
2665
|
+
if (trimClosing !== "=%>" && trimClosing !== "-%>")
|
|
2666
|
+
return;
|
|
2667
|
+
if (!isERBOutputNode(node)) {
|
|
2668
|
+
this.addOffense(`Right-trimming with \`${trimClosing}\` has no effect on non-output ERB tags. Use \`%>\` instead`, node.tag_closing.location);
|
|
2669
|
+
return;
|
|
2670
|
+
}
|
|
2671
|
+
if (trimClosing === "=%>") {
|
|
2672
|
+
this.addOffense("Use `-%>` instead of `=%>` for right-trimming. The `=%>` syntax is obscure and not well-supported in most ERB engines", node.tag_closing.location);
|
|
2673
|
+
}
|
|
2674
|
+
}
|
|
2675
|
+
}
|
|
2676
|
+
class ERBRightTrimRule extends ParserRule {
|
|
2677
|
+
name = "erb-right-trim";
|
|
2678
|
+
check(result, context) {
|
|
2679
|
+
const visitor = new ERBRightTrimVisitor(this.name, context);
|
|
2680
|
+
visitor.visit(result.value);
|
|
2681
|
+
return visitor.offenses;
|
|
2682
|
+
}
|
|
2683
|
+
}
|
|
2684
|
+
|
|
2650
2685
|
const defaultRules = [
|
|
2686
|
+
ERBCommentSyntax,
|
|
2651
2687
|
ERBNoEmptyTagsRule,
|
|
2652
2688
|
ERBNoOutputControlFlowRule,
|
|
2653
2689
|
ERBNoSilentTagInAttributeNameRule,
|
|
@@ -2682,6 +2718,7 @@ const defaultRules = [
|
|
|
2682
2718
|
ParserNoErrorsRule,
|
|
2683
2719
|
SVGTagNameCapitalizationRule,
|
|
2684
2720
|
HTMLNoUnderscoresInAttributeNamesRule,
|
|
2721
|
+
ERBRightTrimRule,
|
|
2685
2722
|
];
|
|
2686
2723
|
|
|
2687
2724
|
class Linter {
|
|
@@ -2902,5 +2939,5 @@ class HTMLNoTitleAttributeRule extends ParserRule {
|
|
|
2902
2939
|
}
|
|
2903
2940
|
}
|
|
2904
2941
|
|
|
2905
|
-
export { ARIA_ATTRIBUTES, AttributeVisitorMixin, BaseLexerRuleVisitor, BaseRuleVisitor, BaseSourceRuleVisitor, ControlFlowTrackingVisitor, ControlFlowType, DEFAULT_LINT_CONTEXT, ERBNoEmptyTagsRule, ERBNoOutputControlFlowRule, ERBNoSilentTagInAttributeNameRule, ERBPreferImageTagHelperRule, ERBRequiresTrailingNewlineRule, HEADING_TAGS, HTMLAnchorRequireHrefRule, HTMLAriaLabelIsWellFormattedRule, HTMLAriaLevelMustBeValidRule, HTMLAriaRoleHeadingRequiresLevelRule, HTMLAriaRoleMustBeValidRule, HTMLAttributeDoubleQuotesRule, HTMLAttributeEqualsSpacingRule, HTMLAttributeValuesRequireQuotesRule, HTMLAvoidBothDisabledAndAriaDisabledRule, HTMLBooleanAttributesNoValueRule, HTMLIframeHasTitleRule, HTMLImgRequireAltRule, HTMLNavigationHasLabelRule, HTMLNoAriaHiddenOnFocusableRule, HTMLNoBlockInsideInlineRule, HTMLNoDuplicateAttributesRule, HTMLNoDuplicateIdsRule, HTMLNoEmptyAttributesRule, HTMLNoEmptyHeadingsRule, HTMLNoNestedLinksRule, HTMLNoPositiveTabIndexRule, HTMLNoSelfClosingRule, HTMLNoTitleAttributeRule, HTMLNoUnderscoresInAttributeNamesRule, HTMLTagNameLowercaseRule, HTML_BLOCK_ELEMENTS, HTML_BOOLEAN_ATTRIBUTES, HTML_INLINE_ELEMENTS, HTML_VOID_ELEMENTS, LexerRule, Linter, ParserRule, SVGTagNameCapitalizationRule, SVG_CAMEL_CASE_ELEMENTS, SVG_LOWERCASE_TO_CAMELCASE, SourceRule, VALID_ARIA_ROLES, createEndOfFileLocation, findAttributeByName, forEachAttribute, getAttribute, getAttributeName, getAttributeValue, getAttributeValueNodes, getAttributeValueQuoteType, getAttributes, getCombinedAttributeNameString, getStaticAttributeValue, getStaticAttributeValueContent, getTagName, hasAttribute, hasAttributeValue, hasDynamicAttributeName, hasDynamicAttributeValue, hasStaticAttributeValue, hasStaticAttributeValueContent, isAttributeValueQuoted, isBlockElement, isBooleanAttribute, isInlineElement, isVoidElement };
|
|
2942
|
+
export { ARIA_ATTRIBUTES, AttributeVisitorMixin, BaseLexerRuleVisitor, BaseRuleVisitor, BaseSourceRuleVisitor, ControlFlowTrackingVisitor, ControlFlowType, DEFAULT_LINT_CONTEXT, ERBCommentSyntax, ERBNoEmptyTagsRule, ERBNoOutputControlFlowRule, ERBNoSilentTagInAttributeNameRule, ERBPreferImageTagHelperRule, ERBRequiresTrailingNewlineRule, ERBRightTrimRule, HEADING_TAGS, HTMLAnchorRequireHrefRule, HTMLAriaLabelIsWellFormattedRule, HTMLAriaLevelMustBeValidRule, HTMLAriaRoleHeadingRequiresLevelRule, HTMLAriaRoleMustBeValidRule, HTMLAttributeDoubleQuotesRule, HTMLAttributeEqualsSpacingRule, HTMLAttributeValuesRequireQuotesRule, HTMLAvoidBothDisabledAndAriaDisabledRule, HTMLBooleanAttributesNoValueRule, HTMLIframeHasTitleRule, HTMLImgRequireAltRule, HTMLNavigationHasLabelRule, HTMLNoAriaHiddenOnFocusableRule, HTMLNoBlockInsideInlineRule, HTMLNoDuplicateAttributesRule, HTMLNoDuplicateIdsRule, HTMLNoEmptyAttributesRule, HTMLNoEmptyHeadingsRule, HTMLNoNestedLinksRule, HTMLNoPositiveTabIndexRule, HTMLNoSelfClosingRule, HTMLNoTitleAttributeRule, HTMLNoUnderscoresInAttributeNamesRule, HTMLTagNameLowercaseRule, HTML_BLOCK_ELEMENTS, HTML_BOOLEAN_ATTRIBUTES, HTML_INLINE_ELEMENTS, HTML_VOID_ELEMENTS, LexerRule, Linter, ParserRule, SVGTagNameCapitalizationRule, SVG_CAMEL_CASE_ELEMENTS, SVG_LOWERCASE_TO_CAMELCASE, SourceRule, VALID_ARIA_ROLES, createEndOfFileLocation, findAttributeByName, forEachAttribute, getAttribute, getAttributeName, getAttributeValue, getAttributeValueNodes, getAttributeValueQuoteType, getAttributes, getCombinedAttributeNameString, getStaticAttributeValue, getStaticAttributeValueContent, getTagName, hasAttribute, hasAttributeValue, hasDynamicAttributeName, hasDynamicAttributeValue, hasStaticAttributeValue, hasStaticAttributeValueContent, isAttributeValueQuoted, isBlockElement, isBooleanAttribute, isInlineElement, isVoidElement };
|
|
2906
2943
|
//# sourceMappingURL=index.js.map
|