@herb-tools/linter 0.8.1 → 0.8.2
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 +42 -2
- package/dist/herb-lint.js +81 -17
- package/dist/herb-lint.js.map +1 -1
- package/dist/index.cjs +51 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +52 -1
- package/dist/index.js.map +1 -1
- package/dist/loader.cjs +63 -8
- package/dist/loader.cjs.map +1 -1
- package/dist/loader.js +63 -8
- package/dist/loader.js.map +1 -1
- package/dist/package.json +7 -7
- package/dist/src/herb-disable-comment-utils.js.map +1 -1
- package/dist/src/linter-ignore.js +42 -0
- package/dist/src/linter-ignore.js.map +1 -0
- package/dist/src/linter.js +12 -0
- package/dist/src/linter.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/types/linter-ignore.d.ts +12 -0
- package/dist/types/src/linter-ignore.d.ts +12 -0
- package/package.json +7 -7
- package/src/herb-disable-comment-utils.ts +3 -0
- package/src/linter-ignore.ts +50 -0
- package/src/linter.ts +14 -0
package/dist/loader.cjs
CHANGED
|
@@ -186,7 +186,7 @@ class Token {
|
|
|
186
186
|
}
|
|
187
187
|
|
|
188
188
|
// NOTE: This file is generated by the templates/template.rb script and should not
|
|
189
|
-
// be modified manually. See /Users/marcoroth/Development/herb-release-0.8.
|
|
189
|
+
// be modified manually. See /Users/marcoroth/Development/herb-release-0.8.2/templates/javascript/packages/core/src/errors.ts.erb
|
|
190
190
|
class HerbError {
|
|
191
191
|
type;
|
|
192
192
|
message;
|
|
@@ -716,7 +716,7 @@ function convertToUTF8(string) {
|
|
|
716
716
|
}
|
|
717
717
|
|
|
718
718
|
// NOTE: This file is generated by the templates/template.rb script and should not
|
|
719
|
-
// be modified manually. See /Users/marcoroth/Development/herb-release-0.8.
|
|
719
|
+
// be modified manually. See /Users/marcoroth/Development/herb-release-0.8.2/templates/javascript/packages/core/src/nodes.ts.erb
|
|
720
720
|
class Node {
|
|
721
721
|
type;
|
|
722
722
|
location;
|
|
@@ -2950,7 +2950,7 @@ class ParseResult extends Result {
|
|
|
2950
2950
|
}
|
|
2951
2951
|
|
|
2952
2952
|
// NOTE: This file is generated by the templates/template.rb script and should not
|
|
2953
|
-
// be modified manually. See /Users/marcoroth/Development/herb-release-0.8.
|
|
2953
|
+
// be modified manually. See /Users/marcoroth/Development/herb-release-0.8.2/templates/javascript/packages/core/src/node-type-guards.ts.erb
|
|
2954
2954
|
/**
|
|
2955
2955
|
* Type guard functions for AST nodes.
|
|
2956
2956
|
* These functions provide type checking by combining both instanceof
|
|
@@ -3340,10 +3340,14 @@ function isERBOutputNode(node) {
|
|
|
3340
3340
|
return ["<%=", "<%=="].includes(node.tag_opening?.value);
|
|
3341
3341
|
}
|
|
3342
3342
|
/**
|
|
3343
|
-
* Checks if a node is a
|
|
3343
|
+
* Checks if a node is a ERB comment node (control flow: <%# %>)
|
|
3344
3344
|
*/
|
|
3345
|
-
function
|
|
3346
|
-
|
|
3345
|
+
function isERBCommentNode(node) {
|
|
3346
|
+
if (!isERBNode(node))
|
|
3347
|
+
return false;
|
|
3348
|
+
if (!node.tag_opening?.value)
|
|
3349
|
+
return false;
|
|
3350
|
+
return node.tag_opening?.value === "<%#" || (node.tag_opening?.value !== "<%#" && (node.content?.value || "").trimStart().startsWith("#"));
|
|
3347
3351
|
}
|
|
3348
3352
|
/**
|
|
3349
3353
|
* Checks if an array of nodes contains any ERB content nodes
|
|
@@ -3462,7 +3466,7 @@ function getTagName$1(node) {
|
|
|
3462
3466
|
* Check if a node is a comment (HTML comment or ERB comment)
|
|
3463
3467
|
*/
|
|
3464
3468
|
function isCommentNode(node) {
|
|
3465
|
-
return
|
|
3469
|
+
return isHTMLCommentNode(node) || isERBCommentNode(node);
|
|
3466
3470
|
}
|
|
3467
3471
|
/**
|
|
3468
3472
|
* Compares two positions to determine if the first comes before the second
|
|
@@ -3649,7 +3653,7 @@ function didyoumean(input, list, threshold) {
|
|
|
3649
3653
|
}
|
|
3650
3654
|
|
|
3651
3655
|
// NOTE: This file is generated by the templates/template.rb script and should not
|
|
3652
|
-
// be modified manually. See /Users/marcoroth/Development/herb-release-0.8.
|
|
3656
|
+
// be modified manually. See /Users/marcoroth/Development/herb-release-0.8.2/templates/javascript/packages/core/src/visitor.ts.erb
|
|
3653
3657
|
class Visitor {
|
|
3654
3658
|
visit(node) {
|
|
3655
3659
|
if (!node)
|
|
@@ -10481,6 +10485,46 @@ const rules = [
|
|
|
10481
10485
|
ParserNoErrorsRule,
|
|
10482
10486
|
];
|
|
10483
10487
|
|
|
10488
|
+
const HERB_LINTER_PREFIX = "herb:linter";
|
|
10489
|
+
const HERB_LINTER_IGNORE_PREFIX = `${HERB_LINTER_PREFIX} ignore`;
|
|
10490
|
+
/**
|
|
10491
|
+
* Check if an ERB content node is a herb:linter ignore comment.
|
|
10492
|
+
*
|
|
10493
|
+
* @param node - The ERB content node to check
|
|
10494
|
+
* @returns true if this is a linter ignore directive
|
|
10495
|
+
*/
|
|
10496
|
+
function isHerbLinterIgnoreComment(node) {
|
|
10497
|
+
if (!isERBCommentNode(node))
|
|
10498
|
+
return false;
|
|
10499
|
+
const content = node?.content?.value || "";
|
|
10500
|
+
return content.trim() === HERB_LINTER_IGNORE_PREFIX;
|
|
10501
|
+
}
|
|
10502
|
+
/**
|
|
10503
|
+
* Check if the document contains a herb:linter ignore directive anywhere.
|
|
10504
|
+
*/
|
|
10505
|
+
function hasLinterIgnoreDirective(parseResult) {
|
|
10506
|
+
if (parseResult.failed)
|
|
10507
|
+
return false;
|
|
10508
|
+
const detector = new LinterIgnoreDetector();
|
|
10509
|
+
detector.visit(parseResult.value);
|
|
10510
|
+
return detector.hasIgnoreDirective;
|
|
10511
|
+
}
|
|
10512
|
+
/**
|
|
10513
|
+
* Visitor that detects if the AST contains a herb:linter ignore directive.
|
|
10514
|
+
*/
|
|
10515
|
+
class LinterIgnoreDetector extends Visitor {
|
|
10516
|
+
hasIgnoreDirective = false;
|
|
10517
|
+
visitERBContentNode(node) {
|
|
10518
|
+
if (isHerbLinterIgnoreComment(node)) {
|
|
10519
|
+
this.hasIgnoreDirective = true;
|
|
10520
|
+
return;
|
|
10521
|
+
}
|
|
10522
|
+
if (this.hasIgnoreDirective)
|
|
10523
|
+
return;
|
|
10524
|
+
this.visitChildNodes(node);
|
|
10525
|
+
}
|
|
10526
|
+
}
|
|
10527
|
+
|
|
10484
10528
|
class Linter {
|
|
10485
10529
|
rules;
|
|
10486
10530
|
allAvailableRules;
|
|
@@ -10691,6 +10735,17 @@ class Linter {
|
|
|
10691
10735
|
let ignoredCount = 0;
|
|
10692
10736
|
let wouldBeIgnoredCount = 0;
|
|
10693
10737
|
const parseResult = this.herb.parse(source, { track_whitespace: true });
|
|
10738
|
+
// Check for file-level ignore directive using visitor
|
|
10739
|
+
if (hasLinterIgnoreDirective(parseResult)) {
|
|
10740
|
+
return {
|
|
10741
|
+
offenses: [],
|
|
10742
|
+
errors: 0,
|
|
10743
|
+
warnings: 0,
|
|
10744
|
+
info: 0,
|
|
10745
|
+
hints: 0,
|
|
10746
|
+
ignored: 0
|
|
10747
|
+
};
|
|
10748
|
+
}
|
|
10694
10749
|
const lexResult = this.herb.lex(source);
|
|
10695
10750
|
const hasParserErrors = parseResult.recursiveErrors().length > 0;
|
|
10696
10751
|
const sourceLines = source.split("\n");
|