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

Add new RSpec/IdenticalEqualityAssertion cop #1132

Merged
merged 1 commit into from
May 25, 2021

Conversation

tejasbubane
Copy link
Contributor

Closes #1130


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).

If you have created a new cop:

  • Added the new cop to config/default.yml.
  • The cop is configured as Enabled: pending in config/default.yml.
  • The cop documents examples of good and bad code.
  • The tests assert both that bad code is reported and that good code is not reported.
  • Set VersionAdded in default/config.yml to the next minor version.

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.

Since it's a new cop, do you mind to run it against https://github.com/pirj/real-world-rspec?
Usually, I remove all .rubocop.yml files in it manually. And each time I wish rubocop had an option to ignore config files in the source code.

Looks good in general.
Just a small note regarding the offence message and sanity check against popular repos using RSpec.

Thank you for another contribution!

lib/rubocop/cop/rspec/identical_equality_assertion.rb Outdated Show resolved Hide resolved
lib/rubocop/cop/rspec/identical_equality_assertion.rb Outdated Show resolved Hide resolved
@tejasbubane tejasbubane force-pushed the fix-1130 branch 2 times, most recently from 8ee8c41 to 3db1f43 Compare February 21, 2021 11:23
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.

Perfect. Thank you!

@pirj pirj requested a review from Darhazer February 21, 2021 11:24
@tejasbubane
Copy link
Contributor Author

@pirj I ran this cop on real-world-rspec and found these offenses:
https://gist.github.com/tejasbubane/e64636d7c7dd97c4b056a09b09a6c61b

@pirj
Copy link
Member

pirj commented Feb 21, 2021

@tejasbubane 99% look completely legit!

expect(true).to eq(true)

😆

Some are (rspec-core) testing the RSpec itself, but it's ok to flag them:

it("equality") { expect(1).to eq(1) }

The only one that is probably a false offence:

expect(fqdn_rand(3)).to eql(fqdn_rand(3))

Thank you!

BTW, did you feel the pain of removing .rubocop YAML files from that repo? 😄

@tejasbubane
Copy link
Contributor Author

BTW, did you feel the pain of removing .rubocop YAML files from that repo?

No I ran with --only RSpec/IdenticalEqualityAssertion :)

@pirj pirj requested review from bquorning and removed request for Darhazer March 22, 2021 21:19
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.

Good stuff. Only nitpick comments.

lib/rubocop/cop/rspec/identical_equality_assertion.rb Outdated Show resolved Hide resolved
lib/rubocop/cop/rspec/identical_equality_assertion.rb Outdated Show resolved Hide resolved
@tejasbubane tejasbubane force-pushed the fix-1130 branch 2 times, most recently from a6e9fd7 to 9bdc6c3 Compare March 23, 2021 11:03
@tejasbubane
Copy link
Contributor Author

tejasbubane commented Mar 23, 2021

@bquorning Thanks. Fixed as per your comments.

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.

Thanks!

@pirj
Copy link
Member

pirj commented May 24, 2021

ran this cop on real-world-rspec and found these offenses:

BTW, did you feel the pain of removing .rubocop YAML files from that repo?

No I ran with --only RSpec/IdenticalEqualityAssertion :)

Do you mind sharing how you do it, @tejasbubane ?

~/source/rubocop-rspec $ rubocop --only RSpec/Rails/AvoidSetupHook ../real-world-rspec/
Error: RuboCop found unsupported Ruby version 2.4 in `TargetRubyVersion` parameter (in /Users/pirj/source/real-world-rspec/fat_free_crm/.rubocop.yml). 2.4-compatible analysis was dropped after version 1.12.
Supported versions: 2.5, 2.6, 2.7, 3.0, 3.1

same for real-world-rspec/camaleon-cms/.rubocop.yml
After removing them:

Error: The `Layout/AlignParameters` cop has been renamed to `Layout/ParameterAlignment`.
(obsolete configuration found in /Users/pirj/source/real-world-rspec/rspec-mocks/.rubocop_rspec_base.yml, please update it)
The `Layout/IndentArray` cop has been renamed to `Layout/FirstArrayElementIndentation`.
(obsolete configuration found in /Users/pirj/source/real-world-rspec/rspec-mocks/.rubocop_rspec_base.yml, please update it)
The `Layout/IndentAssignment` cop has been renamed to `Layout/AssignmentIndentation`.
(obsolete configuration found in /Users/pirj/source/real-world-rspec/rspec-mocks/.rubocop_rspec_base.yml, please update it)
The `Layout/IndentHeredoc` cop has been renamed to `Layout/HeredocIndentation`.
(obsolete configuration found in /Users/pirj/source/real-world-rspec/rspec-mocks/.rubocop_rspec_base.yml, please update it)
The `Style/TrailingCommaInLiteral` cop has been removed. Please use `Style/TrailingCommaInArrayLiteral` and/or `Style/TrailingCommaInHashLiteral` instead.
(obsolete configuration found in /Users/pirj/source/real-world-rspec/rspec-mocks/.rubocop_rspec_base.yml, please update it)
The `Style/MethodMissing` cop has been split into `Style/MethodMissingSuper` and `Style/MissingRespondToMissing`.
(obsolete configuration found in /Users/pirj/source/real-world-rspec/rspec-mocks/.rubocop_rspec_base.yml, please update it)

I have those one-liners handy:

fd --no-ignore --hidden 'rubocop*.yml' | xargs rm

and

for repo in $(fd --type d --maxdepth 1); do; (cd "$repo"; git reset --hard HEAD); done

But I'd rather run rubocop --only and skip those unrelated errors.

@tejasbubane
Copy link
Contributor Author

@pirj Not sure how I ran with --only back then, but this worked when I tried now:

$ cat Gemfile     
source 'https://rubygems.org'

gem 'rubocop', path: '../rubocop'
gem 'rubocop-rspec', path: '../rubocop-rspec' # Contains newly built / unreleased cops
$ cat .rubocop.yml
require:
  - rubocop-rspec

AllCops:
  DisabledByDefault: true

RSpec/IdenticalEqualityAssertion:
  Enabled: true
$ bundle exec rubocop --config .rubocop.yml   
.....
54137 files inspected, 115 offenses detected

@pirj
Copy link
Member

pirj commented May 24, 2021

Thanks, that works!

@bquorning bquorning requested a review from Darhazer May 25, 2021 17:55
@pirj pirj merged commit e0e109c into rubocop:master May 25, 2021
@tejasbubane tejasbubane deleted the fix-1130 branch May 25, 2021 18:06
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.

Cop idea: Identical equality assertion
5 participants