Skip to content

Add max-unique-units rule to stylelint plugin#75

Merged
bartveneman merged 2 commits intomainfrom
claude/implement-stylelint-issue-74-Xyo5o
Mar 23, 2026
Merged

Add max-unique-units rule to stylelint plugin#75
bartveneman merged 2 commits intomainfrom
claude/implement-stylelint-issue-74-Xyo5o

Conversation

@bartveneman
Copy link
Copy Markdown
Member

@bartveneman bartveneman commented Mar 23, 2026

Summary

This PR introduces a new stylelint rule projectwallace/max-unique-units that enforces a maximum limit on the number of unique CSS units used in a stylesheet.

Key Changes

  • New rule implementation (src/rules/max-unique-units/index.ts): Validates that the number of unique CSS units does not exceed a configured threshold
  • Comprehensive test suite (src/rules/max-unique-units/index.test.ts): 8 test cases covering various scenarios including edge cases and unit handling
  • Plugin registration: Added the new rule to the main plugin exports in src/index.ts
  • Recommended config: Set default limit to 10 unique units in the recommended configuration

Implementation Details

  • The rule parses CSS declarations and extracts dimension nodes using the @projectwallace/css-parser library
  • Units are normalized to lowercase for case-insensitive comparison
  • The rule correctly handles:
    • Disabled state (when config value is ≤ 0)
    • Declarations without units
    • Repeated use of the same unit (only counts unique units)
    • Percentage (%) as a valid unit
  • Reports a single error at the root level when the unique unit count exceeds the limit

closes #74

Implements #74. Reports an error when the number of unique CSS units
across all declarations exceeds the configured maximum (default: 10 in
recommended config).

https://claude.ai/code/session_0192BXzpQGBjEwrmTLZWeqMW
@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented Mar 23, 2026

Bundle Report

Changes will increase total bundle size by 1.7kB (3.27%) ⬆️. This is within the configured threshold ✅

Detailed changes
Bundle name Size Change
stylelintPlugin-esm 53.8kB 1.7kB (3.27%) ⬆️

Affected Assets, Files, and Routes:

view changes for bundle: stylelintPlugin-esm

Assets Changed:

Asset Name Size Change Total Size Change (%)
index.mjs 1.61kB 51.0kB 3.27%
configs/recommended.d.mts 47 bytes 1.37kB 3.56%
configs/recommended.mjs 41 bytes 1.28kB 3.3%

Files in index.mjs:

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

  • ./src/rules/max-unique-units/index.ts → Total Size: 1.44kB

Files in configs/recommended.mjs:

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

@codecov-commenter
Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.00%. Comparing base (b6acff3) to head (37dd7b8).

Additional details and impacted files
@@            Coverage Diff             @@
##             main      #75      +/-   ##
==========================================
+ Coverage   97.94%   98.00%   +0.06%     
==========================================
  Files          26       27       +1     
  Lines         778      804      +26     
  Branches      222      226       +4     
==========================================
+ Hits          762      788      +26     
  Misses         13       13              
  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.

@bartveneman bartveneman merged commit 00fab5c into main Mar 23, 2026
4 of 5 checks passed
@bartveneman bartveneman deleted the claude/implement-stylelint-issue-74-Xyo5o branch March 23, 2026 20:21
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.

New rule: max-unique-units

3 participants