Skip to content

Migrate from flake8 to ruff for linting and formatting #2120

Description

@cfxegbert

For linting the code base move from flake8 to ruff.

Motivation

  • Performance: Written in Rust, Ruff is often 10–100x faster than traditional Python-based linters like Flake8. This makes it fast enough to run on every file save, providing near-instant feedback during development.
  • Tool consolidation: Ruff serves as a "Swiss Army knife," replacing not just Flake8 but also isort, pydocstyle, pyupgrade, autoflake, and dozens of popular Flake8 plugins.
  • Built-in auto-fixing: Ruff can automatically fix many violations, such as removing unused imports or upgrading syntax, using the --fix flag.
  • Code formatting: Ruff can also be used for code formatting that matches the formatting from black
  • Doc string linting: Ensure our code documentation is using one style of documentation strings.

Related Issues/PRs

Implementation

  • Create ruff.toml configuration that lints the code base without any changes to the code base.
  • Add GitHub action to add ruff linting to workflow
  • Incrementally enable more ruff rules. Only enable a few rules at a time to limit the size of the pull requests to facilitate code reviews. As mentioned in Automatically format the code base #1584 use .git-blame-ignore-revs to not cause large formatting changes to not muddle up the blame history. Repeat until we feel we have implemented all the rules that we feel are necessary.
  • Disable current flake8 GitHub action in workflow.
  • Enable ruff formatting.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions