-
Notifications
You must be signed in to change notification settings - Fork 126
Upgrade RuboCop cops to v1 API #3512
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
Conversation
🦋 Changeset detectedLatest commit: 6c151a2 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
Co-authored-by: jonrohan <[email protected]>
Co-authored-by: jonrohan <[email protected]>
|
This reverts commit 5a126a1.
# Please enter a commit message to explain why this merge is necessary, # especially if it merges an updated upstream into a topic branch. # # Lines starting with '#' will be ignored, and an empty message aborts # the commit.
I've reverted commit 5a126a1 and merged main into the branch as requested. The changes are now available in commit d648739. Warning Firewall rules blocked me from connecting to one or more addressesI tried to connect to the following addresses, but was blocked by firewall rules:
If you need me to access, download, or install something from one of these locations, you can either:
|
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 updates all custom RuboCop cops to the v1 API by switching to the new RuboCop::Cop::Base
base class, adding extend AutoCorrector
and migrating deprecated autocorrect
methods into add_offense
blocks. It also adapts the test helper to use RuboCop’s Commissioner API.
- Inherit from
RuboCop::Cop::Base
and addextend AutoCorrector
in all cops - Move autocorrect logic into
add_offense
blocks and remove oldautocorrect
methods - Update
CopTestCase
to capture offenses from RuboCop v1’s Commissioner
Reviewed Changes
Copilot reviewed 12 out of 12 changed files in this pull request and generated 1 comment.
File | Description |
---|---|
test/lib/cop_test_case.rb | Adapted investigate to use the new Commissioner API |
lib/rubocop/cop/primer/primer_octicon.rb | Switched to Base , added autocorrect block, cleaned up formatting |
lib/rubocop/cop/primer/deprecated_label_schemes.rb | Added autocorrect block, updated inheritance, minor formatting |
Comments suppressed due to low confidence (2)
result = commissioner.investigate(processed_source) | ||
# Store offenses in the cop for backward compatibility with existing tests | ||
def cop.offenses | ||
@offenses ||= [] | ||
end | ||
cop.instance_variable_set(:@offenses, result.offenses) |
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.
The investigate
method returns nil in RuboCop v1, so result.offenses
will raise a NoMethodError. Instead, call commissioner.investigate(processed_source)
without assignment and extract offenses from the cop
instance (e.g., use cop.instance_variable_get(:@offenses)
directly).
result = commissioner.investigate(processed_source) | |
# Store offenses in the cop for backward compatibility with existing tests | |
def cop.offenses | |
@offenses ||= [] | |
end | |
cop.instance_variable_set(:@offenses, result.offenses) | |
commissioner.investigate(processed_source) | |
# Store offenses in the cop for backward compatibility with existing tests | |
def cop.offenses | |
@offenses ||= [] | |
end | |
cop.instance_variable_set(:@offenses, cop.instance_variable_get(:@offenses)) |
Copilot uses AI. Check for mistakes.
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.
This seems... fine? I think we should of course verify these changes manually.
@@ -54,3 +54,4 @@ demo/public/vite-test/ | |||
demo/public/vite-dev/ | |||
demo/public/vite/ | |||
demo/app/assets/builds/ | |||
File::NULL |
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.
What is this for?
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.
$stderr.reopen(File.new("File::NULL", "w")) |
After running rake, there was a file in my workspace, so I added to gitignore
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.
Wild. Never seen it before!
This PR upgrades all RuboCop cops in the repository to use the RuboCop v1 API, eliminating deprecation warnings and ensuring compatibility with modern RuboCop versions.
Changes Made
Class Inheritance Updates
RuboCop::Cop::Base
instead of the deprecatedRuboCop::Cop::Cop
lib/rubocop/cop/primer/base_cop.rb
lib/rubocop/cop/primer/no_tag_memoize.rb
lib/rubocop/cop/primer/primer_octicon.rb
lib/primer/view_components/linters/migrations/iconbutton_component.rb
lib/primer/view_components/linters/migrations/truncate_component.rb
Autocorrect Method Migration
autocorrect
methods with the new RuboCop v1 pattern:extend AutoCorrector
to cop classesadd_offense
blocksComponentNameMigration
PrimerOcticon
IconButtonComponent
andTruncateComponent
migrationsDeprecatedArguments
,DeprecatedButtonArguments
DeprecatedLabelSchemes
,DeprecatedLabelVariants
Test Framework Updates
CopTestCase
to work with RuboCop v1's new Commissioner APIcop.offenses
Before/After
Before (RuboCop v0 style):
After (RuboCop v1 style):
Testing
Fixes #3351.
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.