Skip to content

Type reordering import { type SomeType } moves top-of-file comment below imports #203

@max-m

Description

@max-m

Your Environment

  • Prettier version: 3.4.2
  • node version: 21.7.1
  • package manager: npm@10

Describe the bug

When type reordering is active and a file has import { type SomeType }-imports, the top-of-file comment gets moved around.
When the type imports are sorted, the top-of-file comment stays put.

To Reproduce

test.ts:

/*
 * Copyright (c) 1234-5678 Some one.
 *
 * This is my top-of-file comment
 */

import SomeThing, { type SomeType } from '../SomeModule'
import Function from '../Functions'
import * as SomeUtil from 'Some/Other/Module'

import type Foo from '../Foo'

gets formatted as

import type Foo from '../Foo'
import type { SomeType } from '../SomeModule'

import * as SomeUtil from 'Some/Other/Module'

import Function from '../Functions'
import SomeThing from '../SomeModule'

/*
 * Copyright (c) 1234-5678 Some one.
 *
 * This is my top-of-file comment
 */

test2.ts

/*
 * Copyright (c) 1234-5678 Some one.
 *
 * This is my top-of-file comment
 */

import SomeThing from '../SomeModule'
import Function from '../Functions'
import * as SomeUtil from 'Some/Other/Module'

import type { SomeType } from '../SomeModule'
import type Foo from '../Foo'

becomes

/*
 * Copyright (c) 1234-5678 Some one.
 *
 * This is my top-of-file comment
 */

import type Foo from '../Foo'
import type { SomeType } from '../SomeModule'

import * as SomeUtil from 'Some/Other/Module'

import Function from '../Functions'
import SomeThing from '../SomeModule'

test3.ts:

/*
 * Copyright (c) 1234-5678 Some one.
 *
 * This is my top-of-file comment
 */

import SomeThing from '../SomeModule'
import Function from '../Functions'
import * as SomeUtil from 'Some/Other/Module'

import { type SomeType } from '../SomeModule'
import type Foo from '../Foo'

becomes

import type Foo from '../Foo'
import type { SomeType } from '../SomeModule'

import * as SomeUtil from 'Some/Other/Module'

import Function from '../Functions'
import SomeThing from '../SomeModule'

/*
 * Copyright (c) 1234-5678 Some one.
 *
 * This is my top-of-file comment
 */

Expected behavior

I expected the top-of-file comment to stay put in all cases.

.prettierrc:

semi: false
singleQuote: true
useTabs: true
trailingComma: all
printWidth: 120

plugins: ["@ianvs/prettier-plugin-sort-imports"]

importOrder:
  - "" # Enforce a blank line after top of file comments
  - "<TYPES>"
  - "" # Seperator
  - "<THIRD_PARTY_MODULES>"
  - "" # Separator
  - "^[.]"
importOrderParserPlugins: ["typescript", "decorators"]
importOrderTypeScriptVersion: '5.7.3'

Error log

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

  • I'm willing to fix this bug 🥇

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions