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

Implement autoflake #1647

Closed
4 of 5 tasks
charliermarsh opened this issue Jan 5, 2023 · 5 comments
Closed
4 of 5 tasks

Implement autoflake #1647

charliermarsh opened this issue Jan 5, 2023 · 5 comments
Labels
plugin Implementing a known but unsupported plugin

Comments

@charliermarsh
Copy link
Member

charliermarsh commented Jan 5, 2023

  • Remove unused imports (F401)
  • Remove duplicate keys (F601)
  • Remove unused variables (F841)
  • Expand star imports (F403)
  • Useless pass statements
@charliermarsh charliermarsh added the plugin Implementing a known but unsupported plugin label Jan 5, 2023
@charliermarsh
Copy link
Member Author

I'm hesitant to add autofix for F601 and F403, because the right behavior isn't clear, and automatically fixing them is very likely to cause problems.

I'd be open to autofixing F601 in the case that the values are duplicated too.

charliermarsh added a commit that referenced this issue Jan 7, 2023
For now, to be safe, we're only removing keys with duplicate _values_.

See: #1647.
@charliermarsh
Copy link
Member Author

Happy with this for now. I'm not planning to do star imports with the current approach, and we already do some subset of pass statements.

@cclauss
Copy link
Contributor

cclauss commented Mar 17, 2023

What about trying the https://github.com/asmeurer/removestar approach for creating an F403 fixer?

@sanmai-NL
Copy link

@charliermarsh

The last item

Useless pass statements

is already implemented as https://beta.ruff.rs/docs/rules/unnecessary-pass/

@RobertDeRose
Copy link

RobertDeRose commented Jun 1, 2024

Why is F841 considered unsafe?

Example

ruff check --fix --config pyproject.toml
gpio/models/pin.py:
  159:9 F841 Local variable `unused` is assigned to but never used

Found 1 error.
No fixes available (1 hidden fix can be enabled with the `--unsafe-fixes` option).

This was a test to see if the behavior of Ruff is the same as autoflake, and it is not. autoflake removes it, Ruff requires the addition of --unsafe-fixes

Ruff version: ruff 0.4.4 (3e8878a 2024-05-09)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
plugin Implementing a known but unsupported plugin
Projects
None yet
Development

No branches or pull requests

4 participants