-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix an infinite loop error for
Style/NonNilCheck
with `Style/NilCom…
…parison` This PR fixes the following infinite loop error for `IncludeSemanticChanges: false` of `Style/NonNilCheck` with `EnforcedStyle: comparison` of `Style/NilComparison`. ```ruby % cat example.rb # frozen_string_literal: true !(foo == nil) ``` ```yaml Style/NilComparison: Enabled: true EnforcedStyle: comparison # alternative config ``` ```console % bundle exec rubocop -A (snip) Inspecting 1 file C Offenses: example.rb:3:1: C: [Corrected] Style/InverseMethods: Use != instead of inverting ==. !(foo == nil) ^^^^^^^^^^^^^ example.rb:3:5: C: [Corrected] Style/NonNilCheck: Prefer !expression.nil? over expression != nil. foo != nil ^^ example.rb:3:6: C: [Corrected] Style/NilComparison: Prefer the use of the == comparison. !foo.nil? ^^^^ 0 files inspected, 3 offenses detected, 3 offenses corrected Infinite loop detected in /Users/koic/src/github.com/koic/rubocop-issues/9387/example.rb and caused by Style/InverseMethods -> Style/NonNilCheck -> Style/NilComparison /Users/koic/src/github.com/rubocop-hq/rubocop/lib/rubocop/runner.rb:304:in `check_for_infinite_loop' /Users/koic/src/github.com/rubocop-hq/rubocop/lib/rubocop/runner.rb:287:in `block in iterate_until_no_changes' /Users/koic/src/github.com/rubocop-hq/rubocop/lib/rubocop/runner.rb:286:in `loop' ``` This PR makes `Style/NonNilCheck` allows `foo != nil` when using `IncludeSemanticChanges: false` of `Style/NonNilCheck` and `EnforcedStyle: comparison` of `Style/NilComparison` cop, then `Style/NonNilCheck` cop does not register an offense for `x != nil` and does no changes to `!x.nil?` style.
- Loading branch information
Showing
4 changed files
with
82 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
* [#9389](https://github.com/rubocop-hq/rubocop/pull/9389): Fix an infinite loop error for `IncludeSemanticChanges: false` of `Style/NonNilCheck` with `EnforcedStyle: comparison` of `Style/NilComparison`. ([@koic][]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters