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

Add ruff as a linter in pre-commit #106

Open
baniasbaabe opened this issue Jun 17, 2023 · 7 comments
Open

Add ruff as a linter in pre-commit #106

baniasbaabe opened this issue Jun 17, 2023 · 7 comments

Comments

@baniasbaabe
Copy link

I noticed there is no linter. ruff is a great option to use.

@OtenMoten
Copy link

OtenMoten commented Jun 19, 2023

First, let's talk about Linter and Ruff.

A linter, in the context of programming, is a tool that analyzes source code to flag programming errors, bugs, stylistic errors, and suspicious constructs. The term originates from a Unix utility that examined C language source code.

In Python, linters are used to enforce a consistent coding style and to catch certain types of errors before the code is even run. Using a linter can help to identify syntax errors, structural problems, code smells, and even more complex issues such as detecting unused variables or imports.

The most modern Linter in context of Python is Ruff.

@wirthual
Copy link
Member

wirthual commented Jul 6, 2023

Great idea, what config is needed so it plays nicely with isort and black? Does it replace one or the other?

@wirthual
Copy link
Member

wirthual commented Jul 6, 2023

From a quick look it seems like it should just work:

Ruff and Black: https://beta.ruff.rs/docs/faq/#is-ruff-compatible-with-black
Ruff and Isort: https://beta.ruff.rs/docs/faq/#how-does-ruffs-import-sorting-compare-to-isort

@christoph-teichmeister
Copy link

christoph-teichmeister commented Feb 29, 2024

You could also entirely replace black with ruff. We've done that multiple times and, subjectively, results stayed the same

@LilithWittmann
Copy link
Member

Isn't black basically doing the job of an opinionated linter already for us? But in a style thats encouraged by the psf?

@christoph-teichmeister
Copy link

Isn't black basically doing the job of an opinionated linter already for us? But in a style thats encouraged by the psf?

I'm not sure that ruff can not be configured to mimic black-formatter behaviour - so you'd keep the style encouraged by the psf!

On top of that, I think the main advantages are, that it comes with so much more than just formatting (black and isort).

Configured correctly, it can, among much more, inform you on upgrade-compitability - one of my personal favourites.

@BobMcFry
Copy link

As of version 0.1.2 ruff also comes with a formatter that should serve as a drop-in replacement for black. In our company, we have gotten rid of black and isort and just use ruff now as it reduces dependencies and also the pain of having compatibility issues between these tools (import sorting usually gets conflicts). There are rare differences between black and ruff formatting, but these were neglegible in the cases I encountered.

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

6 participants