fix: parse CSS rule declarations for RUR metric in figma2code - #51
Open
Jason59000 wants to merge 1 commit into
Open
fix: parse CSS rule declarations for RUR metric in figma2code#51Jason59000 wants to merge 1 commit into
Jason59000 wants to merge 1 commit into
Conversation
extract_declarations() filters QualifiedRule.content for Declaration instances, but tinycss2.parse_stylesheet() returns raw component-value tokens, not Declaration objects. This causes all CSS in <style> blocks to contribute zero declarations to the RUR metric. Add parse_declaration_list() call (already imported) to convert tokens to Declaration objects before filtering.
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.
Problem
extract_declarations()inquality.py(line 170-173) filtersQualifiedRule.contentforDeclarationinstances, buttinycss2.parse_stylesheet()returns raw component-value tokens (WhitespaceToken,IdentToken,DimensionToken, etc.), notDeclarationobjects. As a result, CSS declarations inside<style>blocks and external stylesheets contribute zero declarations to the RUR (Relative Unit Share) metric — only inlinestyle=""attributes are counted.This is consistent with the RUR values in Table 2: all 10 models score between 1.05% and 4.81%, which corresponds to residual inline style usage rather than actual CSS analysis.
Fix
One-line change: call
parse_declaration_list()(already imported) on the rule content before filtering forDeclarationinstances.Reproduction
See also: tinycss2 docs — Common Use Cases