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

Ignored files are not ignored when using --staged or explicitly specified in CLI #3659

Closed
1 task done
Florian-crg opened this issue Aug 14, 2024 · 4 comments
Closed
1 task done
Labels
S-Needs repro Status: needs a reproduction

Comments

@Florian-crg
Copy link

Florian-crg commented Aug 14, 2024

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:           unset
  JS_RUNTIME_NAME:              unset
  NODE_PACKAGE_MANAGER:         unset

Biome Configuration:
  Status:                       Loaded successfully
  Formatter disabled:           false
  Linter disabled:              false
  Organize imports disabled:    false
  VCS disabled:                 false

Workspace:
  Open Documents:               0

What happened?

Files specified in the Biome configuration's "ignore" list are still being linted when:

  1. Using the --staged flag
  2. Explicitly specifying the file in the CLI command

This behavior occurs even when VCS is enabled in the Biome configuration. The ignored files are not present in the .gitignore file.

Steps to reproduce:

  1. Set up a project with Biome.js
  2. Create a biome.json configuration file with the following "ignore" setting:
    {
        "files": {
            "ignore": [
                "file.ts",
                "other_file.js"
            ]
        }
    }
  3. Create the files specified in the "ignore" list (file.ts and other_file.js)
  4. Run biome check --staged
  5. Run biome check file.ts
  6. Observe that the ignored files are still being linted

Expected result

Files specified in the "ignore" list should be ignored in all scenarios, including:

  1. When using the --staged flag
  2. When explicitly specifying the file in the CLI command

The current behavior makes it difficult to use Biome with external tools like lefthook, Husky or in custom scripts. Ignoring specific file is a critical feature when using GraphQL or other tool that will create auto-generated files.

Possible solution:

  1. Ensure that ignored files are consistently skipped in all scenarios, including when using --staged or specifying files directly in the CLI.
  2. Consider implementing an --include-ignored flag for cases where users explicitly want to lint ignored files.

Code of Conduct

  • I agree to follow Biome's Code of Conduct

EDIT: See comment below: #3659 (comment)

@dyc3
Copy link
Contributor

dyc3 commented Aug 14, 2024

I'm not too sure about evaluating ignores when files are explicitly provided via cli args. As a user, I would expect all files provided via cli args to be processed, regardless of ignores because I explicitly pointed biome to the file.

Doing this for --staged definitely makes sense though.

@Florian-crg
Copy link
Author

Thank you for your prompt attention to this issue. I appreciate your perspective on how CLI arguments might be interpreted.

While I understand the logic behind processing explicitly provided files, this approach can lead to unexpected behavior, especially when integrating Biome with other tools or scripts. Consistent handling of ignored files across all scenarios would provide several benefits:

Consistency: It's easier to reason about and maintain a system where ignore rules are always respected.
Unintended consequences: Tools like lefthook, husky, custom scripts, or other use case often rely on consistent behavior, including respects for ignores.

I agree that addressing this for --staged is crucial. Considering an optional --include-ignored flag for cases where users want to override ignore rules is the only option giving consistency by maintaining expected behavior without unintended consequences while offering flexibility when needed.

Very interested to also have others opinion, @ematipico what do you think of it?

@ematipico ematipico added the S-Needs repro Status: needs a reproduction label Aug 19, 2024
@Florian-crg
Copy link
Author

Florian-crg commented Aug 19, 2024

Update: I've identified the root cause while reproducing the issue in a monorepo setup like ours.

  1. The issue occurs when biome.json is at the root level, but the command is run in a subfolder where the package is installed.
  2. File paths in biome.json are interpreted relative to the command execution location, not the JSON file location.
  3. The ignore functionality itself works as expected, correctly ignoring specified files.
  4. We still miss an --include-ignored flag that in my setup would be useful, specially for auto generated files.

The main problem:
Relative paths in biome.json don't work as expected when the config is not in the same directory as the command execution. This is particularly problematic for monorepo architectures.

Reproduction:
I've created a minimal reproduction in a CodeSandbox: https://codesandbox.io/p/devbox/adoring-wilbur-dxckdw?file=%2Fbiome.json%3A19%2C3

To reproduce:

  1. Open the CodeSandbox
  2. Run npx biome check --staged in the terminal

Expected behavior:
Biome should interpret paths in biome.json relative to the config file's location, ensuring consistent behavior across monorepo subfolders.

This issue mainly impacts monorepo setups and needs addressing for better usability in complex project structures.

@ematipico
Copy link
Member

ematipico commented Aug 19, 2024

Relative paths in biome.json don't work as expected when the config is not in the same directory as the command execution.

That's the expected way, we document this: https://biomejs.dev/guides/configure-biome/#ignore-files

Biome resolves the globs relatively from the working directory. The working directory is the directory where you usually run a CLI command. This means that you have to place particular attention when the configuration file is placed in a different directory from where you execute your command. In the case of an editor (LSP) the working directory is the root directory of your project.

For monorepos, we have an issue about that already: #2228

@ematipico ematipico closed this as not planned Won't fix, can't repro, duplicate, stale Aug 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-Needs repro Status: needs a reproduction
Projects
None yet
Development

No branches or pull requests

3 participants