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

[Fix #444] Mark Rails/Blank as unsafe auto-correction #445

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
* [#432](https://github.com/rubocop/rubocop-rails/issues/432): Exclude gemspec file by default for `Rails/TimeZone` cop. ([@koic][])
* [#440](https://github.com/rubocop/rubocop-rails/issues/440): This PR makes `Rails/TimeZone` aware of timezone specifier. ([@koic][])
* [#381](https://github.com/rubocop/rubocop-rails/pull/381): Update `IgnoredMethods` list for `Lint/NumberConversion` to allow Rails' duration methods. ([@dvandersluis][])
* [#444](https://github.com/rubocop/rubocop-rails/issues/444): Mark `Rails/Blank` as unsafe auto-correction. ([@koic][])

## 2.9.1 (2020-12-16)

Expand Down
3 changes: 2 additions & 1 deletion config/default.yml
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,9 @@ Rails/BelongsTo:
Rails/Blank:
Description: 'Enforces use of `blank?`.'
Enabled: true
SafeAutoCorrect: false
VersionAdded: '0.48'
VersionChanged: '0.67'
VersionChanged: '2.10'
# Convert usages of `nil? || empty?` to `blank?`
NilOrEmpty: true
# Convert usages of `!present?` to `blank?`
Expand Down
8 changes: 6 additions & 2 deletions docs/modules/ROOT/pages/cops_rails.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -590,14 +590,18 @@ end

| Enabled
| Yes
| Yes
| Yes (Unsafe)
| 0.48
| 0.67
| 2.10
|===

This cop checks for code that can be written with simpler conditionals
using `Object#blank?` defined by Active Support.

This cop is marked as unsafe auto-correction, because `' '.empty?` returns false,
but `' '.blank?` returns true. Therefore, auto-correction is not compatible
if the receiver is a non-empty blank string, tab, or newline meta characters.

Interaction with `Style/UnlessElse`:
The configuration of `NotPresent` will not produce an offense in the
context of `unless else` if `Style/UnlessElse` is inabled. This is
Expand Down
4 changes: 4 additions & 0 deletions lib/rubocop/cop/rails/blank.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ module Rails
# This cop checks for code that can be written with simpler conditionals
# using `Object#blank?` defined by Active Support.
#
# This cop is marked as unsafe auto-correction, because `' '.empty?` returns false,
# but `' '.blank?` returns true. Therefore, auto-correction is not compatible
# if the receiver is a non-empty blank string, tab, or newline meta characters.
#
# Interaction with `Style/UnlessElse`:
# The configuration of `NotPresent` will not produce an offense in the
# context of `unless else` if `Style/UnlessElse` is inabled. This is
Expand Down