☣️

Biomeを導入してNeoVimで使う

に公開

アプリケーション側

何はともあれ、biomeをインストールして初期設定をする。

$ pnpm add --save-dev --save-exact @biomejs/biome
$ pnpm biome init

これでbiome.jsonが作られて、lintやformatができるようになる。

$ pnpm biome lint
$ pnpm biome format --write

あとは必要に応じてbiome.jsonの中身を設定していく。自分の設定は今のところこんな感じ。

{
  "$schema": "https://biomejs.dev/schemas/1.9.4/schema.json",
  "vcs": {
    "enabled": false,
    "clientKind": "git",
    "useIgnoreFile": false
  },
  "files": {
    "ignoreUnknown": false,
    "ignore": [
      "dist/*",
      "node_modules/*",
      ".nuxt/*",
      ".output/*",
      ".wrangler/*"
    ]
  },
  "formatter": {
    "enabled": true,
    "indentStyle": "space",
    "indentWidth": 2
  },
  "organizeImports": {
    "enabled": true
  },
  "linter": {
    "enabled": true,
    "rules": {
      "recommended": true
    }
  },
  "javascript": {
    "formatter": {
      "quoteStyle": "single",
      "trailingCommas": "all"
    }
  }
}

https://biomejs.dev/reference/configuration/

NeoVim

次にNeoVim側の設定。自分の場合は下記のプラグインを使っているので、その前提。

mason-lspconfig.nvim

オプションのensure_installedにbiomeを追加する。

ensure_installed = {
    "lua_ls",
    "ts_ls",
    "biome", <-- 追加
    "gopls",
    "volar",
    "cssls",
    -- add more arguments for adding more language servers
},

mason-null-ls.nvim

こちらも、オプションのensure_installedにbiomeを追加する。

ensure_installed = {
    "stylua",
    "prettier",
    "biome",
    -- add more arguments for adding more null-ls sources
},

また、handlersの設定でbiome.jsonを見つけたらbiomeを使うようにする。

handlers = {
      -- For biome formatting:
      biome_format = function()
        require("null-ls").register(require("null-ls").builtins.formatting.biome.with {
          condition = function(utils) return utils.root_has_file "biome.json" end,
        })
      end,
},

あとはNeoVimを開けば勝手にMasonがbiomeをインストールしてくれる。

Discussion