Skip to content

Conversation

@cagyirey
Copy link

📝 Change Type

  • chore: Updating linting rules
  • refactor: Introduces linting changes that will make safe stylistic changes to adhere to standard code hygiene rules. Adds ruff and deprecates autoflake, isort, and black.

💡 Description

Consolidate Python linting and formatting into Ruff - a single, fast tool that replaces autoflake, isort, Black, and flake8.

Why Ruff?

  • 10-100x faster than Black/flake8 (Rust-based)
  • Single tool replaces 4 dependencies (autoflake, isort, black, flake8)
  • Better auto-fixes with more comprehensive lint rules
  • Wide adoption - used by FastAPI, Pydantic, Pandas, NumPy, etc.
  • Astral ecosystem - same team behind uv, enabling tighter toolchain integration in future PRs

Key Changes

  1. Add ruff.toml with unified linting/formatting configuration
  2. Update .pre-commit-config.yaml to use ruff hooks (v0.14.6) instead of autoflake/isort/black
  3. Remove black, isort from dev dependencies; update ruff>=0.14.6
  4. Remove [tool.black], [tool.isort], [tool.ruff] sections from pyproject.toml (now in ruff.toml)

Configuration Details

Preserved from existing config:

  • Line length: 100
  • isort profile: Black-compatible
  • Excluded: src/parallax/p2p/proto/ (generated protobuf)

New lint rules enabled:

Rule Set Purpose
E, W, F pycodestyle + Pyflakes (existing)
I isort import sorting
N PEP 8 naming conventions
UP pyupgrade - modernize syntax
B flake8-bugbear - common bugs
C4 flake8-comprehensions
SIM flake8-simplify
RUF Ruff-specific rules
TID Tidy imports
ASYNC Async/await best practices

Deferred rules (extend-ignore):
Some rules require larger refactoring and are deferred to follow-up PRs:

  • PTH (pathlib migration), TCH (TYPE_CHECKING imports), B006 (mutable defaults)
  • N802/803/806 (naming - often intentional for math notation)
  • See ruff.toml for full list with rationale

✅ Checklist

  • I have performed a self-review of my own code.
  • I have added/updated tests that prove my fix or feature works (if applicable).
  • I have updated the documentation (if necessary).
  • My code follows the project's style guidelines.

📋 Test Plan

  • pre-commit run --all-files passes locally after rules are approved
  • Maintainers approve or request changes to the linting rules in ruff.toml
  • .github/workflows/pre-commit.yml validates linting in CI
  • Existing tests continue to pass

Consolidate Python linting and formatting tools into Ruff for faster
execution and simpler configuration:

- Add ruff.toml with comprehensive lint rules (E, W, F, I, N, UP, B, C4,
  SIM, RUF, TCH, PTH, TID, ASYNC)
- Update .pre-commit-config.yaml to use ruff and ruff-format hooks
- Remove autoflake, isort, and black hooks
- Add additional pre-commit checks (large files, json, toml, merge
  conflicts, debug statements)
- Add .ruff_cache/ to .gitignore
- Remove black and isort from dev dependencies (ruff replaces both)
- Update ruff version constraint to >=0.14.6
- Remove [tool.black], [tool.isort], [tool.ruff] sections from pyproject.toml
  (configuration now lives in ruff.toml)
- Add deferred rules to extend-ignore for issues requiring larger refactoring
@cagyirey cagyirey force-pushed the cagyirey/feature/ruff-linting branch from c93d7cc to c4c3554 Compare November 28, 2025 20:08
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.

1 participant