Skip to content

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

Merged
behnazh-w merged 10 commits into
oracle:mainfrom
jenstroeger:ruff
Jun 30, 2026
Merged

chore: introduce the Ruff pre-commit hook to replace a bunch of other code formatters and linter hooks#1419
behnazh-w merged 10 commits 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
@jenstroeger

jenstroeger commented Jun 17, 2026

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) : 178 errors
  • DTZ (ban the usage of unsafe naive datetime class): 19 errors
  • ICN (how certain packages should be imported or aliased): ok bdda354
  • PIE (assortment of various checks, partially overlaps with others like Bugbear or pylint): 2 errors e384b24
  • SIM (various tips about simplifying code): 88 errors 7fbed0a
  • SLOT (ensure __slots__ for subclasses of immutables like str): ok bdda354
  • TID (additional tidying up of imports): 15 errors
  • PERF (see also perflint, a plugin we removed due to inactivity): 15 errors
  • DOC and D (check and enforce docstring comments): 0 and 1635 errors 2ecfb3f
  • PL (this is pylint but also consider Implement Pylint astral-sh/ruff#970): 293 errors
  • FURB (similar to pyupgrade): 31 errors 9e3d859
  • RUF (these are additional checks implemented by Ruff): 144 errors 3c84e50

Now I wouldn’t refer to these as “errors” but some are nice improvements or cleanup.

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

Comment thread tests/slsa_analyzer/checks/test_registry.py
@jenstroeger

Copy link
Copy Markdown
Contributor Author

@behnazh-w while we’re at it, I think addressing both DTZ and SIM would make sense because both contribute useful checks as well.

@behnazh-w behnazh-w changed the title feat: introduce the Ruff pre-commit hook to replace a bunch of other code formatters and linter hooks chore: introduce the Ruff pre-commit hook to replace a bunch of other code formatters and linter hooks Jun 28, 2026
@behnazh-w

Copy link
Copy Markdown
Member

@behnazh-w while we’re at it, I think addressing both DTZ and SIM would make sense because both contribute useful checks as well.

I agree that they are useful. But I prefer to merge this PR soon and add more changes in follow up PRs. What do you think?

@behnazh-w

Copy link
Copy Markdown
Member

@jenstroeger The PR looks good to me. Are you planning to add more changes? Otherwise, could you please mark it as ready for review?

@jenstroeger

Copy link
Copy Markdown
Contributor Author

But I prefer to merge this PR soon and add more changes in follow up PRs. What do you think?

I’m easy, happy to add the changes here or in a separate PR.

Are you planning to add more changes? Otherwise, could you please mark it as ready for review?

I could add the above two checkers in this PR, but it sounds like you’d prefer to avoid that.

@jenstroeger jenstroeger marked this pull request as ready for review June 29, 2026 03:20
@jenstroeger jenstroeger requested a review from behnazh-w as a code owner June 29, 2026 03:20
@behnazh-w

Copy link
Copy Markdown
Member

But I prefer to merge this PR soon and add more changes in follow up PRs. What do you think?

I’m easy, happy to add the changes here or in a separate PR.

Are you planning to add more changes? Otherwise, could you please mark it as ready for review?

I could add the above two checkers in this PR, but it sounds like you’d prefer to avoid that.

OK, if that's something you've already been working on, let's add them to this PR. Thank you!

@jenstroeger jenstroeger marked this pull request as draft June 29, 2026 03:51
@jenstroeger jenstroeger marked this pull request as ready for review June 29, 2026 11:18
@jenstroeger

Copy link
Copy Markdown
Contributor Author

@behnazh-w I think I’ll skip on the DTZ checker because the use of both naive and aware datetimes in the code base is a bit much without me understanding all of the intentions.

PR is open for review.

@behnazh-w behnazh-w merged commit d4c9c9a into oracle:main Jun 30, 2026
17 checks passed
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.

2 participants