astral-sh/ruff-vscode

Whether `lint.per-file-ignores` is respected depends on the file pattern when working in multi-root workspaces

shunichironomura opened this issue · 4 comments

Description

When working in Multi-root Workspaces in Visual Studio Code, whether lint.per-file-ignores takes effect depends on the file pattern.

The extension settings are all set to defaults, except for the ruff.configuration.

Reproduction

Set-up

Follow the steps below or clone https://github.com/shunichironomura/ruff-vscode-ws

  1. Prepare a directory with the following structure and contents:

(EDIT: Fixed the structure by adding the subfolder/)

.
├── a.code-workspace
├── b
│   └── a.py
├── ruff.toml
├── subfolder/
└── t
    └── a.py

a.code-workspace:

{
    "folders": [
        {
            "name": "root",
            "path": "."
        },
        {
            "name": "subfolder",
            "path": "./subfolder"
        }
    ],
    "settings": {
        "ruff.configuration": "${workspaceFolder:root}/ruff.toml"
    }
}

b/a.py and t/a.py (both have the same contents):

import os

ruff.toml:

[lint.per-file-ignores]
"b/**.py" = ["F401"]
"t/**.py" = ["F401"]  # This can be `"t/*.py" = ...` and still get the same issue
  1. Open the directory as a multi-root workspace by code a.code-workspace

Expected behavior

  • Running ruff check . in the root results in reporting no error.
  • For both scripts (b/a.py and t/a.py), no error is shown in the editor.

Actual behavior

  • Running ruff check . in the root results in reporting no error. (As expected)
  • The error message of F401 is not shown in b/a.py, but is shown in t/a.py. (Unexpected)

Environment

  • Ruff version: 0.5.4
  • Ruff VS Code extension version: v2024.36.0
  • Operating system: WSL2 Linux (Ubuntu 22.04)
  • Python version: 3.12.4

Thanks for preparing a way for us to reproduce this very easily! It really helps.

This seems like a bug. I can look at it later today.

Ok, if I remove the ruff.configuration settings from a.code-workspace, then it works correctly.

    "settings": {
        "ruff.configuration": "${workspaceFolder:root}/ruff.toml"
    }

I'm curious as to why do you want to specify the ruff.configuration setting as it's going to be taken by default even if you don't specify it.

In my actual codebase, specifying the ruff.configuration setting makes the extension show some rule (I001 to be specific) correctly in the editor (maybe it's another, related bug). I tried to make a minimal reproducible example but I couldn't.