fix(postcss): preserve interpolations and indentation through stylelint --fix - #1495
Merged
Conversation
🦋 Changeset detectedLatest commit: c3a0f90 The changes in this PR will be included in the next version bump. This PR includes changesets to release 9 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
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.
Fixes #1494.
Summary
raws.value.rawrather thanvalue. PostCSS strips comments out ofvalue, and an interpolation alone on its own line inside a parenthesised value is represented as a comment placeholder, so it was already gone before the stringifier ran.substitutePlaceholdersthe comment placeholder form. Its scan splits on spaces and cannot see/* pcss-lin:N */, whose delimiters are separate tokens.super.atrulere-reads params throughrawValue, so substituting intonode.paramswas discarded whenever the params spanned lines, and@media screen and ${query}came out as@media screen and .pcss-lin0.afterNameraw as well. An interpolation on the line after the at-rule name lands there instead of in the params and was emitted verbatim.afterName, whichcomputeBeforeAfternever handled. A wrapped at-rule prelude lost its leading whitespace on any fix, templates containing no interpolations at all included.The last three problems are older than this issue and surfaced while testing the first. They all have the same cause: the stringifier reads from somewhere other than where the substitution was written. They also live in the same two files, so they are fixed here rather than left for a follow-up.
Validation
pnpm --filter @linaria/postcss-linaria test: 84 tests, 6 of them new. All 6 fail without the source changes, and no existing test is affected.pnpm --filter @linaria/postcss-linaria typecheckpnpm --filter @linaria/postcss-linaria buildpnpm check:all--fixmakes three unwanted edits alongside the intended ones: a leaked/* pcss-lin:0 */, a.pcss-lin1where a media query should be, and a dropped interpolation. After, only the intended edits. A separate file with a wrapped@mediaprelude and no interpolations loses four spaces of indentation before, and is untouched after.