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

Plugin for ruff for linting (and eventually formatting?) #299

Closed
jhossbach opened this issue Nov 11, 2022 · 17 comments
Closed

Plugin for ruff for linting (and eventually formatting?) #299

jhossbach opened this issue Nov 11, 2022 · 17 comments

Comments

@jhossbach
Copy link
Member

I recently came upon ruff which provides a very fast alternative to flake8 written in Rust. It implements all (or most) of the flake8 rules as well as various flake8 plugins with a serious increase of speed.
The plan for this is to eventually plan establish their own LSP but I was wondering if you are interested in a plugin for linting as an alternative to flake8. I am willing to create a pull request if there is some interest.

@ccordoba12
Copy link
Member

ccordoba12 commented Nov 11, 2022

Hey @jhossbach, thanks for the suggestion! Sure, we're interested in having a plugin for Ruff because it's a very interesting project with a lot of potential.

I am willing to create a pull request if there is some interest.

Nice! Looking forward to review it.

@charliermarsh
Copy link

Let me know if I can be helpful, or if you run into any questions or issues with the interface.

@krassowski
Copy link
Contributor

Big +1 from me too. Potential packaging concerns aside this sounds great! Two questions:

  • Does ruff expose precise start/end positions? We hit a wall with this for flake/pyflakes (Unused tag applied to too big range #253).
  • Would the integration run in watch mode, or start a new instance each time?

@charliermarsh
Copy link

Yeah! Ruff exposes a precise start and end position for all checks. (I'm sure the granularity of those spans could be improved in some cases, but they exist for all checks and improving them is something I'm happy to invest in as those cases come up.)

I think it'd be fine to invoke Ruff every time rather than running in watch mode, since watch mode is more useful for monitoring file changes -- but in this case, I'm guessing change events would come from the LSP?

@ccordoba12
Copy link
Member

but in this case, I'm guessing change events would come from the LSP?

No, LSP's don't have a monitoring mechanism. That needs to be provided by clients.

@charliermarsh
Copy link

Sorry, that was just sloppy terminology. What I meant to say is that Ruff doesn't need to handle file-watching in this case, right? That it'll be invoked by the LSP at the appropriate times?

@ccordoba12
Copy link
Member

ccordoba12 commented Nov 11, 2022

Oh yeah, that's correct. Clients send a textDocument/didChange request when a file changes on their side, which triggers linting automatically afterwards here.

@jhossbach
Copy link
Member Author

Currently working on the plugin, I read through #27 but am unsure as to what the naming convention should be from now on. I personally like python-lsp-ruff, or should pylsp-ruff be used instead?

@jhossbach
Copy link
Member Author

jhossbach commented Dec 1, 2022

Also, I am unfamiliar with the kind type given by ruff, can you help on that @charliermarsh?

@charliermarsh
Copy link

@jhossbach - kind is the enum defined here -- it's basically the plain-text name for the check (as opposed to code, which is an identifier like F841). The serialization of kind is a bit odd because it's an enum, so it sometimes has extra, anonymous fields included as a list. I actually removed kind from the JSON output recently for that reason, so you probably want to use code instead?

@ccordoba12
Copy link
Member

I personally like python-lsp-ruff, or should pylsp-ruff be used instead?

python-lsp-ruff sounds good to me because it'd go very well with python-lsp-black.

@jhossbach, would you like to host your plugin in our organization? I think it'd be nice, but of course it's up to you.

@jhossbach
Copy link
Member Author

@jhossbach, would you like to host your plugin in our organization? I think it'd be nice, but of course it's up to you.

Great idea, do I have to be invited to the organization in order to create a new repo there?

@ccordoba12
Copy link
Member

ccordoba12 commented Dec 2, 2022

Great idea, do I have to be invited to the organization in order to create a new repo there?

Yep, I just sent you an invite. After you accept it, you could create your repo here.

@jhossbach
Copy link
Member Author

Great! I'll create the repo as soon as I get it working locally.

@jhossbach
Copy link
Member Author

Closing as completed, you can find the new plugin here: https://github.com/python-lsp/python-lsp-ruff

@charliermarsh
Copy link

Thanks for all your work on this @jhossbach!

@jhossbach
Copy link
Member Author

Thanks for all your work on this @jhossbach!

Happy to contribute :)

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

4 participants