astral-sh / astral-sh/ruff

[FEATURE] Only report errors with safe fixes

Open
#8,701 1 comment 1 reaction 0 assignees View on GitHub
linter wish
Dominant language
Rust
Stars
49.7k
Forks
2.4k
Avg merge
2d 1h
Merged PRs (30d)
458

Description

Apologies if this is already possible somewhere, but I was wondering whether there was a way to configure Ruff to *only* report errors that it has *safe* fixes for. Ideally this could be done on a per-rule level.

My primary use-case is SIM118 (unnecessary `dict.keys()` call) -- unfortunately, we have some internal objects that implement a `def keys(self)` method that that brings up a bunch of false positives when using SIM118. But we *would* like to enforce them for `dict` objects, and the "safe" fix for SIM118 only fires when Ruff infers that it's an actual dictionary under-the-hood.

I guess this specific example could also be addressed by making SIM118 only fire if it can infer an actual dictionary as well... or by having some other configuration to control the false-positive vs false-negative tradeoffs here.

Contributor guide

Open the contributing guide

Research direction

Start by tracing Ruff's configuration handling for per-rule fix safety and the SIM118 rule's safe-fix classification. Done means users can configure reporting to include only diagnostics with safe fixes, ideally per rule, while addressing the stated SIM118 false-positive case.

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.