Skip to content

Add line type classification for formatted CSS output#210

Open
bartveneman wants to merge 4 commits into
mainfrom
claude/refactor-css-formatter-lines-h6c9J
Open

Add line type classification for formatted CSS output#210
bartveneman wants to merge 4 commits into
mainfrom
claude/refactor-css-formatter-lines-h6c9J

Conversation

@bartveneman
Copy link
Copy Markdown
Member

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

  • Added six line type constants (LINE_TYPE_SELECTOR, LINE_TYPE_DECLARATION, LINE_TYPE_BRACKET, LINE_TYPE_ATRULE, LINE_TYPE_COMMENT, LINE_TYPE_EMPTY) to categorize CSS lines
  • Created a LineType union type representing all possible line classifications
  • Implemented classify_line() function that analyzes a CSS line and returns its type based on content patterns (e.g., lines ending with }, @ rules, declarations, etc.)
  • Added new format_with_types() export that returns both the formatted CSS and an array of line types corresponding to each line in the output

Implementation Details

  • Line classification uses simple pattern matching on trimmed line content
  • The function checks for empty lines, comments, brackets, at-rules, selectors, and declarations in a specific order
  • The format_with_types() function leverages the existing format() function and applies line classification to each output line
  • This allows callers to understand the semantic structure of formatted CSS without re-parsing it

https://claude.ai/code/session_01Bx7vr5gtd3KFNqghLacxyc

claude added 2 commits May 16, 2026 13:37
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
@codecov
Copy link
Copy Markdown

codecov Bot commented May 16, 2026

Bundle Report

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

Bundle name Size Change
formatCss-esm 16.5kB 1.89kB (12.95%) ⬆️⚠️

Affected Assets, Files, and Routes:

view changes for bundle: formatCss-esm

Assets Changed:

Asset Name Size Change Total Size Change (%)
index.js 1.21kB 14.3kB 9.27% ⚠️
index.d.ts 679 bytes 2.2kB 44.61% ⚠️

Files in index.js:

  • ./src/lib/index.ts → Total Size: 13.68kB

@codecov
Copy link
Copy Markdown

codecov Bot commented May 16, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 97.12%. Comparing base (b8f6d3b) to head (ebd85ee).

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.
📢 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 2 commits May 16, 2026 13:42
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
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.

2 participants