Skip to content

Add min-selector-uniqueness-ratio and min-declaration-uniqueness-ratio rules#85

Merged
bartveneman merged 4 commits intomainfrom
claude/add-stylelint-rules-L6dos
Mar 24, 2026
Merged

Add min-selector-uniqueness-ratio and min-declaration-uniqueness-ratio rules#85
bartveneman merged 4 commits intomainfrom
claude/add-stylelint-rules-L6dos

Conversation

@bartveneman
Copy link
Copy Markdown
Member

Summary

This PR adds two new stylelint rules to the plugin that enforce minimum uniqueness ratios for selectors and declarations in CSS stylesheets.

Key Changes

  • New Rule: min-selector-uniqueness-ratio - Enforces a minimum ratio of unique selectors to total selectors. Counts individual selectors in selector lists separately (e.g., a, b counts as 2 selectors).
  • New Rule: min-declaration-uniqueness-ratio - Enforces a minimum ratio of unique declarations to total declarations. Uniqueness is determined by the combination of property and value.
  • Added comprehensive test suites for both rules covering:
    • Invalid configuration handling (negative values, values > 1)
    • Edge cases (empty stylesheets, all unique declarations/selectors)
    • Boundary conditions (ratio exactly at limit)
    • Error scenarios (ratio below limit)
    • Special cases (selector lists, config value of 0 and 1)
  • Updated the main plugin index to export both new rules
  • Added both rules to the recommended configuration with sensible defaults (0.66 for selectors, 0.5 for declarations)

Implementation Details

  • Both rules validate that the configuration value is a finite number between 0 and 1 (inclusive), and skip execution for invalid values
  • Selectors are trimmed and counted individually from selector lists
  • Declarations are uniquely identified by the combination of property and trimmed value
  • Rules report errors at the root node with descriptive messages showing the actual ratio vs. required ratio
  • Both rules include metadata with links to their documentation

https://claude.ai/code/session_01VURzQkGPNVKAvhiRHoNudb

…o rules

Implements #43 and #44. Both rules enforce a minimum ratio of unique
selectors/declarations across the stylesheet (0-1 inclusive). Defaults:
selectors 0.66, declarations 0.5. Both added to recommended config.

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

codecov-commenter commented Mar 24, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.11%. Comparing base (23c10dd) to head (2083842).

Additional details and impacted files
@@            Coverage Diff             @@
##             main      #85      +/-   ##
==========================================
+ Coverage   97.97%   98.11%   +0.13%     
==========================================
  Files          28       30       +2     
  Lines         792      847      +55     
  Branches      216      232      +16     
==========================================
+ Hits          776      831      +55     
  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.

claude added 3 commits March 24, 2026 12:28
Verifies that declarations and selectors inside nested CSS rules and
at-rules (e.g. @media, nesting with &) are counted toward the ratio.

https://claude.ai/code/session_01VURzQkGPNVKAvhiRHoNudb
Replace array accumulation + Set construction with a counter + Set.add()
pattern, avoiding storing all values in a separate array.

https://claude.ai/code/session_01VURzQkGPNVKAvhiRHoNudb
Adds per-rule README.md with violation/passing examples and option docs.
Updates root README.md manual config example and rules table per CONTRIBUTING.md.

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

codecov-commenter commented Mar 24, 2026

Bundle Report

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

Bundle name Size Change
stylelintPlugin-esm 57.9kB 3.33kB (6.1%) ⬆️⚠️

Affected Assets, Files, and Routes:

view changes for bundle: stylelintPlugin-esm

Assets Changed:

Asset Name Size Change Total Size Change (%)
index.mjs 3.09kB 53.97kB 6.08% ⚠️
configs/recommended.d.mts 123 bytes 1.49kB 8.99% ⚠️
configs/recommended.mjs 112 bytes 1.4kB 8.72% ⚠️

Files in index.mjs:

  • ./src/rules/min-declaration-uniqueness-ratio/index.ts → Total Size: 1.43kB

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

  • ./src/rules/min-selector-uniqueness-ratio/index.ts → Total Size: 1.5kB

Files in configs/recommended.mjs:

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

@bartveneman bartveneman merged commit e91b663 into main Mar 24, 2026
4 of 5 checks passed
@bartveneman bartveneman deleted the claude/add-stylelint-rules-L6dos branch March 24, 2026 12:50
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