Skip to content

oxfmt: non idempotent formatting on CSS comments in template literals #18522

@re-taro

Description

@re-taro

Description

Oxfmt is not idempotent when formatting CSS comments inside styled-components template literals. Each formatting pass adds additional
indentation to comment lines, causing the indentation to grow indefinitely.

Steps to reproduce

  1. Format the code below with oxfmt
  2. Format the output again with oxfmt
  3. Repeat and observe the indentation increasing each time

Input

import styled from 'styled-components';

export const DocumentedComponent = styled.div`
  /**
   * @description This is a documented section
   * @param {number} value - Some value
   */
  padding: 16px;
`;

Output

After 1st format

export const DocumentedComponent = styled.div`
  /**
     * @description This is a documented section
     * @param {number} value - Some value
     */
  padding: 16px;
`;

After 2nd format

export const DocumentedComponent = styled.div`
  /**
       * @description This is a documented section
       * @param {number} value - Some value
       */
  padding: 16px;
`;

After 3rd format

export const DocumentedComponent = styled.div`
  /**
         * @description This is a documented section
         * @param {number} value - Some value
         */
  padding: 16px;
`;

Expected behavior

Formatting should be idempotent. Running oxfmt on already-formatted code should produce identical output.

Environment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions