Skip to content

Add six new stylelint rules for CSS metrics analysis#58

Merged
bartveneman merged 6 commits intomainfrom
claude/stylelint-new-rules-oPRYZ
Mar 22, 2026
Merged

Add six new stylelint rules for CSS metrics analysis#58
bartveneman merged 6 commits intomainfrom
claude/stylelint-new-rules-oPRYZ

Conversation

@bartveneman
Copy link
Copy Markdown
Member

Summary

This PR adds six new stylelint rules to the plugin that leverage the @projectwallace/css-analyzer library to enforce CSS quality metrics and constraints.

Key Changes

  • New Rules Added:

    • max-file-size: Enforces a maximum file size limit in bytes
    • max-embedded-content-size: Limits the total size of embedded content (data URIs, etc.)
    • max-comment-size: Restricts the total size of CSS comments
    • max-average-selectors-per-rule: Enforces a maximum average number of selectors per rule
    • max-average-declarations-per-rule: Enforces a maximum average number of declarations per rule
    • max-average-selector-complexity: Enforces a maximum average selector complexity
  • Implementation Details:

    • Each rule follows the same pattern: validate options, analyze CSS using @projectwallace/css-analyzer, compare actual metrics against configured thresholds, and report violations
    • All rules skip execution when configured with values ≤ 0 (except max-important-ratio which uses < 0)
    • Comprehensive test coverage for each rule covering edge cases (disabled config, no violations, within limits, exceeding limits)
    • Rules are exported in the main plugin index and included in the recommended configuration
  • Documentation Updates:

    • Updated README.md with example configurations for all new rules
    • Added rules to the recommended configuration with sensible defaults
    • Updated plugin exports and test suite to include new rules

Notable Implementation Details

  • All rules use the same CSS analysis approach via analyze(root.source!.input.css)
  • Error messages are contextual and include both actual and expected values
  • Rules properly integrate with stylelint's validation and reporting utilities
  • Test suite uses Vitest and validates both positive cases (no errors) and negative cases (errors reported)

https://claude.ai/code/session_01N4LARBRwbeExNaaiACWJT6

@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented Mar 21, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 97.99%. Comparing base (25affd6) to head (37e2ce7).
⚠️ Report is 5 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main      #58      +/-   ##
==========================================
+ Coverage   97.46%   97.99%   +0.53%     
==========================================
  Files          18       25       +7     
  Lines         591      749     +158     
  Branches      189      210      +21     
==========================================
+ Hits          576      734     +158     
  Misses         12       12              
  Partials        3        3              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented Mar 21, 2026

Bundle Report

Changes will increase total bundle size by 10.95kB (28.17%) ⬆️⚠️, exceeding the configured threshold of 5%.

Bundle name Size Change
stylelintPlugin-esm 49.82kB 10.95kB (28.17%) ⬆️⚠️

Affected Assets, Files, and Routes:

view changes for bundle: stylelintPlugin-esm

Assets Changed:

Asset Name Size Change Total Size Change (%)
index.mjs 10.22kB 47.21kB 27.64% ⚠️
configs/recommended.d.mts 384 bytes 1.27kB 43.49% ⚠️
configs/recommended.mjs 343 bytes 1.2kB 40.26% ⚠️

Files in index.mjs:

  • ./src/rules/max-embedded-content-size/index.ts → Total Size: 1.46kB

  • ./src/rules/max-file-size/index.ts → Total Size: 1.11kB

  • ./src/rules/max-average-selectors-per-rule/index.ts → Total Size: 1.41kB

  • ./src/index.ts → Total Size: 763 bytes

  • ./src/rules/max-important-ratio/index.ts → Total Size: 1.48kB

  • ./src/rules/max-comment-size/index.ts → Total Size: 1.32kB

  • ./src/rules/max-average-selector-complexity/index.ts → Total Size: 1.5kB

  • ./src/rules/max-average-declarations-per-rule/index.ts → Total Size: 1.45kB

Files in configs/recommended.mjs:

  • ./src/configs/recommended.ts → Total Size: 1.15kB

bartveneman and others added 2 commits March 22, 2026 12:30
Replace analyze() calls with direct PostCSS AST walking and
@projectwallace/css-parser, matching the pattern used by existing rules:

- max-file-size: use root.source.input.css.length
- max-comment-size: walkComments + source offsets
- max-embedded-content-size: walkDecls + parse_declaration + URL nodes
- max-average-declarations-per-rule: walkRules + count decl nodes
- max-average-selectors-per-rule: walkRules + parse_selector
- max-average-selector-complexity: walkRules + parse_selector + selectorComplexity
- max-important-ratio: walkDecls + parse_declaration + is_important

https://claude.ai/code/session_01N4LARBRwbeExNaaiACWJT6
Comment thread src/configs/recommended.ts Outdated
@bartveneman bartveneman merged commit e543e56 into main Mar 22, 2026
4 of 5 checks passed
@bartveneman bartveneman deleted the claude/stylelint-new-rules-oPRYZ branch March 22, 2026 13:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants