Skip to content

Ruff

Ruff checks Python source for rule violations and can also format it.

Visit Ruff

What does Ruff check in Python code?

The linter reports code that matches selected rules, such as an unused import. The formatter handles layout. Choose which rules your project uses and keep those choices with the code so a teammate can reproduce the check.

When does Ruff change a file?

Run a lint check without enabling fixes when you only want a report. Formatter check mode also reports without rewriting. When lint fixes are enabled, Ruff normally applies fixes it labels safe unless you opt into unsafe fixes or change their classification. Review the actual change either way.

What makes the result repeatable?

Keep the rule choices and target Python version in the project configuration. Use the same Ruff version in the editor and the automated check. The MIT-licensed tool can run on your own machine or on a build runner you pay for separately.

Which change would Ruff report and which would it reformat?

On paper, mark a fictional Python file with one unused import and one awkwardly wrapped line. Decide which output you expect from the lint check and which from formatting.

  1. Start with reports
    Write down the expected lint warning and whether a format check would report a change.
  2. Review a proposed edit
    Cross out the unused import in your sketch and rewrap the line separately. Keep the expected behavior of the program the same.