diff options
author | Markus Roberts <Markus@reality.com> | 2010-07-09 18:05:55 -0700 |
---|---|---|
committer | Markus Roberts <Markus@reality.com> | 2010-07-09 18:05:55 -0700 |
commit | e8cf06336b64491a2dd7538a06651e0caaf6a48d (patch) | |
tree | 9f5d4c83d03fefa54c385462f60875056a58a82c /lib/puppet/reference | |
parent | eefccf252527dc5b69af5959b0b0e2ddb5c91b74 (diff) | |
download | puppet-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/reference')
-rw-r--r-- | lib/puppet/reference/configuration.rb | 4 | ||||
-rw-r--r-- | lib/puppet/reference/metaparameter.rb | 4 | ||||
-rw-r--r-- | lib/puppet/reference/providers.rb | 18 | ||||
-rw-r--r-- | lib/puppet/reference/type.rb | 4 |
4 files changed, 15 insertions, 15 deletions
diff --git a/lib/puppet/reference/configuration.rb b/lib/puppet/reference/configuration.rb index 352116cd5..2f60ecc65 100644 --- a/lib/puppet/reference/configuration.rb +++ b/lib/puppet/reference/configuration.rb @@ -31,9 +31,9 @@ config = Puppet::Util::Reference.newreference(:configuration, :depth => 1, :doc end # Leave out the section information; it was apparently confusing people. - #str += "- **Section**: %s\n" % object.section + #str += "- **Section**: #{object.section}\n" unless val == "" - str += "- **Default**: %s\n" % val + str += "- **Default**: #{val}\n" end str += "\n" end diff --git a/lib/puppet/reference/metaparameter.rb b/lib/puppet/reference/metaparameter.rb index 8e0a89ac6..9368de186 100644 --- a/lib/puppet/reference/metaparameter.rb +++ b/lib/puppet/reference/metaparameter.rb @@ -29,7 +29,7 @@ metaparameter = Puppet::Util::Reference.newreference :metaparameter, :doc => "Al a.to_s <=> b.to_s }.each { |param| str += paramwrap(param.to_s, scrub(Puppet::Type.metaparamdoc(param)), :level => 4) - #puts "<dt>" + param.to_s + "</dt>" + #puts "<dt>#{param}</dt>" #puts tab(1) + Puppet::Type.metaparamdoc(param).scrub.indent($tab)gsub(/\n\s*/,' ') #puts "<dd>" #puts indent(scrub(Puppet::Type.metaparamdoc(param)), $tab) @@ -40,7 +40,7 @@ metaparameter = Puppet::Util::Reference.newreference :metaparameter, :doc => "Al } rescue => detail puts detail.backtrace - puts "incorrect metaparams: %s" % detail + puts "incorrect metaparams: #{detail}" exit(1) end diff --git a/lib/puppet/reference/providers.rb b/lib/puppet/reference/providers.rb index 33d85061e..cc47876d6 100644 --- a/lib/puppet/reference/providers.rb +++ b/lib/puppet/reference/providers.rb @@ -53,31 +53,31 @@ providers = Puppet::Util::Reference.newreference :providers, :title => "Provider suit = true functional = true else - data << "[%s]_" % [count] # A pointer to the appropriate footnote + data << "[#{count}]_" # A pointer to the appropriate footnote suit = false end # Add a footnote with the details about why this provider is unsuitable, if that's the case unless suit - details = ".. [%s]\n" % count + details = ".. [#{count}]\n" missing.each do |test, values| case test when :exists - details += " - Missing files %s\n" % values.join(", ") + details += " - Missing files #{values.join(", ")}\n" when :variable values.each do |name, facts| if Puppet.settings.valid?(name) - details += " - Setting %s (currently %s) not in list %s\n" % [name, Puppet.settings.value(name).inspect, facts.join(", ")] + details += " - Setting #{name} (currently #{Puppet.settings.value(name).inspect}) not in list #{facts.join(", ")}\n" else - details += " - Fact %s (currently %s) not in list %s\n" % [name, Facter.value(name).inspect, facts.join(", ")] + details += " - Fact #{name} (currently #{Facter.value(name).inspect}) not in list #{facts.join(", ")}\n" end end when :true - details += " - Got %s true tests that should have been false\n" % values + details += " - Got #{values} true tests that should have been false\n" when :false - details += " - Got %s false tests that should have been true\n" % values + details += " - Got #{values} false tests that should have been true\n" when :feature - details += " - Missing features %s\n" % values.collect { |f| f.to_s }.join(",") + details += " - Missing features #{values.collect { |f| f.to_s }.join(",")}\n" end end notes << details @@ -97,7 +97,7 @@ providers = Puppet::Util::Reference.newreference :providers, :title => "Provider ret += h(type.name.to_s + "_", 2) - ret += ".. _%s: %s\n\n" % [type.name, "http://reductivelabs.com/trac/puppet/wiki/TypeReference#%s" % type.name] + ret += ".. _#{type.name}: #{"http://reductivelabs.com/trac/puppet/wiki/TypeReference##{type.name}"}\n\n" ret += option("Default provider", default) ret += doctable(headers, table_data) diff --git a/lib/puppet/reference/type.rb b/lib/puppet/reference/type.rb index c18681c1f..6bd8be835 100644 --- a/lib/puppet/reference/type.rb +++ b/lib/puppet/reference/type.rb @@ -79,12 +79,12 @@ type = Puppet::Util::Reference.newreference :type, :doc => "All Puppet resource property = type.propertybyname(sname) unless property - raise "Could not retrieve property %s on type %s" % [sname, type.name] + raise "Could not retrieve property #{sname} on type #{type.name}" end doc = nil unless doc = property.doc - $stderr.puts "No docs for %s[%s]" % [type, sname] + $stderr.puts "No docs for #{type}[#{sname}]" next end doc = doc.dup |