astral-sh / astral-sh/ruff

Suppress RUF100 (unused noa) if we see a PGH004 (blanket noqa) error?

Open
#8,601 1 comment 0 reactions 0 assignees View on GitHub
needs-decision suppression
Dominant language
Rust
Stars
49.6k
Forks
2.4k
Avg merge
2d 1h
Merged PRs (30d)
458

Description

This is potentially a very niche request, but I was wondering if there was a way to suppress RUF100 errors for blanket noqa when PGH004 is enabled (and `external` lints are on)?

Right now, we live in a monorepo with flake8 configured along with our particular sub-codebase's `ruff` linting. The monorepo wide linting also comes with some company-specific error codes that we use the [`external`](https://docs.astral.sh/ruff/settings/#external) setting for. Unfortunately, we're hitting a problem with blanket noqas -- things like:

```
some_code_that_triggers_internal_lint # noqa
```

which triggers RUF100 when the *real* problem is that it should be annotated with `# noqa: `. I was hoping to use `PGH004` instead to flag these blanket noqa, but am running into two problems:

* Such errors will trigger two lints (unnecessary noqa and needs a specific error code). This is a little confusing, b/c the error code is actually the one users should pay attention to.
* The RUF100 autofix will delete the `# noqa`, even when it's necessary to silence the monorepo wide flake8.

I think the two things that'd help us with the ruff roll out are to:

* Change the RUF100 to be an unsafe-fix for blanket noqa if `external` is specified
* If PGH004 *and* RUF100 both trigger on the same noqa, only emit the PGH004 lint error (maybe hidden behind some flag)?

Would that make sense? Not sure if this is a reasonable thing to support our if our setup is too idiosyncratic.

Contributor guide

Open the contributing guide

Research direction

Start by reproducing the interaction between PGH004, RUF100, blanket noqa comments, and the external setting in a minimal Ruff configuration. Compare the emitted diagnostics and RUF100 autofix behavior; done means the requested suppression or safer-fix behavior is defined and works without removing noqa comments needed for external lints.

Written by the indexing model from the issue text.

Assessment

Tech stack
python, rust
Domain
tooling
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.