Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix a false positive for
Style/RedundantCondition
This PR fixes the following incorrect autocorrect for `Style/RedundantCondition` when using assignment by hash key access. ### Before The result of auto-correction is syntax error. ```console % cat example.rb if @columns_cache[table_name] @columns_cache[table_name] else @columns_cache[table_name] = super(table_name) end % bundle exec rubocop -a --only Style/RedundantCondition (snip) Inspecting 1 file C Offenses: example.rb:1:1: C: [Corrected] Style/RedundantCondition: Use double pipes || instead. if @columns_cache[table_name] ... ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 1 file inspected, 1 offense detected, 1 offense corrected % cat example.rb @columns_cache[table_name] || []=(table_name, super(table_name)) % ruby -c example.rb example.rb:1: syntax error, unexpected '=', expecting end-of-input ...olumns_cache[table_name] || []=(table_name, super(table_name... ``` ## After The cop accepts the example case.
- Loading branch information
Showing
3 changed files
with
16 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
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