@herb-tools/linter 0.8.1 → 0.8.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.
package/dist/index.cjs CHANGED
@@ -6672,6 +6672,46 @@ const rules = [
6672
6672
  ParserNoErrorsRule,
6673
6673
  ];
6674
6674
 
6675
+ const HERB_LINTER_PREFIX = "herb:linter";
6676
+ const HERB_LINTER_IGNORE_PREFIX = `${HERB_LINTER_PREFIX} ignore`;
6677
+ /**
6678
+ * Check if an ERB content node is a herb:linter ignore comment.
6679
+ *
6680
+ * @param node - The ERB content node to check
6681
+ * @returns true if this is a linter ignore directive
6682
+ */
6683
+ function isHerbLinterIgnoreComment(node) {
6684
+ if (!core.isERBCommentNode(node))
6685
+ return false;
6686
+ const content = node?.content?.value || "";
6687
+ return content.trim() === HERB_LINTER_IGNORE_PREFIX;
6688
+ }
6689
+ /**
6690
+ * Check if the document contains a herb:linter ignore directive anywhere.
6691
+ */
6692
+ function hasLinterIgnoreDirective(parseResult) {
6693
+ if (parseResult.failed)
6694
+ return false;
6695
+ const detector = new LinterIgnoreDetector();
6696
+ detector.visit(parseResult.value);
6697
+ return detector.hasIgnoreDirective;
6698
+ }
6699
+ /**
6700
+ * Visitor that detects if the AST contains a herb:linter ignore directive.
6701
+ */
6702
+ class LinterIgnoreDetector extends core.Visitor {
6703
+ hasIgnoreDirective = false;
6704
+ visitERBContentNode(node) {
6705
+ if (isHerbLinterIgnoreComment(node)) {
6706
+ this.hasIgnoreDirective = true;
6707
+ return;
6708
+ }
6709
+ if (this.hasIgnoreDirective)
6710
+ return;
6711
+ this.visitChildNodes(node);
6712
+ }
6713
+ }
6714
+
6675
6715
  class Linter {
6676
6716
  rules;
6677
6717
  allAvailableRules;
@@ -6882,6 +6922,17 @@ class Linter {
6882
6922
  let ignoredCount = 0;
6883
6923
  let wouldBeIgnoredCount = 0;
6884
6924
  const parseResult = this.herb.parse(source, { track_whitespace: true });
6925
+ // Check for file-level ignore directive using visitor
6926
+ if (hasLinterIgnoreDirective(parseResult)) {
6927
+ return {
6928
+ offenses: [],
6929
+ errors: 0,
6930
+ warnings: 0,
6931
+ info: 0,
6932
+ hints: 0,
6933
+ ignored: 0
6934
+ };
6935
+ }
6885
6936
  const lexResult = this.herb.lex(source);
6886
6937
  const hasParserErrors = parseResult.recursiveErrors().length > 0;
6887
6938
  const sourceLines = source.split("\n");