Skip to content

Conversation

@calebevans
Copy link
Owner

@calebevans calebevans commented Dec 20, 2025

Description

Addresses SonarQube code quality issues including cognitive complexity and floating-point comparison warnings. Also improves README organization.

Type of Change

  • 🐛 Bug fix (non-breaking change that fixes an issue)
  • ✨ New feature (non-breaking change that adds functionality)
  • 💥 Breaking change (fix or feature that would cause existing functionality to change)
  • 📚 Documentation update
  • 🔧 Refactoring (no functional changes)
  • 🧪 Test improvement

Related Issues

Changes Made

  • README.md: Moved GPU Requirements from front matter to Performance section (it's optional, not a requirement)
  • README.md: Centered title and badges
  • thresholder.py: Fixed floating-point equality comparisons using isclose()
  • cli.py: Reduced cognitive complexity by extracting _print_backend_info() and _print_filtering_mode() helpers
  • cli.py: Fixed floating-point equality comparison
  • config.py: Reduced cognitive complexity by extracting validation into _validate_core_params(), _validate_anomaly_range(), _validate_backend(), and _validate_llama_cpp_model_path()

Testing

  • I have run pytest and all tests pass
  • I have added tests that cover my changes (if applicable)
  • I have tested manually with real log files

Checklist

  • I have run pre-commit run --all-files and fixed any issues
  • I have updated the documentation (if applicable)
  • My changes generate no new warnings
  • Any dependent changes have been merged and published

Additional Notes

All changes are refactoring with no functional impact. Validation logic and behavior remain identical.

Summary by CodeRabbit

  • Documentation

    • Updated project status badges in README for better visibility of Security Rating and Quality Gate Status.
  • Bug Fixes

    • Enhanced floating-point tolerance handling in configuration and threshold validation for improved numerical precision.
  • Refactor

    • Restructured configuration validation with dedicated modular checks.
    • Optimized CLI code organization with reusable helper functions.

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai
Copy link

coderabbitai bot commented Dec 20, 2025

Walkthrough

The changes refactor validation logic in the config module into separate methods, replace floating-point exact comparisons with tolerance-based checks using isclose across multiple files, extract CLI helper functions to reduce code duplication, and update README badges.

Changes

Cohort / File(s) Summary
README Presentation
README.md
Added centered container with two new badges (Security Rating and Quality Gate Status); removed existing License badge.
Floating-Point Tolerance
src/cordon/analysis/thresholder.py, src/cordon/cli.py
Replaced exact equality checks (== 1.0, == 0.0) with isclose() comparisons for floating-point anomaly percentile and related threshold logic.
CLI Helper Extraction
src/cordon/cli.py
Introduced two new helper functions (_print_backend_info, _print_filtering_mode) to centralize backend configuration and filtering mode output, replacing inlined printing logic.
Config Validation Refactoring
src/cordon/core/config.py
Extracted four private validation methods (_validate_core_params, _validate_anomaly_range, _validate_backend, _validate_llama_cpp_model_path) and wired them from __post_init__ to modularize configuration checks.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

  • Config validation methods (src/cordon/core/config.py): Verify that all validation constraints (range bounds, file existence, allowed values) are correctly implemented and handle edge cases.
  • Floating-point tolerance usage: Confirm that isclose() default tolerance is appropriate for anomaly percentile comparisons across both files.
  • Helper function refactoring (src/cordon/cli.py): Ensure extracted functions preserve the exact output format and behavior of inlined logic.

Poem

🐰 Precision floats now dance with tolerance so fine,
Validation methods bloom in modular design,
Helper functions hop, reducing code duplication's weight,
README badges gleam—refactored code feels great! ✨

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'Small refactor to fix SonarQube issues' is clearly related to the main objective of the pull request: addressing SonarQube code quality issues through refactoring.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch sonarqube-fixes

📜 Recent review details

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 94eaadb and e5e50fe.

📒 Files selected for processing (4)
  • README.md (1 hunks)
  • src/cordon/analysis/thresholder.py (2 hunks)
  • src/cordon/cli.py (4 hunks)
  • src/cordon/core/config.py (2 hunks)
🧰 Additional context used
🧬 Code graph analysis (2)
src/cordon/cli.py (1)
src/cordon/core/config.py (1)
  • AnalysisConfig (6-96)
src/cordon/core/config.py (1)
tests/test_llama_cpp.py (1)
  • model_path (88-95)
🪛 Ruff (0.14.8)
src/cordon/core/config.py

40-40: Avoid specifying long messages outside the exception class

(TRY003)


42-42: Avoid specifying long messages outside the exception class

(TRY003)


44-44: Avoid specifying long messages outside the exception class

(TRY003)


46-46: Avoid specifying long messages outside the exception class

(TRY003)


48-48: Avoid specifying long messages outside the exception class

(TRY003)


50-50: Avoid specifying long messages outside the exception class

(TRY003)


73-75: Avoid specifying long messages outside the exception class

(TRY003)


81-81: Avoid specifying long messages outside the exception class

(TRY003)


83-83: Avoid specifying long messages outside the exception class

(TRY003)


85-85: Avoid specifying long messages outside the exception class

(TRY003)


87-87: Avoid specifying long messages outside the exception class

(TRY003)


94-94: Avoid specifying long messages outside the exception class

(TRY003)


96-96: Avoid specifying long messages outside the exception class

(TRY003)

⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (6)
  • GitHub Check: Test (Python 3.10)
  • GitHub Check: Test (Python 3.13)
  • GitHub Check: Test (Python 3.11)
  • GitHub Check: Test (Python 3.12)
  • GitHub Check: Container build
  • GitHub Check: Pre-commit checks
🔇 Additional comments (10)
README.md (1)

1-10: LGTM! Good presentation improvement.

The centered layout and SonarQube badges improve the README's visual presentation and provide visibility into code quality metrics.

src/cordon/analysis/thresholder.py (1)

2-2: LGTM! Good practice for floating-point comparisons.

Replacing exact equality checks with isclose() addresses floating-point comparison warnings and is a best practice. The default tolerance is appropriate for these boundary checks.

Also applies to: 63-63, 67-67

src/cordon/cli.py (3)

211-227: LGTM! Well-structured helper reduces cognitive complexity.

The _print_backend_info helper consolidates backend configuration printing logic, making the main function cleaner and easier to maintain.


229-239: LGTM! Clear separation of filtering mode logic.

The _print_filtering_mode helper consolidates the range vs percentile mode display logic. The type narrowing assertion is valid given the config validation guarantees.


255-255: LGTM! Consistent use of float comparison and helper extraction.

Line 255 correctly uses isclose() for comparing the anomaly percentile against its default value. Lines 287-288 effectively reduce cognitive complexity by calling the extracted helper functions.

Also applies to: 287-288

src/cordon/core/config.py (5)

31-35: LGTM! Clean delegation reduces cognitive complexity.

The refactored __post_init__ method cleanly delegates to separate validation methods, making the validation logic more organized and maintainable.


37-50: LGTM! Comprehensive core parameter validation.

The method correctly validates all core analysis parameters with appropriate bounds and type checks. The handling of optional parameters (scoring_batch_size and device) is correct.


52-68: LGTM! Proper anomaly range validation.

The method correctly enforces that anomaly_range_min and anomaly_range_max are either both set or both None, validates their bounds, and ensures min < max. The type narrowing assertion is appropriate.


70-87: LGTM! Thorough backend validation.

The method validates the backend type and all backend-specific parameters correctly. The conditional validation for llama-cpp model path is appropriate, and the parameter bounds are well-defined (e.g., n_gpu_layers >= -1 allows for "all layers" option).


89-96: LGTM! Proper GGUF model path validation.

The method correctly validates that the llama-cpp model path exists and has the required .gguf extension. The assertion is safe given the method is only called when model_path is not None.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@calebevans calebevans added documentation Improvements or additions to documentation chore labels Dec 20, 2025
@calebevans calebevans self-assigned this Dec 20, 2025
@sonarqubecloud
Copy link

@calebevans calebevans merged commit 3c6cae4 into main Dec 20, 2025
8 checks passed
@calebevans calebevans deleted the sonarqube-fixes branch December 20, 2025 17:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

chore documentation Improvements or additions to documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants