Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Biome configuration in monorepo #1556

Closed
0xVinCal opened this issue Jan 13, 2024 · 6 comments
Closed

Biome configuration in monorepo #1556

0xVinCal opened this issue Jan 13, 2024 · 6 comments
Labels
A-LSP Area: language server protocol S-Enhancement Status: Improve an existing feature

Comments

@0xVinCal
Copy link

Current behavior

The VSCode extension take the biome.json at the project root. If it don't find it, it use the default configuration.

What it should do

The extension should apply the same file resolution than the biome cli: https://biomejs.dev/guides/how-biome-works/#configuration-file-resolution

It should use the current file path, and look the parent directory until it find a biome.json.

@nhedger
Copy link
Member

nhedger commented Jan 13, 2024

Hey @0xVinCal,

Thanks for opening this issue.

I'm going to move it to the main repo because this behavior is actually controlled by the biome_lsp crate.

The VS Code extension is mostly an LSP client.

@nhedger nhedger transferred this issue from biomejs/biome-vscode Jan 13, 2024
@ematipico ematipico added A-LSP Area: language server protocol S-Enhancement Status: Improve an existing feature labels Jan 13, 2024
@ematipico
Copy link
Member

It should use the current file path

What's the current file path? It's more obvious when running a command via CLI, but inside an editor you can open any folder inside any project...

@0xVinCal
Copy link
Author

In VSCode we can trigger lint on save with option editor.codeActionsOnSave

So the "current file path" would be the file I save.
If I save multiple file at once, we would have multiple file path.

With eslint we have the vscode option: eslint.workingDirectories.

eslint.workingDirectories - specifies how the working directories ESLint is using are computed. ESLint resolves configuration files (e.g. eslintrc, .eslintignore) relative to a working directory so it is important to configure this correctly. If executing ESLint in the terminal requires you to change the working directory in the terminal into a sub folder then it is usually necessary to tweak this setting. (see also ESLint class options#cwd). Please also keep in mind that the .eslintrc* file is resolved considering the parent directories whereas the .eslintignore file is only honored in the current working directory. The following values can be used:

  • [{ "mode": "location" }] (@SInCE 2.0.0): instructs ESLint to uses the workspace folder location or the file location (if no workspace folder is open) as the working directory. This is the default and is the same strategy as used in older versions of the ESLint extension (1.9.x versions).
  • [{ "mode": "auto" }] (@SInCE 2.0.0): instructs ESLint to infer a working directory based on the location of package.json, .eslintignore and .eslintrc* files. This might work in many cases but can lead to unexpected results as well.
  • string[]: an array of working directories to use. Consider the following directory layout:
root/
  client/
    .eslintrc.json
    client.js
  server/
    .eslintignore
    .eslintrc.json
    server.js

Then using the setting:

  "eslint.workingDirectories": [ "./client", "./server" ]

will validate files inside the server directory with the server directory as the current eslint working directory. Same for files in the client directory. The ESLint extension will also change the process's working directory to the provided directories. If this is not wanted a literal with the !cwd property can be used (e.g. { "directory": "./client", "!cwd": true }). This will use the client directory as the ESLint working directory but will not change the process`s working directory.

  • [{ "pattern": glob pattern }] (@SInCE 2.0.0): Allows to specify a pattern to detect the working directory. This is basically a short cut for listing every directory. If you have a mono repository with all your projects being below a packages folder you can use { "pattern": "./packages/*/" } to make all these folders working directories.

@rob-swu
Copy link

rob-swu commented Mar 4, 2024

we use a mono repo as well and ran into this issue.

I symlinked the biome.json config file from our specific js project to the root, so folks editing the code with the whole repo can still inherit the correct settings.

then to ensure other js projects that didn't migrate to biome yet I created a vscode workspace file for the root, with the following settings.

{
  "folders": [
    {
      "path": ".",
    },
    {
      "path": "./lib-javascript"
    }
  ],
  "settings": {}
}

then can set specific settings for lib-javascript in the config that overrride the workspace

Screenshot 2024-03-04 at 9 51 59 AM
Screenshot 2024-03-04 at 9 52 25 AM

@tony
Copy link
Contributor

tony commented Mar 8, 2024

If this is off topic, feel free to collapse.

In case this is a universal LSP issue, I'm experiencing similar with coc-biome:

@ematipico
Copy link
Member

Closing in favour of #2228

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-LSP Area: language server protocol S-Enhancement Status: Improve an existing feature
Projects
None yet
Development

No branches or pull requests

5 participants