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 comparison style to Style/NilComparison #6218

Merged

Conversation

khiav223577
Copy link
Contributor

@khiav223577 khiav223577 commented Aug 25, 2018

Summary

This PR add a new style for Style/NilComparison. It allows developers to choose which style they prefer (nil? or == nil).


Before submitting the PR make sure the following are checked:

  • 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.
  • Added an entry to the Changelog if the new code introduces user-observable changes. See changelog entry format.
  • The PR relates to only one subject with a clear title
    and description in grammatically correct, complete sentences.
  • Run rake default or rake parallel. It executes all tests and RuboCop for itself, and generates the documentation.

@khiav223577 khiav223577 force-pushed the feature/add_explicit_comparison_style branch from aba301a to a4165e0 Compare August 25, 2018 16:57
@khiav223577 khiav223577 force-pushed the feature/add_explicit_comparison_style branch from a4165e0 to 54ab389 Compare August 25, 2018 16:59
EnforcedStyle: predicate_method
SupportedStyles:
- predicate_method
- explicit_comparison
Copy link
Collaborator

Choose a reason for hiding this comment

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

Think this should be named comparison_method (or operator).

Copy link
Collaborator

Choose a reason for hiding this comment

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

I see we named this simply predicate and comparison in a similar cop (NumericComparison), so we should probably stick to this for consistency.

include ConfigurableEnforcedStyle

PREDICATE_MSG = 'Prefer the use of the `nil?` predicate.'.freeze
EXPLICIT_MSG = 'Prefer the use of the explicit `==` comparison.'.freeze
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'd remove explicit here.

@khiav223577 khiav223577 changed the title Add explicit_comparison style to Style/NilComparison Add explicit style to Style/NilComparison Aug 26, 2018
@khiav223577 khiav223577 changed the title Add explicit style to Style/NilComparison Add comparison style to Style/NilComparison Aug 26, 2018
@bbatsov bbatsov merged commit 134b0ee into rubocop:master Aug 26, 2018
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.

None yet

2 participants