Skip to content

fix(postcss): preserve interpolations and indentation through stylelint --fix - #1495

Merged
Anber merged 1 commit into
masterfrom
anber/fix-stylelint-fix-mangling
Jul 31, 2026
Merged

fix(postcss): preserve interpolations and indentation through stylelint --fix#1495
Anber merged 1 commit into
masterfrom
anber/fix-stylelint-fix-mangling

Conversation

@Anber

@Anber Anber commented Jul 31, 2026

Copy link
Copy Markdown
Collaborator

Fixes #1494.

Summary

  • Read the re-indented declaration value from raws.value.raw rather than value. PostCSS strips comments out of value, 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.
  • Teach substitutePlaceholders the comment placeholder form. Its scan splits on spaces and cannot see /* pcss-lin:N */, whose delimiters are separate tokens.
  • Substitute at-rule params where the stringifier reads them. super.atrule re-reads params through rawValue, so substituting into node.params was discarded whenever the params spanned lines, and @media screen and ${query} came out as @media screen and .pcss-lin0.
  • Substitute placeholders in the afterName raw as well. An interpolation on the line after the at-rule name lands there instead of in the params and was emitted verbatim.
  • Restore base indentation for afterName, which computeBeforeAfter never 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 typecheck
  • pnpm --filter @linaria/postcss-linaria build
  • pnpm check:all
  • End to end through the Stylelint CLI with a real fixable rule enabled. Before, --fix makes three unwanted edits alongside the intended ones: a leaked /* pcss-lin:0 */, a .pcss-lin1 where a media query should be, and a dropped interpolation. After, only the intended edits. A separate file with a wrapped @media prelude and no interpolations loses four spaces of indentation before, and is untouched after.

@changeset-bot

changeset-bot Bot commented Jul 31, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: c3a0f90

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 9 packages
Name Type
@linaria/postcss-linaria Patch
@linaria/atomic Patch
@linaria/babel-plugin-interop Patch
@linaria/core Patch
@linaria/react Patch
@linaria/server Patch
@linaria/stylelint Patch
@linaria/stylelint-config-standard-linaria Patch
linaria Patch

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

@Anber
Anber merged commit d28a5a8 into master Jul 31, 2026
7 checks passed
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.

stylelint --fix drops a trailing interpolation on its own line in a multi-line CSS value

1 participant