Fix rule detection with offset CSS (Svelte embedded styles)#61
Merged
bartveneman merged 2 commits intomainfrom Mar 22, 2026
Merged
Fix rule detection with offset CSS (Svelte embedded styles)#61bartveneman merged 2 commits intomainfrom
bartveneman merged 2 commits intomainfrom
Conversation
…custom-property-assignment
Both rules used `root.source.input.css.substring(start, end)` to extract raw
declaration text. In Svelte files, `input.css` contains the full file while
declaration offsets are relative to the extracted CSS, causing incorrect
substring extraction.
- `no-useless-custom-property-assignment`: Replace substring with
`${declaration.prop}: ${declaration.value}` (same fix as PR #60).
- `no-property-browserhacks`: PostCSS strips hack prefixes (`*`, `_`) from
`declaration.prop` and stores them at the end of `declaration.raws.before`.
Extract the hack prefix from `raws.before` and prepend it when reconstructing
the declaration string, so `parse_declaration` can still detect browserhacks
without relying on source offsets.
Add Svelte offset mismatch tests for both rules using a custom PostCSS syntax
that prepends fake HTML content to `input.css` to simulate Svelte's behavior.
https://claude.ai/code/session_01C6WsJo4uG4ksJ97bjx7StZ
…gnment to use full css-parser parse + walk Instead of running parse_declaration() per-declaration from PostCSS's walkDecls, parse the entire CSS once with parse() from @projectwallace/css-parser and walk the resulting AST to find DECLARATION nodes. This is more reliable because: - No dependency on per-declaration string reconstruction - The css-parser's DECLARATION nodes expose is_browserhack and property directly - Positions come from the css-parser AST (line/column), adjusted by the PostCSS root's start line to correctly resolve absolute positions in Svelte/Vue files https://claude.ai/code/session_01C6WsJo4uG4ksJ97bjx7StZ
Bundle ReportChanges will increase total bundle size by 554 bytes (1.52%) ⬆️. This is within the configured threshold ✅ Detailed changes
Affected Assets, Files, and Routes:view changes for bundle: stylelintPlugin-esmAssets Changed:
Files in
|
bartveneman
pushed a commit
that referenced
this pull request
Mar 22, 2026
Extended the approach from PR #61 to all other rules in the plugin: - Fix max-lines-of-code: use root.toString() instead of root.source.input.css so only the extracted CSS is analyzed (not the surrounding file in Svelte etc.) - Convert max-selector-complexity, no-anonymous-layers, no-static-container-query, no-static-media-query, no-unreachable-media-conditions, and no-unused-layers to use parse() + walk() from @projectwallace/css-parser with line_offset (report against root node with explicit start/end positions) - Add Svelte-simulation test cases to all 11 remaining rules (no-unknown-custom-property, no-unused-custom-properties, no-undeclared-container-names, no-unused-container-names, and all rules converted above) to prevent regressions https://claude.ai/code/session_01MBEABGmrwEbK5Ad8p6Qvy3
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #61 +/- ##
==========================================
+ Coverage 97.33% 97.35% +0.02%
==========================================
Files 18 18
Lines 563 568 +5
Branches 163 167 +4
==========================================
+ Hits 548 553 +5
Misses 12 12
Partials 3 3 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixed two stylelint rules to correctly detect violations when CSS is embedded in other file formats (e.g., Svelte
<style>blocks) where source offsets don't match the extracted CSS.Key Changes
@projectwallace/css-parserinstead of relying on PostCSS declaration offsets, which may be misaligned when CSS is extracted from a larger fileroot.source.start.lineline_offsetto account for CSS that starts at a non-zero line in the source filerootnode with explicitstart/endpositions instead of relying on declaration node positionsImplementation Details
root.walkDecls()with declaration-level offsets to parsing the full CSS string and walking the AST directly(root.source?.start?.line ?? 1) - 1to handle embedded CSS scenariosinput.csscontains the full file while parsed offsets are relative to extracted CSShttps://claude.ai/code/session_01C6WsJo4uG4ksJ97bjx7StZ