Skip to content

Comments before "use strict" and an import line are duplicated below the import line #375

@ian-oneleet

Description

@ian-oneleet

Your Environment

  • Prettier version: 3.6.2
  • node version: 22.14.0
  • package manager: 11.3.0
  • IDE: Cursor and prettier CLI

Describe the bug

Comments before "use strict" and an import line are duplicated below the import line. This also makes formatting not idempotent.

To Reproduce

Format the following:

// foo
/* bar */

"use strict";

import "foo";

Expected behavior

Prettier spits out some reasonable transformation of the code.

Actual behaviour

The comment is duplicated below the import line:

// foo
/* bar */

"use strict";

import "foo";

// foo
/* bar */

This also makes formatting not idempotent, as formatting again produces:

// foo
/* bar */

"use strict";

import "foo";

// foo
/* bar */

// foo
/* bar */

ad infinitum.

Configuration File (cat .prettierrc, prettier.config.js, .prettier.js)

{
  "plugins": ["@trivago/prettier-plugin-sort-imports"]
}

Error log

N/A

Contribute to @trivago/prettier-plugin-sort-imports

  • I'm willing to fix this bug 🥇

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions