Skip to content

chore(linters): Introduce ruff and fix issues #831

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 26 commits into from
Apr 5, 2025
Merged

Conversation

MaxymVlasov
Copy link
Collaborator

@MaxymVlasov MaxymVlasov commented Feb 27, 2025

TBD:
After @webknjaz will approve config, split to 4 PRs:

  1. Config
  2. Automatic ruff fixes
  3. Manual fixes
  4. Unrelated + disable git blame to s.2

Copy link

coderabbitai bot commented Feb 27, 2025

📝 Walkthrough

Summary by CodeRabbit

  • Chores
    • Integrated state-of-the-art Python linting and formatting tools with auto-fix support, enhancing overall code quality.
    • Introduced robust, comprehensive configuration settings for consistent styling and improved error reduction.
  • Documentation
    • Updated error messaging to provide significantly clearer command line feedback during failures.
    • Added deprecation notices for an outdated feature, guiding users toward the new alternative.

Walkthrough

This pull request introduces a new pre-commit hook repository for Python linting by adding two Ruff hooks—one with an auto-fix argument and one for formatting—into the pre-commit configuration. It also adds a new ruff.toml configuration file that defines linting, formatting, and style preferences for the project. Additionally, the CLI documentation is updated to indicate that an error exit raises a specific exception, and a deprecation notice is inserted into the terraform docs replacement hook with guidance for future usage.

Changes

Files Change Summary
.pre-commit-config.yaml, ruff.toml Added new configuration for Ruff: the pre-commit config now references the Ruff repository (v0.8.4) with two hooks (ruff with --fix and ruff-format), and ruff.toml is introduced with settings for Python linting, formatting, line length, import styles, and per-file ignores.
src/pre_commit_terraform/_cli.py, src/pre_commit_terraform/terraform_docs_replace.py Updated source documentation: the CLI function’s docstring now notes that it raises a PreCommitTerraformExit on error, and a deprecation notice is added at the top of the terraform docs replacement file recommending the use of the terraform_docs hook instead.

Sequence Diagram(s)

sequenceDiagram
    participant Dev as Developer
    participant Git as Git Commit Process
    participant PC as Pre-commit Framework
    participant Ruff as Ruff Linter
    participant Formatter as Ruff-Format Hook

    Dev->>Git: Initiate commit
    Git->>PC: Trigger pre-commit hooks
    PC->>Ruff: Run Ruff hook (--fix)
    Ruff-->>PC: Return linting results & auto-fixed code
    PC->>Formatter: Run Ruff-format hook
    Formatter-->>PC: Return formatting results
    PC-->>Git: Validate commit (pass/fail)
    Git-->>Dev: Complete commit
Loading

📜 Recent review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Free

📥 Commits

Reviewing files that changed from the base of the PR and between a6c9b5f and 641399c.

📒 Files selected for processing (2)
  • ruff.toml (1 hunks)
  • src/pre_commit_terraform/_cli.py (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • src/pre_commit_terraform/_cli.py
  • ruff.toml

Note

🎁 Summarized by CodeRabbit Free

Your organization has reached its limit of developer seats under the Pro Plan. For new users, CodeRabbit will generate a high-level summary and a walkthrough for each pull request. For a comprehensive line-by-line review, please add seats to your subscription by visiting https://app.coderabbit.ai/login.If you believe this is a mistake and have available seats, please assign one to the pull request author through the subscription management page using the link above.

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai plan to trigger planning for file edits and PR creation.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

codecov bot commented Feb 27, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 98.44%. Comparing base (e41252b) to head (641399c).
Report is 1 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master     #831   +/-   ##
=======================================
  Coverage   98.44%   98.44%           
=======================================
  Files          28       28           
  Lines         578      578           
  Branches       17       17           
=======================================
  Hits          569      569           
  Misses          9        9           
Flag Coverage Δ
CI-GHA 98.44% <100.00%> (ø)
MyPy 91.43% <100.00%> (ø)
OS-Linux 94.71% <100.00%> (ø)
OS-Windows 100.00% <100.00%> (ø)
OS-macOS 100.00% <ø> (ø)
Py-3.10.11 100.00% <100.00%> (ø)
Py-3.10.16 100.00% <ø> (ø)
Py-3.11.11 100.00% <ø> (ø)
Py-3.11.9 100.00% <100.00%> (ø)
Py-3.12.9 100.00% <100.00%> (ø)
Py-3.13.2 98.44% <100.00%> (ø)
Py-3.9.13 100.00% <100.00%> (ø)
Py-3.9.21 100.00% <ø> (ø)
VM-macos-13 100.00% <ø> (ø)
VM-macos-14 100.00% <ø> (ø)
VM-ubuntu-24.04 100.00% <ø> (ø)
VM-ubuntu-latest 91.43% <100.00%> (ø)
VM-windows-2025 100.00% <100.00%> (ø)
pytest 100.00% <100.00%> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@yermulnik

This comment was marked as resolved.

@MaxymVlasov

This comment was marked as resolved.

@yermulnik

This comment was marked as resolved.

@webknjaz
Copy link
Contributor

4 PRs:

unrelated is a separate PR. blame ignore is a separate PR. Plus I noticed reshuffling logic which is another one. So it's like 6 PRs.

@webknjaz
Copy link
Contributor

Also, plan for adding https://wemake-python-styleguide.rtfd.io on top after all this.

from subprocess import CalledProcessError
from argparse import ArgumentParser
from argparse import Namespace
from subprocess import CalledProcessError # noqa: S404. We invoke cli tools
Copy link
Contributor

Choose a reason for hiding this comment

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

Subprocess interaction should probably be quarantined in a dedicated module where these noqas would be allowed and nowhere else. That module should implement wrappers that the rest of the project would call. This design allows keeping all potentially dangerous code in one place that you can be extra careful about.

@MaxymVlasov MaxymVlasov requested a review from webknjaz March 25, 2025 22:16
@webknjaz
Copy link
Contributor

webknjaz commented Apr 3, 2025

All those noqas could've gone into a separate PR, I think. Or into that manual one. You can split them out or enclose all the justifications here.

@MaxymVlasov MaxymVlasov requested a review from webknjaz April 3, 2025 21:47
@MaxymVlasov MaxymVlasov requested a review from webknjaz April 4, 2025 13:36
@MaxymVlasov MaxymVlasov marked this pull request as ready for review April 5, 2025 12:39
@MaxymVlasov MaxymVlasov merged commit f7717cd into master Apr 5, 2025
47 checks passed
@MaxymVlasov MaxymVlasov deleted the introduce_ruff branch April 5, 2025 12:43
@antonbabenko
Copy link
Owner

This PR is included in version 1.98.1 🎉

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