Skip to content

perf: replace Wallace css parser/walker with PostCSS native APIs where possible#90

Merged
bartveneman merged 1 commit intomainfrom
claude/optimize-perf-bundle-gbdWo
Mar 25, 2026
Merged

perf: replace Wallace css parser/walker with PostCSS native APIs where possible#90
bartveneman merged 1 commit intomainfrom
claude/optimize-perf-bundle-gbdWo

Conversation

@bartveneman
Copy link
Copy Markdown
Member

Summary

Refactored multiple stylelint rules to use PostCSS native APIs instead of the @projectwallace/css-parser library, simplifying the codebase and improving maintainability.

Key Changes

  • no-unused-layers: Replaced custom parser with root.walkAtRules('layer'), simplified position tracking by using AtRule nodes directly, and extracted allowlist logic to isAllowed() utility function
  • max-selector-complexity: Replaced custom parser with root.walkRules() for iterating style rules, removed manual line offset calculations
  • max-average-declarations-per-rule: Replaced custom parser with root.walkRules() and rule.each() for traversing declarations, simplified node type checking
  • max-important-ratio: Removed custom declaration parser, now uses PostCSS's native declaration.important property instead of parsing declaration source text

Implementation Details

  • Removed dependencies on @projectwallace/css-parser modules: parse, walk, nodes constants
  • Eliminated manual line offset calculations (root.source?.start?.line) by using PostCSS node objects directly for reporting
  • Simplified allowlist checking in no-unused-layers by delegating to extracted utility function
  • All rules now leverage PostCSS's built-in traversal methods and node properties, reducing code complexity and improving consistency with stylelint patterns

https://claude.ai/code/session_01VsxyyE2S6uMjaSkPKRej5u

- max-important-ratio: use PostCSS declaration.important instead of
  calling parse_declaration() on every declaration; removes the
  css-parser import entirely from this rule

- max-average-declarations-per-rule: replace root.toString() + full
  css-parser re-parse with root.walkRules() + rule.each(); removes
  all three css-parser imports (parse, walk, node constants)

- max-selector-complexity: replace root.toString() + css-parser
  re-parse + manual walk with root.walkRules(), matching the pattern
  already used by max-average-selector-complexity; removes parse,
  walk, and STYLE_RULE imports

- no-unused-layers: replace root.toString() + css-parser re-parse with
  root.walkAtRules('layer'); also replaces the inline allowlist pattern
  matching with the existing isAllowed() utility; stores the PostCSS
  AtRule node directly instead of a manual {line, column} position

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

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.20%. Comparing base (54ee7d7) to head (f1dbe99).

Additional details and impacted files
@@            Coverage Diff             @@
##             main      #90      +/-   ##
==========================================
- Coverage   98.25%   98.20%   -0.05%     
==========================================
  Files          33       33              
  Lines         917      893      -24     
  Branches      243      230      -13     
==========================================
- Hits          901      877      -24     
  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 changed the title Replace custom CSS parser with PostCSS native APIs perf: replace Wallace css parser/walker with PostCSS native APIs where possible Mar 25, 2026
@bartveneman bartveneman merged commit 648311c into main Mar 25, 2026
4 of 5 checks passed
@bartveneman bartveneman deleted the claude/optimize-perf-bundle-gbdWo branch March 25, 2026 09:20
@codecov-commenter
Copy link
Copy Markdown

Bundle Report

Changes will decrease total bundle size by 1.43kB (-2.27%) ⬇️. This is within the configured threshold ✅

Detailed changes
Bundle name Size Change
stylelintPlugin-esm 61.3kB -1.43kB (-2.27%) ⬇️

Affected Assets, Files, and Routes:

view changes for bundle: stylelintPlugin-esm

Assets Changed:

Asset Name Size Change Total Size Change (%)
index.mjs -1.43kB 57.03kB -2.44%

Files in index.mjs:

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

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

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

  • ./src/rules/no-unused-layers/index.ts → Total Size: 1.64kB

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