Skip to content

Emit a deprecation when custom cops inherit from RuboCop::Cop::Cop #13253

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 1 commit into from
Sep 21, 2024

Conversation

Earlopain
Copy link
Contributor

This has been long-marked as deprecated but not everyone has gotten the memo: https://github.com/search?q=%2F%3C+RuboCop%3A%3ACop%3A%3ACop%2F+lang%3Aruby+-is%3Afork&type=code

Some methods are deprecated but its perfectly possible to just not use any of them.

Followup to #13032 and #13244


Before submitting the PR make sure the following are checked:

  • The PR relates to only one subject with a clear title and description in grammatically correct, complete sentences.
  • Wrote good commit messages.
  • Commit message starts with [Fix #issue-number] (if the related issue exists).
  • Feature branch is up-to-date with master (if not - rebase it).
  • Squashed related commits together.
  • Added tests.
  • Ran bundle exec rake default. It executes all tests and runs RuboCop on its own code.
  • Added an entry (file) to the changelog folder named {change_type}_{change_description}.md if the new code introduces user-observable changes. See changelog entry format for details.

This has been long-marked as deprecated but not everyone has gotten the memo:
https://github.com/search?q=%2F%3C+RuboCop%3A%3ACop%3A%3ACop%2F+lang%3Aruby+-is%3Afork&type=code

Some methods _are_ deprecated but its perfectly possible to just not use any of them.
@koic koic merged commit cabd576 into rubocop:master Sep 21, 2024
22 checks passed
@Earlopain Earlopain deleted the cop-cop-deprecation-warning branch September 29, 2024 19:26
jeromedalbert added a commit to jeromedalbert/rubocop-obsession that referenced this pull request Oct 28, 2024
Rubocop 1.67.0 warns that `RuboCop::Cop::Cop` is deprecated, and
`RuboCop::Cop::Base` should be used instead. See
rubocop/rubocop#13253.

Fixes #2
juliantrueflynn added a commit to ezcater/ezcater_rubocop that referenced this pull request Dec 4, 2024
What did we change?

Refactor following the [V1 Upgrade Guide](https://docs.rubocop.org/rubocop/v1_upgrade_notes.html).

I broke down the upgrade into commits to make it easier to review. The main overview though is:
- Replace custom cops inheriting from `RuboCop::Cop::Cop` to inherit from `RuboCop::Cop::Base`
- Refactor to new `#add_offense` API, which removes `:location` argument
- Refactor tests to now recommended matchers `#expect_offense`, `#expect_no_offenses`, `#expect_correction`, `#expect_no_corrections` (this is the biggest code change). This had to be done because the existing use of `#inspect_source` was tied to `RuboCop::Cop::Cop`.
- Replace `#autocorrect` to new API that yields it from `#add_offense`

NOTE: Based on docs linked, this is all backwards compatible and not a breaking change for clients.

Why are we doing this?

With [rubocop v1.67](https://github.com/rubocop/rubocop/releases/tag/v1.67.0) it now logs deprecation warnings in console for Cops inheriting from `RuboCop::Cop::Cop` instead of `RuboCop::Cop::Base` (see relevant PR [here](rubocop/rubocop#13253)). While doing this fix I followed the rest of the v1 upgrade steps.
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.

2 participants
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy