-
Notifications
You must be signed in to change notification settings - Fork 4k
Description
Describe the bug, including details regarding any error messages, version, and platform.
The below description and proposed solution was generated by claude when I ran into this issue, so while I'm happy to make the change myself, please can someone verify this makes sense to do?
Describe the bug
The rubocop pre-commit hook attempts to install its environment even when committing changes that don't touch any Ruby files. This causes errors for developers who don't have Ruby installed, even when they're only working on R, Python, or other components.
Current behavior:
When committing changes to non-Ruby files (e.g., R package files), pre-commit tries to install the rubocop environment and fails if Ruby is not installed:
[INFO] Installing environment for https://github.com/rubocop/rubocop.
[INFO] Once installed this environment will be reused.
[INFO] This may take a few minutes...
An unexpected error has occurred: CalledProcessError: command: ('gem', 'build', 'rubocop.gemspec')
return code: 1
stdout:
Executable gem not found
Root cause:
In .pre-commit-config.yaml, the rubocop hook (lines 247-258) has an exclude filter but is missing a files filter:
- repo: https://github.com/rubocop/rubocop
rev: "v1.71.0"
hooks:
- id: rubocop
name: Ruby Format
alias: ruby
args:
- "--autocorrect"
exclude: >-
(
?^dev/tasks/homebrew-formulae/.*\.rb$|
)Without a files filter, pre-commit attempts to set up the hook environment for all commits, regardless of which files are being modified.
Proposed fix:
Add a files filter to only activate rubocop for Ruby files:
- repo: https://github.com/rubocop/rubocop
rev: "v1.71.0"
hooks:
- id: rubocop
files: \.rb$ # <-- Add this line
name: Ruby Format
alias: ruby
args:
- "--autocorrect"
exclude: >-
(
?^dev/tasks/homebrew-formulae/.*\.rb$|
)
This pattern is already used correctly in other hooks in the same config file.
Expected behavior:
The rubocop hook should only attempt to install/run when Ruby files are being committed.
Component(s)
Developer Tools