Skip to content

@linaria/postcss-linaria: stylelint --fix repeatedly doubles existing backslashes #1497

Description

@aki05162525

Environment

  • @linaria/postcss-linaria: 8.1.1
  • Stylelint: 17.14.1
  • PostCSS: 8.5.23
  • Node.js: 24.16.0
  • OS: macOS

Description

Running stylelint --fix with customSyntax: '@linaria/postcss-linaria' doubles
existing backslashes inside Linaria CSS templates.

For example:

- content: '\u2022';
+ content: '\\u2022';

This reproduces with zero Stylelint rules configured, so the corruption occurs during
the @linaria/postcss-linaria parse/stringify round trip rather than in a rule fixer.

The change is also non-idempotent. Each subsequent run doubles the backslashes again:

\u2022 → \\u2022 → \\\\u2022

Reproduction

.stylelintrc.mjs:

export default {
  customSyntax: '@linaria/postcss-linaria',
  rules: {},
};

sample.style.ts:

import { css } from '@linaria/core';

export const style = css`
  .foo {
    &:before {
      content: '\u2022';
      color: red;
    }
  }
`;

Run:

stylelint --config .stylelintrc.mjs --fix sample.style.ts

Expected:

content: '\u2022';

Actual:

content: '\\u2022';

Running the same command again changes it to:

content: '\\\\u2022';

Likely cause

LinariaStringifier unconditionally doubles backslashes for every non-root node:

builder(str.replace(/\\/g, '\\\\').replace(/`/g, '\\`'), node, type);

This also runs on unchanged declaration values, so existing backslashes are escaped
again each time the file is stringified.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions