astral-sh / ruff-vscode

A Visual Studio Code extension with support for the Ruff linter.
Other
1.04k stars 52 forks source link

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

Open shunichironomura opened 1 month ago

shunichironomura commented 1 month ago

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

Actual behavior

Environment

dhruvmanila commented 1 month ago

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.

dhruvmanila commented 1 month ago

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

    "settings": {
        "ruff.configuration": "${workspaceFolder:root}/ruff.toml"
    }
dhruvmanila commented 1 month ago

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.

shunichironomura commented 1 month ago

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.