biomejs / biome

A toolchain for web projects, aimed to provide functionalities to maintain them. Biome offers formatter and linter, usable via CLI and LSP.

Home Page:https://biomejs.dev

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

πŸ› Override behavior with multiple matches

Conaclos opened this issue Β· comments

Discussed in #3166

Originally posted by redbmk June 10, 2024
I'm not sure if this is a bug so starting it out as a discussion.

I expected to be able to add multiple blocks of "overrides" and have items that have multiple matches pick up all of the overrides.

Here's a simplified example of my setup:

{
  "$schema": "https://biomejs.dev/schemas/1.7.1/schema.json",
  "linter": {
    "enabled": true,
    "rules": {
      "recommended": true,
      "correctness": { "all": true, "noUndeclaredVariables": "error" },
      "suspicious": { "noConsoleLog": "warn" }
    }
  },
  "overrides": [
    { "include": ["scripts/k6.js"], "javascript": { "globals": ["__ENV", "__VU"] } },
    {
      "include": ["scripts"],
      "linter": { "rules": { "suspicious": { "noConsoleLog": "off" } } }
    }
  ]
}

and lets say somewhere in scripts/k6.js I have console.log({ __ENV, __VU })

If I have it set up like this, then scripts/k6.js throws errors that __ENV and __VU are undeclared. If I swap the order of the two override sections, it picks up on the globals but then throws warnings that I'm using console.log.

I'm having trouble finding documentation on how exactly the overrides work.

Is there a way I can update the overrides so that scripts/k6.js has both those overrides without having to repeat the noConsoleLog override?

It seems that we propagate the base settings to every override item.
Thus, the following config:

{
  "$schema": "https://biomejs.dev/schemas/1.7.1/schema.json",
  "linter": {
    "rules": {
      "suspicious": { "noConsoleLog": "warn" }
    }
  },
  "overrides": [
    {
      "include": ["index.js"], 
        "javascript": { "globals": ["__ENV", "__VU"] }
    }, {
      "include": ["index.js"],
      "linter": { "rules": { "suspicious": { "noConsoleLog": "off" } } },
    }
  ]
}

is resolved to:

{
  "$schema": "https://biomejs.dev/schemas/1.7.1/schema.json",
  "linter": {
    "rules": {
      "suspicious": { "noConsoleLog": "warn" }
    }
  },
  "overrides": [
    {
      "include": ["index.js"], 
      "linter": {
        "rules": {
          "suspicious": { "noConsoleLog": "warn" }
        },
        "javascript": { "globals": ["__ENV", "__VU"] }
    }, {
      "include": ["index.js"],
      "linter": { "rules": { "suspicious": { "noConsoleLog": "off" } } },
      "javascript": { "globals": [] } },
    }
  ]
}