Skip to content

Conversation

@jverbus
Copy link
Contributor

@jverbus jverbus commented Mar 24, 2025

Add pre-commit hooks for Python & Scala, configure Black/Ruff/Flake8/scalafmt, and reformat code

Overview

This PR introduces a consistent style/linting workflow for both Python and Scala modules in this project. It adds a new .pre-commit-config.yaml plus supporting configuration files so that any staged changes will be automatically formatted and checked before commit.


Key Highlights

  1. .pre-commit-config.yaml

    • Black to auto-format Python code in isolation-forest-onnx/
    • Ruff + Flake8 for Python lint/fix checks
    • Local hook to run scalafmt for Scala code in isolation-forest/
  2. Python

    • New pyproject.toml in isolation-forest-onnx/ for Black (88-char line length, py39 target).
    • Adjusted setup.cfg for Flake8 to match line length = 88 and ignore certain dirs.
    • Reformatted Python files with consistent quoting, docstring formatting, and line-wrapping.
  3. Scala

    • New scalafmt.conf in isolation-forest/ (maxColumn=100, trailing commas, docstring style, etc.).
    • Reformatted Scala files for consistent indentation, parentheses, and docstring alignment.
  4. General Cleanup

    • Minor improvements in tests (removing extra prints, aligning docstrings, short-lining).
    • Documentation comments updated for clarity and consistency.

How to Use

  1. Install/Update pre-commit locally:

    pip install pre-commit
  2. Install scalafmt (for Scala formatting), for example:

    brew install coursier/formulas/coursier
    coursier install scalafmt
  3. Re-install hooks (at the repository root):

    pre-commit install --force
  4. Verify by committing any changes to .py or .scala files. The configured hooks will run automatically, formatting code and checking for lint errors.


Testing

  • Ran pre-commit run --all-files to confirm hooks apply cleanly on the entire codebase.
  • Verified code still compiles and tests pass for both Python (pytest) and Scala (e.g., sbt test or Gradle equivalent).
  • Confirmed that incremental commits also auto-format newly added or modified code.

jverbus added 2 commits March 24, 2025 11:59
…scalafmt, and reformat code

- Introduce .pre-commit-config.yaml with:
  • Black, Ruff, and Flake8 for Python (isolation-forest-onnx)
  • Local scalafmt hook for Scala (isolation-forest)
- Add isolation-forest-onnx/pyproject.toml to configure Black (line-length=88, py39 target, excludes)
- Update setup.cfg in isolation-forest-onnx to align Flake8 max-line-length=88
- Apply Black/Flake8 fixes to Python code (notable quoting, line breaks, docstring formatting)
- Add isolation-forest/scalafmt.conf for consistent Scala style (maxColumn=100, trailingCommas=always, etc.)
- Reformat Scala code in isolation-forest (extensive line-wrapping, docstring updates, alignment)
- Minor cleanups in test files (removing redundant prints, adjusting lines)
- Ensures consistent code style and prepares repository for automated pre-commit checks
@wangzhongqing
Copy link

wangzhongqing commented Mar 24, 2025 via email

Copy link

@angie-z angie-z left a comment

Choose a reason for hiding this comment

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

LGTM

@jverbus jverbus merged commit 3f9bb5c into master Mar 25, 2025
13 checks passed
@jverbus jverbus deleted the lint branch March 25, 2025 04:30
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.

4 participants