Skip to content

Commit 66232ea

Browse files
authored
Remove redundant return statements (#266)
Very slight behavior change here in `REXML::Valdiation::Event#matches?`, which is to align the predicate method's return value with the expected behavior of a predicate method (which is to return one of true or false).
1 parent 63f3e97 commit 66232ea

File tree

14 files changed

+118
-130
lines changed

14 files changed

+118
-130
lines changed

lib/rexml/attribute.rb

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -199,9 +199,7 @@ def inspect
199199
end
200200

201201
def xpath
202-
path = @element.xpath
203-
path += "/@#{self.expanded_name}"
204-
return path
202+
@element.xpath + "/@#{self.expanded_name}"
205203
end
206204

207205
def document

lib/rexml/document.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -415,7 +415,7 @@ def Document::entity_expansion_limit=( val )
415415
#
416416
# Deprecated. Use REXML::Security.entity_expansion_limit= instead.
417417
def Document::entity_expansion_limit
418-
return Security.entity_expansion_limit
418+
Security.entity_expansion_limit
419419
end
420420

421421
# Set the entity expansion limit. By default the limit is set to 10240.
@@ -429,7 +429,7 @@ def Document::entity_expansion_text_limit=( val )
429429
#
430430
# Deprecated. Use REXML::Security.entity_expansion_text_limit instead.
431431
def Document::entity_expansion_text_limit
432-
return Security.entity_expansion_text_limit
432+
Security.entity_expansion_text_limit
433433
end
434434

435435
attr_reader :entity_expansion_count

lib/rexml/element.rb

Lines changed: 19 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -565,7 +565,7 @@ def prefixes
565565
prefixes = []
566566
prefixes = parent.prefixes if parent
567567
prefixes |= attributes.prefixes
568-
return prefixes
568+
prefixes
569569
end
570570

571571
# :call-seq:
@@ -624,7 +624,7 @@ def namespace(prefix=nil)
624624
ns = namespaces[prefix]
625625

626626
ns = '' if ns.nil? and prefix == 'xmlns'
627-
return ns
627+
ns
628628
end
629629

630630
# :call-seq:
@@ -956,7 +956,7 @@ def get_elements( xpath )
956956
def next_element
957957
element = next_sibling
958958
element = element.next_sibling until element.nil? or element.kind_of? Element
959-
return element
959+
element
960960
end
961961

962962
# :call-seq:
@@ -972,7 +972,7 @@ def next_element
972972
def previous_element
973973
element = previous_sibling
974974
element = element.previous_sibling until element.nil? or element.kind_of? Element
975-
return element
975+
element
976976
end
977977

978978

@@ -1022,8 +1022,7 @@ def has_text?
10221022
#
10231023
def text( path = nil )
10241024
rv = get_text(path)
1025-
return rv.value unless rv.nil?
1026-
nil
1025+
rv&.value
10271026
end
10281027

10291028
# :call-seq:
@@ -1051,7 +1050,7 @@ def get_text path = nil
10511050
else
10521051
rv = @children.find { |node| node.kind_of? Text }
10531052
end
1054-
return rv
1053+
rv
10551054
end
10561055

10571056
# :call-seq:
@@ -1095,7 +1094,7 @@ def text=( text )
10951094
old_text.replace_with( text )
10961095
end
10971096
end
1098-
return self
1097+
self
10991098
end
11001099

11011100
# :call-seq:
@@ -1146,7 +1145,7 @@ def add_text( text )
11461145
text = Text.new( text, whitespace(), nil, raw() )
11471146
end
11481147
self << text unless text.nil?
1149-
return self
1148+
self
11501149
end
11511150

11521151
# :call-seq:
@@ -1190,7 +1189,7 @@ def xpath
11901189
cur = cur.parent
11911190
path_elements << __to_xpath_helper( cur )
11921191
end
1193-
return path_elements.reverse.join( "/" )
1192+
path_elements.reverse.join( "/" )
11941193
end
11951194

11961195
#################################################
@@ -1292,7 +1291,6 @@ def attribute( name, namespace=nil )
12921291
return nil unless ( namespaces[ prefix ] == namespaces[ 'xmlns' ] )
12931292

12941293
attributes.get_attribute( name )
1295-
12961294
end
12971295

12981296
# :call-seq:
@@ -1306,7 +1304,7 @@ def attribute( name, namespace=nil )
13061304
# b.has_attributes? # => false
13071305
#
13081306
def has_attributes?
1309-
return !@attributes.empty?
1307+
!@attributes.empty?
13101308
end
13111309

13121310
# :call-seq:
@@ -1684,11 +1682,7 @@ def []( index, name=nil)
16841682
(num += 1) == index
16851683
}
16861684
else
1687-
return XPath::first( @element, index )
1688-
#{ |element|
1689-
# return element if element.kind_of? Element
1690-
#}
1691-
#return nil
1685+
XPath::first( @element, index )
16921686
end
16931687
end
16941688

@@ -1735,7 +1729,7 @@ def []=( index, element )
17351729
else
17361730
previous.replace_with element
17371731
end
1738-
return previous
1732+
previous
17391733
end
17401734

17411735
# :call-seq:
@@ -1774,7 +1768,7 @@ def index element
17741768
child == element
17751769
end
17761770
return rv if found == element
1777-
return -1
1771+
-1
17781772
end
17791773

17801774
# :call-seq:
@@ -1853,7 +1847,7 @@ def delete_all( xpath )
18531847
@element.delete element
18541848
element.remove
18551849
end
1856-
return rv
1850+
rv
18571851
end
18581852

18591853
# :call-seq:
@@ -2180,8 +2174,7 @@ def initialize element
21802174
#
21812175
def [](name)
21822176
attr = get_attribute(name)
2183-
return attr.value unless attr.nil?
2184-
return nil
2177+
attr&.value
21852178
end
21862179

21872180
# :call-seq:
@@ -2336,7 +2329,7 @@ def get_attribute( name )
23362329
if attr.kind_of? Hash
23372330
attr = attr[ @element.prefix ]
23382331
end
2339-
return attr
2332+
attr
23402333
end
23412334

23422335
# :call-seq:
@@ -2390,7 +2383,7 @@ def []=( name, value )
23902383
else
23912384
store value.name, value
23922385
end
2393-
return @element
2386+
@element
23942387
end
23952388

23962389
# :call-seq:
@@ -2494,9 +2487,7 @@ def delete( attribute )
24942487
old.each_value{|v| repl = v}
24952488
store name, repl
24962489
end
2497-
elsif old.nil?
2498-
return @element
2499-
else # the supplied attribute is a top-level one
2490+
elsif old # the supplied attribute is a top-level one
25002491
super(name)
25012492
end
25022493
@element
@@ -2550,7 +2541,7 @@ def delete_all( name )
25502541
rv << attribute if attribute.expanded_name == name
25512542
}
25522543
rv.each{ |attr| attr.remove }
2553-
return rv
2544+
rv
25542545
end
25552546

25562547
# :call-seq:

lib/rexml/functions.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,11 @@ def Functions::context=(value); @@context = value; end
3939

4040
def Functions::text( )
4141
if @@context[:node].node_type == :element
42-
return @@context[:node].find_all{|n| n.node_type == :text}.collect{|n| n.value}
42+
@@context[:node].find_all{|n| n.node_type == :text}.collect{|n| n.value}
4343
elsif @@context[:node].node_type == :text
44-
return @@context[:node].value
44+
@@context[:node].value
4545
else
46-
return false
46+
false
4747
end
4848
end
4949

lib/rexml/namespace.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,11 @@ def name=( name )
4242
# Compares names optionally WITH namespaces
4343
def has_name?( other, ns=nil )
4444
if ns
45-
return (namespace() == ns and name() == other)
45+
namespace() == ns and name() == other
4646
elsif other.include? ":"
47-
return fully_expanded_name == other
47+
fully_expanded_name == other
4848
else
49-
return name == other
49+
name == other
5050
end
5151
end
5252

@@ -57,7 +57,7 @@ def has_name?( other, ns=nil )
5757
def fully_expanded_name
5858
ns = prefix
5959
return "#{ns}:#@name" if ns.size > 0
60-
return @name
60+
@name
6161
end
6262
end
6363
end

lib/rexml/node.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ def find_first_recursive(&block) # :yields: node
6868
each_recursive {|node|
6969
return node if block.call(node)
7070
}
71-
return nil
71+
nil
7272
end
7373

7474
# Returns the position that +self+ holds in its parent's array, indexed

lib/rexml/parsers/baseparser.rb

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -206,12 +206,12 @@ def position
206206

207207
# Returns true if there are no more events
208208
def empty?
209-
return (@source.empty? and @stack.empty?)
209+
(@source.empty? and @stack.empty?)
210210
end
211211

212212
# Returns true if there are more events. Synonymous with !empty?
213213
def has_next?
214-
return !(@source.empty? and @stack.empty?)
214+
!(@source.empty? and @stack.empty?)
215215
end
216216

217217
# Push an event back on the head of the stream. This method
@@ -522,7 +522,8 @@ def pull_event
522522
raise REXML::ParseException.new( "Exception parsing",
523523
@source, self, (error ? error : $!) )
524524
end
525-
return [ :dummy ]
525+
# NOTE: The end of the method never runs, because it is unreachable.
526+
# All branches of code above have explicit unconditional return or raise statements.
526527
end
527528
private :pull_event
528529

lib/rexml/parsers/xpathparser.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ def predicate_to_path(parsed, &block)
215215
else
216216
path << yield( parsed )
217217
end
218-
return path.squeeze(" ")
218+
path.squeeze(" ")
219219
end
220220
# For backward compatibility
221221
alias_method :preciate_to_string, :predicate_to_path
@@ -252,7 +252,7 @@ def LocationPath path, parsed
252252
path = path[1..-1]
253253
end
254254
end
255-
return RelativeLocationPath( path, parsed ) if path.size > 0
255+
RelativeLocationPath( path, parsed ) if path.size > 0
256256
end
257257

258258
#RelativeLocationPath
@@ -388,7 +388,7 @@ def NodeTest path, parsed
388388
else
389389
path = original_path
390390
end
391-
return path
391+
path
392392
end
393393

394394
# Filters the supplied nodeset on the predicate(s)
@@ -600,7 +600,7 @@ def PathExpr path, parsed
600600
end
601601
rest = LocationPath(rest, n) if rest =~ /\A[\/\.\@\[\w*]/
602602
parsed.concat(n)
603-
return rest
603+
rest
604604
end
605605

606606
#| FilterExpr Predicate

0 commit comments

Comments
 (0)