Skip to content

feat: add max-average-specificity rule#86

Merged
bartveneman merged 5 commits intomainfrom
claude/implement-max-average-specificity-7uUvH
Mar 24, 2026
Merged

feat: add max-average-specificity rule#86
bartveneman merged 5 commits intomainfrom
claude/implement-max-average-specificity-7uUvH

Conversation

@bartveneman
Copy link
Copy Markdown
Member

Closes #77

Summary

  • New rule projectwallace/max-average-specificity that tracks the specificity of all selectors and reports when the average exceeds the configured [a, b, c] maximum
  • Primary option is a tuple of 3 non-negative numbers (floats allowed), e.g. [0, 2.5, 1]
  • Uses calculateSpecificity and compareSpecificity from @projectwallace/css-analyzer
  • Uses ruleFunction.primaryOptionArray = true so stylelint correctly treats the tuple as the primary option (not [primaryOption, secondaryOptions])
  • Added to recommended config with value [0, 2.5, 1]
  • Registered in src/index.ts and documented in README.md per CONTRIBUTING.md

Test plan

  • Invalid options (not an array, wrong length, negative values) produce invalidOptionWarnings
  • No selectors → no violation
  • Average specificity within limit → no violation
  • Average specificity equal to limit → no violation
  • Average specificity exceeding limit → violation reported
  • Float values in primary option work correctly
  • All 310 tests pass

https://claude.ai/code/session_015qh5mN6GXk2cUWQy2JFV7L

Implements #77. Tracks the specificity of all selectors and reports
when the average exceeds the configured [a, b, c] maximum. Added to
the recommended config with default value [0, 2.5, 1].

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

codecov-commenter commented Mar 24, 2026

Bundle Report

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

Detailed changes
Bundle name Size Change
stylelintPlugin-esm 59.96kB 2.05kB (3.54%) ⬆️

Affected Assets, Files, and Routes:

view changes for bundle: stylelintPlugin-esm

Assets Changed:

Asset Name Size Change Total Size Change (%)
index.mjs 1.93kB 55.9kB 3.57%
configs/recommended.d.mts 56 bytes 1.55kB 3.76%
configs/recommended.mjs 70 bytes 1.47kB 5.01% ⚠️

Files in index.mjs:

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

  • ./src/rules/max-average-specificity/index.ts → Total Size: 1.75kB

Files in configs/recommended.mjs:

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

@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.17%. Comparing base (e91b663) to head (5453869).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main      #86      +/-   ##
==========================================
+ Coverage   98.11%   98.17%   +0.06%     
==========================================
  Files          30       31       +1     
  Lines         847      878      +31     
  Branches      232      238       +6     
==========================================
+ Hits          831      862      +31     
  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 and others added 4 commits March 24, 2026 15:37
Follow the same convention as stylelint's own selector-max-specificity
rule, which accepts "0,2,0" strings rather than arrays. This avoids
needing primaryOptionArray and is more idiomatic stylelint.

https://claude.ai/code/session_015qh5mN6GXk2cUWQy2JFV7L
…cificity

Uses primaryOptionArray = true so stylelint correctly interprets the
tuple as the primary option rather than [primaryOption, secondaryOptions].

https://claude.ai/code/session_015qh5mN6GXk2cUWQy2JFV7L
RuleMessage args must be primitive types; pass specificity as joined
strings instead of tuple arrays.

https://claude.ai/code/session_015qh5mN6GXk2cUWQy2JFV7L
@bartveneman bartveneman merged commit c6b82d1 into main Mar 24, 2026
4 of 5 checks passed
@bartveneman bartveneman deleted the claude/implement-max-average-specificity-7uUvH branch March 24, 2026 15:47
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-specificity-average

3 participants