Skip to content

Linter: Implement html-no-style-attributes and html-no-style-elements rules#1539

Open
markokajzer wants to merge 2 commits intomarcoroth:mainfrom
markokajzer:marko/erb-disallow-inline-styles
Open

Linter: Implement html-no-style-attributes and html-no-style-elements rules#1539
markokajzer wants to merge 2 commits intomarcoroth:mainfrom
markokajzer:marko/erb-disallow-inline-styles

Conversation

@markokajzer
Copy link
Copy Markdown
Contributor

@markokajzer markokajzer commented Mar 30, 2026

closes #162


Rule: html-no-style-attributes

Description

Disallow the use of inline style attributes on HTML elements. All styling should be applied via external stylesheets or class-based styling.

Rationale

Inline style attributes make templates harder to maintain, promote duplication, and prevent adoption of strict CSP policies (style-src 'self'). Using CSS classes and external stylesheets improves maintainability and security.


Rule: html-no-style-elements

Description

Disallow the use of inline <style> tags in HTML templates. All styling should be applied via external stylesheets.

Rationale

Inline <style> tags make templates harder to maintain, promote duplication, and prevent adoption of strict CSP policies (style-src 'self'). Centralizing styles via external stylesheets improves maintainability and security.

This rule enforces:

  • No <style> tags embedded directly in templates.
  • No style tags generated via content_tag or tag helpers.

@github-actions github-actions bot added documentation Improvements or additions to documentation linter typescript linter-rule labels Mar 30, 2026
Copy link
Copy Markdown
Owner

@marcoroth marcoroth left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for working on this @markokajzer! 🙏🏼

Similar to #1536 (review), I think we also want to rename this rule to have a html-* prefix and have it split up to two rules, something like:

  • html-no-style-attributes: no style=""
  • html-no-style-elements: no <style>...</style>

@markokajzer markokajzer force-pushed the marko/erb-disallow-inline-styles branch 2 times, most recently from 27b8088 to 19465be Compare March 30, 2026 20:32
@markokajzer markokajzer changed the title Linter: Implement erb-disallow-inline-styles Linter: Implement html-no-style-attributes and html-no-style-elements rules Mar 30, 2026
@markokajzer markokajzer marked this pull request as draft March 30, 2026 20:37
@markokajzer markokajzer force-pushed the marko/erb-disallow-inline-styles branch from 19465be to 87fcbc9 Compare March 30, 2026 20:56
@markokajzer markokajzer marked this pull request as ready for review March 30, 2026 20:57
@markokajzer
Copy link
Copy Markdown
Contributor Author

markokajzer commented Mar 30, 2026

changes:

  1. split out html-no-style-attributes
  2. split out html-no-style-elements
  3. both scan for action view helpers
  4. added some additional specs with more edge cases

i can separate into two PRs 👍

@markokajzer markokajzer requested a review from marcoroth March 30, 2026 21:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation linter linter-rule typescript

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Linter Rule: Disallow inline <style> tags and style attributes

2 participants