Skip to content

Use ruff as linter and code formatter #502

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

Merged
merged 10 commits into from
Jan 19, 2024
Merged

Conversation

tkrabel
Copy link
Contributor

@tkrabel tkrabel commented Dec 24, 2023

Ruff is incredibly fast (running it on the pylsp code base is INSTANT; static code analysis in our pipeline now only takes 21s!) and a drop-in replacement for pylint, pycodestyle, isort, and black.

This PR suggests the following:

  1. Use ruff as a replacement for pylint and pycodestyle. This simplifies the devloop (no need to run two commands anymore) and makes it much faster (ruff is REALLY fast and offers an autofix option, which I used already to address 10+ issues).
  2. Use ruff as a replacement for black. Since we use ruff as a linter, using it as a formatter keeps the devloop simple. The diff to black is minimal: only 5 function definitions we're indented differently. The rest was the same.
  3. Use ruff for sorting imports. We don't have automated import sorting yet, and this would address issues like Make autoimport cache generation non-blocking #499 (comment)

@tkrabel
Copy link
Contributor Author

tkrabel commented Dec 24, 2023

Addresses #499 (comment)

target-version = "py38"

[lint]
select = ["E", "F", "W", "C", "I"]
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"I" is for isort functionality

Copy link
Contributor

@doolio doolio Jan 19, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not use the existing pyproject.toml rather than introduce a new config file in ruff.toml?

Edit: cc @ccordoba12

@tkrabel tkrabel changed the title Use ruff as linter and code formatter 🎁 🎄 Use ruff as linter and code formatter 🎄 🎁 Dec 24, 2023
@tkrabel
Copy link
Contributor Author

tkrabel commented Dec 24, 2023

@ccordoba12 this PR is my Christmas present for you 😄. No more checking import order! Ruff takes care of that for you now 🎄 🎁 . Happy holidays! :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed this since we're not using pycodestyle anymore. ruff takes care of that for us now.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't we also remove .pylintrc as well?

cc: @ccordoba12

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, that's a good idea. I'll do that in a follow up PR.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I submitted a PR for consideration for this just now.

@tkrabel tkrabel changed the title 🎁 🎄 Use ruff as linter and code formatter 🎄 🎁 Use ruff as linter and code formatter Dec 30, 2023
@tkrabel-db
Copy link
Contributor

@krassowski @ccordoba12 don't want to look impatient, but I'd love to get this in for all the contributors, making any lint/code style checks blazingly fast! :)

@ccordoba12 ccordoba12 added this to the v1.10.0 milestone Jan 19, 2024
@ccordoba12
Copy link
Member

this PR is my Christmas present for you 😄. No more checking import order! Ruff takes care of that for you now 🎄 🎁 . Happy holidays! :)

Thanks! This was a nice present indeed and sorry for answering until now but I was taking advantage of the holidays to finish several PRs in Spyder.

don't want to look impatient, but I'd love to get this in for all the contributors, making any lint/code style checks blazingly fast! :)

Totally agree, so I'm going to merge your work now.

Copy link
Member

@ccordoba12 ccordoba12 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @tkrabel!

@ccordoba12 ccordoba12 merged commit fc2851a into python-lsp:develop Jan 19, 2024
@Shane-XB-Qian
Copy link

Shane-XB-Qian commented Jan 21, 2024 via email

@doolio
Copy link
Contributor

doolio commented Jan 21, 2024

This PR was to use ruff to lint/format the python-lsp-server project not as a way for users to use ruff as a linter/formatter for their own projects via the python-lsp-server. For the latter users should use the python-lsp-ruff plugin as suggested in the README.

@Shane-XB-Qian
Copy link

Shane-XB-Qian commented Jan 21, 2024 via email

@doolio
Copy link
Contributor

doolio commented Jan 21, 2024

ok. but since when ruff supported py project.toml instead of ruff.toml?

I think from the very beginning. See here.

Edit: Specifially

If Ruff detects multiple configuration files in the same directory, the .ruff.toml file will take precedence over the ruff.toml file, and the ruff.toml file will take precedence over the pyproject.toml file.

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

Successfully merging this pull request may close these issues.

5 participants