Skip to content

Commit dd865ae

Browse files
committed
Use Node#type? with multiple arguments
1 parent 5dccbcd commit dd865ae

File tree

6 files changed

+7
-17
lines changed

6 files changed

+7
-17
lines changed

.rubocop_todo.yml

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,6 @@
66
# Note that changes in the inspected code, or installation of new
77
# versions of RuboCop, may require this file to be generated again.
88

9-
# This cop supports safe autocorrection (--autocorrect).
10-
InternalAffairs/NodeTypeMultiplePredicates:
11-
Exclude:
12-
- 'lib/rubocop/cop/rspec/empty_example_group.rb'
13-
- 'lib/rubocop/cop/rspec/predicate_matcher.rb'
14-
- 'lib/rubocop/cop/rspec/receive_messages.rb'
15-
- 'lib/rubocop/cop/rspec/variable_definition.rb'
16-
- 'lib/rubocop/cop/rspec/variable_name.rb'
17-
189
Rake/MethodDefinitionInTask:
1910
Exclude:
2011
- 'tasks/cut_release.rake'

lib/rubocop/cop/rspec/empty_example_group.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -155,15 +155,15 @@ def offensive?(body)
155155
return true unless body
156156
return false if conditionals_with_examples?(body)
157157

158-
if body.if_type? || body.case_type?
158+
if body.type?(:if, :case)
159159
!examples_in_branches?(body)
160160
else
161161
!examples?(body)
162162
end
163163
end
164164

165165
def conditionals_with_examples?(body)
166-
return false unless body.begin_type? || body.case_type?
166+
return false unless body.type?(:begin, :case)
167167

168168
body.each_descendant(:if, :case).any? do |condition_node|
169169
examples_in_branches?(condition_node)
@@ -172,7 +172,7 @@ def conditionals_with_examples?(body)
172172

173173
def examples_in_branches?(condition_node)
174174
return false unless condition_node
175-
return false if !condition_node.if_type? && !condition_node.case_type?
175+
return false unless condition_node.type?(:if, :case)
176176

177177
condition_node.branches.any? { |branch| examples?(branch) }
178178
end

lib/rubocop/cop/rspec/predicate_matcher.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ def uncorrectable_matcher?(node, matcher)
182182

183183
def heredoc_argument?(matcher)
184184
matcher.arguments.select do |arg|
185-
arg.str_type? || arg.dstr_type? || arg.xstr_type?
185+
arg.type?(:str, :dstr, :xstr)
186186
end.any?(&:heredoc?)
187187
end
188188

lib/rubocop/cop/rspec/receive_messages.rb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,8 +148,7 @@ def item_range_by_whole_lines(item)
148148
end
149149

150150
def heredoc_or_splat?(node)
151-
((node.str_type? || node.dstr_type?) && node.heredoc?) ||
152-
node.splat_type?
151+
(node.type?(:str, :dstr) && node.heredoc?) || node.splat_type?
153152
end
154153

155154
def requires_quotes?(value)

lib/rubocop/cop/rspec/variable_definition.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ def string?(node)
6969
end
7070

7171
def symbol?(node)
72-
node.sym_type? || node.dsym_type?
72+
node.type?(:sym, :dsym)
7373
end
7474
end
7575
end

lib/rubocop/cop/rspec/variable_name.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ def on_send(node)
5050
return unless inside_example_group?(node)
5151

5252
variable_definition?(node) do |variable|
53-
return if variable.dstr_type? || variable.dsym_type?
53+
return if variable.type?(:dstr, :dsym)
5454
return if matches_allowed_pattern?(variable.value)
5555

5656
check_name(node, variable.value, variable.source_range)

0 commit comments

Comments
 (0)