Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automated fixing of issues? #103

Open
The-Compiler opened this issue Nov 8, 2022 · 4 comments
Open

Automated fixing of issues? #103

The-Compiler opened this issue Nov 8, 2022 · 4 comments
Labels

Comments

@The-Compiler
Copy link

I realize this is a "shooting for the sky" idea (and my last issue here for now 馃槉) - but especially for bigger codebases, it would be amazing if refurb could at least fix some issues automatically, similarly to what e.g. pyupgrade does.

I'd like to adopt refurb for my codebase, but it currently points out some 375 issues - cleaning them all up would require a significant amount of work (though I might end up ignoring some, also see #100). If refurb could fix them for me, that would be amazing!

While I'm not sure if this is even on the horizon with the current architecture being based on mypy (?), I thought it couldn't hurt to ask!

@dosisod
Copy link
Owner

dosisod commented Nov 8, 2022

This is definitely on my todo list! It is a tall order, but something I would like to do at some point, even if it is for some of the more trivial checks.

And yes, Refurb does use Mypy under the hood. I don't know if Mypy is capable of doing code refactoring, though I would assume that it probably does not. For single line changes, we could probably do some search and replace magic, but for more complex situations we would probably have to bring in a separate library. I would be curious to see how Pyupgrade/Black implement their code refactoring.

Also, thank you for all the issues you've opened, they have been very helpful!

@dosisod dosisod added the v2 label Nov 8, 2022
@gpshead
Copy link

gpshead commented Nov 10, 2022

I came here to suggest the same thing, great to find it already requested! We already do this within Google, many of our custom pylint or similar analysis tooling checks emit what we call "suggested edits" that both our IDE and our code review system consume. They show up as automated review comments with an edit attached that can simply be viewed and/or applied via a single click. So rather than cut-and-pasting from a tool's suggestion, the edit is magically made to the file in the authors source control checkout/client/branch/PR/etc with minimal effort.

From a command line tool point of view you could have a flag to enable "just fix it all", but be wary about confidence levels of the suggested fixes. Interactive systems let the human confirm correctness.

@dosisod
Copy link
Owner

dosisod commented Nov 11, 2022

@gpshead that is very interesting! I have never heard of a tool that provides code review suggestions in that way before, but I could see how that would be really convenient.

As I said before, this is a bit of a ways down the road, but there is no harm in postulating how this might look in the future. I will look into this on my own later on, but I thought I would ask now as well: Is there a standard schema or format that both the IDE's and this code review system use, or are they both different? If there is some existing schema for defining code refactoring for IDE's and such, Refurb would have to do a lot less work I would think.

@Skylion007
Copy link

Skylion007 commented Jan 1, 2024

FYI, ruff now does this for many of the rules that it implements: https://docs.astral.sh/ruff/rules/#refurb-furb

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants