Skip to content

CLI: Show fixes by default in ruff check #7352

@zanieb

Description

@zanieb

Requires #7350 for opt-out of display.

ruff check should display fixes that Ruff can apply. Currently this is only possible for the whole file with --diff.

Some fixes may modify content across a file, e.g. when renaming a binding. We should limit the display of fixes to roughly match the range of source context displayed (#7349). If we do not display the entire fix, we should include a notice of the number of additional lines that will be modified if the fix is applied. Naively, we may be able to implement this by only selecting a portion of the fix. In a more comprehensive implementation, we may need to add a new diagnostic range attribute for this display and address it in each problem case.

Clippy has a nice example user experience of showing fixes:

error[E0308]: mismatched types
--> crates/ruff_python_semantic/src/model.rs:224:21
    |
224 |             source: &self.stmt_id,
    |                     ^^^^^^^^^^^^^ expected `Option<NodeId>`, found `&Option<NodeId>`
    |
    = note:   expected enum `std::option::Option<node::NodeId>`
            found reference `&std::option::Option<node::NodeId>`
help: consider removing the borrow
    |
224 -             source: &self.stmt_id,
224 +             source: self.stmt_id,
    |

For more information about this error, try `rustc --explain E0308`.

Metadata

Metadata

Assignees

No one assigned

    Labels

    cliRelated to the command-line interface

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions