Skip to content

Commit 51ed214

Browse files
dreyksbbatsov
authored andcommitted
[Fix #3511] Style/TernaryParentheses false positive (#3513)
1 parent 2e3607d commit 51ed214

File tree

3 files changed

+10
-1
lines changed

3 files changed

+10
-1
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
## master (unreleased)
44

5+
### Bug fixes
6+
7+
[#3513](https://github.com/bbatsov/rubocop/pull/3513): Fix false positive in `Style/TernaryParentheses` for a ternary with ranges. ([@dreyks][])
8+
59
## 0.43.0 (2016-09-19)
610

711
### New features

lib/rubocop/cop/style/ternary_parentheses.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ def redundant_parentheses_enabled?
9191
end
9292

9393
def parenthesized?(node)
94-
node.source =~ /^\(.*\)$/
94+
node.begin_type?
9595
end
9696

9797
# When this cop is configured to enforce parentheses and the

spec/rubocop/cop/style/ternary_parentheses_spec.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,11 @@
168168
'foo = (baz.foo? bar, baz) ? a : b'
169169
end
170170
end
171+
172+
context 'with condition including a range' do
173+
it_behaves_like 'code without offense',
174+
'(foo..bar).include?(baz) ? a : b'
175+
end
171176
end
172177

173178
context 'when `RedundantParenthesis` would cause an infinite loop' do

0 commit comments

Comments
 (0)