summaryrefslogtreecommitdiffstats
path: root/lib/puppet/parser
diff options
context:
space:
mode:
authorMarkus Roberts <Markus@reality.com>2010-07-09 18:06:33 -0700
committerMarkus Roberts <Markus@reality.com>2010-07-09 18:06:33 -0700
commit8d1fbe4586c91682cdda0cb271649e918fd9778b (patch)
tree314508ca21830874d9e4ec6e27880fede14193bd /lib/puppet/parser
parent889158ad57e33df083613d6f7d136b2e11aaa16a (diff)
downloadpuppet-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')
-rw-r--r--lib/puppet/parser/ast/astarray.rb4
-rw-r--r--lib/puppet/parser/ast/asthash.rb2
-rw-r--r--lib/puppet/parser/ast/caseopt.rb4
-rw-r--r--lib/puppet/parser/ast/else.rb2
-rw-r--r--lib/puppet/parser/ast/function.rb2
-rw-r--r--lib/puppet/parser/ast/in_operator.rb2
-rw-r--r--lib/puppet/parser/ast/leaf.rb16
-rw-r--r--lib/puppet/parser/ast/minus.rb2
-rw-r--r--lib/puppet/parser/ast/not.rb2
-rw-r--r--lib/puppet/parser/collector.rb8
-rw-r--r--lib/puppet/parser/compiler.rb6
-rw-r--r--lib/puppet/parser/files.rb4
-rw-r--r--lib/puppet/parser/functions.rb2
-rw-r--r--lib/puppet/parser/lexer.rb6
-rw-r--r--lib/puppet/parser/parser_support.rb4
-rw-r--r--lib/puppet/parser/resource.rb4
-rw-r--r--lib/puppet/parser/resource/param.rb2
-rw-r--r--lib/puppet/parser/scope.rb12
-rw-r--r--lib/puppet/parser/templatewrapper.rb6
-rw-r--r--lib/puppet/parser/type_loader.rb2
20 files changed, 46 insertions, 46 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
diff --git a/lib/puppet/parser/collector.rb b/lib/puppet/parser/collector.rb
index d2b993017..c03add304 100644
--- a/lib/puppet/parser/collector.rb
+++ b/lib/puppet/parser/collector.rb
@@ -125,7 +125,7 @@ class Puppet::Parser::Collector
query[:conditions] = [search, *values]
- return query
+ query
end
# Collect exported objects.
@@ -152,7 +152,7 @@ class Puppet::Parser::Collector
scope.debug("Collected %s %s resource%s in %.2f seconds" % [count, @type, count == 1 ? "" : "s", time])
- return resources
+ resources
end
def collect_resources
@@ -182,7 +182,7 @@ class Puppet::Parser::Collector
# of collections.
@scope.compiler.delete_collection(self) if @resources.empty?
- return result
+ result
end
# Collect just virtual objects, from our local compiler.
@@ -208,7 +208,7 @@ class Puppet::Parser::Collector
scope.compiler.add_resource(scope, resource)
- return resource
+ resource
end
# Does the resource match our tests? We don't yet support tests,
diff --git a/lib/puppet/parser/compiler.rb b/lib/puppet/parser/compiler.rb
index 7ed000e19..01892ee44 100644
--- a/lib/puppet/parser/compiler.rb
+++ b/lib/puppet/parser/compiler.rb
@@ -87,7 +87,7 @@ class Puppet::Parser::Compiler
# Return a list of all of the defined classes.
def classlist
- return @catalog.classes
+ @catalog.classes
end
# Compiler our catalog. This mostly revolves around finding and evaluating classes.
@@ -109,7 +109,7 @@ class Puppet::Parser::Compiler
fail_on_unevaluated()
- return @catalog
+ @catalog
end
# LAK:FIXME There are no tests for this.
@@ -243,7 +243,7 @@ class Puppet::Parser::Compiler
end
end
- return found_something
+ found_something
end
# Make sure all of our resources have been evaluated into native resources.
diff --git a/lib/puppet/parser/files.rb b/lib/puppet/parser/files.rb
index aad74699f..875a87826 100644
--- a/lib/puppet/parser/files.rb
+++ b/lib/puppet/parser/files.rb
@@ -24,7 +24,7 @@ module Puppet::Parser::Files
# Than that would be a "no."
end
abspat = File::expand_path(start, cwd)
- return [nil, Dir.glob(abspat + (File.extname(abspat).empty? ? '{,.pp,.rb}' : '' )).reject { |f| FileTest.directory?(f) }]
+ [nil, Dir.glob(abspat + (File.extname(abspat).empty? ? '{,.pp,.rb}' : '' )).reject { |f| FileTest.directory?(f) }]
end
# Find the concrete file denoted by +file+. If +file+ is absolute,
@@ -52,7 +52,7 @@ module Puppet::Parser::Files
return td_file
end
- return nil
+ nil
end
def find_template_in_module(template, environment = nil)
diff --git a/lib/puppet/parser/functions.rb b/lib/puppet/parser/functions.rb
index c86548bfb..3e56f2a95 100644
--- a/lib/puppet/parser/functions.rb
+++ b/lib/puppet/parser/functions.rb
@@ -97,7 +97,7 @@ module Puppet::Parser::Functions
ret += "\n\n- **Type**: #{hash[:type]}\n\n"
end
- return ret
+ ret
end
def self.functions(env = nil)
diff --git a/lib/puppet/parser/lexer.rb b/lib/puppet/parser/lexer.rb
index b5eab9fc8..7668722d4 100644
--- a/lib/puppet/parser/lexer.rb
+++ b/lib/puppet/parser/lexer.rb
@@ -306,7 +306,7 @@ class Puppet::Parser::Lexer
@indefine = false
array.push([token,str])
}
- return array
+ array
end
def file=(file)
@@ -558,7 +558,7 @@ class Puppet::Parser::Lexer
# returns the content of the currently accumulated content cache
def commentpop
- return @commentstack.pop[0]
+ @commentstack.pop[0]
end
def getcomment(line = nil)
@@ -568,7 +568,7 @@ class Puppet::Parser::Lexer
@commentstack.push(['', @line])
return comment[0]
end
- return ''
+ ''
end
def commentpush
diff --git a/lib/puppet/parser/parser_support.rb b/lib/puppet/parser/parser_support.rb
index e63483050..18d17252c 100644
--- a/lib/puppet/parser/parser_support.rb
+++ b/lib/puppet/parser/parser_support.rb
@@ -26,7 +26,7 @@ class Puppet::Parser::Parser
message += " in file #{file}"
end
- return message
+ message
end
# Create an AST array out of all of the args
@@ -40,7 +40,7 @@ class Puppet::Parser::Parser
result = ast AST::ASTArray, :children => args
end
- return result
+ result
end
# Create an AST object, and automatically add the file and line information if
diff --git a/lib/puppet/parser/resource.rb b/lib/puppet/parser/resource.rb
index e29beeb95..baae78a8f 100644
--- a/lib/puppet/parser/resource.rb
+++ b/lib/puppet/parser/resource.rb
@@ -216,14 +216,14 @@ class Puppet::Parser::Resource < Puppet::Resource
result.virtual = self.virtual
result.tag(*self.tags)
- return result
+ result
end
# Translate our object to a transportable object.
def to_trans
return nil if virtual?
- return to_resource.to_trans
+ to_resource.to_trans
end
# Convert this resource to a RAL resource. We hackishly go via the
diff --git a/lib/puppet/parser/resource/param.rb b/lib/puppet/parser/resource/param.rb
index 3514f1d0c..7ca240df7 100644
--- a/lib/puppet/parser/resource/param.rb
+++ b/lib/puppet/parser/resource/param.rb
@@ -18,7 +18,7 @@ class Puppet::Parser::Resource::Param
end
def line_to_i
- return line ? Integer(line) : nil
+ line ? Integer(line) : nil
end
def to_s
diff --git a/lib/puppet/parser/scope.rb b/lib/puppet/parser/scope.rb
index f0c7d77bd..3bda512d7 100644
--- a/lib/puppet/parser/scope.rb
+++ b/lib/puppet/parser/scope.rb
@@ -65,7 +65,7 @@ class Puppet::Parser::Scope
# Is the value true? This allows us to control the definition of truth
# in one place.
def self.true?(value)
- return (value != false and value != "" and value != :undef)
+ (value != false and value != "" and value != :undef)
end
# Is the value a number?, return the correct object or nil if not a number
@@ -86,7 +86,7 @@ class Puppet::Parser::Scope
end
end
# it is one of Fixnum,Bignum or Float
- return value
+ value
end
# Add to our list of namespaces.
@@ -207,7 +207,7 @@ class Puppet::Parser::Scope
#Puppet.debug "Got defaults for %s: %s" %
# [type,values.inspect]
- return values
+ values
end
# Look up a defined type.
@@ -228,7 +228,7 @@ class Puppet::Parser::Scope
warning "Could not look up qualified variable '#{name}'; class #{klassname} has not been evaluated"
return usestring ? "" : :undefined
end
- return kscope.lookupvar(shortname, usestring)
+ kscope.lookupvar(shortname, usestring)
end
private :lookup_qualified_var
@@ -271,7 +271,7 @@ class Puppet::Parser::Scope
target[name] = value
end
}
- return target
+ target
end
def namespaces
@@ -410,7 +410,7 @@ class Puppet::Parser::Scope
end
end
- return out
+ out
end
# Return the tags associated with this scope. It's basically
diff --git a/lib/puppet/parser/templatewrapper.rb b/lib/puppet/parser/templatewrapper.rb
index 36dc62261..6966387cf 100644
--- a/lib/puppet/parser/templatewrapper.rb
+++ b/lib/puppet/parser/templatewrapper.rb
@@ -28,17 +28,17 @@ class Puppet::Parser::TemplateWrapper
# Allow templates to access the defined classes
def classes
- return scope.catalog.classes
+ scope.catalog.classes
end
# Allow templates to access the tags defined in the current scope
def tags
- return scope.tags
+ scope.tags
end
# Allow templates to access the all the defined tags
def all_tags
- return scope.catalog.tags
+ scope.catalog.tags
end
# Ruby treats variables like methods, so we used to expose variables
diff --git a/lib/puppet/parser/type_loader.rb b/lib/puppet/parser/type_loader.rb
index 24411522b..37fa03f20 100644
--- a/lib/puppet/parser/type_loader.rb
+++ b/lib/puppet/parser/type_loader.rb
@@ -55,7 +55,7 @@ class Puppet::Parser::TypeLoader
parse_file(file)
end
- return modname
+ modname
end
def imported?(file)