Skip to content

formatter: type import moved inside multiline header comment #17467

Description

@david-crespo

Input

/*
 * hi
 */
import cn from 'classnames'
import type { Hello } from 'pkg'

Notably it only happens when the type import is below and needs to be moved up. If the type import is before the other one, oxfmt does not move it into the comment.

Config

{
  "experimentalSortImports": {}
}

Oxfmt output

Oxfmt version: 0.21.0

/*
 * hi
import type { Hello } from "pkg";

 */
import cn from "classnames";

Oxfmt playground link

https://playground.oxc.rs/#eNrtVMFO3DAQ/ZXIFyS0FRSpEtpbBV0ViRZaqnLh4jiTYHBsdzxhF6323/scEi+VUL+AU+IZz8yb53mzVUYt1dHhna8Oq3ubP0d33vYxsFTGVy2HvjowTqfkdU/poDjlOVK1rb6Sc6HaTRfjY3egFiqo5Vbx4PPHWS9q2WqXaKHawL0WIVZL4QEGYe1TtpYrNgWnhZpzQlXWYoNPxbm+t0IpakPF1Gvfuf3RhD4ypX1IMiHC/VIuPfd1cPPJtN10bbdQUXPKuLaKNkI+oS6YkbRBPxo9rn+SDOyvBkm2odXgTYY2p8o1iZ/oWjNiZ+sY9/v0wgtbZDTFkQiwxZovzIEnKzBkrkYM+H9F1VYNiX7pet+U6PrWNnKvlicLRb65ai+tR5fKtYAbUU0m/+kxqtlM0Y8hyJ6nh7S5ecP8J5+uOUTUUjp98EQNNciJh7KA152FvtfZ5xys6MOWZtHLeu4f/rV+TrhSszaPJDd4NITPl2crZuoF+VQ/1A9k5JZ1RI6Z1FxoxPpZQGQ9ACHxP2G0icS2Jy/a3WA6L8YZBY6RyR4D+M7h/zncgagixpehE80dgTpF6eT44ydkAIXn1CJoFfgs74SVJdeUqX79CpBvgHrLdMPbWynWbyS60QIWptF/W/ZblYA2QkDEXkO4s1pNaKijccH4LJSi6YfUBKy0iU7vg4y5Zoujbr47ZpmXRZ6TeZOg8xAv6YlK0kei+D2vv9cAIOrgVhB4jngirkMqZKIfnx8hu8pfprgZ6cvm8rcbqQfNe8Xv/gLZ1/yW

Prettier output

Prettier output is irrelevant because oxfmt is clearly wrong, plus Prettier doesn't sort imports natively

Prettier playground link

No response

Additional notes

Create the following .oxfmtrc.json

{
  "experimentalSortImports": {}
}

and the following one-liner will repro the issue:

echo -e "/*\n * hi\n */\nimport cn from 'classnames'\nimport type { Hello } from 'pkg'" | npx [email protected] --stdin-filepath f.ts

Metadata

Metadata

Assignees

Labels

Type

Fields

Priority

None yet

Effort

None yet

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions