@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/README.md +42 -2
- package/dist/herb-lint.js +135 -56
- 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 +8 -8
- 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 +8 -8
- package/src/herb-disable-comment-utils.ts +3 -0
- package/src/linter-ignore.ts +50 -0
- package/src/linter.ts +14 -0
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { getNodesBeforePosition, getNodesAfterPosition, filterNodes, ERBContentNode, isERBOutputNode, Visitor, isToken, isParseResult, getStaticAttributeName, hasDynamicAttributeName as hasDynamicAttributeName$1, getCombinedAttributeName, hasStaticContent, getStaticContentFromNodes, Location, hasERBOutput, isEffectivelyStatic, getValidatableStaticContent, isERBNode, isWhitespaceNode, isCommentNode, isLiteralNode, isHTMLTextNode, Position, filterERBContentNodes, isNode, LiteralNode, didyoumean, filterLiteralNodes, Token, getTagName as getTagName$1, isHTMLElementNode, HTMLCloseTagNode, isHTMLOpenTagNode, WhitespaceNode, filterWhitespaceNodes, HTMLOpenTagNode } from '@herb-tools/core';
|
|
1
|
+
import { getNodesBeforePosition, getNodesAfterPosition, filterNodes, ERBContentNode, isERBOutputNode, Visitor, isToken, isParseResult, getStaticAttributeName, hasDynamicAttributeName as hasDynamicAttributeName$1, getCombinedAttributeName, hasStaticContent, getStaticContentFromNodes, Location, hasERBOutput, isEffectivelyStatic, getValidatableStaticContent, isERBNode, isWhitespaceNode, isCommentNode, isLiteralNode, isHTMLTextNode, Position, filterERBContentNodes, isNode, LiteralNode, didyoumean, filterLiteralNodes, Token, getTagName as getTagName$1, isHTMLElementNode, HTMLCloseTagNode, isHTMLOpenTagNode, WhitespaceNode, filterWhitespaceNodes, HTMLOpenTagNode, isERBCommentNode } from '@herb-tools/core';
|
|
2
2
|
|
|
3
3
|
class PrintContext {
|
|
4
4
|
output = "";
|
|
@@ -6670,6 +6670,46 @@ const rules = [
|
|
|
6670
6670
|
ParserNoErrorsRule,
|
|
6671
6671
|
];
|
|
6672
6672
|
|
|
6673
|
+
const HERB_LINTER_PREFIX = "herb:linter";
|
|
6674
|
+
const HERB_LINTER_IGNORE_PREFIX = `${HERB_LINTER_PREFIX} ignore`;
|
|
6675
|
+
/**
|
|
6676
|
+
* Check if an ERB content node is a herb:linter ignore comment.
|
|
6677
|
+
*
|
|
6678
|
+
* @param node - The ERB content node to check
|
|
6679
|
+
* @returns true if this is a linter ignore directive
|
|
6680
|
+
*/
|
|
6681
|
+
function isHerbLinterIgnoreComment(node) {
|
|
6682
|
+
if (!isERBCommentNode(node))
|
|
6683
|
+
return false;
|
|
6684
|
+
const content = node?.content?.value || "";
|
|
6685
|
+
return content.trim() === HERB_LINTER_IGNORE_PREFIX;
|
|
6686
|
+
}
|
|
6687
|
+
/**
|
|
6688
|
+
* Check if the document contains a herb:linter ignore directive anywhere.
|
|
6689
|
+
*/
|
|
6690
|
+
function hasLinterIgnoreDirective(parseResult) {
|
|
6691
|
+
if (parseResult.failed)
|
|
6692
|
+
return false;
|
|
6693
|
+
const detector = new LinterIgnoreDetector();
|
|
6694
|
+
detector.visit(parseResult.value);
|
|
6695
|
+
return detector.hasIgnoreDirective;
|
|
6696
|
+
}
|
|
6697
|
+
/**
|
|
6698
|
+
* Visitor that detects if the AST contains a herb:linter ignore directive.
|
|
6699
|
+
*/
|
|
6700
|
+
class LinterIgnoreDetector extends Visitor {
|
|
6701
|
+
hasIgnoreDirective = false;
|
|
6702
|
+
visitERBContentNode(node) {
|
|
6703
|
+
if (isHerbLinterIgnoreComment(node)) {
|
|
6704
|
+
this.hasIgnoreDirective = true;
|
|
6705
|
+
return;
|
|
6706
|
+
}
|
|
6707
|
+
if (this.hasIgnoreDirective)
|
|
6708
|
+
return;
|
|
6709
|
+
this.visitChildNodes(node);
|
|
6710
|
+
}
|
|
6711
|
+
}
|
|
6712
|
+
|
|
6673
6713
|
class Linter {
|
|
6674
6714
|
rules;
|
|
6675
6715
|
allAvailableRules;
|
|
@@ -6880,6 +6920,17 @@ class Linter {
|
|
|
6880
6920
|
let ignoredCount = 0;
|
|
6881
6921
|
let wouldBeIgnoredCount = 0;
|
|
6882
6922
|
const parseResult = this.herb.parse(source, { track_whitespace: true });
|
|
6923
|
+
// Check for file-level ignore directive using visitor
|
|
6924
|
+
if (hasLinterIgnoreDirective(parseResult)) {
|
|
6925
|
+
return {
|
|
6926
|
+
offenses: [],
|
|
6927
|
+
errors: 0,
|
|
6928
|
+
warnings: 0,
|
|
6929
|
+
info: 0,
|
|
6930
|
+
hints: 0,
|
|
6931
|
+
ignored: 0
|
|
6932
|
+
};
|
|
6933
|
+
}
|
|
6883
6934
|
const lexResult = this.herb.lex(source);
|
|
6884
6935
|
const hasParserErrors = parseResult.recursiveErrors().length > 0;
|
|
6885
6936
|
const sourceLines = source.split("\n");
|