@reteps/tree-sitter-htmlmustache 0.5.0 → 0.5.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/README.md CHANGED
@@ -247,6 +247,17 @@ Additionally, the following rules are configurable. Set their severities (`"erro
247
247
 
248
248
  <!-- RULES_TABLE_END -->
249
249
 
250
+ ### Disabling Lint Rules
251
+
252
+ Disable a configurable lint rule for an entire file with an inline comment:
253
+
254
+ ```html
255
+ <!-- htmlmustache-disable preferMustacheComments -->
256
+ {{! htmlmustache-disable selfClosingNonVoidTags }}
257
+ ```
258
+
259
+ The comment can appear anywhere in the file. Only configurable rules (listed above) can be disabled. Use multiple comments to disable multiple rules.
260
+
250
261
  ### EditorConfig
251
262
 
252
263
  Both the CLI and VS Code extension respect your `.editorconfig` file for indentation settings (`indent_style`, `indent_size`). EditorConfig values override `.htmlmustache.jsonc` for indentation, and CLI flags override everything.
package/cli/out/main.js CHANGED
@@ -1425,6 +1425,35 @@ function errorMessageForNode(nodeType, node) {
1425
1425
  function resolveRuleSeverity(rules, ruleName) {
1426
1426
  return rules?.[ruleName] ?? RULE_DEFAULTS[ruleName] ?? "off";
1427
1427
  }
1428
+ function parseDisableDirective(node) {
1429
+ if (node.type !== "html_comment" && node.type !== "mustache_comment") return null;
1430
+ let inner = null;
1431
+ if (node.type === "html_comment") {
1432
+ const match = node.text.match(/^<!--([\s\S]*)-->$/);
1433
+ if (match) inner = match[1].trim();
1434
+ } else {
1435
+ const match = node.text.match(/^\{\{!([\s\S]*)\}\}$/);
1436
+ if (match) inner = match[1].trim();
1437
+ }
1438
+ if (!inner) return null;
1439
+ const prefix = "htmlmustache-disable ";
1440
+ if (!inner.startsWith(prefix)) return null;
1441
+ const ruleName = inner.slice(prefix.length).trim();
1442
+ return KNOWN_RULE_NAMES.has(ruleName) ? ruleName : null;
1443
+ }
1444
+ function collectDisabledRules(rootNode) {
1445
+ const disabled = /* @__PURE__ */ new Set();
1446
+ function walk(node) {
1447
+ const rule = parseDisableDirective(node);
1448
+ if (rule) {
1449
+ disabled.add(rule);
1450
+ return;
1451
+ }
1452
+ for (const child of node.children) walk(child);
1453
+ }
1454
+ walk(rootNode);
1455
+ return disabled;
1456
+ }
1428
1457
  function collectErrors(tree, rules) {
1429
1458
  const errors = [];
1430
1459
  const cursor = tree.walk();
@@ -1454,6 +1483,11 @@ function collectErrors(tree, rules) {
1454
1483
  for (const error of unclosedErrors) {
1455
1484
  errors.push({ node: error.node, message: error.message });
1456
1485
  }
1486
+ const disabledRules = collectDisabledRules(tree.rootNode);
1487
+ const effectiveRules = { ...rules };
1488
+ for (const rule of disabledRules) {
1489
+ effectiveRules[rule] = "off";
1490
+ }
1457
1491
  const sourceText = tree.rootNode.text;
1458
1492
  const ruleChecks = [
1459
1493
  { rule: "nestedDuplicateSections", errors: () => checkNestedSameNameSections(tree.rootNode) },
@@ -1465,7 +1499,7 @@ function collectErrors(tree, rules) {
1465
1499
  { rule: "preferMustacheComments", errors: () => checkHtmlComments(tree.rootNode) }
1466
1500
  ];
1467
1501
  for (const { rule, errors: getErrors } of ruleChecks) {
1468
- const severity = resolveRuleSeverity(rules, rule);
1502
+ const severity = resolveRuleSeverity(effectiveRules, rule);
1469
1503
  if (severity === "off") continue;
1470
1504
  for (const error of getErrors()) {
1471
1505
  errors.push({
@@ -1477,7 +1511,9 @@ function collectErrors(tree, rules) {
1477
1511
  });
1478
1512
  }
1479
1513
  }
1480
- return errors;
1514
+ return errors.filter(
1515
+ (e) => !(e.message.includes("HTML comment found") && parseDisableDirective(e.node) !== null)
1516
+ );
1481
1517
  }
1482
1518
 
1483
1519
  // cli/src/check.ts
@@ -3252,7 +3288,8 @@ function formatBlockChildren(nodes, context) {
3252
3288
  pendingBlankLine = false;
3253
3289
  } else if (node.type === "html_comment" || node.type === "mustache_comment") {
3254
3290
  const isMultiline = node.startPosition.row !== node.endPosition.row;
3255
- if (isMultiline) {
3291
+ const isOnOwnLine = i > 0 && node.startPosition.row > nodes[i - 1].endPosition.row;
3292
+ if (isMultiline || isOnOwnLine) {
3256
3293
  if (currentLine.length > 0) {
3257
3294
  const lineContent = trimDoc(flushCurrentLine());
3258
3295
  if (hasDocContent(lineContent)) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@reteps/tree-sitter-htmlmustache",
3
- "version": "0.5.0",
3
+ "version": "0.5.1",
4
4
  "description": "HTML with Mustache/Handlebars template syntax grammar for tree-sitter",
5
5
  "repository": {
6
6
  "type": "git",