summaryrefslogtreecommitdiffstats
path: root/lib/puppet/parser/ast
diff options
context:
space:
mode:
authorMarkus Roberts <Markus@reality.com>2010-07-09 18:05:55 -0700
committerMarkus Roberts <Markus@reality.com>2010-07-09 18:05:55 -0700
commite8cf06336b64491a2dd7538a06651e0caaf6a48d (patch)
tree9f5d4c83d03fefa54c385462f60875056a58a82c /lib/puppet/parser/ast
parenteefccf252527dc5b69af5959b0b0e2ddb5c91b74 (diff)
downloadpuppet-e8cf06336b64491a2dd7538a06651e0caaf6a48d.tar.gz
puppet-e8cf06336b64491a2dd7538a06651e0caaf6a48d.tar.xz
puppet-e8cf06336b64491a2dd7538a06651e0caaf6a48d.zip
Code smell: Use string interpolation
* Replaced 83 occurances of (.*)" *[+] *([$@]?[\w_0-9.:]+?)(.to_s\b)?(?! *[*(%\w_0-9.:{\[]) with \1#{\2}" 3 Examples: The code: puts "PUPPET " + status + ": " + process + ", " + state becomes: puts "PUPPET " + status + ": " + process + ", #{state}" The code: puts "PUPPET " + status + ": #{process}" + ", #{state}" becomes: puts "PUPPET #{status}" + ": #{process}" + ", #{state}" The code: }.compact.join( "\n" ) + "\n" + t + "]\n" becomes: }.compact.join( "\n" ) + "\n#{t}" + "]\n" * Replaced 21 occurances of (.*)" *[+] *" with \1 3 Examples: The code: puts "PUPPET #{status}" + ": #{process}" + ", #{state}" becomes: puts "PUPPET #{status}" + ": #{process}, #{state}" The code: puts "PUPPET #{status}" + ": #{process}, #{state}" becomes: puts "PUPPET #{status}: #{process}, #{state}" The code: res = self.class.name + ": #{@name}" + "\n" becomes: res = self.class.name + ": #{@name}\n" * Don't use string concatenation to split lines unless they would be very long. Replaced 11 occurances of (.*)(['"]) *[+] *(['"])(.*) with 3 Examples: The code: o.define_head "The check_puppet Nagios plug-in checks that specified " + "Puppet process is running and the state file is no " + becomes: o.define_head "The check_puppet Nagios plug-in checks that specified Puppet process is running and the state file is no " + The code: o.separator "Mandatory arguments to long options are mandatory for " + "short options too." becomes: o.separator "Mandatory arguments to long options are mandatory for short options too." The code: o.define_head "The check_puppet Nagios plug-in checks that specified Puppet process is running and the state file is no " + "older than specified interval." becomes: o.define_head "The check_puppet Nagios plug-in checks that specified Puppet process is running and the state file is no older than specified interval." * Replaced no occurances of do (.*?) end with {\1} * Replaced 1488 occurances of "([^"\n]*%s[^"\n]*)" *% *(.+?)(?=$| *\b(do|if|while|until|unless|#)\b) with 20 Examples: The code: args[0].split(/\./).map do |s| "dc=%s"%[s] end.join(",") becomes: args[0].split(/\./).map do |s| "dc=#{s}" end.join(",") The code: puts "%s" % Puppet.version becomes: puts "#{Puppet.version}" The code: raise "Could not find information for %s" % node becomes: raise "Could not find information for #{node}" The code: raise Puppet::Error, "Cannot create %s: basedir %s is a file" % [dir, File.join(path)] becomes: raise Puppet::Error, "Cannot create #{dir}: basedir #{File.join(path)} is a file" The code: Puppet.err "Could not run %s: %s" % [client_class, detail] becomes: Puppet.err "Could not run #{client_class}: #{detail}" The code: raise "Could not find handler for %s" % arg becomes: raise "Could not find handler for #{arg}" The code: Puppet.err "Will not start without authorization file %s" % Puppet[:authconfig] becomes: Puppet.err "Will not start without authorization file #{Puppet[:authconfig]}" The code: raise Puppet::Error, "Could not deserialize catalog from pson: %s" % detail becomes: raise Puppet::Error, "Could not deserialize catalog from pson: #{detail}" The code: raise "Could not find facts for %s" % Puppet[:certname] becomes: raise "Could not find facts for #{Puppet[:certname]}" The code: raise ArgumentError, "%s is not readable" % path becomes: raise ArgumentError, "#{path} is not readable" The code: raise ArgumentError, "Invalid handler %s" % name becomes: raise ArgumentError, "Invalid handler #{name}" The code: debug "Executing '%s' in zone %s with '%s'" % [command, @resource[:name], str] becomes: debug "Executing '#{command}' in zone #{@resource[:name]} with '#{str}'" The code: raise Puppet::Error, "unknown cert type '%s'" % hash[:type] becomes: raise Puppet::Error, "unknown cert type '#{hash[:type]}'" The code: Puppet.info "Creating a new certificate request for %s" % Puppet[:certname] becomes: Puppet.info "Creating a new certificate request for #{Puppet[:certname]}" The code: "Cannot create alias %s: object already exists" % [name] becomes: "Cannot create alias #{name}: object already exists" The code: return "replacing from source %s with contents %s" % [metadata.source, metadata.checksum] becomes: return "replacing from source #{metadata.source} with contents #{metadata.checksum}" The code: it "should have a %s parameter" % param do becomes: it "should have a #{param} parameter" do The code: describe "when registring '%s' messages" % log do becomes: describe "when registring '#{log}' messages" do The code: paths = %w{a b c d e f g h}.collect { |l| "/tmp/iteration%stest" % l } becomes: paths = %w{a b c d e f g h}.collect { |l| "/tmp/iteration#{l}test" } The code: assert_raise(Puppet::Error, "Check '%s' did not fail on false" % check) do becomes: assert_raise(Puppet::Error, "Check '#{check}' did not fail on false") do
Diffstat (limited to 'lib/puppet/parser/ast')
-rw-r--r--lib/puppet/parser/ast/arithmetic_operator.rb6
-rw-r--r--lib/puppet/parser/ast/boolean_operator.rb2
-rw-r--r--lib/puppet/parser/ast/branch.rb2
-rw-r--r--lib/puppet/parser/ast/collexpr.rb7
-rw-r--r--lib/puppet/parser/ast/comparison_operator.rb2
-rw-r--r--lib/puppet/parser/ast/function.rb10
-rw-r--r--lib/puppet/parser/ast/leaf.rb4
-rw-r--r--lib/puppet/parser/ast/match_operator.rb2
-rw-r--r--lib/puppet/parser/ast/minus.rb2
-rw-r--r--lib/puppet/parser/ast/resource_override.rb2
-rw-r--r--lib/puppet/parser/ast/selector.rb2
11 files changed, 20 insertions, 21 deletions
diff --git a/lib/puppet/parser/ast/arithmetic_operator.rb b/lib/puppet/parser/ast/arithmetic_operator.rb
index 8d9cef86a..b4c0215cc 100644
--- a/lib/puppet/parser/ast/arithmetic_operator.rb
+++ b/lib/puppet/parser/ast/arithmetic_operator.rb
@@ -18,12 +18,12 @@ class Puppet::Parser::AST
lval = @lval.safeevaluate(scope)
lval = Puppet::Parser::Scope.number?(lval)
if lval == nil
- raise ArgumentError, "left operand of %s is not a number" % @operator
+ raise ArgumentError, "left operand of #{@operator} is not a number"
end
rval = @rval.safeevaluate(scope)
rval = Puppet::Parser::Scope.number?(rval)
if rval == nil
- raise ArgumentError, "right operand of %s is not a number" % @operator
+ raise ArgumentError, "right operand of #{@operator} is not a number"
end
# compute result
@@ -34,7 +34,7 @@ class Puppet::Parser::AST
super
unless %w{+ - * / << >>}.include?(@operator)
- raise ArgumentError, "Invalid arithmetic operator %s" % @operator
+ raise ArgumentError, "Invalid arithmetic operator #{@operator}"
end
end
end
diff --git a/lib/puppet/parser/ast/boolean_operator.rb b/lib/puppet/parser/ast/boolean_operator.rb
index 89725d73b..9214afbd5 100644
--- a/lib/puppet/parser/ast/boolean_operator.rb
+++ b/lib/puppet/parser/ast/boolean_operator.rb
@@ -41,7 +41,7 @@ class Puppet::Parser::AST
super
unless %w{and or}.include?(@operator)
- raise ArgumentError, "Invalid boolean operator %s" % @operator
+ raise ArgumentError, "Invalid boolean operator #{@operator}"
end
end
end
diff --git a/lib/puppet/parser/ast/branch.rb b/lib/puppet/parser/ast/branch.rb
index 0c481ffe6..c0fa0da30 100644
--- a/lib/puppet/parser/ast/branch.rb
+++ b/lib/puppet/parser/ast/branch.rb
@@ -31,7 +31,7 @@ class Puppet::Parser::AST
@children.each { |child|
unless child.is_a?(AST)
raise Puppet::DevError,
- "child %s is a %s instead of ast" % [child, child.class]
+ "child #{child} is a #{child.class} instead of ast"
end
}
end
diff --git a/lib/puppet/parser/ast/collexpr.rb b/lib/puppet/parser/ast/collexpr.rb
index eae2b0e42..95fb5a94f 100644
--- a/lib/puppet/parser/ast/collexpr.rb
+++ b/lib/puppet/parser/ast/collexpr.rb
@@ -68,11 +68,10 @@ class CollExpr < AST::Branch
when "tag"
str = "puppet_tags.name #{oper} '#{str2}'"
else
- str = "param_values.value #{oper} '#{str2}' and " +
- "param_names.name = '#{str1}'"
+ str = "param_values.value #{oper} '#{str2}' and param_names.name = '#{str1}'"
end
else
- str = "(%s) %s (%s)" % [str1, oper, str2]
+ str = "(#{str1}) #{oper} (#{str2})"
end
return str, code
@@ -82,7 +81,7 @@ class CollExpr < AST::Branch
super
unless %w{== != and or}.include?(@oper)
- raise ArgumentError, "Invalid operator %s" % @oper
+ raise ArgumentError, "Invalid operator #{@oper}"
end
end
end
diff --git a/lib/puppet/parser/ast/comparison_operator.rb b/lib/puppet/parser/ast/comparison_operator.rb
index 0d2f8b16d..85903ec31 100644
--- a/lib/puppet/parser/ast/comparison_operator.rb
+++ b/lib/puppet/parser/ast/comparison_operator.rb
@@ -34,7 +34,7 @@ class Puppet::Parser::AST
super
unless %w{== != < > <= >=}.include?(@operator)
- raise ArgumentError, "Invalid comparison operator %s" % @operator
+ raise ArgumentError, "Invalid comparison operator #{@operator}"
end
end
end
diff --git a/lib/puppet/parser/ast/function.rb b/lib/puppet/parser/ast/function.rb
index 98204b14a..c3769cbd4 100644
--- a/lib/puppet/parser/ast/function.rb
+++ b/lib/puppet/parser/ast/function.rb
@@ -14,28 +14,28 @@ class Puppet::Parser::AST
# Make sure it's a defined function
unless Puppet::Parser::Functions.function(@name)
- raise Puppet::ParseError, "Unknown function %s" % @name
+ raise Puppet::ParseError, "Unknown function #{@name}"
end
# Now check that it's been used correctly
case @ftype
when :rvalue
unless Puppet::Parser::Functions.rvalue?(@name)
- raise Puppet::ParseError, "Function '%s' does not return a value" % @name
+ raise Puppet::ParseError, "Function '#{@name}' does not return a value"
end
when :statement
if Puppet::Parser::Functions.rvalue?(@name)
raise Puppet::ParseError,
- "Function '%s' must be the value of a statement" % @name
+ "Function '#{@name}' must be the value of a statement"
end
else
- raise Puppet::DevError, "Invalid function type %s" % @ftype.inspect
+ raise Puppet::DevError, "Invalid function type #{@ftype.inspect}"
end
# We don't need to evaluate the name, because it's plaintext
args = @arguments.safeevaluate(scope)
- return scope.send("function_" + @name, args)
+ return scope.send("function_#{@name}", args)
end
def initialize(hash)
diff --git a/lib/puppet/parser/ast/leaf.rb b/lib/puppet/parser/ast/leaf.rb
index 30c4a958f..6ef346123 100644
--- a/lib/puppet/parser/ast/leaf.rb
+++ b/lib/puppet/parser/ast/leaf.rb
@@ -40,7 +40,7 @@ class Puppet::Parser::AST
unless @value == true or @value == false
raise Puppet::DevError,
- "'%s' is not a boolean" % @value
+ "'#{@value}' is not a boolean"
end
@value
end
@@ -108,7 +108,7 @@ class Puppet::Parser::AST
@value = @value.to_s.downcase unless @value.is_a?(Regex)
if @value =~ /[^-\w.]/
raise Puppet::DevError,
- "'%s' is not a valid hostname" % @value
+ "'#{@value}' is not a valid hostname"
end
end
diff --git a/lib/puppet/parser/ast/match_operator.rb b/lib/puppet/parser/ast/match_operator.rb
index 17e27826e..c528a90e5 100644
--- a/lib/puppet/parser/ast/match_operator.rb
+++ b/lib/puppet/parser/ast/match_operator.rb
@@ -24,7 +24,7 @@ class Puppet::Parser::AST
super
unless %w{!~ =~}.include?(@operator)
- raise ArgumentError, "Invalid regexp operator %s" % @operator
+ raise ArgumentError, "Invalid regexp operator #{@operator}"
end
end
end
diff --git a/lib/puppet/parser/ast/minus.rb b/lib/puppet/parser/ast/minus.rb
index b0779a8ee..52d158e0b 100644
--- a/lib/puppet/parser/ast/minus.rb
+++ b/lib/puppet/parser/ast/minus.rb
@@ -15,7 +15,7 @@ class Puppet::Parser::AST
val = @value.safeevaluate(scope)
val = Puppet::Parser::Scope.number?(val)
if val == nil
- raise ArgumentError, "minus operand %s is not a number" % val
+ raise ArgumentError, "minus operand #{val} is not a number"
end
return -val
end
diff --git a/lib/puppet/parser/ast/resource_override.rb b/lib/puppet/parser/ast/resource_override.rb
index f667ed23a..f9071fe96 100644
--- a/lib/puppet/parser/ast/resource_override.rb
+++ b/lib/puppet/parser/ast/resource_override.rb
@@ -13,7 +13,7 @@ class Puppet::Parser::AST
# Iterate across all of our children.
def each
[@object,@parameters].flatten.each { |param|
- #Puppet.debug("yielding param %s" % param)
+ #Puppet.debug("yielding param #{param}")
yield param
}
end
diff --git a/lib/puppet/parser/ast/selector.rb b/lib/puppet/parser/ast/selector.rb
index 647bdcde1..8eb930cc4 100644
--- a/lib/puppet/parser/ast/selector.rb
+++ b/lib/puppet/parser/ast/selector.rb
@@ -34,7 +34,7 @@ class Puppet::Parser::AST
# Unless we found something, look for the default.
return default.value.safeevaluate(scope) if default
- self.fail Puppet::ParseError, "No matching value for selector param '%s'" % paramvalue
+ self.fail Puppet::ParseError, "No matching value for selector param '#{paramvalue}'"
ensure
scope.unset_ephemeral_var(level)
end