Skip to content
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

Better assist rspec rails cop users when migrating to 3 #1931

Merged
merged 1 commit into from
Jul 2, 2024

Conversation

jeppester
Copy link
Contributor

@jeppester jeppester commented Jun 24, 2024

Related issue: #1928

Previously you would first get:

Error: The `RSpec/Rails/InferredSpecType` cop has been moved to `RSpecRails/InferredSpecType`.
(obsolete configuration found in .rubocop.yml, please update it)

Then after renaming the cop, you would get:

Error: unrecognized cop or department RSpecRails/InferredSpecType found in .rubocop.yml
Did you mean `RSpec/RepeatedDescription`?

Which would be a dead end.

This is my attempt to lead users in a better direction.

I'm unsure about how to test this. Are there tests for obsoletion texts?
I'm also unsure if I need to check the documentation checkboxes for this?


Before submitting the PR make sure the following are checked:

  • Feature branch is up-to-date with master (if not - rebase it).
  • Squashed related commits together.
  • Added tests.
  • Updated documentation.
  • Added an entry to the CHANGELOG.md if the new code introduces user-observable changes.
  • The build (bundle exec rake) passes (be sure to run this locally, since it may produce updated documentation that you will need to commit).

@jeppester jeppester requested a review from a team as a code owner June 24, 2024 07:20
Copy link
Collaborator

@bquorning bquorning left a comment

Choose a reason for hiding this comment

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

You’re right, we forgot to change the obsoletion configuration before releasing v3.0.0, sorry about that.

A couple of things:

  1. We should probably use the extracted key instead,
    extracted of removed, e.g.
    extracted:
      RSpec/Rails/*: rubocop-rspec_rails
  2. I don’t see that RuboCop tests the extracted feature with nested namespaces, so we should at least to manual testing to ensure it actually works.
  3. In v3.0.0 we also extracted rubocop-factory_bot and rubocop-capybara, so we should fix the config for those cops as well.

Let me know if this is too much scope creep; I’m happy to fix it myself as well 😄

@jeppester
Copy link
Contributor Author

jeppester commented Jun 24, 2024

We should probably use the extracted key instead,
extracted of removed, e.g.

extracted:
  RSpec/Rails/*: rubocop-rspec_rails

Nice, I was not aware of this feature, I just reused what was already in the config file 👍

I don’t see that RuboCop tests the extracted feature with nested namespaces, so we should at least to manual testing to ensure it actually works.

I'll have a look

In v3.0.0 we also extracted rubocop-factory_bot and rubocop-capybara, so we should fix the config for those cops as well.

Makes sense. I took those from #1830, but it would obviously make sense to include the others.

Let me know if this is too much scope creep; I’m happy to fix it myself as well 😄

I'll give it a shot, then hand it over if it grows too much in complexity. 😄

@bquorning bquorning requested a review from a team June 24, 2024 08:45
@jeppester
Copy link
Contributor Author

jeppester commented Jun 24, 2024

I've changed it as suggested.

The extra layer of nesting seems to be working fine.

  1. Before adding rubocop-rspec_rails I get:
Error: `RSpec/Rails/*` has been extracted to the `rubocop-rspec_rails` gem.
(obsolete configuration found in .rubocop.yml, please update it)
  1. After adding rubocop-rspec_rails to require, rubocop finishes successfully, but I get a warning:
.rubocop.yml: RSpec/Rails/InferredSpecType has the wrong namespace - replace it with RSpecRails/InferredSpecType
  1. After updating the config file, the warning goes away.

Will this warning trigger for all the affected cops? And is it okay that it's only a warning?
I'm thinking if it would make sense to add the renamed config that this PR removes from rubocop-rspec to each of the new gems respectively, or if that would be unnecessary?

@bquorning
Copy link
Collaborator

I'm thinking if it would make sense to add the renamed config that this PR removes from rubocop-rspec to each of the new gems respectively, or if that would be unnecessary?

@ydah what you think about this suggestion?

@bquorning bquorning requested a review from pirj June 26, 2024 14:30
Copy link
Member

@pirj pirj left a comment

Choose a reason for hiding this comment

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

Wow, this is incredible! 🤩

I feel ashamed to have missed this, as it was indeed present in the rubocop's own obsoletion config.

LGTM, and thank you, @jeppester !

@pirj
Copy link
Member

pirj commented Jun 26, 2024

I can't push to your master @jeppester , can you please add the changelog (please feel free to reword):

diff --git CHANGELOG.md CHANGELOG.md
index f35c9f36..a932dab9 100644
--- CHANGELOG.md
+++ CHANGELOG.md
@@ -4,6 +4,7 @@

 - Fix wrong autocorrect for `RSpec/ScatteredSetup` when hook contains heredoc. ([@earlopain])
 - Fix false negative for `RSpec/PredicateMatcher` when expectation contains custom failure message. ([@earlopain])
+- Facilitate the 3.0 upgrade flow with proper extracted cop messages. ([@jeppester])

 ## 3.0.1 (2024-06-11)

@@ -936,6 +937,7 @@ Compatibility release so users can upgrade RuboCop to 0.51.0. No new features.
 [@jaredmoody]: https://github.com/jaredmoody
 [@jdufresne]: https://github.com/jdufresne
 [@jeffreyc]: https://github.com/jeffreyc
+[@jeppester]: https://github.com/jeppester
 [@jessieay]: https://github.com/jessieay
 [@jfragoulis]: https://github.com/jfragoulis
 [@johnny-miyake]: https://github.com/johnny-miyake

@ydah
Copy link
Member

ydah commented Jun 27, 2024

I'm thinking if it would make sense to add the renamed config that this PR removes from rubocop-rspec to each of the new gems respectively, or if that would be unnecessary?

@ydah what you think about this suggestion?

I would like to know how the output would look like if I add that.

@ydah
Copy link
Member

ydah commented Jun 27, 2024

Perhaps the following changes should be implemented in rubocop-capybara, rubocop-factory_bot and rubocop-rspec_rails.

# example of rubocop-capybara
extracted:
  RSpec/Capybara/*: ~

refs: rubocop/rubocop-rails@ec17390

@pirj
Copy link
Member

pirj commented Jun 27, 2024

I think that extracted made renamed entirely redundant in our case.

The output for the cases when the extracted gems aren’t bundled and are bundled, but extracted cops are still referenced by their old names are in this comment.

I’d be most interested in edge cases, like:

  1. Telling the user to also explicitly enable those new departments if they have AllCops/Enabled: false
  2. Double-check if we’ve done something more than just changed the department like RSpec/Capybara/PredicateMatcher Capybara/RSpec/PredicateMatcher (instead of just Capybara/PredicateMatcher. @ydah would you like to check how it worked for our users during the upgrade to 3.0 with renamed obsoletion and the new extracted? Like you say, we may need to add renamed in the extracted extensions’ obsoletion config.

In any case, I don’t see those as blockers, as this change makes the upgrade smoother anyway.

@jeppester
Copy link
Contributor Author

I can't push to your master @jeppester , can you please add the changelog (please feel free to reword):

Done.

Let me know if there's more I need to do.

Copy link
Member

@ydah ydah left a comment

Choose a reason for hiding this comment

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

Thank you!

@ydah
Copy link
Member

ydah commented Jul 1, 2024

@jeppester Could you squash two commits?

Previously you would first get:
```
Error: The `RSpec/Rails/InferredSpecType` cop has been moved to `RSpecRails/InferredSpecType`.
(obsolete configuration found in .rubocop.yml, please update it)
```

Then after renaming the cop, you would get:
```
Error: unrecognized cop or department RSpecRails/InferredSpecType found in .rubocop.yml
Did you mean `RSpec/RepeatedDescription`?
```

Which would be a dead end.
@jeppester
Copy link
Contributor Author

@jeppester Could you squash two commits?

Done

@pirj pirj merged commit 9ca2541 into rubocop:master Jul 2, 2024
24 checks passed
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.

4 participants