@herb-tools/linter 0.8.9 → 0.9.0
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 +5 -5
- package/dist/{src/cli → cli}/argument-parser.js +15 -2
- package/dist/cli/argument-parser.js.map +1 -0
- package/dist/{src/cli → cli}/file-processor.js +155 -9
- package/dist/cli/file-processor.js.map +1 -0
- package/dist/cli/file-url.js +6 -0
- package/dist/cli/file-url.js.map +1 -0
- package/dist/cli/formatters/base-formatter.js.map +1 -0
- package/dist/{src/cli → cli}/formatters/detailed-formatter.js +16 -19
- package/dist/cli/formatters/detailed-formatter.js.map +1 -0
- package/dist/cli/formatters/github-actions-formatter.js.map +1 -0
- package/dist/cli/formatters/index.js.map +1 -0
- package/dist/cli/formatters/json-formatter.js.map +1 -0
- package/dist/cli/formatters/simple-formatter.js +54 -0
- package/dist/cli/formatters/simple-formatter.js.map +1 -0
- package/dist/cli/index.js.map +1 -0
- package/dist/cli/lint-worker.js +143 -0
- package/dist/cli/lint-worker.js.map +1 -0
- package/dist/cli/output-manager.js.map +1 -0
- package/dist/{src/cli → cli}/summary-reporter.js +13 -16
- package/dist/cli/summary-reporter.js.map +1 -0
- package/dist/{src/cli.js → cli.js} +5 -3
- package/dist/cli.js.map +1 -0
- package/dist/{src/custom-rule-loader.js → custom-rule-loader.js} +20 -4
- package/dist/custom-rule-loader.js.map +1 -0
- package/dist/herb-disable-comment-utils.js.map +1 -0
- package/dist/herb-lint.js +60648 -17513
- package/dist/herb-lint.js.map +1 -1
- package/dist/index.cjs +2621 -934
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +2554 -873
- package/dist/index.js.map +1 -1
- package/dist/lint-worker.js +71462 -0
- package/dist/lint-worker.js.map +1 -0
- package/dist/linter-ignore.js.map +1 -0
- package/dist/{src/linter.js → linter.js} +89 -74
- package/dist/linter.js.map +1 -0
- package/dist/loader.cjs +31206 -7834
- package/dist/loader.cjs.map +1 -1
- package/dist/loader.js +31168 -7802
- package/dist/loader.js.map +1 -1
- package/dist/parse-cache.js +30 -0
- package/dist/parse-cache.js.map +1 -0
- package/dist/rules/actionview-no-silent-helper.js +45 -0
- package/dist/rules/actionview-no-silent-helper.js.map +1 -0
- package/dist/{src/rules → rules}/erb-comment-syntax.js +2 -2
- package/dist/rules/erb-comment-syntax.js.map +1 -0
- package/dist/{src/rules → rules}/erb-no-case-node-children.js +2 -2
- package/dist/rules/erb-no-case-node-children.js.map +1 -0
- package/dist/rules/erb-no-conditional-html-element.js +38 -0
- package/dist/rules/erb-no-conditional-html-element.js.map +1 -0
- package/dist/rules/erb-no-conditional-open-tag.js +24 -0
- package/dist/rules/erb-no-conditional-open-tag.js.map +1 -0
- package/dist/rules/erb-no-duplicate-branch-elements.js +245 -0
- package/dist/rules/erb-no-duplicate-branch-elements.js.map +1 -0
- package/dist/{src/rules → rules}/erb-no-empty-tags.js +2 -2
- package/dist/rules/erb-no-empty-tags.js.map +1 -0
- package/dist/{src/rules → rules}/erb-no-extra-newline.js +4 -21
- package/dist/rules/erb-no-extra-newline.js.map +1 -0
- package/dist/{src/rules → rules}/erb-no-extra-whitespace-inside-tags.js +39 -13
- package/dist/rules/erb-no-extra-whitespace-inside-tags.js.map +1 -0
- package/dist/rules/erb-no-inline-case-conditions.js +40 -0
- package/dist/rules/erb-no-inline-case-conditions.js.map +1 -0
- package/dist/rules/erb-no-instance-variables-in-partials.js +67 -0
- package/dist/rules/erb-no-instance-variables-in-partials.js.map +1 -0
- package/dist/rules/erb-no-interpolated-class-names.js +47 -0
- package/dist/rules/erb-no-interpolated-class-names.js.map +1 -0
- package/dist/rules/erb-no-javascript-tag-helper.js +34 -0
- package/dist/rules/erb-no-javascript-tag-helper.js.map +1 -0
- package/dist/{src/rules → rules}/erb-no-output-control-flow.js +9 -12
- package/dist/rules/erb-no-output-control-flow.js.map +1 -0
- package/dist/rules/erb-no-output-in-attribute-name.js +30 -0
- package/dist/rules/erb-no-output-in-attribute-name.js.map +1 -0
- package/dist/rules/erb-no-output-in-attribute-position.js +30 -0
- package/dist/rules/erb-no-output-in-attribute-position.js.map +1 -0
- package/dist/rules/erb-no-raw-output-in-attribute-value.js +35 -0
- package/dist/rules/erb-no-raw-output-in-attribute-value.js.map +1 -0
- package/dist/{src/rules → rules}/erb-no-silent-tag-in-attribute-name.js +2 -2
- package/dist/rules/erb-no-silent-tag-in-attribute-name.js.map +1 -0
- package/dist/rules/erb-no-statement-in-script.js +58 -0
- package/dist/rules/erb-no-statement-in-script.js.map +1 -0
- package/dist/rules/erb-no-then-in-control-flow.js +45 -0
- package/dist/rules/erb-no-then-in-control-flow.js.map +1 -0
- package/dist/rules/erb-no-trailing-whitespace.js +138 -0
- package/dist/rules/erb-no-trailing-whitespace.js.map +1 -0
- package/dist/rules/erb-no-unsafe-js-attribute.js +36 -0
- package/dist/rules/erb-no-unsafe-js-attribute.js.map +1 -0
- package/dist/rules/erb-no-unsafe-raw.js +63 -0
- package/dist/rules/erb-no-unsafe-raw.js.map +1 -0
- package/dist/rules/erb-no-unsafe-script-interpolation.js +54 -0
- package/dist/rules/erb-no-unsafe-script-interpolation.js.map +1 -0
- package/dist/{src/rules → rules}/erb-prefer-image-tag-helper.js +5 -4
- package/dist/rules/erb-prefer-image-tag-helper.js.map +1 -0
- package/dist/{src/rules → rules}/erb-require-trailing-newline.js +2 -2
- package/dist/rules/erb-require-trailing-newline.js.map +1 -0
- package/dist/{src/rules → rules}/erb-require-whitespace-inside-tags.js +39 -15
- package/dist/rules/erb-require-whitespace-inside-tags.js.map +1 -0
- package/dist/{src/rules → rules}/erb-right-trim.js +2 -2
- package/dist/rules/erb-right-trim.js.map +1 -0
- package/dist/{src/rules → rules}/erb-strict-locals-comment-syntax.js +5 -5
- package/dist/rules/erb-strict-locals-comment-syntax.js.map +1 -0
- package/dist/{src/rules → rules}/erb-strict-locals-required.js +2 -2
- package/dist/rules/erb-strict-locals-required.js.map +1 -0
- package/dist/rules/file-utils.js.map +1 -0
- package/dist/rules/herb-disable-comment-base.js.map +1 -0
- package/dist/{src/rules → rules}/herb-disable-comment-malformed.js +2 -2
- package/dist/rules/herb-disable-comment-malformed.js.map +1 -0
- package/dist/{src/rules → rules}/herb-disable-comment-missing-rules.js +2 -2
- package/dist/rules/herb-disable-comment-missing-rules.js.map +1 -0
- package/dist/{src/rules → rules}/herb-disable-comment-no-duplicate-rules.js +2 -2
- package/dist/rules/herb-disable-comment-no-duplicate-rules.js.map +1 -0
- package/dist/{src/rules → rules}/herb-disable-comment-no-redundant-all.js +2 -2
- package/dist/rules/herb-disable-comment-no-redundant-all.js.map +1 -0
- package/dist/{src/rules → rules}/herb-disable-comment-unnecessary.js +2 -2
- package/dist/rules/herb-disable-comment-unnecessary.js.map +1 -0
- package/dist/{src/rules → rules}/herb-disable-comment-valid-rule-name.js +2 -2
- package/dist/rules/herb-disable-comment-valid-rule-name.js.map +1 -0
- package/dist/rules/html-allowed-script-type.js +57 -0
- package/dist/rules/html-allowed-script-type.js.map +1 -0
- package/dist/rules/html-anchor-require-href.js +68 -0
- package/dist/rules/html-anchor-require-href.js.map +1 -0
- package/dist/{src/rules → rules}/html-aria-attribute-must-be-valid.js +3 -3
- package/dist/rules/html-aria-attribute-must-be-valid.js.map +1 -0
- package/dist/{src/rules → rules}/html-aria-label-is-well-formatted.js +3 -3
- package/dist/rules/html-aria-label-is-well-formatted.js.map +1 -0
- package/dist/{src/rules → rules}/html-aria-level-must-be-valid.js +3 -3
- package/dist/rules/html-aria-level-must-be-valid.js.map +1 -0
- package/dist/{src/rules → rules}/html-aria-role-heading-requires-level.js +5 -4
- package/dist/rules/html-aria-role-heading-requires-level.js.map +1 -0
- package/dist/{src/rules → rules}/html-aria-role-must-be-valid.js +3 -3
- package/dist/rules/html-aria-role-must-be-valid.js.map +1 -0
- package/dist/{src/rules → rules}/html-attribute-double-quotes.js +4 -4
- package/dist/rules/html-attribute-double-quotes.js.map +1 -0
- package/dist/{src/rules → rules}/html-attribute-equals-spacing.js +2 -2
- package/dist/rules/html-attribute-equals-spacing.js.map +1 -0
- package/dist/{src/rules → rules}/html-attribute-values-require-quotes.js +2 -2
- package/dist/rules/html-attribute-values-require-quotes.js.map +1 -0
- package/dist/{src/rules → rules}/html-avoid-both-disabled-and-aria-disabled.js +9 -9
- package/dist/rules/html-avoid-both-disabled-and-aria-disabled.js.map +1 -0
- package/dist/{src/rules → rules}/html-body-only-elements.js +5 -4
- package/dist/rules/html-body-only-elements.js.map +1 -0
- package/dist/{src/rules → rules}/html-boolean-attributes-no-value.js +4 -3
- package/dist/rules/html-boolean-attributes-no-value.js.map +1 -0
- package/dist/rules/html-details-has-summary.js +52 -0
- package/dist/rules/html-details-has-summary.js.map +1 -0
- package/dist/{src/rules → rules}/html-head-only-elements.js +6 -5
- package/dist/rules/html-head-only-elements.js.map +1 -0
- package/dist/{src/rules → rules}/html-iframe-has-title.js +8 -11
- package/dist/rules/html-iframe-has-title.js.map +1 -0
- package/dist/{src/rules → rules}/html-img-require-alt.js +11 -5
- package/dist/rules/html-img-require-alt.js.map +1 -0
- package/dist/{src/rules → rules}/html-input-require-autocomplete.js +7 -10
- package/dist/rules/html-input-require-autocomplete.js.map +1 -0
- package/dist/{src/rules → rules}/html-navigation-has-label.js +6 -5
- package/dist/rules/html-navigation-has-label.js.map +1 -0
- package/dist/rules/html-no-abstract-roles.js +29 -0
- package/dist/rules/html-no-abstract-roles.js.map +1 -0
- package/dist/rules/html-no-aria-hidden-on-body.js +42 -0
- package/dist/rules/html-no-aria-hidden-on-body.js.map +1 -0
- package/dist/{src/rules → rules}/html-no-aria-hidden-on-focusable.js +6 -5
- package/dist/rules/html-no-aria-hidden-on-focusable.js.map +1 -0
- package/dist/{src/rules → rules}/html-no-block-inside-inline.js +6 -9
- package/dist/rules/html-no-block-inside-inline.js.map +1 -0
- package/dist/{src/rules → rules}/html-no-duplicate-attributes.js +4 -3
- package/dist/rules/html-no-duplicate-attributes.js.map +1 -0
- package/dist/{src/rules → rules}/html-no-duplicate-ids.js +14 -11
- package/dist/rules/html-no-duplicate-ids.js.map +1 -0
- package/dist/{src/rules → rules}/html-no-duplicate-meta-names.js +22 -20
- package/dist/rules/html-no-duplicate-meta-names.js.map +1 -0
- package/dist/{src/rules → rules}/html-no-empty-attributes.js +2 -2
- package/dist/rules/html-no-empty-attributes.js.map +1 -0
- package/dist/rules/html-no-empty-headings.js +98 -0
- package/dist/rules/html-no-empty-headings.js.map +1 -0
- package/dist/{src/rules → rules}/html-no-nested-links.js +23 -15
- package/dist/rules/html-no-nested-links.js.map +1 -0
- package/dist/{src/rules → rules}/html-no-positive-tab-index.js +3 -3
- package/dist/rules/html-no-positive-tab-index.js.map +1 -0
- package/dist/{src/rules → rules}/html-no-self-closing.js +4 -4
- package/dist/rules/html-no-self-closing.js.map +1 -0
- package/dist/{src/rules → rules}/html-no-space-in-tag.js +4 -6
- package/dist/rules/html-no-space-in-tag.js.map +1 -0
- package/dist/{src/rules → rules}/html-no-title-attribute.js +6 -5
- package/dist/rules/html-no-title-attribute.js.map +1 -0
- package/dist/{src/rules → rules}/html-no-underscores-in-attribute-names.js +2 -2
- package/dist/rules/html-no-underscores-in-attribute-names.js.map +1 -0
- package/dist/rules/html-require-closing-tags.js +29 -0
- package/dist/rules/html-require-closing-tags.js.map +1 -0
- package/dist/{src/rules → rules}/html-tag-name-lowercase.js +13 -9
- package/dist/rules/html-tag-name-lowercase.js.map +1 -0
- package/dist/{src/rules → rules}/index.js +19 -0
- package/dist/rules/index.js.map +1 -0
- package/dist/{src/rules → rules}/parser-no-errors.js +3 -3
- package/dist/rules/parser-no-errors.js.map +1 -0
- package/dist/{src/rules → rules}/rule-utils.js +141 -219
- package/dist/rules/rule-utils.js.map +1 -0
- package/dist/rules/string-utils.js.map +1 -0
- package/dist/{src/rules → rules}/svg-tag-name-capitalization.js +7 -6
- package/dist/rules/svg-tag-name-capitalization.js.map +1 -0
- package/dist/rules/turbo-permanent-require-id.js +34 -0
- package/dist/rules/turbo-permanent-require-id.js.map +1 -0
- package/dist/{src/rules.js → rules.js} +56 -10
- package/dist/rules.js.map +1 -0
- package/dist/types/cli/argument-parser.d.ts +1 -0
- package/dist/types/cli/file-processor.d.ts +13 -0
- package/dist/types/cli/file-url.d.ts +1 -0
- package/dist/types/cli/index.d.ts +1 -0
- package/dist/types/cli/lint-worker.d.ts +34 -0
- package/dist/types/custom-rule-loader.d.ts +4 -0
- package/dist/types/index.d.ts +1 -0
- package/dist/types/linter.d.ts +13 -6
- package/dist/types/parse-cache.d.ts +9 -0
- package/dist/types/{src/rules/html-aria-level-must-be-valid.d.ts → rules/actionview-no-silent-helper.d.ts} +4 -3
- package/dist/types/rules/erb-comment-syntax.d.ts +1 -1
- package/dist/types/rules/erb-no-case-node-children.d.ts +1 -1
- package/dist/types/{src/rules/herb-disable-comment-malformed.d.ts → rules/erb-no-conditional-html-element.d.ts} +3 -3
- package/dist/types/{src/rules/erb-prefer-image-tag-helper.d.ts → rules/erb-no-conditional-open-tag.d.ts} +3 -3
- package/dist/types/rules/erb-no-duplicate-branch-elements.d.ts +17 -0
- package/dist/types/rules/erb-no-empty-tags.d.ts +1 -1
- package/dist/types/rules/erb-no-extra-newline.d.ts +1 -1
- package/dist/types/rules/erb-no-extra-whitespace-inside-tags.d.ts +1 -1
- package/dist/types/{src/rules/html-no-duplicate-attributes.d.ts → rules/erb-no-inline-case-conditions.d.ts} +4 -3
- package/dist/types/rules/erb-no-instance-variables-in-partials.d.ts +10 -0
- package/dist/types/{src/rules/html-no-aria-hidden-on-focusable.d.ts → rules/erb-no-interpolated-class-names.d.ts} +2 -2
- package/dist/types/{src/rules/html-aria-attribute-must-be-valid.d.ts → rules/erb-no-javascript-tag-helper.d.ts} +2 -2
- package/dist/types/rules/erb-no-output-control-flow.d.ts +1 -1
- package/dist/types/{src/rules/erb-no-silent-tag-in-attribute-name.d.ts → rules/erb-no-output-in-attribute-name.d.ts} +2 -2
- package/dist/types/{src/rules/herb-disable-comment-missing-rules.d.ts → rules/erb-no-output-in-attribute-position.d.ts} +2 -2
- package/dist/types/{src/rules/erb-no-empty-tags.d.ts → rules/erb-no-raw-output-in-attribute-value.d.ts} +2 -2
- package/dist/types/rules/erb-no-silent-tag-in-attribute-name.d.ts +1 -1
- package/dist/types/{src/rules/html-navigation-has-label.d.ts → rules/erb-no-statement-in-script.d.ts} +2 -2
- package/dist/types/rules/erb-no-then-in-control-flow.d.ts +9 -0
- package/dist/types/rules/erb-no-trailing-whitespace.d.ts +19 -0
- package/dist/types/{src/rules/html-no-positive-tab-index.d.ts → rules/erb-no-unsafe-js-attribute.d.ts} +2 -2
- package/dist/types/{src/rules/erb-no-case-node-children.d.ts → rules/erb-no-unsafe-raw.d.ts} +2 -2
- package/dist/types/rules/erb-no-unsafe-script-interpolation.d.ts +8 -0
- package/dist/types/rules/erb-prefer-image-tag-helper.d.ts +1 -1
- package/dist/types/rules/erb-require-trailing-newline.d.ts +1 -1
- package/dist/types/rules/erb-require-whitespace-inside-tags.d.ts +1 -1
- package/dist/types/rules/erb-right-trim.d.ts +1 -1
- package/dist/types/rules/erb-strict-locals-comment-syntax.d.ts +1 -1
- package/dist/types/rules/erb-strict-locals-required.d.ts +1 -1
- package/dist/types/rules/herb-disable-comment-malformed.d.ts +1 -1
- package/dist/types/rules/herb-disable-comment-missing-rules.d.ts +1 -1
- package/dist/types/rules/herb-disable-comment-no-duplicate-rules.d.ts +1 -1
- package/dist/types/rules/herb-disable-comment-no-redundant-all.d.ts +1 -1
- package/dist/types/rules/herb-disable-comment-unnecessary.d.ts +1 -1
- package/dist/types/rules/herb-disable-comment-valid-rule-name.d.ts +1 -1
- package/dist/types/{src/rules/html-anchor-require-href.d.ts → rules/html-allowed-script-type.d.ts} +2 -2
- package/dist/types/rules/html-anchor-require-href.d.ts +3 -2
- package/dist/types/rules/html-aria-attribute-must-be-valid.d.ts +1 -1
- package/dist/types/rules/html-aria-label-is-well-formatted.d.ts +1 -1
- package/dist/types/rules/html-aria-level-must-be-valid.d.ts +1 -1
- package/dist/types/rules/html-aria-role-heading-requires-level.d.ts +1 -1
- package/dist/types/rules/html-aria-role-must-be-valid.d.ts +1 -1
- package/dist/types/rules/html-attribute-double-quotes.d.ts +1 -1
- package/dist/types/rules/html-attribute-equals-spacing.d.ts +1 -1
- package/dist/types/rules/html-attribute-values-require-quotes.d.ts +1 -1
- package/dist/types/rules/html-avoid-both-disabled-and-aria-disabled.d.ts +1 -1
- package/dist/types/rules/html-body-only-elements.d.ts +1 -1
- package/dist/types/rules/html-boolean-attributes-no-value.d.ts +1 -1
- package/dist/types/{src/rules/html-no-empty-attributes.d.ts → rules/html-details-has-summary.d.ts} +4 -3
- package/dist/types/rules/html-head-only-elements.d.ts +1 -1
- package/dist/types/rules/html-iframe-has-title.d.ts +1 -1
- package/dist/types/rules/html-img-require-alt.d.ts +1 -1
- package/dist/types/rules/html-input-require-autocomplete.d.ts +1 -1
- package/dist/types/rules/html-navigation-has-label.d.ts +1 -1
- package/dist/types/{src/rules/html-no-empty-headings.d.ts → rules/html-no-abstract-roles.d.ts} +2 -2
- package/dist/types/{src/rules/erb-no-output-control-flow.d.ts → rules/html-no-aria-hidden-on-body.d.ts} +3 -3
- package/dist/types/rules/html-no-aria-hidden-on-focusable.d.ts +1 -1
- package/dist/types/rules/html-no-block-inside-inline.d.ts +1 -1
- package/dist/types/rules/html-no-duplicate-attributes.d.ts +1 -1
- package/dist/types/rules/html-no-duplicate-ids.d.ts +1 -1
- package/dist/types/rules/html-no-duplicate-meta-names.d.ts +1 -1
- package/dist/types/rules/html-no-empty-attributes.d.ts +1 -1
- package/dist/types/rules/html-no-empty-headings.d.ts +1 -1
- package/dist/types/rules/html-no-nested-links.d.ts +1 -1
- package/dist/types/rules/html-no-positive-tab-index.d.ts +1 -1
- package/dist/types/rules/html-no-self-closing.d.ts +1 -1
- package/dist/types/rules/html-no-space-in-tag.d.ts +1 -1
- package/dist/types/rules/html-no-title-attribute.d.ts +1 -1
- package/dist/types/rules/html-no-underscores-in-attribute-names.d.ts +1 -1
- package/dist/types/{src/rules/html-body-only-elements.d.ts → rules/html-require-closing-tags.d.ts} +4 -3
- package/dist/types/rules/html-tag-name-lowercase.d.ts +1 -1
- package/dist/types/rules/index.d.ts +19 -0
- package/dist/types/rules/parser-no-errors.d.ts +1 -1
- package/dist/types/rules/rule-utils.d.ts +35 -88
- package/dist/types/rules/svg-tag-name-capitalization.d.ts +1 -1
- package/dist/types/{src/rules/html-aria-role-must-be-valid.d.ts → rules/turbo-permanent-require-id.d.ts} +2 -2
- package/dist/types/types.d.ts +25 -7
- package/dist/types/urls.d.ts +1 -0
- package/dist/{src/types.js → types.js} +53 -0
- package/dist/types.js.map +1 -0
- package/dist/urls.js +5 -0
- package/dist/urls.js.map +1 -0
- package/docs/rules/README.md +23 -2
- package/docs/rules/actionview-no-silent-helper.md +57 -0
- package/docs/rules/erb-no-conditional-html-element.md +90 -0
- package/docs/rules/erb-no-conditional-open-tag.md +130 -0
- package/docs/rules/erb-no-duplicate-branch-elements.md +98 -0
- package/docs/rules/erb-no-inline-case-conditions.md +85 -0
- package/docs/rules/erb-no-instance-variables-in-partials.md +43 -0
- package/docs/rules/erb-no-interpolated-class-names.md +57 -0
- package/docs/rules/erb-no-javascript-tag-helper.md +33 -0
- package/docs/rules/erb-no-output-in-attribute-name.md +38 -0
- package/docs/rules/erb-no-output-in-attribute-position.md +60 -0
- package/docs/rules/erb-no-raw-output-in-attribute-value.md +37 -0
- package/docs/rules/erb-no-statement-in-script.md +68 -0
- package/docs/rules/erb-no-then-in-control-flow.md +86 -0
- package/docs/rules/erb-no-trailing-whitespace.md +69 -0
- package/docs/rules/erb-no-unsafe-js-attribute.md +41 -0
- package/docs/rules/erb-no-unsafe-raw.md +47 -0
- package/docs/rules/erb-no-unsafe-script-interpolation.md +73 -0
- package/docs/rules/html-allowed-script-type.md +59 -0
- package/docs/rules/html-anchor-require-href.md +19 -6
- package/docs/rules/html-details-has-summary.md +46 -0
- package/docs/rules/html-img-require-alt.md +5 -3
- package/docs/rules/html-no-abstract-roles.md +74 -0
- package/docs/rules/html-no-aria-hidden-on-body.md +44 -0
- package/docs/rules/html-require-closing-tags.md +142 -0
- package/docs/rules/parser-no-errors.md +4 -17
- package/docs/rules/turbo-permanent-require-id.md +41 -0
- package/package.json +12 -11
- package/src/cli/argument-parser.ts +20 -2
- package/src/cli/file-processor.ts +189 -10
- package/src/cli/file-url.ts +6 -0
- package/src/cli/formatters/detailed-formatter.ts +19 -21
- package/src/cli/formatters/simple-formatter.ts +23 -13
- package/src/cli/index.ts +2 -0
- package/src/cli/lint-worker.ts +208 -0
- package/src/cli/summary-reporter.ts +14 -15
- package/src/cli.ts +5 -3
- package/src/custom-rule-loader.ts +20 -5
- package/src/herb-disable-comment-utils.ts +0 -3
- package/src/index.ts +1 -0
- package/src/linter.ts +98 -79
- package/src/parse-cache.ts +39 -0
- package/src/rules/actionview-no-silent-helper.ts +58 -0
- package/src/rules/erb-comment-syntax.ts +2 -2
- package/src/rules/erb-no-case-node-children.ts +2 -2
- package/src/rules/erb-no-conditional-html-element.ts +53 -0
- package/src/rules/erb-no-conditional-open-tag.ts +37 -0
- package/src/rules/erb-no-duplicate-branch-elements.ts +320 -0
- package/src/rules/erb-no-empty-tags.ts +2 -2
- package/src/rules/erb-no-extra-newline.ts +5 -25
- package/src/rules/erb-no-extra-whitespace-inside-tags.ts +45 -15
- package/src/rules/erb-no-inline-case-conditions.ts +54 -0
- package/src/rules/erb-no-instance-variables-in-partials.ts +101 -0
- package/src/rules/erb-no-interpolated-class-names.ts +65 -0
- package/src/rules/erb-no-javascript-tag-helper.ts +47 -0
- package/src/rules/erb-no-output-control-flow.ts +10 -10
- package/src/rules/erb-no-output-in-attribute-name.ts +39 -0
- package/src/rules/erb-no-output-in-attribute-position.ts +39 -0
- package/src/rules/erb-no-raw-output-in-attribute-value.ts +47 -0
- package/src/rules/erb-no-silent-tag-in-attribute-name.ts +2 -2
- package/src/rules/erb-no-statement-in-script.ts +82 -0
- package/src/rules/erb-no-then-in-control-flow.ts +62 -0
- package/src/rules/erb-no-trailing-whitespace.ts +187 -0
- package/src/rules/erb-no-unsafe-js-attribute.ts +47 -0
- package/src/rules/erb-no-unsafe-raw.ts +83 -0
- package/src/rules/erb-no-unsafe-script-interpolation.ts +76 -0
- package/src/rules/erb-prefer-image-tag-helper.ts +5 -4
- package/src/rules/erb-require-trailing-newline.ts +2 -2
- package/src/rules/erb-require-whitespace-inside-tags.ts +42 -18
- package/src/rules/erb-right-trim.ts +2 -2
- package/src/rules/erb-strict-locals-comment-syntax.ts +5 -5
- package/src/rules/erb-strict-locals-required.ts +2 -2
- package/src/rules/herb-disable-comment-malformed.ts +2 -2
- package/src/rules/herb-disable-comment-missing-rules.ts +2 -2
- package/src/rules/herb-disable-comment-no-duplicate-rules.ts +2 -2
- package/src/rules/herb-disable-comment-no-redundant-all.ts +2 -2
- package/src/rules/herb-disable-comment-unnecessary.ts +2 -2
- package/src/rules/herb-disable-comment-valid-rule-name.ts +2 -2
- package/src/rules/html-allowed-script-type.ts +84 -0
- package/src/rules/html-anchor-require-href.ts +73 -11
- package/src/rules/html-aria-attribute-must-be-valid.ts +3 -3
- package/src/rules/html-aria-label-is-well-formatted.ts +3 -3
- package/src/rules/html-aria-level-must-be-valid.ts +3 -3
- package/src/rules/html-aria-role-heading-requires-level.ts +5 -4
- package/src/rules/html-aria-role-must-be-valid.ts +3 -3
- package/src/rules/html-attribute-double-quotes.ts +4 -4
- package/src/rules/html-attribute-equals-spacing.ts +2 -2
- package/src/rules/html-attribute-values-require-quotes.ts +2 -2
- package/src/rules/html-avoid-both-disabled-and-aria-disabled.ts +10 -11
- package/src/rules/html-body-only-elements.ts +5 -4
- package/src/rules/html-boolean-attributes-no-value.ts +4 -3
- package/src/rules/html-details-has-summary.ts +69 -0
- package/src/rules/html-head-only-elements.ts +6 -5
- package/src/rules/html-iframe-has-title.ts +8 -11
- package/src/rules/html-img-require-alt.ts +16 -5
- package/src/rules/html-input-require-autocomplete.ts +7 -10
- package/src/rules/html-navigation-has-label.ts +6 -5
- package/src/rules/html-no-abstract-roles.ts +40 -0
- package/src/rules/html-no-aria-hidden-on-body.ts +58 -0
- package/src/rules/html-no-aria-hidden-on-focusable.ts +6 -5
- package/src/rules/html-no-block-inside-inline.ts +7 -13
- package/src/rules/html-no-duplicate-attributes.ts +4 -3
- package/src/rules/html-no-duplicate-ids.ts +16 -13
- package/src/rules/html-no-duplicate-meta-names.ts +20 -19
- package/src/rules/html-no-empty-attributes.ts +2 -2
- package/src/rules/html-no-empty-headings.ts +44 -58
- package/src/rules/html-no-nested-links.ts +25 -16
- package/src/rules/html-no-positive-tab-index.ts +3 -3
- package/src/rules/html-no-self-closing.ts +5 -5
- package/src/rules/html-no-space-in-tag.ts +5 -8
- package/src/rules/html-no-title-attribute.ts +6 -5
- package/src/rules/html-no-underscores-in-attribute-names.ts +2 -2
- package/src/rules/html-require-closing-tags.ts +41 -0
- package/src/rules/html-tag-name-lowercase.ts +14 -9
- package/src/rules/index.ts +19 -0
- package/src/rules/parser-no-errors.ts +3 -3
- package/src/rules/rule-utils.ts +162 -279
- package/src/rules/svg-tag-name-capitalization.ts +10 -10
- package/src/rules/turbo-permanent-require-id.ts +49 -0
- package/src/rules.ts +60 -10
- package/src/types.ts +76 -7
- package/src/urls.ts +5 -0
- package/dist/package.json +0 -65
- package/dist/src/cli/argument-parser.js.map +0 -1
- package/dist/src/cli/file-processor.js.map +0 -1
- package/dist/src/cli/formatters/base-formatter.js.map +0 -1
- package/dist/src/cli/formatters/detailed-formatter.js.map +0 -1
- package/dist/src/cli/formatters/github-actions-formatter.js.map +0 -1
- package/dist/src/cli/formatters/index.js.map +0 -1
- package/dist/src/cli/formatters/json-formatter.js.map +0 -1
- package/dist/src/cli/formatters/simple-formatter.js +0 -44
- package/dist/src/cli/formatters/simple-formatter.js.map +0 -1
- package/dist/src/cli/index.js.map +0 -1
- package/dist/src/cli/output-manager.js.map +0 -1
- package/dist/src/cli/summary-reporter.js.map +0 -1
- package/dist/src/cli.js.map +0 -1
- package/dist/src/custom-rule-loader.js.map +0 -1
- package/dist/src/herb-disable-comment-utils.js.map +0 -1
- package/dist/src/herb-lint.js +0 -5
- package/dist/src/herb-lint.js.map +0 -1
- package/dist/src/index.js +0 -5
- package/dist/src/index.js.map +0 -1
- package/dist/src/linter-ignore.js.map +0 -1
- package/dist/src/linter.js.map +0 -1
- package/dist/src/loader.js +0 -17
- package/dist/src/loader.js.map +0 -1
- package/dist/src/rules/erb-comment-syntax.js.map +0 -1
- package/dist/src/rules/erb-no-case-node-children.js.map +0 -1
- package/dist/src/rules/erb-no-empty-tags.js.map +0 -1
- package/dist/src/rules/erb-no-extra-newline.js.map +0 -1
- package/dist/src/rules/erb-no-extra-whitespace-inside-tags.js.map +0 -1
- package/dist/src/rules/erb-no-output-control-flow.js.map +0 -1
- package/dist/src/rules/erb-no-silent-tag-in-attribute-name.js.map +0 -1
- package/dist/src/rules/erb-prefer-image-tag-helper.js.map +0 -1
- package/dist/src/rules/erb-require-trailing-newline.js.map +0 -1
- package/dist/src/rules/erb-require-whitespace-inside-tags.js.map +0 -1
- package/dist/src/rules/erb-right-trim.js.map +0 -1
- package/dist/src/rules/erb-strict-locals-comment-syntax.js.map +0 -1
- package/dist/src/rules/erb-strict-locals-required.js.map +0 -1
- package/dist/src/rules/file-utils.js.map +0 -1
- package/dist/src/rules/herb-disable-comment-base.js.map +0 -1
- package/dist/src/rules/herb-disable-comment-malformed.js.map +0 -1
- package/dist/src/rules/herb-disable-comment-missing-rules.js.map +0 -1
- package/dist/src/rules/herb-disable-comment-no-duplicate-rules.js.map +0 -1
- package/dist/src/rules/herb-disable-comment-no-redundant-all.js.map +0 -1
- package/dist/src/rules/herb-disable-comment-unnecessary.js.map +0 -1
- package/dist/src/rules/herb-disable-comment-valid-rule-name.js.map +0 -1
- package/dist/src/rules/html-anchor-require-href.js +0 -32
- package/dist/src/rules/html-anchor-require-href.js.map +0 -1
- package/dist/src/rules/html-aria-attribute-must-be-valid.js.map +0 -1
- package/dist/src/rules/html-aria-label-is-well-formatted.js.map +0 -1
- package/dist/src/rules/html-aria-level-must-be-valid.js.map +0 -1
- package/dist/src/rules/html-aria-role-heading-requires-level.js.map +0 -1
- package/dist/src/rules/html-aria-role-must-be-valid.js.map +0 -1
- package/dist/src/rules/html-attribute-double-quotes.js.map +0 -1
- package/dist/src/rules/html-attribute-equals-spacing.js.map +0 -1
- package/dist/src/rules/html-attribute-values-require-quotes.js.map +0 -1
- package/dist/src/rules/html-avoid-both-disabled-and-aria-disabled.js.map +0 -1
- package/dist/src/rules/html-body-only-elements.js.map +0 -1
- package/dist/src/rules/html-boolean-attributes-no-value.js.map +0 -1
- package/dist/src/rules/html-head-only-elements.js.map +0 -1
- package/dist/src/rules/html-iframe-has-title.js.map +0 -1
- package/dist/src/rules/html-img-require-alt.js.map +0 -1
- package/dist/src/rules/html-input-require-autocomplete.js.map +0 -1
- package/dist/src/rules/html-navigation-has-label.js.map +0 -1
- package/dist/src/rules/html-no-aria-hidden-on-focusable.js.map +0 -1
- package/dist/src/rules/html-no-block-inside-inline.js.map +0 -1
- package/dist/src/rules/html-no-duplicate-attributes.js.map +0 -1
- package/dist/src/rules/html-no-duplicate-ids.js.map +0 -1
- package/dist/src/rules/html-no-duplicate-meta-names.js.map +0 -1
- package/dist/src/rules/html-no-empty-attributes.js.map +0 -1
- package/dist/src/rules/html-no-empty-headings.js +0 -115
- package/dist/src/rules/html-no-empty-headings.js.map +0 -1
- package/dist/src/rules/html-no-nested-links.js.map +0 -1
- package/dist/src/rules/html-no-positive-tab-index.js.map +0 -1
- package/dist/src/rules/html-no-self-closing.js.map +0 -1
- package/dist/src/rules/html-no-space-in-tag.js.map +0 -1
- package/dist/src/rules/html-no-title-attribute.js.map +0 -1
- package/dist/src/rules/html-no-underscores-in-attribute-names.js.map +0 -1
- package/dist/src/rules/html-tag-name-lowercase.js.map +0 -1
- package/dist/src/rules/index.js.map +0 -1
- package/dist/src/rules/parser-no-errors.js.map +0 -1
- package/dist/src/rules/rule-utils.js.map +0 -1
- package/dist/src/rules/string-utils.js.map +0 -1
- package/dist/src/rules/svg-tag-name-capitalization.js.map +0 -1
- package/dist/src/rules.js.map +0 -1
- package/dist/src/types.js.map +0 -1
- package/dist/tsconfig.tsbuildinfo +0 -1
- package/dist/types/src/cli/argument-parser.d.ts +0 -25
- package/dist/types/src/cli/file-processor.d.ts +0 -43
- package/dist/types/src/cli/formatters/base-formatter.d.ts +0 -6
- package/dist/types/src/cli/formatters/detailed-formatter.d.ts +0 -13
- package/dist/types/src/cli/formatters/github-actions-formatter.d.ts +0 -17
- package/dist/types/src/cli/formatters/index.d.ts +0 -5
- package/dist/types/src/cli/formatters/json-formatter.d.ts +0 -48
- package/dist/types/src/cli/formatters/simple-formatter.d.ts +0 -8
- package/dist/types/src/cli/index.d.ts +0 -5
- package/dist/types/src/cli/output-manager.d.ts +0 -32
- package/dist/types/src/cli/summary-reporter.d.ts +0 -28
- package/dist/types/src/cli.d.ts +0 -28
- package/dist/types/src/custom-rule-loader.d.ts +0 -62
- package/dist/types/src/herb-disable-comment-utils.d.ts +0 -69
- package/dist/types/src/herb-lint.d.ts +0 -2
- package/dist/types/src/index.d.ts +0 -4
- package/dist/types/src/linter-ignore.d.ts +0 -12
- package/dist/types/src/linter.d.ts +0 -133
- package/dist/types/src/loader.d.ts +0 -20
- package/dist/types/src/rules/erb-comment-syntax.d.ts +0 -14
- package/dist/types/src/rules/erb-no-extra-newline.d.ts +0 -14
- package/dist/types/src/rules/erb-no-extra-whitespace-inside-tags.d.ts +0 -18
- package/dist/types/src/rules/erb-require-trailing-newline.d.ts +0 -9
- package/dist/types/src/rules/erb-require-whitespace-inside-tags.d.ts +0 -18
- package/dist/types/src/rules/erb-right-trim.d.ts +0 -14
- package/dist/types/src/rules/erb-strict-locals-comment-syntax.d.ts +0 -9
- package/dist/types/src/rules/erb-strict-locals-required.d.ts +0 -9
- package/dist/types/src/rules/file-utils.d.ts +0 -13
- package/dist/types/src/rules/herb-disable-comment-base.d.ts +0 -37
- package/dist/types/src/rules/herb-disable-comment-no-duplicate-rules.d.ts +0 -8
- package/dist/types/src/rules/herb-disable-comment-no-redundant-all.d.ts +0 -8
- package/dist/types/src/rules/herb-disable-comment-unnecessary.d.ts +0 -8
- package/dist/types/src/rules/herb-disable-comment-valid-rule-name.d.ts +0 -8
- package/dist/types/src/rules/html-aria-label-is-well-formatted.d.ts +0 -8
- package/dist/types/src/rules/html-aria-role-heading-requires-level.d.ts +0 -8
- package/dist/types/src/rules/html-attribute-double-quotes.d.ts +0 -15
- package/dist/types/src/rules/html-attribute-equals-spacing.d.ts +0 -14
- package/dist/types/src/rules/html-attribute-values-require-quotes.d.ts +0 -15
- package/dist/types/src/rules/html-avoid-both-disabled-and-aria-disabled.d.ts +0 -8
- package/dist/types/src/rules/html-boolean-attributes-no-value.d.ts +0 -14
- package/dist/types/src/rules/html-head-only-elements.d.ts +0 -9
- package/dist/types/src/rules/html-iframe-has-title.d.ts +0 -8
- package/dist/types/src/rules/html-img-require-alt.d.ts +0 -8
- package/dist/types/src/rules/html-input-require-autocomplete.d.ts +0 -8
- package/dist/types/src/rules/html-no-block-inside-inline.d.ts +0 -8
- package/dist/types/src/rules/html-no-duplicate-ids.d.ts +0 -8
- package/dist/types/src/rules/html-no-duplicate-meta-names.d.ts +0 -9
- package/dist/types/src/rules/html-no-nested-links.d.ts +0 -8
- package/dist/types/src/rules/html-no-self-closing.d.ts +0 -16
- package/dist/types/src/rules/html-no-space-in-tag.d.ts +0 -16
- package/dist/types/src/rules/html-no-title-attribute.d.ts +0 -8
- package/dist/types/src/rules/html-no-underscores-in-attribute-names.d.ts +0 -8
- package/dist/types/src/rules/html-tag-name-lowercase.d.ts +0 -18
- package/dist/types/src/rules/index.d.ts +0 -54
- package/dist/types/src/rules/parser-no-errors.d.ts +0 -9
- package/dist/types/src/rules/rule-utils.d.ts +0 -351
- package/dist/types/src/rules/string-utils.d.ts +0 -15
- package/dist/types/src/rules/svg-tag-name-capitalization.d.ts +0 -16
- package/dist/types/src/rules.d.ts +0 -2
- package/dist/types/src/types.d.ts +0 -190
- /package/dist/{src/cli → cli}/formatters/base-formatter.js +0 -0
- /package/dist/{src/cli → cli}/formatters/github-actions-formatter.js +0 -0
- /package/dist/{src/cli → cli}/formatters/index.js +0 -0
- /package/dist/{src/cli → cli}/formatters/json-formatter.js +0 -0
- /package/dist/{src/cli → cli}/index.js +0 -0
- /package/dist/{src/cli → cli}/output-manager.js +0 -0
- /package/dist/{src/herb-disable-comment-utils.js → herb-disable-comment-utils.js} +0 -0
- /package/dist/{src/linter-ignore.js → linter-ignore.js} +0 -0
- /package/dist/{src/rules → rules}/file-utils.js +0 -0
- /package/dist/{src/rules → rules}/herb-disable-comment-base.js +0 -0
- /package/dist/{src/rules → rules}/string-utils.js +0 -0
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
# Linter Rule: Require explicit closing tags
|
|
2
|
+
|
|
3
|
+
**Rule:** `html-require-closing-tags`
|
|
4
|
+
|
|
5
|
+
## Description
|
|
6
|
+
|
|
7
|
+
Disallow the omission of optional closing tags for HTML elements where the closing tag is technically optional according to the HTML specification. This rule flags elements that have an `HTMLOmittedCloseTagNode` as their close tag.
|
|
8
|
+
|
|
9
|
+
## Rationale
|
|
10
|
+
|
|
11
|
+
While HTML allows certain closing tags to be omitted (implicitly closed by sibling elements or parent closing), explicit closing tags improve code readability and maintainability. They make the document structure clear at a glance and reduce ambiguity about where elements end.
|
|
12
|
+
|
|
13
|
+
Explicit closing tags also:
|
|
14
|
+
|
|
15
|
+
- Make templates easier to understand for developers unfamiliar with HTML's implicit closing rules
|
|
16
|
+
- Reduce potential for subtle bugs when refactoring or moving code
|
|
17
|
+
- Improve consistency across the codebase
|
|
18
|
+
- Make diffs cleaner when adding content to elements
|
|
19
|
+
|
|
20
|
+
## Elements with Optional Closing Tags
|
|
21
|
+
|
|
22
|
+
This rule would flag elements that have omitted closing tags:
|
|
23
|
+
|
|
24
|
+
- `<li>` - list items
|
|
25
|
+
- `<dt>`, `<dd>` - definition list terms and descriptions
|
|
26
|
+
- `<p>` - paragraphs
|
|
27
|
+
- `<option>`, `<optgroup>` - select options and groups
|
|
28
|
+
- `<thead>`, `<tbody>`, `<tfoot>` - table sections
|
|
29
|
+
- `<tr>` - table rows
|
|
30
|
+
- `<td>`, `<th>` - table cells
|
|
31
|
+
- `<colgroup>` - table column groups
|
|
32
|
+
- `<rt>`, `<rp>` - ruby annotations
|
|
33
|
+
|
|
34
|
+
## Examples
|
|
35
|
+
|
|
36
|
+
### ✅ Good
|
|
37
|
+
|
|
38
|
+
Explicit closing tags:
|
|
39
|
+
|
|
40
|
+
```erb
|
|
41
|
+
<ul>
|
|
42
|
+
<li>Item 1</li>
|
|
43
|
+
<li>Item 2</li>
|
|
44
|
+
<li>Item 3</li>
|
|
45
|
+
</ul>
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
```erb
|
|
49
|
+
<dl>
|
|
50
|
+
<dt>Term 1</dt>
|
|
51
|
+
<dd>Definition 1</dd>
|
|
52
|
+
<dt>Term 2</dt>
|
|
53
|
+
<dd>Definition 2</dd>
|
|
54
|
+
</dl>
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
```erb
|
|
58
|
+
<table>
|
|
59
|
+
<thead>
|
|
60
|
+
<tr>
|
|
61
|
+
<th>Header 1</th>
|
|
62
|
+
<th>Header 2</th>
|
|
63
|
+
</tr>
|
|
64
|
+
</thead>
|
|
65
|
+
<tbody>
|
|
66
|
+
<tr>
|
|
67
|
+
<td>Cell 1</td>
|
|
68
|
+
<td>Cell 2</td>
|
|
69
|
+
</tr>
|
|
70
|
+
</tbody>
|
|
71
|
+
</table>
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
```erb
|
|
75
|
+
<select>
|
|
76
|
+
<option>Option 1</option>
|
|
77
|
+
<option>Option 2</option>
|
|
78
|
+
<option>Option 3</option>
|
|
79
|
+
</select>
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
```erb
|
|
83
|
+
<div>
|
|
84
|
+
<p>Paragraph 1</p>
|
|
85
|
+
<p>Paragraph 2</p>
|
|
86
|
+
</div>
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
### 🚫 Bad
|
|
90
|
+
|
|
91
|
+
Omitted closing tags (implicitly closed):
|
|
92
|
+
|
|
93
|
+
```erb
|
|
94
|
+
<ul>
|
|
95
|
+
<li>Item 1
|
|
96
|
+
<li>Item 2
|
|
97
|
+
<li>Item 3
|
|
98
|
+
</ul>
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
```erb
|
|
102
|
+
<dl>
|
|
103
|
+
<dt>Term 1
|
|
104
|
+
<dd>Definition 1
|
|
105
|
+
<dt>Term 2
|
|
106
|
+
<dd>Definition 2
|
|
107
|
+
</dl>
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
```erb
|
|
111
|
+
<table>
|
|
112
|
+
<thead>
|
|
113
|
+
<tr>
|
|
114
|
+
<th>Header 1
|
|
115
|
+
<th>Header 2
|
|
116
|
+
<tbody>
|
|
117
|
+
<tr>
|
|
118
|
+
<td>Cell 1
|
|
119
|
+
<td>Cell 2
|
|
120
|
+
</table>
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
```erb
|
|
124
|
+
<select>
|
|
125
|
+
<option>Option 1
|
|
126
|
+
<option>Option 2
|
|
127
|
+
<option>Option 3
|
|
128
|
+
</select>
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
```erb
|
|
132
|
+
<div>
|
|
133
|
+
<p>Paragraph 1
|
|
134
|
+
<p>Paragraph 2
|
|
135
|
+
</div>
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
## References
|
|
139
|
+
|
|
140
|
+
- [HTML Spec: Optional Tags](https://html.spec.whatwg.org/multipage/syntax.html#optional-tags)
|
|
141
|
+
- [HTML Spec: Tag Omission](https://html.spec.whatwg.org/multipage/dom.html#concept-element-tag-omission)
|
|
142
|
+
- [CSS-Tricks: Fighting the Space Between Inline Block Elements](https://css-tricks.com/fighting-the-space-between-inline-block-elements/)
|
|
@@ -39,15 +39,16 @@ By surfacing parser errors through the linter, developers can catch these critic
|
|
|
39
39
|
### 🚫 Bad
|
|
40
40
|
|
|
41
41
|
```html
|
|
42
|
-
<!-- Mismatched closing tag -->
|
|
43
42
|
<h2>Welcome to our site</h3>
|
|
43
|
+
```
|
|
44
44
|
|
|
45
|
-
|
|
45
|
+
```html
|
|
46
46
|
<div>
|
|
47
47
|
<p>This paragraph is never closed
|
|
48
48
|
</div>
|
|
49
|
+
```
|
|
49
50
|
|
|
50
|
-
|
|
51
|
+
```html
|
|
51
52
|
Some content
|
|
52
53
|
</div>
|
|
53
54
|
```
|
|
@@ -63,20 +64,6 @@ Some content
|
|
|
63
64
|
<img src="image.jpg" alt="Description"></img>
|
|
64
65
|
```
|
|
65
66
|
|
|
66
|
-
## Error Types
|
|
67
|
-
|
|
68
|
-
This rule reports various parser error types:
|
|
69
|
-
|
|
70
|
-
- **`UNCLOSED_ELEMENT_ERROR`**: Elements that are opened but never closed
|
|
71
|
-
- **`MISSING_CLOSING_TAG_ERROR`**: Opening tags without matching closing tags
|
|
72
|
-
- **`MISSING_OPENING_TAG_ERROR`**: Closing tags without matching opening tags
|
|
73
|
-
- **`TAG_NAMES_MISMATCH_ERROR`**: Opening and closing tags with different names
|
|
74
|
-
- **`QUOTES_MISMATCH_ERROR`**: Mismatched quotation marks in attributes
|
|
75
|
-
- **`VOID_ELEMENT_CLOSING_TAG_ERROR`**: Void elements (like `<img>`) with closing tags
|
|
76
|
-
- **`RUBY_PARSE_ERROR`**: Invalid Ruby syntax within ERB tags
|
|
77
|
-
- **`UNEXPECTED_TOKEN_ERROR`**: Unexpected tokens during parsing
|
|
78
|
-
- **`UNEXPECTED_ERROR`**: Other unexpected parsing issues
|
|
79
|
-
|
|
80
67
|
## References
|
|
81
68
|
|
|
82
69
|
* [HTML Living Standard - Parsing](https://html.spec.whatwg.org/multipage/parsing.html)
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
# Linter Rule: Require `id` attribute on elements with `data-turbo-permanent`
|
|
2
|
+
|
|
3
|
+
**Rule:** `turbo-permanent-require-id`
|
|
4
|
+
|
|
5
|
+
## Description
|
|
6
|
+
|
|
7
|
+
Ensure that all HTML elements with the `data-turbo-permanent` attribute also have an `id` attribute. Without an `id`, Turbo can't track the element across page changes and the permanent behavior won't work as expected.
|
|
8
|
+
|
|
9
|
+
## Rationale
|
|
10
|
+
|
|
11
|
+
Turbo's `data-turbo-permanent` attribute marks an element to be persisted across page navigations. Turbo uses the element's `id` to match it between the current page and the new page. If no `id` is present, Turbo has no way to identify and preserve the element, so the `data-turbo-permanent` attribute has no effect.
|
|
12
|
+
|
|
13
|
+
## Examples
|
|
14
|
+
|
|
15
|
+
### ✅ Good
|
|
16
|
+
|
|
17
|
+
```erb
|
|
18
|
+
<div id="player" data-turbo-permanent>
|
|
19
|
+
<!-- This element will persist across page navigations -->
|
|
20
|
+
</div>
|
|
21
|
+
|
|
22
|
+
<audio id="background-music" data-turbo-permanent>
|
|
23
|
+
<source src="/music.mp3" type="audio/mpeg">
|
|
24
|
+
</audio>
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
### 🚫 Bad
|
|
28
|
+
|
|
29
|
+
```erb
|
|
30
|
+
<div data-turbo-permanent>
|
|
31
|
+
<!-- Missing id: Turbo can't track this element -->
|
|
32
|
+
</div>
|
|
33
|
+
|
|
34
|
+
<audio data-turbo-permanent>
|
|
35
|
+
<source src="/music.mp3" type="audio/mpeg">
|
|
36
|
+
</audio>
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
## References
|
|
40
|
+
|
|
41
|
+
- [Turbo Handbook: Persisting Elements Across Page Loads](https://turbo.hotwired.dev/handbook/building#persisting-elements-across-page-loads)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@herb-tools/linter",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.9.0",
|
|
4
4
|
"description": "HTML+ERB linter for validating HTML structure and enforcing best practices",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"homepage": "https://herb-tools.dev",
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
"watch": "tsc -b -w",
|
|
23
23
|
"test": "vitest run",
|
|
24
24
|
"test:watch": "vitest --watch",
|
|
25
|
-
"prepublishOnly": "yarn clean && yarn build
|
|
25
|
+
"prepublishOnly": "yarn clean && yarn build"
|
|
26
26
|
},
|
|
27
27
|
"exports": {
|
|
28
28
|
"./package.json": "./package.json",
|
|
@@ -33,9 +33,10 @@
|
|
|
33
33
|
"default": "./dist/index.js"
|
|
34
34
|
},
|
|
35
35
|
"./cli": {
|
|
36
|
-
"types": "./dist/types/
|
|
37
|
-
"
|
|
38
|
-
"
|
|
36
|
+
"types": "./dist/types/cli.d.ts",
|
|
37
|
+
"import": "./dist/cli.js",
|
|
38
|
+
"require": "./dist/cli.js",
|
|
39
|
+
"default": "./dist/cli.js"
|
|
39
40
|
},
|
|
40
41
|
"./loader": {
|
|
41
42
|
"types": "./dist/types/loader.d.ts",
|
|
@@ -45,12 +46,12 @@
|
|
|
45
46
|
}
|
|
46
47
|
},
|
|
47
48
|
"dependencies": {
|
|
48
|
-
"@herb-tools/config": "0.
|
|
49
|
-
"@herb-tools/core": "0.
|
|
50
|
-
"@herb-tools/highlighter": "0.
|
|
51
|
-
"@herb-tools/node-wasm": "0.
|
|
52
|
-
"@herb-tools/printer": "0.
|
|
53
|
-
"@herb-tools/rewriter": "0.
|
|
49
|
+
"@herb-tools/config": "0.9.0",
|
|
50
|
+
"@herb-tools/core": "0.9.0",
|
|
51
|
+
"@herb-tools/highlighter": "0.9.0",
|
|
52
|
+
"@herb-tools/node-wasm": "0.9.0",
|
|
53
|
+
"@herb-tools/printer": "0.9.0",
|
|
54
|
+
"@herb-tools/rewriter": "0.9.0",
|
|
54
55
|
"picomatch": "^4.0.2",
|
|
55
56
|
"tinyglobby": "^0.2.15"
|
|
56
57
|
},
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import dedent from "dedent"
|
|
2
2
|
|
|
3
|
+
import { availableParallelism } from "node:os"
|
|
3
4
|
import { parseArgs } from "util"
|
|
4
5
|
import { Herb } from "@herb-tools/node-wasm"
|
|
5
6
|
|
|
@@ -27,6 +28,7 @@ export interface ParsedArguments {
|
|
|
27
28
|
init: boolean
|
|
28
29
|
loadCustomRules: boolean
|
|
29
30
|
failLevel?: DiagnosticSeverity
|
|
31
|
+
jobs: number
|
|
30
32
|
}
|
|
31
33
|
|
|
32
34
|
export class ArgumentParser {
|
|
@@ -53,6 +55,8 @@ export class ArgumentParser {
|
|
|
53
55
|
--github enable GitHub Actions annotations (combines with --format)
|
|
54
56
|
--no-github disable GitHub Actions annotations (even in GitHub Actions environment)
|
|
55
57
|
--no-custom-rules disable loading custom rules from project (custom rules are loaded by default from .herb/rules/**/*.{mjs,js})
|
|
58
|
+
-j, --jobs <n> number of parallel workers for linting files [default: auto]
|
|
59
|
+
use "auto" to detect based on available CPU cores
|
|
56
60
|
--theme syntax highlighting theme (${THEME_NAMES.join("|")}) or path to custom theme file [default: ${DEFAULT_THEME}]
|
|
57
61
|
--no-color disable colored output
|
|
58
62
|
--no-timing hide timing information
|
|
@@ -83,7 +87,8 @@ export class ArgumentParser {
|
|
|
83
87
|
"no-timing": { type: "boolean" },
|
|
84
88
|
"no-wrap-lines": { type: "boolean" },
|
|
85
89
|
"truncate-lines": { type: "boolean" },
|
|
86
|
-
"no-custom-rules": { type: "boolean" }
|
|
90
|
+
"no-custom-rules": { type: "boolean" },
|
|
91
|
+
jobs: { type: "string", short: "j" }
|
|
87
92
|
},
|
|
88
93
|
allowPositionals: true
|
|
89
94
|
})
|
|
@@ -163,7 +168,20 @@ export class ArgumentParser {
|
|
|
163
168
|
}
|
|
164
169
|
}
|
|
165
170
|
|
|
166
|
-
|
|
171
|
+
let jobs = availableParallelism()
|
|
172
|
+
|
|
173
|
+
if (values.jobs && values.jobs !== "auto") {
|
|
174
|
+
const parsed = parseInt(values.jobs, 10)
|
|
175
|
+
|
|
176
|
+
if (isNaN(parsed) || parsed < 1) {
|
|
177
|
+
console.error(`Error: Invalid --jobs value "${values.jobs}". Must be a positive integer or "auto".`)
|
|
178
|
+
process.exit(1)
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
jobs = parsed
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
return { patterns, configFile, formatOption, showTiming, theme, wrapLines, truncateLines, useGitHubActions, fix, fixUnsafe, ignoreDisableComments, force, init, loadCustomRules, failLevel, jobs }
|
|
167
185
|
}
|
|
168
186
|
|
|
169
187
|
private getFilePatterns(positionals: string[]): string[] {
|
|
@@ -3,13 +3,17 @@ import { Linter } from "../linter.js"
|
|
|
3
3
|
import { loadCustomRules } from "../loader.js"
|
|
4
4
|
import { Config } from "@herb-tools/config"
|
|
5
5
|
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
6
|
+
import { Worker } from "node:worker_threads"
|
|
7
|
+
import { readFileSync, writeFileSync } from "node:fs"
|
|
8
|
+
import { resolve, dirname, join } from "node:path"
|
|
9
|
+
import { fileURLToPath } from "node:url"
|
|
10
|
+
import { availableParallelism } from "node:os"
|
|
8
11
|
import { colorize } from "@herb-tools/highlighter"
|
|
9
12
|
|
|
10
13
|
import type { Diagnostic } from "@herb-tools/core"
|
|
11
14
|
import type { FormatOption } from "./argument-parser.js"
|
|
12
15
|
import type { HerbConfigOptions } from "@herb-tools/config"
|
|
16
|
+
import type { WorkerInput, WorkerResult } from "./lint-worker.js"
|
|
13
17
|
|
|
14
18
|
export interface ProcessedFile {
|
|
15
19
|
filename: string
|
|
@@ -20,6 +24,7 @@ export interface ProcessedFile {
|
|
|
20
24
|
|
|
21
25
|
export interface ProcessingContext {
|
|
22
26
|
projectPath?: string
|
|
27
|
+
configPath?: string
|
|
23
28
|
pattern?: string
|
|
24
29
|
fix?: boolean
|
|
25
30
|
fixUnsafe?: boolean
|
|
@@ -27,6 +32,7 @@ export interface ProcessingContext {
|
|
|
27
32
|
linterConfig?: HerbConfigOptions['linter']
|
|
28
33
|
config?: Config
|
|
29
34
|
loadCustomRules?: boolean
|
|
35
|
+
jobs?: number
|
|
30
36
|
}
|
|
31
37
|
|
|
32
38
|
export interface ProcessingResult {
|
|
@@ -44,6 +50,13 @@ export interface ProcessingResult {
|
|
|
44
50
|
context?: ProcessingContext
|
|
45
51
|
}
|
|
46
52
|
|
|
53
|
+
/**
|
|
54
|
+
* Minimum number of files required to use parallel processing.
|
|
55
|
+
* Below this threshold, sequential processing is faster due to
|
|
56
|
+
* worker thread startup overhead (loading WASM, config, etc.).
|
|
57
|
+
*/
|
|
58
|
+
const PARALLEL_FILE_THRESHOLD = 10
|
|
59
|
+
|
|
47
60
|
export class FileProcessor {
|
|
48
61
|
private linter: Linter | null = null
|
|
49
62
|
private customRulesLoaded: boolean = false
|
|
@@ -51,18 +64,27 @@ export class FileProcessor {
|
|
|
51
64
|
private isRuleAutocorrectable(ruleName: string): boolean {
|
|
52
65
|
if (!this.linter) return false
|
|
53
66
|
|
|
54
|
-
const
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
return instance.name === ruleName
|
|
58
|
-
})
|
|
67
|
+
const ruleClass = (this.linter as any).rules.find(
|
|
68
|
+
(rule: any) => rule.ruleName === ruleName
|
|
69
|
+
)
|
|
59
70
|
|
|
60
|
-
if (!
|
|
71
|
+
if (!ruleClass) return false
|
|
61
72
|
|
|
62
|
-
return
|
|
73
|
+
return ruleClass.autocorrectable === true
|
|
63
74
|
}
|
|
64
75
|
|
|
65
76
|
async processFiles(files: string[], formatOption: FormatOption = 'detailed', context?: ProcessingContext): Promise<ProcessingResult> {
|
|
77
|
+
const jobs = context?.jobs ?? 1
|
|
78
|
+
const shouldParallelize = jobs > 1 && files.length >= PARALLEL_FILE_THRESHOLD
|
|
79
|
+
|
|
80
|
+
if (shouldParallelize) {
|
|
81
|
+
return this.processFilesInParallel(files, jobs, formatOption, context)
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
return this.processFilesSequentially(files, formatOption, context)
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
private async processFilesSequentially(files: string[], formatOption: FormatOption = 'detailed', context?: ProcessingContext): Promise<ProcessingResult> {
|
|
66
88
|
let totalErrors = 0
|
|
67
89
|
let totalWarnings = 0
|
|
68
90
|
let totalInfo = 0
|
|
@@ -147,7 +169,7 @@ export class FileProcessor {
|
|
|
147
169
|
filesFixed++
|
|
148
170
|
|
|
149
171
|
if (formatOption !== 'json') {
|
|
150
|
-
console.log(`${colorize("✓", "brightGreen")} ${colorize(filename, "cyan")} - ${colorize(`Fixed ${autofixResult.fixed.length} offense
|
|
172
|
+
console.log(`${colorize("✓", "brightGreen")} ${colorize(filename, "cyan")} - ${colorize(`Fixed ${autofixResult.fixed.length} ${autofixResult.fixed.length === 1 ? "offense" : "offenses"}`, "green")}`)
|
|
151
173
|
}
|
|
152
174
|
}
|
|
153
175
|
|
|
@@ -225,4 +247,161 @@ export class FileProcessor {
|
|
|
225
247
|
|
|
226
248
|
return result
|
|
227
249
|
}
|
|
250
|
+
|
|
251
|
+
private async processFilesInParallel(files: string[], jobs: number, formatOption: FormatOption, context?: ProcessingContext): Promise<ProcessingResult> {
|
|
252
|
+
const workerCount = Math.min(jobs, files.length)
|
|
253
|
+
const chunks = this.splitIntoChunks(files, workerCount)
|
|
254
|
+
const workerPath = this.resolveWorkerPath()
|
|
255
|
+
|
|
256
|
+
const workerPromises = chunks.map(chunk => this.runWorker(workerPath, chunk, context))
|
|
257
|
+
const workerResults = await Promise.all(workerPromises)
|
|
258
|
+
|
|
259
|
+
for (const result of workerResults) {
|
|
260
|
+
if (result.error) {
|
|
261
|
+
throw new Error(`Worker error: ${result.error}`)
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
return this.aggregateWorkerResults(workerResults, formatOption, context)
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
private resolveWorkerPath(): string {
|
|
269
|
+
try {
|
|
270
|
+
const currentDir = dirname(fileURLToPath(import.meta.url))
|
|
271
|
+
|
|
272
|
+
return join(currentDir, "lint-worker.js")
|
|
273
|
+
} catch {
|
|
274
|
+
return join(__dirname, "lint-worker.js")
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
private splitIntoChunks(files: string[], chunkCount: number): string[][] {
|
|
279
|
+
const chunks: string[][] = Array.from({ length: chunkCount }, () => [])
|
|
280
|
+
|
|
281
|
+
for (let i = 0; i < files.length; i++) {
|
|
282
|
+
chunks[i % chunkCount].push(files[i])
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
return chunks.filter(chunk => chunk.length > 0)
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
private runWorker(workerPath: string, files: string[], context?: ProcessingContext): Promise<WorkerResult> {
|
|
289
|
+
return new Promise((resolve, reject) => {
|
|
290
|
+
const workerData: WorkerInput = {
|
|
291
|
+
files,
|
|
292
|
+
projectPath: context?.projectPath || process.cwd(),
|
|
293
|
+
configPath: context?.configPath,
|
|
294
|
+
fix: context?.fix || false,
|
|
295
|
+
fixUnsafe: context?.fixUnsafe || false,
|
|
296
|
+
ignoreDisableComments: context?.ignoreDisableComments || false,
|
|
297
|
+
loadCustomRules: context?.loadCustomRules || false,
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
const worker = new Worker(workerPath, { workerData })
|
|
301
|
+
|
|
302
|
+
worker.on("message", (result: WorkerResult) => {
|
|
303
|
+
resolve(result)
|
|
304
|
+
})
|
|
305
|
+
|
|
306
|
+
worker.on("error", (error) => {
|
|
307
|
+
reject(error)
|
|
308
|
+
})
|
|
309
|
+
|
|
310
|
+
worker.on("exit", (code) => {
|
|
311
|
+
if (code !== 0) {
|
|
312
|
+
reject(new Error(`Worker exited with code ${code}`))
|
|
313
|
+
}
|
|
314
|
+
})
|
|
315
|
+
})
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
private aggregateWorkerResults(results: WorkerResult[], formatOption: FormatOption, context?: ProcessingContext): ProcessingResult {
|
|
319
|
+
let totalErrors = 0
|
|
320
|
+
let totalWarnings = 0
|
|
321
|
+
let totalInfo = 0
|
|
322
|
+
let totalHints = 0
|
|
323
|
+
let totalIgnored = 0
|
|
324
|
+
let totalWouldBeIgnored = 0
|
|
325
|
+
let filesWithOffenses = 0
|
|
326
|
+
let filesFixed = 0
|
|
327
|
+
let ruleCount = 0
|
|
328
|
+
|
|
329
|
+
const allOffenses: ProcessedFile[] = []
|
|
330
|
+
const ruleOffenses = new Map<string, { count: number, files: Set<string> }>()
|
|
331
|
+
|
|
332
|
+
for (const result of results) {
|
|
333
|
+
totalErrors += result.totalErrors
|
|
334
|
+
totalWarnings += result.totalWarnings
|
|
335
|
+
totalInfo += result.totalInfo
|
|
336
|
+
totalHints += result.totalHints
|
|
337
|
+
totalIgnored += result.totalIgnored
|
|
338
|
+
totalWouldBeIgnored += result.totalWouldBeIgnored
|
|
339
|
+
filesWithOffenses += result.filesWithOffenses
|
|
340
|
+
filesFixed += result.filesFixed
|
|
341
|
+
|
|
342
|
+
if (result.ruleCount > 0) {
|
|
343
|
+
ruleCount = result.ruleCount
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
for (const offense of result.offenses) {
|
|
347
|
+
allOffenses.push({
|
|
348
|
+
filename: offense.filename,
|
|
349
|
+
offense: offense.offense,
|
|
350
|
+
content: offense.content,
|
|
351
|
+
autocorrectable: offense.autocorrectable
|
|
352
|
+
})
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
for (const [rule, data] of result.ruleOffenses) {
|
|
356
|
+
const existing = ruleOffenses.get(rule) || { count: 0, files: new Set<string>() }
|
|
357
|
+
existing.count += data.count
|
|
358
|
+
|
|
359
|
+
for (const file of data.files) {
|
|
360
|
+
existing.files.add(file)
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
ruleOffenses.set(rule, existing)
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
if (formatOption !== 'json') {
|
|
367
|
+
for (const fixMessage of result.fixMessages) {
|
|
368
|
+
const [filename, countStr] = fixMessage.split("\t")
|
|
369
|
+
const count = parseInt(countStr, 10)
|
|
370
|
+
console.log(`${colorize("\u2713", "brightGreen")} ${colorize(filename, "cyan")} - ${colorize(`Fixed ${count} ${count === 1 ? "offense" : "offenses"}`, "green")}`)
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
const processingResult: ProcessingResult = {
|
|
376
|
+
totalErrors,
|
|
377
|
+
totalWarnings,
|
|
378
|
+
totalInfo,
|
|
379
|
+
totalHints,
|
|
380
|
+
totalIgnored,
|
|
381
|
+
filesWithOffenses,
|
|
382
|
+
filesFixed,
|
|
383
|
+
ruleCount,
|
|
384
|
+
allOffenses,
|
|
385
|
+
ruleOffenses,
|
|
386
|
+
context
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
if (totalWouldBeIgnored > 0) {
|
|
390
|
+
processingResult.totalWouldBeIgnored = totalWouldBeIgnored
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
return processingResult
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
/**
|
|
397
|
+
* Returns the default number of parallel jobs based on available CPU cores.
|
|
398
|
+
* Returns 1 if parallelism detection fails.
|
|
399
|
+
*/
|
|
400
|
+
static defaultJobs(): number {
|
|
401
|
+
try {
|
|
402
|
+
return availableParallelism()
|
|
403
|
+
} catch {
|
|
404
|
+
return 1
|
|
405
|
+
}
|
|
406
|
+
}
|
|
228
407
|
}
|
|
@@ -2,6 +2,8 @@ import { colorize, Highlighter, type ThemeInput, DEFAULT_THEME } from "@herb-too
|
|
|
2
2
|
|
|
3
3
|
import { BaseFormatter } from "./base-formatter.js"
|
|
4
4
|
import { LineWrapper } from "@herb-tools/highlighter"
|
|
5
|
+
import { ruleDocumentationUrl } from "../../urls.js"
|
|
6
|
+
import { fileUrl } from "../file-url.js"
|
|
5
7
|
|
|
6
8
|
import type { Diagnostic } from "@herb-tools/core"
|
|
7
9
|
import type { ProcessedFile } from "../file-processor.js"
|
|
@@ -27,24 +29,24 @@ export class DetailedFormatter extends BaseFormatter {
|
|
|
27
29
|
await this.highlighter.initialize()
|
|
28
30
|
}
|
|
29
31
|
|
|
32
|
+
const correctableTag = colorize(colorize("[Correctable]", "green"), "bold")
|
|
33
|
+
const autocorrectableSet = new Set(
|
|
34
|
+
allOffenses.filter(item => item.autocorrectable).map(item => item.offense)
|
|
35
|
+
)
|
|
36
|
+
|
|
30
37
|
if (isSingleFile) {
|
|
31
38
|
const { filename, content } = allOffenses[0]
|
|
32
|
-
const diagnostics = allOffenses.map(item =>
|
|
33
|
-
if (item.autocorrectable && item.offense.code) {
|
|
34
|
-
return {
|
|
35
|
-
...item.offense,
|
|
36
|
-
message: `${item.offense.message} ${colorize(colorize("[Correctable]", "green"), "bold")}`
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
return item.offense
|
|
40
|
-
})
|
|
39
|
+
const diagnostics = allOffenses.map(item => item.offense)
|
|
41
40
|
|
|
42
41
|
const highlighted = this.highlighter.highlight(filename, content, {
|
|
43
42
|
diagnostics: diagnostics,
|
|
44
43
|
splitDiagnostics: true,
|
|
45
44
|
contextLines: 2,
|
|
46
45
|
wrapLines: this.wrapLines,
|
|
47
|
-
truncateLines: this.truncateLines
|
|
46
|
+
truncateLines: this.truncateLines,
|
|
47
|
+
codeUrlBuilder: ruleDocumentationUrl,
|
|
48
|
+
fileUrlBuilder: (path) => fileUrl(path),
|
|
49
|
+
suffixBuilder: (diagnostic) => autocorrectableSet.has(diagnostic) ? correctableTag : undefined,
|
|
48
50
|
})
|
|
49
51
|
|
|
50
52
|
console.log(`\n${highlighted}`)
|
|
@@ -54,19 +56,15 @@ export class DetailedFormatter extends BaseFormatter {
|
|
|
54
56
|
for (let i = 0; i < allOffenses.length; i++) {
|
|
55
57
|
const { filename, offense, content, autocorrectable } = allOffenses[i]
|
|
56
58
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
modifiedOffense = {
|
|
61
|
-
...offense,
|
|
62
|
-
message: `${offense.message} ${colorize(colorize("[Correctable]", "green"), "bold")}`
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
const formatted = this.highlighter.highlightDiagnostic(filename, modifiedOffense, content, {
|
|
59
|
+
const codeUrl = offense.code ? ruleDocumentationUrl(offense.code) : undefined
|
|
60
|
+
const suffix = autocorrectable ? correctableTag : undefined
|
|
61
|
+
const formatted = this.highlighter.highlightDiagnostic(filename, offense, content, {
|
|
67
62
|
contextLines: 2,
|
|
68
63
|
wrapLines: this.wrapLines,
|
|
69
|
-
truncateLines: this.truncateLines
|
|
64
|
+
truncateLines: this.truncateLines,
|
|
65
|
+
codeUrl,
|
|
66
|
+
fileUrl: fileUrl(filename),
|
|
67
|
+
suffix,
|
|
70
68
|
})
|
|
71
69
|
console.log(`\n${formatted}`)
|
|
72
70
|
|