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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RUF004 is not autofixable #1038

Closed
LefterisJP opened this issue Dec 4, 2022 · 6 comments
Closed

RUF004 is not autofixable #1038

LefterisJP opened this issue Dec 4, 2022 · 6 comments

Comments

@LefterisJP
Copy link

This is with ruff 0.0.155

Consider the following:

a = 1
while a < 10:
    a += 1

exit()

running ruff on it with RUF004 activated works and detects the problem.
But if you try to fix it with ruff --fix it does not autofix it. And afaics this should be autofixable.

@charliermarsh
Copy link
Member

It’s because sys isn’t imported, and we don’t have the ability to add it to the import list (yet) since edits are currently localized.

@charliermarsh
Copy link
Member

(Or, that’s my guess — I’m on the subway :))

@LefterisJP
Copy link
Author

No worries :)

Do you think it's something ruff can fix at some point?

@charliermarsh
Copy link
Member

Yes absolutely!

@charliermarsh
Copy link
Member

It’s tracked somewhat obliquely by #835 so I’m going to close this one out in favor of the existing issue.

@LefterisJP
Copy link
Author

It’s tracked somewhat obliquely by #835 so I’m going to close this one out in favor of the existing issue.

Sure no problem. I fixed it in our case by adding import sys manually and changing one exit to sys.exit(). Then ruff did autofix all the rest on its own ;)

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

No branches or pull requests

2 participants