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.59k stars 458 forks source link

📝 Ignore option not respected #3345

Open marvinhagemeister opened 3 months ago

marvinhagemeister commented 3 months ago

Environment information

CLI:
  Version:                      1.8.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.13.1"
  JS_RUNTIME_NAME:              "node"
  NODE_PACKAGE_MANAGER:         "yarn/1.22.22"

Biome Configuration:
  Error:                        The property trailingComma is deprecated. Use javascript.formatter.trailingCommas instead.
  Status:                       Loaded with errors
  Formatter disabled:           false
  Linter disabled:              false
  Organize imports disabled:    false
  VCS disabled:                 true

Formatter:
  Format with errors:           false
  Indent style:                 Tab
  Indent width:                 2
  Line ending:                  Lf
  Line width:                   80
  Attribute position:           Auto
  Ignore:                       ["**/.DS_Store", "**/node_modules", "**/npm-debug.log", "**/dist/", "*/package-lock.json", "**/yarn.lock", "**/.vscode", "**/.idea", "test/ts/**/*.js", "**/coverage", "**/*.sw[op]", "**/*.log", "**/package/", "**/preact-*.tgz", "**/preact.tgz", "benches/dist/", "benches/results/", "benches/logs/", "benches/logs-saved/", "benches/node_modules/", "benches/proxy-packages/*/package-lock.json", "**/package-lock.json"]
  Include:                      []

JavaScript Formatter:
  Enabled:                      false
  JSX quote style:              Double
  Quote properties:             AsNeeded
  Trailing commas:              None
  Semicolons:                   Always
  Arrow parentheses:            AsNeeded
  Bracket spacing:              true
  Bracket same line:            false
  Quote style:                  Single
  Indent style:                 unset
  Indent width:                 unset
  Line ending:                  unset
  Line width:                   unset
  Attribute position:           Auto

JSON Formatter:
  Enabled:                      true
  Indent style:                 unset
  Indent width:                 unset
  Line ending:                  unset
  Line width:                   unset
  Trailing Commas:              unset

CSS Formatter:
  Enabled:                      false
  Indent style:                 unset
  Indent width:                 unset
  Line ending:                  unset
  Line width:                   unset
  Quote style:                  Double

Workspace:
  Open Documents:               0

Configuration

{
  "formatter": {
    "enabled": true,
    "formatWithErrors": false,
    "indentStyle": "tab",
    "indentWidth": 2,
    "lineEnding": "lf",
    "lineWidth": 80,
    "attributePosition": "auto",
    "ignore": [
      "**/.DS_Store",
      "**/node_modules",
      "**/npm-debug.log",
      "**/dist",
      "*/package-lock.json",
      "**/yarn.lock",
      "**/.vscode",
      "**/.idea",
      "test/ts/**/*.js",
      "**/coverage",
      "**/*.sw[op]",
      "**/*.log",
      "**/package/",
      "**/preact-*.tgz",
      "**/preact.tgz",
      "benches/dist/",
      "benches/results/",
      "benches/logs/",
      "benches/logs-saved/",
      "benches/node_modules/",
      "benches/proxy-packages/*/package-lock.json",
      "**/package-lock.json"
    ]
  },
  "organizeImports": { "enabled": true },
  "linter": { "enabled": true, "rules": { "recommended": true } },
  "javascript": {
    "formatter": {
      "jsxQuoteStyle": "double",
      "quoteProperties": "asNeeded",
      "trailingComma": "none",
      "semicolons": "always",
      "arrowParentheses": "asNeeded",
      "bracketSpacing": true,
      "bracketSameLine": false,
      "quoteStyle": "single",
      "attributePosition": "auto"
    }
  },
  "overrides": [
    {
      "include": ["*.json", ".*rc", "*.yml"],
      "formatter": { "indentWidth": 2, "indentStyle": "space" }
    }
  ]
}

Playground link

Steps to reproduce:

  1. Clone https://github.com/preactjs/preact
  2. Run npm i
  3. Run npm run build
  4. Run biome format .

It will try to format all generated files in dist/ folders despite them being ignored in the config.

Code of Conduct

Conaclos commented 3 months ago

Have you tried **/dist/** instead of **/dist?

ematipico commented 3 months ago

That will work, but I think it's a workaround. **/dist should be still valid I think. Looking at how they run the command, they use biome format ., so the folder will be crawled with a path like this ./dist, which I think should match the pattern, however we know there's a bug filed (it's somewhere), and we came to the conclusion that we prefer to evaluate a better glob lib.

Conaclos commented 3 months ago

We have #2000.

Maybe it is a regression, because I remember making a change to ignore entire folders when specified under ignore. We should try the reproduction on different versions of Biome.

marvinhagemeister commented 3 months ago

When I add the folders explicitly they are ignored as expected:

    "ignore": [
-     "**/dist/",
+     "hooks/dist/",
+     "debug/dist/",
+     "compat/dist/",
+     "dist/",
    ]

Seems like the leading ** are not working, or maybe I'm misunderstanding the syntax.

Sec-ant commented 3 months ago

While I was working on #3317, I noticed some code that might be related to this issue: https://github.com/biomejs/biome/blob/3c23f599d96a67e4a32e296c0419006b3e82a835/crates/biome_service/src/matcher/mod.rs#L104-L115

I think it was meant to be starts_with, but that will still match many false positives.

And I can't see where the root field in the Matcher is used.

Conaclos commented 3 months ago

We have many issues with the glob matcher library. This is something we want to improve in Biome 2.0 I started some experimentation two month ago.

mattfysh commented 2 months ago

one thing that could be fixed is how "foo/*/" will match both <rootDir>/foo/x and <rootDir>/nested/dir/foo/x. there's currently no way to clamp down the glob to say just the /foo at root

the only workaround i've found so far is using the parent directory name, e.g. my_repo_dir/foo/**/*

emilte commented 2 weeks ago

I believe I'm having this issue. https://github.com/emilte/biome-issues/tree/json-format-ignore-not-respected