Ruff full migration Phase 2: Replace Black with Ruff formatter and enable additional rules Closes #3142#3250
Conversation
- 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
There was a problem hiding this comment.
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 formatand 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.
frontend/tests/components/scan/ScanForm/ScanForm.toastRedirect.test.jsx
Outdated
Show resolved
Hide resolved
|
@mlodic Hello Current Status - 2 Commits CompletedAs requested in your "Option 1" feedback, I've created a fresh branch from Commit 1: Phase 2 - Ruff formatting (348 files)
Commit 2: Fix formatting bugs (13 files)
All CI checks pass I have a question about commits 3 & 4 - see next comment. |
|
@mlodic In your "Option 1" approval, you mentioned including commits for:
After analyzing the codebase, I discovered these changes are more extensive than initially estimated: N818 Scope (Exception naming - add "Error" suffix)
B904 Scope (Exception chaining - add
|
|
option C is fine, thanks! |
….test.jsx Co-authored-by: Copilot <[email protected]>
|
I committed the copilot suggestion but I think we are gtg. let's wait for the CI then I'll merge. thanks |
Description
This PR completes Phase 2 of the Ruff migration (following PR #3145), replacing Black formatter with
ruff formatand enabling additional rule categories.Summary
Commit 1: Phase 2 - Ruff formatting
ruff format(line-length: 140 → 110)black --checkwithruff format --checkblack==24.10.0from test-requirements.txtCommit 2: Fix formatting bugs
Testing
ruff check .PASS (0 errors)ruff format . --checkPASS (727 files formatted)act pull_request -j lintersPASSType of change
Checklist
developblack)Ruff) gave 0 errors