Skip to content

Ruff full migration Phase 2: Replace Black with Ruff formatter and enable additional rules Closes #3142#3250

Merged
mlodic merged 3 commits intointelowlproject:developfrom
kami922:ruff-full-migration-clean
Jan 30, 2026
Merged

Ruff full migration Phase 2: Replace Black with Ruff formatter and enable additional rules Closes #3142#3250
mlodic merged 3 commits intointelowlproject:developfrom
kami922:ruff-full-migration-clean

Conversation

@kami922
Copy link
Contributor

@kami922 kami922 commented Jan 30, 2026

Description

This PR completes Phase 2 of the Ruff migration (following PR #3145), replacing Black formatter with ruff format and enabling additional rule categories.

Summary

Commit 1: Phase 2 - Ruff formatting

  • Replace Black formatter with ruff format (line-length: 140 → 110)
  • Enable additional Ruff rule categories: UP (pyupgrade), C4 (comprehensions), DJ (Django)
  • Update CI/CD: replaced black --check with ruff format --check
  • Remove black==24.10.0 from test-requirements.txt
  • Format 345 Python files with Ruff formatter
  • Add global ignores for UP/C4 rules (defer complex refactors to follow-up PRs)
  • Add per-file ignores for DJ rules (model field ordering, str methods)

Commit 2: Fix formatting bugs

  • Fix mutable default list in email_sender.py
  • Fix 12 files with missing spaces in error messages
  • Fix typo in websocket.py: "used tried" → "user tried"
  • Fix variable reference in docguard_get.py
  • Move jest.setTimeout() into beforeAll() hook

Testing

  • ✅ Local validation: ruff check . PASS (0 errors)
  • ✅ Local validation: ruff format . --check PASS (727 files formatted)
  • ✅ CI validation: act pull_request -j linters PASS

Type of change

  • Bug fix (non-breaking change which fixes an issue)

Checklist

  • I have read and understood the rules about how to Contribute
  • The pull request is for the branch develop
  • Please avoid adding new libraries as requirements (✅ Only removed black)
  • Linters (Ruff) gave 0 errors

- Replace Black formatter with ruff format (line-length: 140 → 110)
- Enable additional Ruff rule categories: UP (pyupgrade), C4 (comprehensions), DJ (Django)
- Update CI/CD: replaced 'black --check' with 'ruff format --check'
- Remove black==24.10.0 from test-requirements.txt
- Format 345 Python files with Ruff formatter
- Add global ignores for UP/C4 rules to defer complex refactors to follow-up PRs
- Add per-file ignores for DJ rules (model field ordering, __str__ methods)
- Fix mutable default list in email_sender.py (CCs: List[str] = None)
- Fix missing spaces in error messages for readability:
  - classic_dns_resolver.py: ".Reason" → ". Reason"
  - circl_pssl.py: ".Template" → ". Template"
  - circl_pdns.py: ".Template" → ". Template"
  - zoomeye.py: ".Supported" → ". Supported"
  - docguard_get.py: ".Supported" → ". Supported" + fix variable reference
  - spyse.py: ".Supported" → ". Supported"
  - censys.py: ".Supported" → ". Supported"
  - triage_search.py: ".Supported" → ". Supported"
  - threatstream.py: Add spaces between concatenated strings (2 instances)
  - validin.py: "for{" → "for {"
- Fix typo in websocket.py: "used tried" → "user tried"
- Move jest.setTimeout() into beforeAll() hook in ScanForm.toastRedirect.test.jsx
Copilot AI review requested due to automatic review settings January 30, 2026 16:13
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR completes Phase 2 of the Ruff migration by replacing the Black formatter with Ruff's built-in formatter, reducing the line length from 140 to 110 characters, and enabling additional Ruff rule categories (UP, C4, DJ). The changes include reformatting 345 Python files, updating CI/CD workflows, removing Black as a dependency, and fixing several bugs discovered during the reformatting process.

Changes:

  • Replaced Black formatter with ruff format and reduced line length to 110 characters
  • Enabled additional Ruff rules (pyupgrade, comprehensions, Django) with selective ignores
  • Fixed bugs including mutable default arguments, missing spaces in error messages, and incorrect variable references

Reviewed changes

Copilot reviewed 300 out of 350 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
requirements/test-requirements.txt Removed black==24.10.0 dependency
pyproject.toml Updated line-length to 110, added UP/C4/DJ rules with per-file ignores
.github/workflows/pull_request_automation.yml Replaced Black check with Ruff format check
api_app/connectors_manager/connectors/email_sender.py Fixed mutable default list argument
api_app/websocket.py Fixed typo: "used tried" → "user tried"
api_app/analyzers_manager/observable_analyzers/docguard_get.py Fixed incorrect variable reference from 'hash' to 'self.observable_name'
frontend/tests/components/scan/ScanForm/ScanForm.toastRedirect.test.jsx Moved jest.setTimeout() into beforeAll() hook
Multiple test files Reformatted code to comply with 110-character line length

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@kami922
Copy link
Contributor Author

kami922 commented Jan 30, 2026

@mlodic Hello

Current Status - 2 Commits Completed

As requested in your "Option 1" feedback, I've created a fresh branch from develop with clean commit history. This PR currently contains the first 2 commits:

Commit 1: Phase 2 - Ruff formatting (348 files)

  • Replaced Black with ruff format (line-length: 140 → 110)
  • Enabled UP, C4, DJ rule categories
  • Updated CI/CD pipeline
  • Formatted 345 Python files

Commit 2: Fix formatting bugs (13 files)

  • Fixed mutable default list bug (email_sender.py)
  • Fixed 12 files with missing spaces after periods in error messages (bugs introduced by Ruff's string compression)
  • Fixed typo and variable reference issues

All CI checks pass

I have a question about commits 3 & 4 - see next comment.

@kami922
Copy link
Contributor Author

kami922 commented Jan 30, 2026

@mlodic In your "Option 1" approval, you mentioned including commits for:

  • Commit 3: Fix N818 violations (~20 exception renames)
  • Commit 4: Fix B904 violations (~117 exception chaining)

After analyzing the codebase, I discovered these changes are more extensive than initially estimated:

N818 Scope (Exception naming - add "Error" suffix)

  • 22 exception classes need renaming (e.g., AnalyzerRunExceptionAnalyzerRunError)
  • 127+ files use these exceptions and need updates
  • This is a breaking API change affecting imports and usage throughout the codebase

B904 Scope (Exception chaining - add raise ... from err)

  • ~117 exception handlers need individual analysis
  • Each requires determining whether to use from e or from None
  • Cannot be automated - needs manual review for correctness

Options

Option A: Keep this PR with 2 commits (formatting + bug fixes), create separate follow-up PRs for N818 and B904

  • Pros: Clean, focused PR; easier to review; can be merged quickly
  • Cons: Deviates slightly from "Option 1" structure

Option B: Add commits 3 & 4 to this PR

  • Pros: Follows "Option 1" exactly as discussed
  • Cons: Large PR (127+ files for N818 alone); risky breaking changes

Option C: Add N818/B904 to pyproject.toml ignores, defer indefinitely

  • Pros: Simple, no breaking changes
  • Cons: Technical debt accumulates

Which approach would you prefer?

@mlodic
Copy link
Member

mlodic commented Jan 30, 2026

option C is fine, thanks!

Copilot AI review requested due to automatic review settings January 30, 2026 16:46
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

Copy link
Member

@mlodic mlodic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

great work now

@mlodic
Copy link
Member

mlodic commented Jan 30, 2026

I committed the copilot suggestion but I think we are gtg. let's wait for the CI then I'll merge. thanks

@mlodic mlodic merged commit e17364b into intelowlproject:develop Jan 30, 2026
8 of 9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants