-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Using ruff as a drop-in replacement for flake8 #414
Comments
Making adoption + migration easier is very important to me! I'm happy to both work directly on and support efforts in this vein. (And definitely interested to learn from your experience on what would be helpful here.) I think you're right that supporting all Flake8 flags + configuration files is less desirable. We could do it, we already mimic Flake8 configuration for certain settings... Honestly, I'm somewhat tempted to do it... But it might be a mistake. I like the idea of making the I'll start by making the pyproject.toml configurable (or you're welcome to! I won't get to it tonight). |
I think we can provide a config converter: It would be a good path forward. New tools should use new |
Agreed! |
My thought was more about being able to do that on-the-fly. I want to be able to use ruff locally on projects that use flake8 and cannot be migrated x) I'll work on something like that that leverages the new |
@charliermarsh I'm thinking I'll take a very lazy approach with a python package that depends on flake8 and ruff. I wonder if you plan on eventually providing a Python interface to invoke ruff? Or is Rust the only language that will have access to ruff's API? |
Wrote a rudimentary hack here: https://github.com/fsouza/flake8-ruff-wrapper I feel like having something like this living in ruff may be easier to keep supported settings and rule in sync. |
Nice! We may want two things here:
Does that distinction make sense? If we had a command within Ruff that automatically generated a |
Yeah, that would definitely work! edit: it would be even more convenient if that command operated over stdin/stdout, this way the wrapper wouldn't have to manage too many files/make sure that the file generated by ruff gets deleted and what not |
Ok cool, that work is being tracked under #423. |
@charliermarsh hey, one difference that I noticed between ruff and flake8 is that ruff uses 0-indexed column numbers and flake8 uses 1-indexed column numbers. Somewhat redacted example from a real piece of code:
Since I have this integrated in my editor, I end-up jumping to the wrong position. I can try to figure out this on my side, but I'm curious if you intended to have columns reported on a 0-index base (I know that this is somewhat controversial, so I'll adapt either way hah)? |
@fsouza - Good question. RustPython used to use 1-indexing for both row and column numbers, but they recently switched to zero-indexed columns, so I reflected that change in Ruff. (This actually matches the CPython I guess editors tend to use 1-indexing, so maybe I should switch back to a 1-index for error reports, even if we're using a zero-index internally. What do you think? What's more intuitive? |
@charliermarsh yeah I noticed that many tools do that, track columns as 0-indexed and then report it as 1-indexed. For example, mypy uses 0-based indices for the column number (https://github.com/python/mypy/blob/9227bceb629a1b566a60cbdd09fef6731f7bfcb1/mypy/errors.py#L52-L53), but then when reporting the error they make it 1-based (https://github.com/python/mypy/blob/8b825472a02f0a30419c02e285ba931107a42959/mypy/errors.py#L778) |
Ah ok, cool. I'll just do that. Will make an issue. |
Thank you! I can send a PR later today if you want! |
@fsouza - Awesome! PRs always welcome! |
Closing as we now have |
Is there any reason that https://github.com/fsouza/flake8-ruff-wrapper isn't just the built-in behavior for ruff? I would love to be able to just use a single configuration but let users use whichever tool that like. |
As mentioned in the flake8-ruff-wrapper description: "flake8-to-ruff is no longer supported. You may experience warnings or breakages when using it with versions of Ruff released after v0.0.233.". |
I'd love to be able to replace flake8 with ruff, and while most things are compatible, one current limitation is the configuration: flake8 can be configured via setup.cfg and .flake8, and at work it's a pretty common setup. Migrating everyone to pyproject.toml will likely not happen anytime soon. So I was wondering what could be done here. I thought of two options:
This is probably not something you'd like to have, as it becomes a layer of configuration that you don't have support for.
This can be done by a third party (I'm happy to do it), but in order to make it happen, ruff would need to support taking the configuration in some alternative mechanism (I can think of either (1) allow all settings to be defined via command line flags or (2) add a command line flag to allow the user to override the location of
pyproject.toml
- that way the "bridge" tool would generate the config file and invoke ruff with that flag)Let me know if you have any thoughts!
The text was updated successfully, but these errors were encountered: