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
14.95k stars 464 forks source link

📝 Biome's import sorting is being cancelled out by vscode's import sorting #1165

Closed ChiefORZ closed 2 months ago

ChiefORZ commented 10 months ago

Environment information

CLI:
  Version:                      1.4.1
  Color support:                true

Platform:
  CPU Architecture:             x86_64
  OS:                           macos

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

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",
  "vcs": {
    "enabled": true,
    "clientKind": "git",
    "useIgnoreFile": true
  },
  "organizeImports": {
    "enabled": false
  },
  "linter": {
    "enabled": false
  },
  "files": {
    "ignoreUnknown": true
  },
  "formatter": {
    "enabled": true,
    "formatWithErrors": true,
    "indentStyle": "space",
    "indentWidth": 2,
    "lineWidth": 100,
    "ignore": ["**/.next", "**/.wireit", "**/dist", "**/node_modules"]
  },
  "javascript": {
    "formatter": {
      "enabled": true,
      "quoteStyle": "double",
      "arrowParentheses": "always",
      "trailingComma": "all",
      "lineEnding": "lf"
    }
  },
  "json": {
    "formatter": {
      "enabled": true
    }
  }
}

Playground link

https://biomejs.dev/playground/?code=aQBtAHAAbwByAHQAIAB7ACAAagB3AHQARABlAGMAbwBkAGUAIAB9ACAAZgByAG8AbQAgACIAagB3AHQALQBkAGUAYwBvAGQAZQAiADsACgBpAG0AcABvAHIAdAAgAGMAcgBlAGEAdABlAE0AaQBkAGQAbABlAHcAYQByAGUAIABmAHIAbwBtACAAIgBuAGUAeAB0AC0AaQBuAHQAbAAvAG0AaQBkAGQAbABlAHcAYQByAGUAIgA7AAoAaQBtAHAAbwByAHQAIAB7ACAATgBlAHgAdABSAGUAcwBwAG8AbgBzAGUALAAgAHQAeQBwAGUAIABOAGUAeAB0AFIAZQBxAHUAZQBzAHQAIAB9ACAAZgByAG8AbQAgACIAbgBlAHgAdAAvAHMAZQByAHYAZQByACIAOwA%3D

Code of Conduct

ChiefORZ commented 10 months ago

For a better understanding what i mean with the title:

For me to get biome's import sorting to work i needed to enable the vscode's default import sorting aswell, so my vscode's settings.json looks like this:

// settings.json 
{
    "editor.codeActionsOnSave": {
      "quickfix.biome": "explicit",
      "source.fixAll": "explicit",
      "source.organizeImports": "explicit",
      "source.organizeImports.biome": "explicit",
      "source.sortPackageJson": "explicit"
    }
}

If i remove the option source.organizeImports - no imports will be sorted at all, vscode will not do anything.

In the playground provided the sorting will always be

import { type NextRequest, NextResponse } from "next/server";

so this is the correct way biome is sorting things.

But when Cmd+S and the codeActions run, the result will be

import { NextResponse, type NextRequest } from "next/server";

which i guess is vscode's default formatting/sorting.

I tried to remove all other codeActions, as well as re-ordering both "source.organizeImports" rules so that maybe the "source.organizeImports.biome" rule wins, but this did nothing -.-

jpenna commented 3 months ago

Same here... I was considering using Prettier just because of this...

I have Biome formatting in pre-commit and every time I have to re-commit the organized imports because Biome doesn't do it automatically in VSCode.

ematipico commented 3 months ago

"source.organizeImports": "explicit",

This is action code that triggers the built-in import sorting of VSCode, it should not be used if you want to use only Biome: source.organizeImports.biome.

If the import sorting isn't applied, I suspect there's something wrong with how the project is set up. Any chance you can create a reproduction to look at? Without that, we can't help you

jpenna commented 3 months ago

I'm using it like this in my Workspace settings:

  "[javascript]": {
    "editor.defaultFormatter": "biomejs.biome",
    "editor.codeActionsOnSave": {
      "quickfix.biome": "explicit",
      "source.organizeImports.biome": "explicit",
      "source.organizeImports": "never",
      "source.fixAll": "explicit"
    }
  },
... and the same for typescript, typescriptreact, etc.

Because source.organizeImports is "never", it isn't organizing any imports now... If I set it to "explicit", it overrides Biome's.

Conaclos commented 2 months ago

Is the problem still there?