-
Notifications
You must be signed in to change notification settings - Fork 4
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
Allow independent inclusion of the ruff linter and formatter #580
Conversation
CodSpeed Performance ReportMerging #580 will not alter performanceComparing Summary
|
Codecov ReportAll modified and coverable lines are covered by tests ✅
✅ All tests successful. No failed tests found. Additional details and impacted files@@ Coverage Diff @@
## main #580 +/- ##
==========================================
+ Coverage 97.51% 97.54% +0.02%
==========================================
Files 102 102
Lines 4463 4515 +52
==========================================
+ Hits 4352 4404 +52
Misses 111 111 ☔ View full report in Codecov by Sentry. |
There was a problem hiding this 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()
I think this needs some more thought. The attributes Bearing in mind that the user might be using the Ruff formatter even if they haven't used |
Two options - [tool.usethis] configuration to over-ride the heuristic. Or - add dummy default config for the formatter to use instead. |
|
However, I think we need to be realistic about how common it will be for the ruff formatter to be used without any configuration... A lack of config shouldn't be a sign that the formatter isn't being used necessarily. On the other hand, if the linter doesn't have any config, that's another matter. |
…linter-and-formatter
Ultimately, there needs to be some heuristic to determine whether each of the linter and formatter are being used. The exact heuristic that is used might not be clear yet. But that shouldn't affect this re-architecting. For now, I will keep it simple and rely on the presence of a This might be perceived as a breaking change, since users without the |
…linter-and-formatter
….py:_run_tool The idea here is to try and keep things in-sync with the UseToolFunc protocol and avoid accidentally omitting the `how` kwarg. The type checker should detect this issue now.
…linter-and-formatter
…linter-and-formatter
…linter-and-formatter
…ormatter_used` methods.
In this case, we assume both the formatter and the linter are used.
…flects new behaviour to assume all submodels are used when none of them have config.
There was a problem hiding this 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 enables users to include the Ruff linter and formatter independently by introducing --linter
and --formatter
flags throughout the CLI, core logic, and tool implementation. Key changes include:
- Adding
force_linter
/force_formatter
flags and subtool detection toRuffTool
- Extending the CLI (
usethis tool ruff
) anduse_ruff
core function to accept and pass through new flags - Updating tests to cover default, linter-only, and formatter-only scenarios, and adjusting removal output order
Reviewed Changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated no comments.
Show a summary per file
File | Description |
---|---|
tests/usethis/_tool/impl/test_ruff.py | Added tests for default, linter-only, and formatter-only cases |
tests/usethis/_core/test_core_tool.py | Introduced tests for subtool-only addition and reordered removal output |
src/usethis/_tool/impl/ruff.py | Enhanced RuffTool with conditional config, hooks, and CI steps based on subtool flags |
src/usethis/_interface/tool.py | Added --linter /--formatter CLI options and passed them into _run_tool |
src/usethis/_core/tool.py | Updated use_ruff signature and logic to use force_linter /force_formatter |
Comments suppressed due to low confidence (2)
src/usethis/_core/tool.py:415
- The removal branch always drops both linter and formatter artifacts, ignoring the
linter
/formatter
flags. Update this to conditionally remove only the requested subtool (e.g., wrapremove_pre_commit_repo_configs
,remove_configs
, etc., inif linter:
orif formatter:
checks).
else:
src/usethis/_interface/tool.py:249
Any
is only imported underif TYPE_CHECKING
, so this runtime annotation will raise a NameError. Movefrom typing import Any
out of theTYPE_CHECKING
block or quote the annotation to defer evaluation.
def _run_tool(caller: UseToolFunc, *, remove: bool, how: bool, **kwargs: Any):
… exist in a TOML file
…itly in Bitbucket integration
There was a problem hiding this 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 enables independent inclusion and removal of Ruff’s linter and formatter by updating both the underlying tool configuration and the CI pipelines.
- Updated test cases to assert independent detection of linter and formatter usage.
- Modified the command‐line interface to support distinct linter/formatter options.
- Refactored the RuffTool class to add detection logic and adjust configuration specifications accordingly.
Reviewed Changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated 1 comment.
Show a summary per file
File | Description |
---|---|
tests/usethis/_tool/impl/test_ruff.py | Added tests for independent detection of linter and formatter configurations. |
tests/usethis/_interface/test_ci.py | Updated CI test output to include the Ruff Formatter. |
tests/usethis/_core/test_core_ci.py | Enhanced Bitbucket pipeline tests with Ruff Formatter steps. |
src/usethis/_tool/impl/ruff.py | Refactored RuffTool to accept separate detection parameters and adjusted config and pre-commit repo settings. |
src/usethis/_tool/base.py | Optimized config spec retrieval by reusing a stored variable for maintainability. |
src/usethis/_interface/tool.py | Extended the CLI, adding options for linter and formatter selection. |
src/usethis/_integrations/ci/bitbucket/steps.py | Updated Bitbucket steps to include running Ruff Formatter. |
src/usethis/_core/tool.py | Modified the use_ruff function to pass linter/formatter options to RuffTool, adjusting behavior for adding and removal. |
Comments suppressed due to low confidence (2)
src/usethis/_tool/impl/ruff.py:208
- The hook IDs have been swapped (linter now uses 'ruff' and formatter uses 'ruff-format'), which might be confusing. Please confirm that these IDs align with the project's naming conventions and update comments if necessary.
id="ruff",
src/usethis/_tool/impl/ruff.py:535
- The auto detection logic now hinges on the absence of both subtool configurations. Consider adding test cases to cover scenarios where only one configuration is present versus none to ensure the logic behaves as expected.
def is_no_subtool_config_present(self) -> bool:
No description provided.