feat(postcss-syntax): update parse
function to generate css rules one line per slot(makeStyles)/declaration(makeResetStyles)
#548
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.
Background:
parse
function was created for linting griffel styles with stylelint. It reads the css-in-js styles, and output a post css AST that can be used by stylelint.Before:
parse
function adjusts the location directly the the returned AST. But it doesn't work well with stylelint.For example:
parse
maps the location of nodecolor: '#111'
to{ line: 4, column: 2, endLine: 6, endColumn: 3 }
, which is the location of entireroot
slot. When stylelint lints the AST and tries to give a warning on"#111"
, it takes the start location and adds length of the 4-character string"#111"
on top. The result warning location is{ line: 4, column: 2, endLine: 4, endColumn: 6 }
, which is not the best.To guarantee accurate result from stylelint, the location in AST must match the original css source.
After:
parse
function does:makeStyles
and eachmakeResetStyles
will be one line in the output.postcss.parse
on the generated rule to get ASTWhen stylelint lint the AST, it gives warnings based on the location in css source. We can use stylelint processors to re-map the warnings to slot location in original js.
Here's an example processor:
With the above processor, stylelint result has meaningful location:
Related
stylelint/stylelint#7567
stylelint/stylelint#7568