Skip to content

Allow independent inclusion of the ruff linter and formatter #580

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

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

nathanjmcdougall
Copy link
Owner

No description provided.

Copy link

codspeed-hq bot commented Apr 26, 2025

CodSpeed Performance Report

Merging #580 will not alter performance

Comparing 561-allow-independent-inclusion-of-the-ruff-linter-and-formatter (252b8b0) with main (cced25a)

Summary

✅ 1 untouched benchmarks

Copy link

codecov bot commented Apr 26, 2025

Codecov Report

Attention: Patch coverage is 97.14286% with 1 line in your changes missing coverage. Please review.

Project coverage is 97.44%. Comparing base (cced25a) to head (252b8b0).

✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
src/usethis/_tool/impl/ruff.py 96.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #580      +/-   ##
==========================================
- Coverage   97.45%   97.44%   -0.01%     
==========================================
  Files         102      102              
  Lines        4408     4431      +23     
==========================================
+ Hits         4296     4318      +22     
- Misses        112      113       +1     

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

@nathanjmcdougall nathanjmcdougall marked this pull request as ready for review April 27, 2025 01:59
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR allows users to enable the Ruff linter and formatter independently by introducing separate flags across the tool’s implementation and CLI interface.

  • Introduces new linter and formatter parameters to RuffTool and updates its methods accordingly.
  • Adjusts pre-commit repository definitions, Bitbucket step generation, and test expectations to match the new behavior.

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

File Description
tests/usethis/_core/test_core_tool.py Updates expected hook removal message order to match the new hook ID assignment.
src/usethis/_tool/impl/ruff.py Adds independent toggles for linter/formatter and adjusts hook definitions and steps.
src/usethis/_interface/tool.py Updates the CLI options for the ruff command to pass the new linter and formatter flags.
src/usethis/_core/tool.py Modifies use_ruff to accept and forward the new flags; updates rule config logic accordingly.
Comments suppressed due to low confidence (1)

src/usethis/_core/tool.py:350

  • Consider using the existing 'tool' instance (i.e. tool.get_selected_rules()) instead of creating a new RuffTool instance to ensure the correct linter/formatter configuration is used.
or not RuffTool().get_selected_rules()


if not linter and not formatter:
msg = f"{self.name} must be used as either a linter, a formatter, or both."
raise NotImplementedError(msg)
Copy link
Preview

Copilot AI Apr 27, 2025

Choose a reason for hiding this comment

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

Consider raising a ValueError instead of NotImplementedError when both linter and formatter are false, as this reflects an invalid argument state.

Suggested change
raise NotImplementedError(msg)
raise ValueError(msg)

Copilot uses AI. Check for mistakes.

@nathanjmcdougall
Copy link
Owner Author

I think this needs some more thought. The attributes self.using_linter and self.using_formatter will be set to defaults when using RuffTool outside of a use_ruff context - e.g. in integrations with pre-commit etc.
I wonder whether we need a heuristic e.g. to see whether tool.ruff.lint config is set.

Bearing in mind that the user might be using the Ruff formatter even if they haven't used usethis tool ruff to do it, so we shouldn't assume too much.

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.

Allow independent inclusion of the Ruff linter and formatter
1 participant