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 NegatedMatcher configuration option to RSpec/ChangeByZero #1349

Merged
merged 1 commit into from
Aug 9, 2022

Conversation

ydah
Copy link
Member

@ydah ydah commented Aug 3, 2022

This PR is add NegatedMatcher option to RSpec/ChangeByZero.

In the case of composite expectations, cop suggest using the negation matchers of RSpec::Matchers#change.
By default doe's not support autocorrect, but if you set the negation matcher of RSpec::Matchers#change defined in NegatedMatcher option, will be autocorrect.


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 is configured as Enabled: true in .rubocop.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.

If you have modified an existing cop's configuration options:

  • Set VersionChanged in config/default.yml to the next major 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.

Looks great, thank you!

I've just learned to use the suggestion feature the other day, please don't judge me too hard for its abuse, and please don't hesitate to reject and discuss suggestions just as before as you see fit.

lib/rubocop/cop/rspec/change_by_zero.rb Outdated Show resolved Hide resolved
lib/rubocop/cop/rspec/change_by_zero.rb Outdated Show resolved Hide resolved
lib/rubocop/cop/rspec/change_by_zero.rb Outdated Show resolved Hide resolved
lib/rubocop/cop/rspec/change_by_zero.rb Outdated Show resolved Hide resolved
lib/rubocop/cop/rspec/change_by_zero.rb Outdated Show resolved Hide resolved
config/default.yml Outdated Show resolved Hide resolved
spec/rubocop/cop/rspec/change_by_zero_spec.rb Outdated Show resolved Hide resolved
spec/rubocop/cop/rspec/change_by_zero_spec.rb Outdated Show resolved Hide resolved
spec/rubocop/cop/rspec/change_by_zero_spec.rb Outdated Show resolved Hide resolved
spec/rubocop/cop/rspec/change_by_zero_spec.rb Outdated Show resolved Hide resolved
@pirj pirj requested review from Darhazer and bquorning August 3, 2022 18:26
@ydah ydah force-pushed the add_option_for_change_by_zero branch 4 times, most recently from 118054e to 9a19cac Compare August 3, 2022 22:43
ydah added a commit to ydah/rubocop-rspec that referenced this pull request Aug 4, 2022
@pirj pirj closed this in #1352 Aug 4, 2022
@pirj pirj reopened this Aug 4, 2022
@pirj pirj force-pushed the add_option_for_change_by_zero branch from 9a19cac to 4e7abe7 Compare August 4, 2022 00:33
@ydah
Copy link
Member Author

ydah commented Aug 4, 2022

Now passed the CI for default.yml .

compound expectations, but if you set the
negated matcher for `change`, e.g. `not_change` with
the `NegatedMatcher` option, the cop will perform the autocorrection.
`NegatedMatcher` option, will be autocorrect.
Copy link
Member

Choose a reason for hiding this comment

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

this seems redundant?

Copy link
Member Author

Choose a reason for hiding this comment

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

I was adding that I thought it might be confusing for cases that does not support autocorrected. I think a polite explanation would be about right. What do you think?

Copy link
Member

Choose a reason for hiding this comment

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

I mean that the last sentence, ``NegatedMatcher option, will be autocorrect. is just repeating the previous one, and it's also incomplete anyway

Copy link
Member Author

Choose a reason for hiding this comment

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

Ah! I was mistaken. Thank you very much. It is indeed so I have corrected it. How about it?

spec/rubocop/cop/rspec/change_by_zero_spec.rb Show resolved Hide resolved
@ydah ydah force-pushed the add_option_for_change_by_zero branch 3 times, most recently from 8bddf70 to b01f898 Compare August 4, 2022 22:52
@ydah ydah mentioned this pull request Aug 4, 2022
4 tasks
@ydah ydah requested a review from Darhazer August 5, 2022 04:43
This PR is add `NegatedMatcher` option to `RSpec/ChangeByZero`.

In the case of composite expectations, cop suggest
using the negation matchers of `RSpec::Matchers#change`.

By default doe's not support autocorrect,
but if you set the negation matcher of `RSpec::Matchers#change`
defined in `NegatedMatcher` option, will be autocorrect.
@ydah ydah force-pushed the add_option_for_change_by_zero branch from b01f898 to 2d32d0d Compare August 7, 2022 01:25
@Darhazer Darhazer merged commit 8363111 into rubocop:master Aug 9, 2022
@ydah ydah deleted the add_option_for_change_by_zero branch August 9, 2022 09:54
pirj pushed a commit to rubocop/rubocop-capybara that referenced this pull request Dec 29, 2022
ydah added a commit to rubocop/rubocop-factory_bot that referenced this pull request Apr 13, 2023
ydah added a commit to rubocop/rubocop-rspec_rails that referenced this pull request Mar 27, 2024
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.

3 participants