Skip to content

Switch from Flake8/isort/Black to Ruff for linting and formatting #247

@kattni

Description

@kattni

What is the problem or limitation you are having?

This repository currently uses Flake8/isort/Black for code linting and formatting.

Describe the solution you'd like

Ruff should replace Flake8/isort/Black as the code linter and formatter.

This should be done as follows:

  1. Add Ruff configuration to pyproject.toml as included here
  2. Add Ruff checks to .pre-commit-config.yaml as included here
  3. Remove the [tool.isort] configuration section from pyproject.toml.
  4. Remove [flake8] configuration section from tox.ini.
  5. Run pre-commit run -a in the repo directory, and let Ruff do any formatting or linting that it can do automatically.
  6. You will almost certainly end up with a list of errors, each identified by an error number.
  7. In this PR, you will not be making any significant code changes.
  8. Add a global ignore list to pyproject.toml in the [tool.ruff.lint] section, below the extend-select configuration section, including only the rules that apply to this repository. You can find an example of an ignore list here. Include a comment next to the rule indicating what it relates to, as shown.
  9. Run pre-commit run -a to ensure that all the rules are being successfully ignored.
  10. Add .ruff_cache to the .gitignore file.
  11. There may be some minor code changes necessary because Flake8 and Black don't always agree; these changes should be kept to a minimum.
  12. Submit the pull request.

Describe alternatives you've considered

None.

Additional context

Once the initial PR is merged, the next step in this process is to begin working through resolving the errors indicated by the rules.

Each rule begins with a letter or set of letters. Each set of rules that begins with the same letter or letters is related. For example, errors B007, B018, and B904 are part of the same ruleset.

Each set of related rules should be worked through together, and submitted as a separate PR for each set of related rules, i.e. submit a PR for the BXXX rules, and a separate PR for the EXXX rules.

The SIMXXX checks are explicitly disabled in the configuration. Do not remove the commented out SIM check, and avoid resolving the SIMXXX errors.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew features, or improvements to existing features.good first issueIs this your first time contributing? This could be a good place to start!

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions