@herb-tools/linter 0.8.10 → 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 +60509 -17442
- package/dist/herb-lint.js.map +1 -1
- package/dist/index.cjs +2620 -933
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +2553 -872
- 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 +31203 -7866
- package/dist/loader.cjs.map +1 -1
- package/dist/loader.js +31165 -7834
- 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 +4 -4
- 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 +4 -4
- 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,65 @@
|
|
|
1
|
+
import { isLiteralNode, isPureWhitespaceNode, splitLiteralsAtWhitespace, groupNodesByClass } from "@herb-tools/core"
|
|
2
|
+
import { IdentityPrinter } from "@herb-tools/printer"
|
|
3
|
+
|
|
4
|
+
import { ParserRule } from "../types.js"
|
|
5
|
+
import { AttributeVisitorMixin } from "./rule-utils.js"
|
|
6
|
+
|
|
7
|
+
import type { Node } from "@herb-tools/core"
|
|
8
|
+
import type { StaticAttributeDynamicValueParams } from "./rule-utils.js"
|
|
9
|
+
import type { UnboundLintOffense, LintContext, FullRuleConfig } from "../types.js"
|
|
10
|
+
import type { ParseResult } from "@herb-tools/core"
|
|
11
|
+
|
|
12
|
+
function groupToString(group: Node[]): string {
|
|
13
|
+
return group.map(node => {
|
|
14
|
+
if (isLiteralNode(node)) {
|
|
15
|
+
return node.content
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
return IdentityPrinter.print(node, { ignoreErrors: true })
|
|
19
|
+
}).join("")
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
class ERBNoInterpolatedClassNamesVisitor extends AttributeVisitorMixin {
|
|
23
|
+
protected checkStaticAttributeDynamicValue({ attributeName, valueNodes, attributeNode }: StaticAttributeDynamicValueParams) {
|
|
24
|
+
if (attributeName !== "class") return
|
|
25
|
+
|
|
26
|
+
const splitNodes = splitLiteralsAtWhitespace(valueNodes)
|
|
27
|
+
const groups = groupNodesByClass(splitNodes)
|
|
28
|
+
|
|
29
|
+
for (const group of groups) {
|
|
30
|
+
if (group.every(node => isPureWhitespaceNode(node))) continue
|
|
31
|
+
|
|
32
|
+
const isInterpolated = group.some(node => !isLiteralNode(node))
|
|
33
|
+
if (!isInterpolated) continue
|
|
34
|
+
|
|
35
|
+
const hasAttachedLiteral = group.some(node => isLiteralNode(node) && node.content.trim())
|
|
36
|
+
if (!hasAttachedLiteral) continue
|
|
37
|
+
|
|
38
|
+
const className = groupToString(group)
|
|
39
|
+
|
|
40
|
+
this.addOffense(
|
|
41
|
+
`Avoid ERB interpolation inside class names: \`${className}\`. Use standalone ERB expressions that output complete class names instead.`,
|
|
42
|
+
attributeNode.value!.location,
|
|
43
|
+
)
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export class ERBNoInterpolatedClassNamesRule extends ParserRule {
|
|
49
|
+
static ruleName = "erb-no-interpolated-class-names"
|
|
50
|
+
|
|
51
|
+
get defaultConfig(): FullRuleConfig {
|
|
52
|
+
return {
|
|
53
|
+
enabled: true,
|
|
54
|
+
severity: "warning"
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
check(result: ParseResult, context?: Partial<LintContext>): UnboundLintOffense[] {
|
|
59
|
+
const visitor = new ERBNoInterpolatedClassNamesVisitor(this.ruleName, context)
|
|
60
|
+
|
|
61
|
+
visitor.visit(result.value)
|
|
62
|
+
|
|
63
|
+
return visitor.offenses
|
|
64
|
+
}
|
|
65
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { ParserRule } from "../types.js"
|
|
2
|
+
import { BaseRuleVisitor } from "./rule-utils.js"
|
|
3
|
+
import { isERBNode, isERBOutputNode } from "@herb-tools/core"
|
|
4
|
+
|
|
5
|
+
import type { UnboundLintOffense, LintContext, FullRuleConfig } from "../types.js"
|
|
6
|
+
import type { ParseResult, DocumentNode } from "@herb-tools/core"
|
|
7
|
+
|
|
8
|
+
const JAVASCRIPT_TAG_PATTERN = /\bjavascript_tag\b/
|
|
9
|
+
|
|
10
|
+
class ERBNoJavascriptTagHelperVisitor extends BaseRuleVisitor {
|
|
11
|
+
visitDocumentNode(node: DocumentNode): void {
|
|
12
|
+
for (const child of node.children || []) {
|
|
13
|
+
if (!isERBNode(child)) continue
|
|
14
|
+
if (!isERBOutputNode(child)) continue
|
|
15
|
+
|
|
16
|
+
const content = child.content?.value || ""
|
|
17
|
+
|
|
18
|
+
if (JAVASCRIPT_TAG_PATTERN.test(content)) {
|
|
19
|
+
this.addOffense(
|
|
20
|
+
"Avoid `javascript_tag`. Use inline `<script>` tags instead.",
|
|
21
|
+
child.location,
|
|
22
|
+
)
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
super.visitDocumentNode(node)
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export class ERBNoJavascriptTagHelperRule extends ParserRule {
|
|
31
|
+
static ruleName = "erb-no-javascript-tag-helper"
|
|
32
|
+
|
|
33
|
+
get defaultConfig(): FullRuleConfig {
|
|
34
|
+
return {
|
|
35
|
+
enabled: true,
|
|
36
|
+
severity: "warning"
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
check(result: ParseResult, context?: Partial<LintContext>): UnboundLintOffense[] {
|
|
41
|
+
const visitor = new ERBNoJavascriptTagHelperVisitor(this.ruleName, context)
|
|
42
|
+
|
|
43
|
+
visitor.visit(result.value)
|
|
44
|
+
|
|
45
|
+
return visitor.offenses
|
|
46
|
+
}
|
|
47
|
+
}
|
|
@@ -25,6 +25,13 @@ class ERBNoOutputControlFlowRuleVisitor extends BaseRuleVisitor {
|
|
|
25
25
|
this.visitChildNodes(node)
|
|
26
26
|
}
|
|
27
27
|
|
|
28
|
+
private static readonly CONTROL_BLOCK_NAMES: Record<string, string> = {
|
|
29
|
+
"AST_ERB_IF_NODE": "if",
|
|
30
|
+
"AST_ERB_ELSE_NODE": "else",
|
|
31
|
+
"AST_ERB_END_NODE": "end",
|
|
32
|
+
"AST_ERB_UNLESS_NODE": "unless"
|
|
33
|
+
}
|
|
34
|
+
|
|
28
35
|
private checkOutputControlFlow(controlBlock: ERBIfNode | ERBUnlessNode | ERBElseNode | ERBEndNode): void {
|
|
29
36
|
const openTag = controlBlock.tag_opening;
|
|
30
37
|
if (!openTag) {
|
|
@@ -32,25 +39,18 @@ class ERBNoOutputControlFlowRuleVisitor extends BaseRuleVisitor {
|
|
|
32
39
|
}
|
|
33
40
|
|
|
34
41
|
if (openTag.value === "<%="){
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
if (controlBlock.type === "AST_ERB_IF_NODE") controlBlockType = "if"
|
|
38
|
-
if (controlBlock.type === "AST_ERB_ELSE_NODE") controlBlockType = "else"
|
|
39
|
-
if (controlBlock.type === "AST_ERB_END_NODE") controlBlockType = "end"
|
|
40
|
-
if (controlBlock.type === "AST_ERB_UNLESS_NODE") controlBlockType = "unless"
|
|
42
|
+
const controlBlockType = ERBNoOutputControlFlowRuleVisitor.CONTROL_BLOCK_NAMES[controlBlock.type] || controlBlock.type
|
|
41
43
|
|
|
42
44
|
this.addOffense(
|
|
43
45
|
`Control flow statements like \`${controlBlockType}\` should not be used with output tags. Use \`<% ${controlBlockType} ... %>\` instead.`,
|
|
44
46
|
openTag.location,
|
|
45
47
|
)
|
|
46
48
|
}
|
|
47
|
-
|
|
48
|
-
return
|
|
49
49
|
}
|
|
50
50
|
}
|
|
51
51
|
|
|
52
52
|
export class ERBNoOutputControlFlowRule extends ParserRule {
|
|
53
|
-
|
|
53
|
+
static ruleName = "erb-no-output-control-flow"
|
|
54
54
|
|
|
55
55
|
get defaultConfig(): FullRuleConfig {
|
|
56
56
|
return {
|
|
@@ -60,7 +60,7 @@ export class ERBNoOutputControlFlowRule extends ParserRule {
|
|
|
60
60
|
}
|
|
61
61
|
|
|
62
62
|
check(result: ParseResult, context?: Partial<LintContext>): UnboundLintOffense[] {
|
|
63
|
-
const visitor = new ERBNoOutputControlFlowRuleVisitor(this.
|
|
63
|
+
const visitor = new ERBNoOutputControlFlowRuleVisitor(this.ruleName, context)
|
|
64
64
|
|
|
65
65
|
visitor.visit(result.value)
|
|
66
66
|
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { ParserRule } from "../types.js"
|
|
2
|
+
import { BaseRuleVisitor } from "./rule-utils.js"
|
|
3
|
+
import { isERBNode, isERBOutputNode } from "@herb-tools/core"
|
|
4
|
+
|
|
5
|
+
import type { UnboundLintOffense, LintContext, FullRuleConfig } from "../types.js"
|
|
6
|
+
import type { ParseResult, HTMLAttributeNameNode } from "@herb-tools/core"
|
|
7
|
+
|
|
8
|
+
class ERBNoOutputInAttributeNameVisitor extends BaseRuleVisitor {
|
|
9
|
+
visitHTMLAttributeNameNode(node: HTMLAttributeNameNode): void {
|
|
10
|
+
for (const child of node.children) {
|
|
11
|
+
if (!isERBNode(child)) continue
|
|
12
|
+
if (!isERBOutputNode(child)) continue
|
|
13
|
+
|
|
14
|
+
this.addOffense(
|
|
15
|
+
"Avoid ERB output in attribute names. Use static attribute names with dynamic values instead.",
|
|
16
|
+
child.location,
|
|
17
|
+
)
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
super.visitHTMLAttributeNameNode(node)
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export class ERBNoOutputInAttributeNameRule extends ParserRule {
|
|
25
|
+
static ruleName = "erb-no-output-in-attribute-name"
|
|
26
|
+
|
|
27
|
+
get defaultConfig(): FullRuleConfig {
|
|
28
|
+
return {
|
|
29
|
+
enabled: true,
|
|
30
|
+
severity: "error"
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
check(result: ParseResult, context?: Partial<LintContext>): UnboundLintOffense[] {
|
|
35
|
+
const visitor = new ERBNoOutputInAttributeNameVisitor(this.ruleName, context)
|
|
36
|
+
visitor.visit(result.value)
|
|
37
|
+
return visitor.offenses
|
|
38
|
+
}
|
|
39
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { ParserRule } from "../types.js"
|
|
2
|
+
import { BaseRuleVisitor } from "./rule-utils.js"
|
|
3
|
+
import { isERBNode, isERBOutputNode } from "@herb-tools/core"
|
|
4
|
+
|
|
5
|
+
import type { UnboundLintOffense, LintContext, FullRuleConfig } from "../types.js"
|
|
6
|
+
import type { ParseResult, HTMLOpenTagNode } from "@herb-tools/core"
|
|
7
|
+
|
|
8
|
+
class ERBNoOutputInAttributePositionVisitor extends BaseRuleVisitor {
|
|
9
|
+
visitHTMLOpenTagNode(node: HTMLOpenTagNode): void {
|
|
10
|
+
for (const child of node.children) {
|
|
11
|
+
if (!isERBNode(child)) continue
|
|
12
|
+
if (!isERBOutputNode(child)) continue
|
|
13
|
+
|
|
14
|
+
this.addOffense(
|
|
15
|
+
"Avoid `<%= %>` in attribute position. Use `<% if ... %>` with static attributes instead.",
|
|
16
|
+
child.location,
|
|
17
|
+
)
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
super.visitHTMLOpenTagNode(node)
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export class ERBNoOutputInAttributePositionRule extends ParserRule {
|
|
25
|
+
static ruleName = "erb-no-output-in-attribute-position"
|
|
26
|
+
|
|
27
|
+
get defaultConfig(): FullRuleConfig {
|
|
28
|
+
return {
|
|
29
|
+
enabled: true,
|
|
30
|
+
severity: "error"
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
check(result: ParseResult, context?: Partial<LintContext>): UnboundLintOffense[] {
|
|
35
|
+
const visitor = new ERBNoOutputInAttributePositionVisitor(this.ruleName, context)
|
|
36
|
+
visitor.visit(result.value)
|
|
37
|
+
return visitor.offenses
|
|
38
|
+
}
|
|
39
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { ParserRule } from "../types.js"
|
|
2
|
+
import { AttributeVisitorMixin } from "./rule-utils.js"
|
|
3
|
+
import { isERBNode } from "@herb-tools/core"
|
|
4
|
+
|
|
5
|
+
import type { UnboundLintOffense, LintContext, FullRuleConfig } from "../types.js"
|
|
6
|
+
import type { ParseResult, Node } from "@herb-tools/core"
|
|
7
|
+
import type { StaticAttributeDynamicValueParams, DynamicAttributeDynamicValueParams } from "./rule-utils.js"
|
|
8
|
+
|
|
9
|
+
class ERBNoRawOutputInAttributeValueVisitor extends AttributeVisitorMixin {
|
|
10
|
+
protected checkStaticAttributeDynamicValue({ valueNodes, attributeNode }: StaticAttributeDynamicValueParams): void {
|
|
11
|
+
this.checkValueNodes(valueNodes)
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
protected checkDynamicAttributeDynamicValue({ valueNodes }: DynamicAttributeDynamicValueParams): void {
|
|
15
|
+
this.checkValueNodes(valueNodes)
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
private checkValueNodes(nodes: Node[]): void {
|
|
19
|
+
for (const node of nodes) {
|
|
20
|
+
if (!isERBNode(node)) continue
|
|
21
|
+
|
|
22
|
+
if (node.tag_opening?.value === "<%==") {
|
|
23
|
+
this.addOffense(
|
|
24
|
+
"Avoid `<%==` in attribute values. Use `<%= %>` instead to ensure proper HTML escaping.",
|
|
25
|
+
node.location,
|
|
26
|
+
)
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export class ERBNoRawOutputInAttributeValueRule extends ParserRule {
|
|
33
|
+
static ruleName = "erb-no-raw-output-in-attribute-value"
|
|
34
|
+
|
|
35
|
+
get defaultConfig(): FullRuleConfig {
|
|
36
|
+
return {
|
|
37
|
+
enabled: true,
|
|
38
|
+
severity: "error"
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
check(result: ParseResult, context?: Partial<LintContext>): UnboundLintOffense[] {
|
|
43
|
+
const visitor = new ERBNoRawOutputInAttributeValueVisitor(this.ruleName, context)
|
|
44
|
+
visitor.visit(result.value)
|
|
45
|
+
return visitor.offenses
|
|
46
|
+
}
|
|
47
|
+
}
|
|
@@ -27,7 +27,7 @@ class ERBNoSilentTagInAttributeNameVisitor extends BaseRuleVisitor {
|
|
|
27
27
|
}
|
|
28
28
|
|
|
29
29
|
export class ERBNoSilentTagInAttributeNameRule extends ParserRule {
|
|
30
|
-
|
|
30
|
+
static ruleName = "erb-no-silent-tag-in-attribute-name"
|
|
31
31
|
|
|
32
32
|
get defaultConfig(): FullRuleConfig {
|
|
33
33
|
return {
|
|
@@ -37,7 +37,7 @@ export class ERBNoSilentTagInAttributeNameRule extends ParserRule {
|
|
|
37
37
|
}
|
|
38
38
|
|
|
39
39
|
check(result: ParseResult, context?: Partial<LintContext>): UnboundLintOffense[] {
|
|
40
|
-
const visitor = new ERBNoSilentTagInAttributeNameVisitor(this.
|
|
40
|
+
const visitor = new ERBNoSilentTagInAttributeNameVisitor(this.ruleName, context)
|
|
41
41
|
|
|
42
42
|
visitor.visit(result.value)
|
|
43
43
|
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { ParserRule } from "../types.js"
|
|
2
|
+
import { BaseRuleVisitor } from "./rule-utils.js"
|
|
3
|
+
import {
|
|
4
|
+
getTagLocalName,
|
|
5
|
+
getAttribute,
|
|
6
|
+
getStaticAttributeValue,
|
|
7
|
+
isERBNode,
|
|
8
|
+
isERBOutputNode,
|
|
9
|
+
isERBCommentNode,
|
|
10
|
+
isHTMLOpenTagNode,
|
|
11
|
+
} from "@herb-tools/core"
|
|
12
|
+
|
|
13
|
+
import type { UnboundLintOffense, LintContext, FullRuleConfig } from "../types.js"
|
|
14
|
+
import type { ParseResult, HTMLElementNode, Node } from "@herb-tools/core"
|
|
15
|
+
|
|
16
|
+
const END_PATTERN = /^\s*end\b/
|
|
17
|
+
|
|
18
|
+
class ERBNoStatementInScriptVisitor extends BaseRuleVisitor {
|
|
19
|
+
visitHTMLElementNode(node: HTMLElementNode): void {
|
|
20
|
+
if (!isHTMLOpenTagNode(node.open_tag)) {
|
|
21
|
+
super.visitHTMLElementNode(node)
|
|
22
|
+
return
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
if (getTagLocalName(node.open_tag) === "script") {
|
|
26
|
+
this.checkScriptElement(node)
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
super.visitHTMLElementNode(node)
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
private checkScriptElement(node: HTMLElementNode): void {
|
|
33
|
+
if (!isHTMLOpenTagNode(node.open_tag)) return
|
|
34
|
+
|
|
35
|
+
const typeAttribute = getAttribute(node.open_tag, "type")
|
|
36
|
+
const typeValue = typeAttribute ? getStaticAttributeValue(typeAttribute) : null
|
|
37
|
+
|
|
38
|
+
if (typeValue === "text/html") {
|
|
39
|
+
return
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
if (!node.body || node.body.length === 0) {
|
|
43
|
+
return
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
this.checkNodesForStatements(node.body)
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
private checkNodesForStatements(nodes: Node[]): void {
|
|
50
|
+
for (const child of nodes) {
|
|
51
|
+
if (!isERBNode(child)) continue
|
|
52
|
+
if (isERBOutputNode(child)) continue
|
|
53
|
+
if (isERBCommentNode(child)) continue
|
|
54
|
+
|
|
55
|
+
const content = child.content?.value || ""
|
|
56
|
+
|
|
57
|
+
if (END_PATTERN.test(content)) continue
|
|
58
|
+
|
|
59
|
+
this.addOffense(
|
|
60
|
+
"Avoid `<% %>` tags inside `<script>`. Use `<%= %>` to interpolate values into JavaScript.",
|
|
61
|
+
child.location,
|
|
62
|
+
)
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export class ERBNoStatementInScriptRule extends ParserRule {
|
|
68
|
+
static ruleName = "erb-no-statement-in-script"
|
|
69
|
+
|
|
70
|
+
get defaultConfig(): FullRuleConfig {
|
|
71
|
+
return {
|
|
72
|
+
enabled: true,
|
|
73
|
+
severity: "warning"
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
check(result: ParseResult, context?: Partial<LintContext>): UnboundLintOffense[] {
|
|
78
|
+
const visitor = new ERBNoStatementInScriptVisitor(this.ruleName, context)
|
|
79
|
+
visitor.visit(result.value)
|
|
80
|
+
return visitor.offenses
|
|
81
|
+
}
|
|
82
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { ParserRule } from "../types.js"
|
|
2
|
+
import { BaseRuleVisitor } from "./rule-utils.js"
|
|
3
|
+
|
|
4
|
+
import type { UnboundLintOffense, LintContext, FullRuleConfig } from "../types.js"
|
|
5
|
+
import type { ERBIfNode, ERBUnlessNode, ERBWhenNode, ERBInNode, ParseResult, ParserOptions, Location } from "@herb-tools/core"
|
|
6
|
+
|
|
7
|
+
class ERBNoThenInControlFlowVisitor extends BaseRuleVisitor {
|
|
8
|
+
visitERBIfNode(node: ERBIfNode): void {
|
|
9
|
+
const content = node.content?.value?.trim() ?? ""
|
|
10
|
+
const keyword = content.startsWith("elsif") ? "elsif" : "if"
|
|
11
|
+
|
|
12
|
+
this.checkThenKeyword(keyword, node.then_keyword)
|
|
13
|
+
this.visitChildNodes(node)
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
visitERBUnlessNode(node: ERBUnlessNode): void {
|
|
17
|
+
this.checkThenKeyword("unless", node.then_keyword)
|
|
18
|
+
this.visitChildNodes(node)
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
visitERBWhenNode(node: ERBWhenNode): void {
|
|
22
|
+
this.checkThenKeyword("when", node.then_keyword)
|
|
23
|
+
this.visitChildNodes(node)
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
visitERBInNode(node: ERBInNode): void {
|
|
27
|
+
this.checkThenKeyword("in", node.then_keyword)
|
|
28
|
+
this.visitChildNodes(node)
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
private checkThenKeyword(keyword: string, thenKeyword: Location | null): void {
|
|
32
|
+
if (thenKeyword === null) return
|
|
33
|
+
|
|
34
|
+
this.addOffense(
|
|
35
|
+
`Avoid using \`then\` in \`${keyword}\` expressions inside ERB templates. Use the multiline block form instead.`,
|
|
36
|
+
thenKeyword,
|
|
37
|
+
)
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export class ERBNoThenInControlFlowRule extends ParserRule {
|
|
42
|
+
static ruleName = "erb-no-then-in-control-flow"
|
|
43
|
+
|
|
44
|
+
get defaultConfig(): FullRuleConfig {
|
|
45
|
+
return {
|
|
46
|
+
enabled: true,
|
|
47
|
+
severity: "warning",
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
get parserOptions(): Partial<ParserOptions> {
|
|
52
|
+
return { strict: true }
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
check(result: ParseResult, context?: Partial<LintContext>): UnboundLintOffense[] {
|
|
56
|
+
const visitor = new ERBNoThenInControlFlowVisitor(this.ruleName, context)
|
|
57
|
+
|
|
58
|
+
visitor.visit(result.value)
|
|
59
|
+
|
|
60
|
+
return visitor.offenses
|
|
61
|
+
}
|
|
62
|
+
}
|
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
import { Location, Visitor } from "@herb-tools/core"
|
|
2
|
+
import { ParserRule, Mutable, BaseAutofixContext } from "../types.js"
|
|
3
|
+
|
|
4
|
+
import { isHTMLOpenTagNode, isHTMLTextNode, isLiteralNode, getTagLocalName } from "@herb-tools/core"
|
|
5
|
+
import { findNodeAtPosition } from "./rule-utils.js"
|
|
6
|
+
|
|
7
|
+
import type { UnboundLintOffense, LintOffense, LintContext, FullRuleConfig } from "../types.js"
|
|
8
|
+
import type { HTMLElementNode, HTMLTextNode, LiteralNode, ParseResult, DocumentNode, ERBNode } from "@herb-tools/core"
|
|
9
|
+
|
|
10
|
+
const TRAILING_WHITESPACE = /[ \t\r\v\f\u00A0]+$/
|
|
11
|
+
const TRAILING_WHITESPACE_BEFORE_NEWLINE = /[ \t\r\v\f\u00A0]+(?=\n)/g
|
|
12
|
+
const ONLY_WHITESPACE = /^[ \t\r\v\f\u00A0]+$/
|
|
13
|
+
|
|
14
|
+
interface SkipZone {
|
|
15
|
+
startLine: number
|
|
16
|
+
startColumn: number
|
|
17
|
+
endLine: number
|
|
18
|
+
endColumn: number
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
interface TrailingWhitespaceCandidate {
|
|
22
|
+
line: number
|
|
23
|
+
column: number
|
|
24
|
+
length: number
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
interface ERBNoTrailingWhitespaceAutofixContext extends BaseAutofixContext {
|
|
28
|
+
node: Mutable<HTMLTextNode> | Mutable<LiteralNode>
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
class SkipZoneCollector extends Visitor {
|
|
32
|
+
skipZones: SkipZone[] = []
|
|
33
|
+
|
|
34
|
+
SKIP_TAGS = new Set(["pre", "textarea", "script", "style"])
|
|
35
|
+
|
|
36
|
+
visitHTMLElementNode(node: HTMLElementNode): void {
|
|
37
|
+
if (isHTMLOpenTagNode(node.open_tag)) {
|
|
38
|
+
const tagName = getTagLocalName(node.open_tag)
|
|
39
|
+
|
|
40
|
+
if (tagName && this.SKIP_TAGS.has(tagName)) {
|
|
41
|
+
this.skipZones.push({
|
|
42
|
+
startLine: node.location.start.line,
|
|
43
|
+
startColumn: node.location.start.column,
|
|
44
|
+
endLine: node.location.end.line,
|
|
45
|
+
endColumn: node.location.end.column
|
|
46
|
+
})
|
|
47
|
+
|
|
48
|
+
return
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
super.visitHTMLElementNode(node)
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
visitERBNode(node: ERBNode) {
|
|
56
|
+
if (!node.tag_opening) return
|
|
57
|
+
if (!node.tag_closing) return
|
|
58
|
+
|
|
59
|
+
this.skipZones.push({
|
|
60
|
+
startLine: node.tag_opening.location.start.line,
|
|
61
|
+
startColumn: node.tag_opening.location.start.column,
|
|
62
|
+
endLine: node.tag_closing.location.end.line,
|
|
63
|
+
endColumn: node.tag_closing.location.end.column
|
|
64
|
+
})
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
export class ERBNoTrailingWhitespaceRule extends ParserRule<ERBNoTrailingWhitespaceAutofixContext> {
|
|
69
|
+
static autocorrectable = true
|
|
70
|
+
static ruleName = "erb-no-trailing-whitespace"
|
|
71
|
+
|
|
72
|
+
get defaultConfig(): FullRuleConfig {
|
|
73
|
+
return {
|
|
74
|
+
enabled: true,
|
|
75
|
+
severity: "error",
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
check(result: ParseResult, _context?: Partial<LintContext>): UnboundLintOffense<ERBNoTrailingWhitespaceAutofixContext>[] {
|
|
80
|
+
const offenses: UnboundLintOffense<ERBNoTrailingWhitespaceAutofixContext>[] = []
|
|
81
|
+
const lines = result.source.split("\n")
|
|
82
|
+
const candidates = this.findTrailingWhitespaceCandidates(lines)
|
|
83
|
+
|
|
84
|
+
if (candidates.length === 0) return offenses
|
|
85
|
+
|
|
86
|
+
const skipZones = this.collectSkipZones(result.value)
|
|
87
|
+
|
|
88
|
+
for (const candidate of candidates) {
|
|
89
|
+
if (!this.isInSkipZone(candidate, skipZones)) {
|
|
90
|
+
const location = Location.from(candidate.line, candidate.column, candidate.line, candidate.column + candidate.length)
|
|
91
|
+
const node = findNodeAtPosition(result.value, candidate.line, candidate.column, (n) => isHTMLTextNode(n) || isLiteralNode(n)) as HTMLTextNode | LiteralNode | null
|
|
92
|
+
|
|
93
|
+
offenses.push({
|
|
94
|
+
rule: this.ruleName,
|
|
95
|
+
message: "Extra whitespace detected at end of line.",
|
|
96
|
+
location,
|
|
97
|
+
autofixContext: node ? { node } : undefined
|
|
98
|
+
})
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
return offenses
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
private findTrailingWhitespaceCandidates(lines: string[]): TrailingWhitespaceCandidate[] {
|
|
106
|
+
const candidates: TrailingWhitespaceCandidate[] = []
|
|
107
|
+
|
|
108
|
+
for (let i = 0; i < lines.length; i++) {
|
|
109
|
+
const line = lines[i]
|
|
110
|
+
const match = line.match(TRAILING_WHITESPACE)
|
|
111
|
+
|
|
112
|
+
if (match && match.index !== undefined) {
|
|
113
|
+
candidates.push({
|
|
114
|
+
line: i + 1,
|
|
115
|
+
column: match.index,
|
|
116
|
+
length: match[0].length
|
|
117
|
+
})
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
return candidates
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
private collectSkipZones(root: DocumentNode): SkipZone[] {
|
|
125
|
+
const collector = new SkipZoneCollector()
|
|
126
|
+
|
|
127
|
+
collector.visit(root)
|
|
128
|
+
|
|
129
|
+
return collector.skipZones
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
private isInSkipZone(candidate: TrailingWhitespaceCandidate, skipZones: SkipZone[]): boolean {
|
|
133
|
+
for (const zone of skipZones) {
|
|
134
|
+
if (candidate.line < zone.startLine || candidate.line > zone.endLine) continue
|
|
135
|
+
if (candidate.line === zone.endLine && candidate.column >= zone.endColumn) continue
|
|
136
|
+
if (candidate.line === zone.startLine && candidate.column < zone.startColumn) continue
|
|
137
|
+
|
|
138
|
+
return true
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
return false
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
autofix(offense: LintOffense<ERBNoTrailingWhitespaceAutofixContext>, result: ParseResult, _context?: Partial<LintContext>): ParseResult | null {
|
|
145
|
+
if (!offense.autofixContext) return null
|
|
146
|
+
|
|
147
|
+
const { node } = offense.autofixContext
|
|
148
|
+
|
|
149
|
+
if (node.type === "AST_HTML_TEXT_NODE" || node.type === "AST_LITERAL_NODE") {
|
|
150
|
+
let fixedContent = node.content.replace(TRAILING_WHITESPACE_BEFORE_NEWLINE, "")
|
|
151
|
+
const offenseIsAtEndOfContent = this.isOffenseAtEndOfContent(offense, node)
|
|
152
|
+
|
|
153
|
+
if (offenseIsAtEndOfContent) {
|
|
154
|
+
if (this.hasTrailingWhitespaceNotIndentation(fixedContent)) {
|
|
155
|
+
fixedContent = fixedContent.replace(TRAILING_WHITESPACE, "")
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
if (ONLY_WHITESPACE.test(fixedContent) && node.location.start.column !== 0) {
|
|
159
|
+
fixedContent = ""
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
node.content = fixedContent
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
return result
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
private isOffenseAtEndOfContent(offense: LintOffense<ERBNoTrailingWhitespaceAutofixContext>, node: Mutable<HTMLTextNode> | Mutable<LiteralNode>): boolean {
|
|
170
|
+
return offense.location.end.line === node.location.end.line && offense.location.end.column === node.location.end.column
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
private hasTrailingWhitespaceNotIndentation(content: string): boolean {
|
|
174
|
+
if (content.endsWith("\n")) return false
|
|
175
|
+
|
|
176
|
+
const endMatch = content.match(TRAILING_WHITESPACE)
|
|
177
|
+
if (!endMatch) return false
|
|
178
|
+
|
|
179
|
+
const whitespaceStart = content.length - endMatch[0].length
|
|
180
|
+
if (whitespaceStart === 0) return false
|
|
181
|
+
|
|
182
|
+
const characterBefore = content[whitespaceStart - 1]
|
|
183
|
+
if (characterBefore === "\n") return false
|
|
184
|
+
|
|
185
|
+
return true
|
|
186
|
+
}
|
|
187
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { ParserRule } from "../types.js"
|
|
2
|
+
import { AttributeVisitorMixin } from "./rule-utils.js"
|
|
3
|
+
import { isERBNode, isERBOutputNode } from "@herb-tools/core"
|
|
4
|
+
|
|
5
|
+
import type { UnboundLintOffense, LintContext, FullRuleConfig } from "../types.js"
|
|
6
|
+
import type { ParseResult, Node } from "@herb-tools/core"
|
|
7
|
+
import type { StaticAttributeDynamicValueParams } from "./rule-utils.js"
|
|
8
|
+
|
|
9
|
+
const JS_ATTRIBUTE_PATTERN = /^on/i
|
|
10
|
+
const SAFE_PATTERN = /\.to_json\s*$|\bj\s*[\s(]|\bescape_javascript\s*[\s(]/
|
|
11
|
+
|
|
12
|
+
class ERBNoUnsafeJSAttributeVisitor extends AttributeVisitorMixin {
|
|
13
|
+
protected checkStaticAttributeDynamicValue({ attributeName, valueNodes }: StaticAttributeDynamicValueParams): void {
|
|
14
|
+
if (!JS_ATTRIBUTE_PATTERN.test(attributeName)) return
|
|
15
|
+
|
|
16
|
+
for (const node of valueNodes) {
|
|
17
|
+
if (!isERBNode(node)) continue
|
|
18
|
+
if (!isERBOutputNode(node)) continue
|
|
19
|
+
|
|
20
|
+
const content = node.content?.value?.trim() || ""
|
|
21
|
+
|
|
22
|
+
if (SAFE_PATTERN.test(content)) continue
|
|
23
|
+
|
|
24
|
+
this.addOffense(
|
|
25
|
+
`Unsafe ERB output in \`${attributeName}\` attribute. Use \`.to_json\`, \`j()\`, or \`escape_javascript()\` to safely encode values.`,
|
|
26
|
+
node.location,
|
|
27
|
+
)
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export class ERBNoUnsafeJSAttributeRule extends ParserRule {
|
|
33
|
+
static ruleName = "erb-no-unsafe-js-attribute"
|
|
34
|
+
|
|
35
|
+
get defaultConfig(): FullRuleConfig {
|
|
36
|
+
return {
|
|
37
|
+
enabled: true,
|
|
38
|
+
severity: "error"
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
check(result: ParseResult, context?: Partial<LintContext>): UnboundLintOffense[] {
|
|
43
|
+
const visitor = new ERBNoUnsafeJSAttributeVisitor(this.ruleName, context)
|
|
44
|
+
visitor.visit(result.value)
|
|
45
|
+
return visitor.offenses
|
|
46
|
+
}
|
|
47
|
+
}
|