Skip to content

feat: introduce the Ruff pre-commit hook to replace a bunch of other code formatters and linter hooks#1419

Draft
jenstroeger wants to merge 1 commit into
oracle:mainfrom
jenstroeger:ruff
Draft

feat: introduce the Ruff pre-commit hook to replace a bunch of other code formatters and linter hooks#1419
jenstroeger wants to merge 1 commit into
oracle:mainfrom
jenstroeger:ruff

Conversation

@jenstroeger

@jenstroeger jenstroeger commented Jun 17, 2026

Copy link
Copy Markdown
Contributor

Summary

This change replaces black, bandit, isort, flake8, and pyupgrade git hooks with a single ruff hook.

Description of changes

Ruff is supposed to be a drop-in replacement for the aforementioned checkers, linters, and code formatters and it mostly works. However, it also

  • reformatted a few lines of code;
  • complained about a few issues here and there;
  • complained about FooBarException which should be named FooBarError which could be considered a breaking change;
  • required renaming bandit comments nosec Bxxx to noqa: Sxxx.

In addition to the rules covering the existing Macaron setup, Ruff provides a bunch of new rules and checkers (e.g. boolean trap) that are probably interesting to add… 🤓

Related issues

n/a

Checklist

  • I have reviewed the contribution guide.
  • My PR title and commits follow the Conventional Commits convention.
  • My commits include the "Signed-off-by" line.
  • I have signed my commits following the instructions provided by GitHub. Note that we run GitHub's commit verification tool to check the commit signatures. A green verified label should appear next to all of your commits on GitHub.
  • I have updated the relevant documentation, if applicable.
  • I have tested my changes and verified they work as expected.

@oracle-contributor-agreement oracle-contributor-agreement Bot added the OCA Verified All contributors have signed the Oracle Contributor Agreement. label Jun 17, 2026
…code formatters and linter hooks

Signed-off-by: Jens Troeger <jens.troeger@light-speed.de>
@jenstroeger

Copy link
Copy Markdown
Contributor Author

@behnazh-w in addition to the existing checks, perhaps it would make sense to add the following:

  • FBT (check for boolean trap)
  • DTZ (ban the usage of unsafe naive datetime class)
  • ICN (how certain packages should be imported or aliased)
  • PIE (assortment of various checks, partially overlaps with others like Bugbear or pylint)
  • SIM (various tips about simplifying code)
  • SLOT (ensure __slots__ for subclasses of immutables like str)
  • TID (additional tidying up of imports)
  • PERF (see also perflint, a plugin we removed due to inactivity)
  • DOC and D (check and enforce docstring comments)
  • F (check various lint and flakes)
  • PL (this is pylint but also consider Implement Pylint astral-sh/ruff#970)
  • FURB (similar to pyupgrade)
  • RUF (these are additional checks implemented by Ruff)

Also, note that there’s a CPY (copyright) rule which might replace this:

# Checks the copyright header for .js, .py, and .java, etc. files.
- repo: local
hooks:
- id: copyright-checker
name: Copyright checker
entry: scripts/dev_scripts/copyright-checker.sh
language: system
always_run: true
pass_filenames: false

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

OCA Verified All contributors have signed the Oracle Contributor Agreement.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant