biomejs / biome

A toolchain for web projects, aimed to provide functionalities to maintain them. Biome offers formatter and linter, usable via CLI and LSP.
https://biomejs.dev
Apache License 2.0
15.3k stars 475 forks source link

šŸ“ The sorting of imports by type #1933

Closed Shyam-Chen closed 8 months ago

Shyam-Chen commented 8 months ago

Why are the types of imports different for global modules and local modules? Is this a bug?

Input:

import type { FastifyPluginAsyncTypebox } from '@fastify/type-provider-typebox';
import { Type } from '@sinclair/typebox';

import useTableControl, { TableControlBox } from '~/composables/useTableControl';

import type { TodoItem } from './types';
import { BodyBox, EntityBox, MessageBox } from './schema';

Output:

import type { FastifyPluginAsyncTypebox } from '@fastify/type-provider-typebox';
import { Type } from '@sinclair/typebox';

import useTableControl, { TableControlBox } from '~/composables/useTableControl';

+ import { BodyBox, EntityBox, MessageBox } from './schema';
import type { TodoItem } from './types';
- import { BodyBox, EntityBox, MessageBox } from './schema';

Environment information

CLI:
  Version:                      1.5.3
  Color support:                true

Platform:
  CPU Architecture:             aarch64
  OS:                           macos

Environment:
  BIOME_LOG_DIR:                unset
  NO_COLOR:                     unset
  TERM:                         "xterm-256color"
  JS_RUNTIME_VERSION:           "v20.11.0"
  JS_RUNTIME_NAME:              "node"
  NODE_PACKAGE_MANAGER:         "pnpm/8.15.4"

Biome Configuration:
  Status:                       Loaded successfully
  Formatter disabled:           false
  Linter disabled:              false
  Organize imports disabled:    false
  VCS disabled:                 true

Workspace:
  Open Documents:               0

Configuration

{
  "$schema": "./node_modules/@biomejs/biome/configuration_schema.json",
  "formatter": {
    "indentStyle": "space",
    "lineWidth": 100
  },
  "javascript": {
    "formatter": {
      "quoteStyle": "single"
    }
  }
}

Playground link

https://biomejs.dev/playground/?lineWidth=100&indentStyle=space&quoteStyle=single&code=aQBtAHAAbwByAHQAIAB0AHkAcABlACAAewAgAEYAYQBzAHQAaQBmAHkAUABsAHUAZwBpAG4AQQBzAHkAbgBjAFQAeQBwAGUAYgBvAHgAIAB9ACAAZgByAG8AbQAgACcAQABmAGEAcwB0AGkAZgB5AC8AdAB5AHAAZQAtAHAAcgBvAHYAaQBkAGUAcgAtAHQAeQBwAGUAYgBvAHgAJwA7AAoAaQBtAHAAbwByAHQAIAB7ACAAVAB5AHAAZQAgAH0AIABmAHIAbwBtACAAJwBAAHMAaQBuAGMAbABhAGkAcgAvAHQAeQBwAGUAYgBvAHgAJwA7AAoACgBpAG0AcABvAHIAdAAgAHUAcwBlAFQAYQBiAGwAZQBDAG8AbgB0AHIAbwBsACwAIAB7ACAAVABhAGIAbABlAEMAbwBuAHQAcgBvAGwAQgBvAHgAIAB9ACAAZgByAG8AbQAgACcAfgAvAGMAbwBtAHAAbwBzAGEAYgBsAGUAcwAvAHUAcwBlAFQAYQBiAGwAZQBDAG8AbgB0AHIAbwBsACcAOwAKAAoAaQBtAHAAbwByAHQAIAB0AHkAcABlACAAewAgAFQAbwBkAG8ASQB0AGUAbQAgAH0AIABmAHIAbwBtACAAJwAuAC8AdAB5AHAAZQBzACcAOwAKAGkAbQBwAG8AcgB0ACAAewAgAEIAbwBkAHkAQgBvAHgALAAgAEUAbgB0AGkAdAB5AEIAbwB4ACwAIABNAGUAcwBzAGEAZwBlAEIAbwB4ACAAfQAgAGYAcgBvAG0AIAAnAC4ALwBzAGMAaABlAG0AYQAnADsA

Code of Conduct

Additional Information

When I add the scope module, it behaves the same as the global module.

Input:

import type { FastifyPluginAsyncTypebox } from '@fastify/type-provider-typebox';
import { Type } from '@sinclair/typebox';

import type { TableControl } from '~/composables/useTableControl';
import useTableControl, { TableControlBox } from '~/composables/useTableControl';

import type { TodoItem } from './types';
import { BodyBox, EntityBox, MessageBox } from './schema';

Output:

import type { FastifyPluginAsyncTypebox } from '@fastify/type-provider-typebox';
import { Type } from '@sinclair/typebox';

import type { TableControl } from '~/composables/useTableControl';
import useTableControl, { TableControlBox } from '~/composables/useTableControl';

+ import { BodyBox, EntityBox, MessageBox } from './schema';
import type { TodoItem } from './types';
- import { BodyBox, EntityBox, MessageBox } from './schema';
ematipico commented 8 months ago

The module ./schema comes before the module ./types, in alphabetical order

Shyam-Chen commented 8 months ago

Is it need to separate the sorting of type-imports and imports? If not, this issue can be closed.

import type { TodoItem } from './types';
import { type TodoItem } from './types';
arendjr commented 8 months ago

We currently don't support sorting type vs "regular" imports, but something similar was mentioned in the discussion over here: https://github.com/biomejs/biome/discussions/645

Maybe if you want us to support it, you could weigh in there? Thanks!