Skip to content

Refactor applicability handling in Display impl for message::diff::Diff #12597

@chriskrycho

Description

@chriskrycho

Spinning this out of some of the discussion on #12595, as requested by @zanieb.

That PR adds support for displaying fixes, but hard codes in displaying only fixes at the Applicability::Safe level in the Display implementation. That really isn’t where it belongs: the TextEmitter is more appropriate. However, that also bumps into a number of other pieces related to design questions around what exactly to do for displaying those.

The Diff itself should simply produce the diff and any appropriate CTA, without configuration or handling for availability. The TextEmitter should be responsible for determining what to print. However, at present that is somewhat coupled because the Diff::from_message consumes the Message from which it is constructed, and produces an Option<Diff>. (As an aside: an implementation like from_message should idiomatically use std::from::From.)

Additionally, this should make it possible to solve the other problem with the current implementation: that it hard-codes displaying only safe fixes even when the user runs ruff check --unsafe-fixes (which does work in the absence of --fix, and should only display) fixes.

Metadata

Metadata

Assignees

No one assigned

    Labels

    internalAn internal refactor or improvement

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions