Add line type classification for formatted CSS output#210
Open
bartveneman wants to merge 4 commits into
Open
Conversation
Closes #84. Exports LINE_TYPE_* numeric constants (1–6) for selector, declaration, bracket, atrule, comment, and empty. format_with_types() wraps format() and classifies each output line by its trailing character, which is deterministic given the formatter's own guarantees. minify mode is excluded as the option type reflects. https://claude.ai/code/session_01Bx7vr5gtd3KFNqghLacxyc
Bundle ReportChanges will increase total bundle size by 1.89kB (10.93%) ⬆️
Affected Assets, Files, and Routes:view changes for bundle: formatCss-esmAssets Changed:
Files in
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #210 +/- ##
==========================================
+ Coverage 96.83% 97.12% +0.28%
==========================================
Files 2 2
Lines 348 382 +34
Branches 127 137 +10
==========================================
+ Hits 337 371 +34
Misses 10 10
Partials 1 1 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Replaces stateless classify_line with a stateful classify_lines that tracks when a /* opens without a closing */ on the same line, tagging all intermediate lines as LINE_TYPE_COMMENT. Adds 16 tests covering selectors, declarations, brackets, atrules (with and without block), single-line comments, multiline comments (2-line, 3-line, inside a rule), and edge cases like comments containing ; or }. https://claude.ai/code/session_01Bx7vr5gtd3KFNqghLacxyc
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
This PR adds functionality to classify each line of formatted CSS by its type, enabling consumers to understand the structure of the formatted output programmatically.
Key Changes
LINE_TYPE_SELECTOR,LINE_TYPE_DECLARATION,LINE_TYPE_BRACKET,LINE_TYPE_ATRULE,LINE_TYPE_COMMENT,LINE_TYPE_EMPTY) to categorize CSS linesLineTypeunion type representing all possible line classificationsclassify_line()function that analyzes a CSS line and returns its type based on content patterns (e.g., lines ending with},@rules, declarations, etc.)format_with_types()export that returns both the formatted CSS and an array of line types corresponding to each line in the outputImplementation Details
format_with_types()function leverages the existingformat()function and applies line classification to each output linehttps://claude.ai/code/session_01Bx7vr5gtd3KFNqghLacxyc