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 EnforcedStyle for Style/DoubleNegation cop #7985

Merged

Conversation

koic
Copy link
Member

@koic koic commented May 17, 2020

This PR adds EnforcedStyle option for Style/DoubleNegation cop, and EnforcedStyle: context by default based on #7833 survey.

# @example EnforcedStyle: context (default)
#   # good
#   def foo?
#     !!return_value
#   end
#
# @example EnforcedStyle: always
#   # bad
#   def foo?
#     !!return_value
#   end

Ruby will return the last evaluated value.

This PR only supports simple contexts, such as the end of line value of method, and when using return.
A complex contexts should also be supported, such as when branching with if and others in the future.


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 bundle exec rake default. It executes all tests and RuboCop for itself, and generates the documentation.

@koic koic force-pushed the add_enforced_style_for_style_double_negation branch from 03a16c3 to 496620b Compare May 17, 2020 07:17
@@ -2699,6 +2699,11 @@ Style/DoubleNegation:
StyleGuide: '#no-bang-bang'
Enabled: true
VersionAdded: '0.19'
VersionChanged: '1.0'
Copy link
Collaborator

Choose a reason for hiding this comment

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

Make this 0.84, please. I'll cut one more release before 1.0 to make sure the rubocop-ast separation didn't cause problems.

VersionChanged: '1.0'
EnforcedStyle: context
SupportedStyles:
- context
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think better names would be forbidden and allowed_in_returns or something along those lines.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Or allowed_in_boolean_context?

Copy link
Member Author

@koic koic May 17, 2020

Choose a reason for hiding this comment

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

Thank you for suggesting a good name! I think allowed_in_returns is clear and straightforward!

@bbatsov
Copy link
Collaborator

bbatsov commented May 17, 2020

The cop description should also be updated, as it currently pertains only to the forbidden style.

@koic koic force-pushed the add_enforced_style_for_style_double_negation branch 4 times, most recently from ee97052 to 3d8d795 Compare May 17, 2020 07:54
koic added a commit to koic/rubocop that referenced this pull request May 17, 2020
Follow up to rubocop#7985 (comment).

RuboCop 0.84 will be cut before RuboCop 1.0.
@koic koic mentioned this pull request May 17, 2020
8 tasks
This PR adds `EnforcedStyle` option for `Style/DoubleNegation` cop,
and `EnforcedStyle: allowed_in_boolean_context` by default based on rubocop#7833 survey.

```ruby
# @example EnforcedStyle: allowed_in_boolean_context (default)
#   # good
#   def foo?
#     !!return_value
#   end
#
# @example EnforcedStyle: always
#   # bad
#   def foo?
#     !!return_value
#   end
```

Ruby will return the last evaluated value.

This PR only supports simple contexts, such as the end of line value of
method, and when using `return`.
A complex contexts should also be supported, such as when branching with
`if` and others in the future.
@koic koic force-pushed the add_enforced_style_for_style_double_negation branch from 3d8d795 to 9d19019 Compare May 17, 2020 08:00
bbatsov pushed a commit that referenced this pull request May 17, 2020
Follow up to #7985 (comment).

RuboCop 0.84 will be cut before RuboCop 1.0.
@bbatsov bbatsov merged commit 18e726b into rubocop:master May 17, 2020
@koic koic deleted the add_enforced_style_for_style_double_negation branch May 17, 2020 08:29
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