diff options
| author | Markus Roberts <Markus@reality.com> | 2010-07-09 18:06:33 -0700 |
|---|---|---|
| committer | Markus Roberts <Markus@reality.com> | 2010-07-09 18:06:33 -0700 |
| commit | 8d1fbe4586c91682cdda0cb271649e918fd9778b (patch) | |
| tree | 314508ca21830874d9e4ec6e27880fede14193bd /lib/puppet/parser/ast | |
| parent | 889158ad57e33df083613d6f7d136b2e11aaa16a (diff) | |
| download | puppet-8d1fbe4586c91682cdda0cb271649e918fd9778b.tar.gz puppet-8d1fbe4586c91682cdda0cb271649e918fd9778b.tar.xz puppet-8d1fbe4586c91682cdda0cb271649e918fd9778b.zip | |
Code smell: Avoid explicit returns
Replaced 583 occurances of
(DEF)
(LINES)
return (.*)
end
with
3 Examples:
The code:
def consolidate_failures(failed)
filters = Hash.new { |h,k| h[k] = [] }
failed.each do |spec, failed_trace|
if f = test_files_for(failed).find { |f| failed_trace =~ Regexp.new(f) }
filters[f] << spec
break
end
end
return filters
end
becomes:
def consolidate_failures(failed)
filters = Hash.new { |h,k| h[k] = [] }
failed.each do |spec, failed_trace|
if f = test_files_for(failed).find { |f| failed_trace =~ Regexp.new(f) }
filters[f] << spec
break
end
end
filters
end
The code:
def retrieve
return_value = super
return_value = return_value[0] if return_value && return_value.is_a?(Array)
return return_value
end
becomes:
def retrieve
return_value = super
return_value = return_value[0] if return_value && return_value.is_a?(Array)
return_value
end
The code:
def fake_fstab
os = Facter['operatingsystem']
if os == "Solaris"
name = "solaris.fstab"
elsif os == "FreeBSD"
name = "freebsd.fstab"
else
# Catchall for other fstabs
name = "linux.fstab"
end
oldpath = @provider_class.default_target
return fakefile(File::join("data/types/mount", name))
end
becomes:
def fake_fstab
os = Facter['operatingsystem']
if os == "Solaris"
name = "solaris.fstab"
elsif os == "FreeBSD"
name = "freebsd.fstab"
else
# Catchall for other fstabs
name = "linux.fstab"
end
oldpath = @provider_class.default_target
fakefile(File::join("data/types/mount", name))
end
Diffstat (limited to 'lib/puppet/parser/ast')
| -rw-r--r-- | lib/puppet/parser/ast/astarray.rb | 4 | ||||
| -rw-r--r-- | lib/puppet/parser/ast/asthash.rb | 2 | ||||
| -rw-r--r-- | lib/puppet/parser/ast/caseopt.rb | 4 | ||||
| -rw-r--r-- | lib/puppet/parser/ast/else.rb | 2 | ||||
| -rw-r--r-- | lib/puppet/parser/ast/function.rb | 2 | ||||
| -rw-r--r-- | lib/puppet/parser/ast/in_operator.rb | 2 | ||||
| -rw-r--r-- | lib/puppet/parser/ast/leaf.rb | 16 | ||||
| -rw-r--r-- | lib/puppet/parser/ast/minus.rb | 2 | ||||
| -rw-r--r-- | lib/puppet/parser/ast/not.rb | 2 |
9 files changed, 18 insertions, 18 deletions
diff --git a/lib/puppet/parser/ast/astarray.rb b/lib/puppet/parser/ast/astarray.rb index dfd2bcd09..f0a0c5602 100644 --- a/lib/puppet/parser/ast/astarray.rb +++ b/lib/puppet/parser/ast/astarray.rb @@ -34,7 +34,7 @@ class Puppet::Parser::AST rets = items.flatten.collect { |child| child.safeevaluate(scope) } - return rets.reject { |o| o.nil? } + rets.reject { |o| o.nil? } end def push(*ary) @@ -45,7 +45,7 @@ class Puppet::Parser::AST @children.push(child) } - return self + self end def to_s diff --git a/lib/puppet/parser/ast/asthash.rb b/lib/puppet/parser/ast/asthash.rb index d04901912..d16b7459f 100644 --- a/lib/puppet/parser/ast/asthash.rb +++ b/lib/puppet/parser/ast/asthash.rb @@ -13,7 +13,7 @@ class Puppet::Parser::AST items.merge!({ key => v.safeevaluate(scope) }) end - return items + items end def merge(hash) diff --git a/lib/puppet/parser/ast/caseopt.rb b/lib/puppet/parser/ast/caseopt.rb index 1268aa7b9..b18a40320 100644 --- a/lib/puppet/parser/ast/caseopt.rb +++ b/lib/puppet/parser/ast/caseopt.rb @@ -31,7 +31,7 @@ class Puppet::Parser::AST @default = false unless defined?(@default) - return @default + @default end # You can specify a list of values; return each in turn. @@ -58,7 +58,7 @@ class Puppet::Parser::AST # Evaluate the actual statements; this only gets called if # our option matched. def evaluate(scope) - return @statements.safeevaluate(scope) + @statements.safeevaluate(scope) end end end diff --git a/lib/puppet/parser/ast/else.rb b/lib/puppet/parser/ast/else.rb index 70e80b4ee..2da9191c8 100644 --- a/lib/puppet/parser/ast/else.rb +++ b/lib/puppet/parser/ast/else.rb @@ -16,7 +16,7 @@ class Puppet::Parser::AST # Evaluate the actual statements; this only gets called if # our test was true matched. def evaluate(scope) - return @statements.safeevaluate(scope) + @statements.safeevaluate(scope) end end end diff --git a/lib/puppet/parser/ast/function.rb b/lib/puppet/parser/ast/function.rb index 79d3d95ed..6f6c869f5 100644 --- a/lib/puppet/parser/ast/function.rb +++ b/lib/puppet/parser/ast/function.rb @@ -31,7 +31,7 @@ class Puppet::Parser::AST # We don't need to evaluate the name, because it's plaintext args = @arguments.safeevaluate(scope) - return scope.send("function_#{@name}", args) + scope.send("function_#{@name}", args) end def initialize(hash) diff --git a/lib/puppet/parser/ast/in_operator.rb b/lib/puppet/parser/ast/in_operator.rb index 05f864edc..1b17b1006 100644 --- a/lib/puppet/parser/ast/in_operator.rb +++ b/lib/puppet/parser/ast/in_operator.rb @@ -18,7 +18,7 @@ class Puppet::Parser::AST unless rval.respond_to?(:include?) raise ArgumentError, "'#{rval}' from right operand of 'in' expression is not of a supported type (string, array or hash)" end - return rval.include?(lval) + rval.include?(lval) end end end diff --git a/lib/puppet/parser/ast/leaf.rb b/lib/puppet/parser/ast/leaf.rb index 666edd66a..a62edc61e 100644 --- a/lib/puppet/parser/ast/leaf.rb +++ b/lib/puppet/parser/ast/leaf.rb @@ -7,7 +7,7 @@ class Puppet::Parser::AST # Return our value. def evaluate(scope) - return @value + @value end # evaluate ourselves, and match @@ -26,7 +26,7 @@ class Puppet::Parser::AST end def to_s - return @value.to_s unless @value.nil? + @value.to_s unless @value.nil? end end @@ -64,7 +64,7 @@ class Puppet::Parser::AST # An uninterpreted string. class FlatString < AST::Leaf def evaluate(scope) - return @value + @value end def to_s @@ -116,11 +116,11 @@ class Puppet::Parser::AST # in a hash it has the same hashing properties as the underlying value def eql?(value) value = value.value if value.is_a?(HostName) - return @value.eql?(value) + @value.eql?(value) end def hash - return @value.hash + @value.hash end def to_s @@ -164,7 +164,7 @@ class Puppet::Parser::AST raise Puppet::ParseError, "#{variable} is not an hash or array when accessing it with #{accesskey}" unless object.is_a?(Hash) or object.is_a?(Array) - return object[evaluate_key(scope)] + object[evaluate_key(scope)] end # Assign value to this hashkey or array index @@ -201,7 +201,7 @@ class Puppet::Parser::AST # this way, we don't have to modify this test specifically for handling # regexes. def evaluate(scope) - return self + self end def evaluate_match(value, scope, options = {}) @@ -218,7 +218,7 @@ class Puppet::Parser::AST end def to_s - return "/#{@value.source}/" + "/#{@value.source}/" end end end diff --git a/lib/puppet/parser/ast/minus.rb b/lib/puppet/parser/ast/minus.rb index 52d158e0b..40f64336c 100644 --- a/lib/puppet/parser/ast/minus.rb +++ b/lib/puppet/parser/ast/minus.rb @@ -17,7 +17,7 @@ class Puppet::Parser::AST if val == nil raise ArgumentError, "minus operand #{val} is not a number" end - return -val + -val end end end diff --git a/lib/puppet/parser/ast/not.rb b/lib/puppet/parser/ast/not.rb index c8fa1df2c..24d5e838b 100644 --- a/lib/puppet/parser/ast/not.rb +++ b/lib/puppet/parser/ast/not.rb @@ -13,7 +13,7 @@ class Puppet::Parser::AST def evaluate(scope) val = @value.safeevaluate(scope) - return ! Puppet::Parser::Scope.true?(val) + ! Puppet::Parser::Scope.true?(val) end end end |
