summaryrefslogtreecommitdiffstats
path: root/lib/puppet/util/rdoc
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/util/rdoc
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/util/rdoc')
-rw-r--r--lib/puppet/util/rdoc/code_objects.rb8
-rw-r--r--lib/puppet/util/rdoc/generators/puppet_generator.rb8
-rw-r--r--lib/puppet/util/rdoc/parser.rb30
3 files changed, 23 insertions, 23 deletions
diff --git a/lib/puppet/util/rdoc/code_objects.rb b/lib/puppet/util/rdoc/code_objects.rb
index 995869987..9ee26f47d 100644
--- a/lib/puppet/util/rdoc/code_objects.rb
+++ b/lib/puppet/util/rdoc/code_objects.rb
@@ -169,7 +169,7 @@ module RDoc
end
def to_s
- res = self.class.name + ": " + @name + " (" + @type + ")\n"
+ res = self.class.name + ": #{@name} (#{@type})\n"
res << @comment.to_s
res
end
@@ -200,7 +200,7 @@ module RDoc
end
def to_s
- res = self.class.name + ": " + @name + "\n"
+ res = self.class.name + ": #{@name}\n"
res << @comment.to_s
res
end
@@ -225,7 +225,7 @@ module RDoc
end
def full_name
- @type + "[" + @title + "]"
+ @type + "[#{@title}]"
end
def name
@@ -233,7 +233,7 @@ module RDoc
end
def to_s
- res = @type + "[" + @title + "]\n"
+ res = @type + "[#{@title}]\n"
res << @comment.to_s
res
end
diff --git a/lib/puppet/util/rdoc/generators/puppet_generator.rb b/lib/puppet/util/rdoc/generators/puppet_generator.rb
index c32a401bd..f73b18dce 100644
--- a/lib/puppet/util/rdoc/generators/puppet_generator.rb
+++ b/lib/puppet/util/rdoc/generators/puppet_generator.rb
@@ -241,7 +241,7 @@ module Generators
res2 = []
collection['methods'].sort.each do |f|
if f.document_self
- res2 << { "href" => "../"+f.path, "name" => f.index_name.sub(/\(.*\)$/,'') }
+ res2 << { "href" => "../#{f.path}", "name" => f.index_name.sub(/\(.*\)$/,'') }
end
end
@@ -593,7 +593,7 @@ module Generators
@values["parent"] = CGI.escapeHTML(parent_class)
if parent_name
- lookup = parent_name + "::" + parent_class
+ lookup = parent_name + "::#{parent_class}"
else
lookup = parent_class
end
@@ -839,7 +839,7 @@ module Generators
def as_href(from_path)
if @options.all_one_file
- "#" + path
+ "##{path}"
else
HTMLGenerator.gen_url(from_path, path)
end
@@ -877,7 +877,7 @@ module Generators
if @options.all_one_file
aref
else
- @html_class.path + "#" + aref
+ @html_class.path + "##{aref}"
end
end
diff --git a/lib/puppet/util/rdoc/parser.rb b/lib/puppet/util/rdoc/parser.rb
index 9c86ec360..9d14ae6eb 100644
--- a/lib/puppet/util/rdoc/parser.rb
+++ b/lib/puppet/util/rdoc/parser.rb
@@ -31,7 +31,7 @@ class Parser
# main entry point
def scan
- Puppet.info "rdoc: scanning %s" % @input_file_name
+ Puppet.info "rdoc: scanning #{@input_file_name}"
if @input_file_name =~ /\.pp$/
@parser = Puppet::Parser::Parser.new(Puppet[:environment])
@parser.file = @input_file_name
@@ -81,14 +81,14 @@ class Parser
def split_module(path)
# find a module
fullpath = File.expand_path(path)
- Puppet.debug "rdoc: testing %s" % fullpath
+ Puppet.debug "rdoc: testing #{fullpath}"
if fullpath =~ /(.*)\/([^\/]+)\/(?:manifests|plugins|lib)\/.+\.(pp|rb)$/
modpath = $1
name = $2
- Puppet.debug "rdoc: module %s into %s ?" % [name, modpath]
+ Puppet.debug "rdoc: module #{name} into #{modpath} ?"
Puppet::Module.modulepath().each do |mp|
if File.identical?(modpath,mp)
- Puppet.debug "rdoc: found module %s" % name
+ Puppet.debug "rdoc: found module #{name}"
return name
end
end
@@ -127,7 +127,7 @@ class Parser
return
end
- Puppet.debug "rdoc: scanning for %s" % name
+ Puppet.debug "rdoc: scanning for #{name}"
container.module_name = name
container.global=true if name == "<site>"
@@ -185,7 +185,7 @@ class Parser
scan_for_vardef(container,stmt.children) if stmt.is_a?(Puppet::Parser::AST::ASTArray)
if stmt.is_a?(Puppet::Parser::AST::VarDef)
- Puppet.debug "rdoc: found constant: %s = %s" % [stmt.name.to_s, stmt.value.to_s]
+ Puppet.debug "rdoc: found constant: #{stmt.name} = #{stmt.value}"
container.add_constant(Constant.new(stmt.name.to_s, stmt.value.to_s, stmt.doc))
end
end
@@ -202,7 +202,7 @@ class Parser
begin
type = stmt.type.split("::").collect { |s| s.capitalize }.join("::")
title = stmt.title.is_a?(Puppet::Parser::AST::ASTArray) ? stmt.title.to_s.gsub(/\[(.*)\]/,'\1') : stmt.title.to_s
- Puppet.debug "rdoc: found resource: %s[%s]" % [type,title]
+ Puppet.debug "rdoc: found resource: #{type}[#{title}]"
param = []
stmt.params.children.each do |p|
@@ -233,7 +233,7 @@ class Parser
# create documentation for a class named +name+
def document_class(name, klass, container)
- Puppet.debug "rdoc: found new class %s" % name
+ Puppet.debug "rdoc: found new class #{name}"
container, name = get_class_or_module(container, name)
superclass = klass.parent
@@ -265,7 +265,7 @@ class Parser
# create documentation for a node
def document_node(name, node, container)
- Puppet.debug "rdoc: found new node %s" % name
+ Puppet.debug "rdoc: found new node #{name}"
superclass = node.parent
superclass = "" if superclass.nil? or superclass.empty?
@@ -290,7 +290,7 @@ class Parser
# create documentation for a define
def document_define(name, define, container)
- Puppet.debug "rdoc: found new definition %s" % name
+ Puppet.debug "rdoc: found new definition #{name}"
# find superclas if any
@stats.num_methods += 1
@@ -308,7 +308,7 @@ class Parser
when Puppet::Parser::AST::Leaf
declaration << "'#{value.value}'"
when Puppet::Parser::AST::ASTArray
- declaration << "[%s]" % value.children.collect { |v| "'#{v}'" }.join(", ")
+ declaration << "[#{value.children.collect { |v| "'#{v}'" }.join(", ")}]"
else
declaration << "#{value.to_s}"
end
@@ -322,7 +322,7 @@ class Parser
meth.comment = define.doc
container.add_method(meth)
look_for_directives_in(container, meth.comment) unless meth.comment.empty?
- meth.params = "( " + declaration + " )"
+ meth.params = "( #{declaration} )"
meth.visibility = :public
meth.document_self = true
meth.singleton = false
@@ -386,7 +386,7 @@ class Parser
container.add_fact(current_fact)
current_fact.record_location(@top_level)
comments = ""
- Puppet.debug "rdoc: found custom fact %s" % current_fact.name
+ Puppet.debug "rdoc: found custom fact #{current_fact.name}"
elsif line =~ /^[ \t]*confine[ \t]*:(.*?)[ \t]*=>[ \t]*(.*)$/
current_fact.confine = { :type => $1, :value => $2 } unless current_fact.nil?
else # unknown line type
@@ -414,7 +414,7 @@ class Parser
current_plugin.comment = comments
current_plugin.record_location(@top_level)
comments = ""
- Puppet.debug "rdoc: found new function plugins %s" % current_plugin.name
+ Puppet.debug "rdoc: found new function plugins #{current_plugin.name}"
elsif line =~ /^[ \t]*Puppet::Type.newtype[ \t]*\([ \t]*:(.*?)\)/
current_plugin = Plugin.new($1, "type")
container.add_plugin(current_plugin)
@@ -422,7 +422,7 @@ class Parser
current_plugin.comment = comments
current_plugin.record_location(@top_level)
comments = ""
- Puppet.debug "rdoc: found new type plugins %s" % current_plugin.name
+ Puppet.debug "rdoc: found new type plugins #{current_plugin.name}"
elsif line =~ /module Puppet::Parser::Functions/
# skip
else # unknown line type