DEV Community

Carlos Armando Marcano Vargas
Carlos Armando Marcano Vargas

Posted on • Originally published at carlosmv.hashnode.dev on

Ruff: A Python Linter built with Rust

Ruff is a Python linter built with Rust, and is extremely fast in comparison with other linters(10-100x faster) in the Python ecosystem, according to its documentation.

One of the things that make Ruff different from the alternative tools, it is faster and has more functionality behind a single interface.

What is a linter?

According to this page in Wikipedia, a linter is a tool that analyzes the source code to flag programming errors, bugs, stylistic errors and suspicious constructs.

So, when we are writing a program, we can use a linter to check if there is an error or a bug. Also, when we are contributing to a code base, we use a linter to check if we are writing the code with stylistic errors.

This tool allows us to write idiomatic code, more consistent with the code base and with fewer errors and bugs.

Requirements

  • Pip installed

Installation

pip install ruff

Enter fullscreen mode Exit fullscreen mode

Usage

The examples are very simple, we are going to write a function in a Python file, import a module without using it, and run Ruff to see its output in the console.

import os 

def say_hello():
    print('Hello')

say_hello()

Enter fullscreen mode Exit fullscreen mode

Now, in the console, we run the command ruff check <python file>

If we use the command ruff --fix <python file>, ruff fixes the problem for us.

Next, we declare a variable, without using it. And use an undeclared variable.

def say_hello():
    message = "hello"
    print(messag)

Enter fullscreen mode Exit fullscreen mode

If there are no problems with the code, then, ruff will not show any message.

Conclusion

I had the opportunity to try Ruff in an open-source project that I'm contributing to, and it was my first time using a linter. The project uses it before the code is pushed to a branch. But now, every time I make a modification or add a piece of code I run Ruff, is so fast and allows me to catch any error or bug before I run the program.

References

Ruff Documentation

Ruff README

Linter

Heroku

Build apps, not infrastructure.

Dealing with servers, hardware, and infrastructure can take up your valuable time. Discover the benefits of Heroku, the PaaS of choice for developers since 2007.

Visit Site

Top comments (0)

👋 Kindness is contagious

Discover a treasure trove of wisdom within this insightful piece, highly respected in the nurturing DEV Community enviroment. Developers, whether novice or expert, are encouraged to participate and add to our shared knowledge basin.

A simple "thank you" can illuminate someone's day. Express your appreciation in the comments section!

On DEV, sharing ideas smoothens our journey and strengthens our community ties. Learn something useful? Offering a quick thanks to the author is deeply appreciated.

Okay