Skip to content

oxfmt: Header Comments / Preambles are moved when using sort-imports #16655

@florianwittmann

Description

@florianwittmann

When having a file with header comments / preambles they are moved when using sort-imports.

Example Pre-Formatting:

// THIS IS A GENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.

import { apiClient } from "../../apiClient";
import { useMutation, UseMutationOptions } from "@tanstack/react-query";
import { ApiErrorDisconnected, ApiError } from "../../apiErrors";
import { validateResponse } from "../../validateResponse";
import { z } from "zod";

Will be formatted to:

import { z } from "zod";

import { useMutation, UseMutationOptions } from "@tanstack/react-query";

// THIS IS A GENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.

import { apiClient } from "../../apiClient";
import { ApiErrorDisconnected, ApiError } from "../../apiErrors";
import { validateResponse } from "../../validateResponse";

My .oxfmtrc.jsonc:

{
  "$schema": "./node_modules/oxfmt/configuration_schema.json",

  "printWidth": 80,
  "trailingComma": "all",

  "experimentalSortImports": {
    "ignoreCase": true
  }
}

The same happens when using a multi line comment /* some comment */ instead of a line comment.

We are currently using biome and have used prettier (with @ianvs/prettier-plugin-sort-imports) in the past, neither of these move(d) the header comments.

(I am aware of the experimental state of import sorting, but this is the only thing blocking us to switch fully to oxfmt and I did not find another issue tracking this yet).

Metadata

Metadata

Assignees

Labels

Type

Priority

None yet

Effort

None yet

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions