summaryrefslogtreecommitdiffstats
Commit message (Collapse)AuthorAgeFilesLines
* Updated CHANGELOG for 2.6.0James Turnbull2010-07-201-0/+11
|
* Fixing #4268 - manifests always importedLuke Kanies2010-07-194-38/+26
| | | | | | | | | | | | | | The problem is that the environment list gets cleared when Settings#set_value is called, and it was being called every time Settings#use was called, which is more often than obvious but especially if reporting is enabled. Previously we ignored noop when running inside of Settings, and this essentially adds that back in, so we can remove the special noop behaviour in Settings itself. Signed-off-by: Luke Kanies <luke@puppetlabs.com>
* [#4269] Undef variables interpolate to empty stringNick Lewis2010-07-192-1/+32
| | | | | This fixes double-quoted strings to interpolate undef variables as an empty string. This is the behavior present in 0.25.x.
* [#4270] Force inherited classes to load into the correct environmentJesse Wolfe2010-07-196-13/+43
| | | | | | | | | Parent classes were getting searched for in a way that fails if they were not already loaded into an environment. This patch replaces that codepath with a call that will load them if they are needed. This bug was masked by another bug that loads all classes into "production", whether they are used there or not.
* [#4287] Fix the undefined evaluate_match error when comparing functionsMatt Robinson2010-07-194-71/+84
| | | | | | | | | | | | | | Ticket #4238 introduced a problem that a function couldn't compare to another value until after it was evaluated, and AST::Function didn't have the evaluate_match method. This change moves that method from AST::Leaf to AST. The special casing necessary for doing comparisons between AST objects feels messy and could probably be encapsulated better. I've created ticket #4291 to remind us to refactor this at some point. Paired with: Nick Lewis Signed-off-by: Matt Robinson <matt@puppetlabs.com>
* Tweak to tweak to fix for #4233 -- ":" is valid in type namesMarkus Roberts2010-07-191-1/+1
| | | | | The tweak to the fix for #4233 was too narrow, and precluded the possibility that a type name would contain colons e.g. (MySQL::User)
* Bandaid for #4285 -- :name vs <namevar>Markus Roberts2010-07-191-1/+5
| | | | | | | We sometimes refer to the namevar as its name and sometimes as :name; there is no consistant pattern in the code for when this is done one way or the other. This problem was exposed by the composite namevar refactor; the present patch adjusts the crucial routine to work with either.
* Tweak to fix for #4233 -- only accept word chars in typesMarkus Roberts2010-07-191-1/+1
| | | | | | | With the title carrying semantic information it may contain arbitrary chars; when parsing a ref we only want word chars in the type (up to the first open square bracket) and everything else, enclosed in "[" / "]" to the end of the string, is the title.
* Updated CHANGELOG for 2.6.0RC4James Turnbull2010-07-191-0/+18
|
* [#4233] Ruby regexps are not multiline by default, but Resource titles can ↵Jesse Wolfe2010-07-186-3/+47
| | | | | | | | be multiline Puppet allows resource titles to contain newlines. We recently introduced several regexps that were failing on resources with multiline titles.
* Fix for #4234 -- ruby DSL fails on second resourceMarkus Roberts2010-07-181-1/+1
| | | | | | The loop detection mechanism isn't great (it should, for example, allow nesting if the signatures differ) but the key problem was that the ensure was simply backwards.
* Fix for #4236 -- Only interpolate $ if followed by a variableMarkus Roberts2010-07-182-8/+16
| | | | | | | | | | | | | | | | | | This is a modification of the Nick/Jesse/Matt patch, retaining their tests and the analysis of the problem but reversing the implementation direction of the solution. Rather than trying to make the already somewhat brittle slurpstring smarter, which requires telling it what following strings will be accepted by the caller with a zero-width-lookahead negation of the regular expression used to extract a variable name, this patch keeps that responsibility in the caller where it belongs. The caller (tokenize_interpolated_string) now checks to see if it got a variable name _before_ emitting a variable token; if it got one, it proceeds normally, but if it didn't it simply tries again from that point in the string (accumulating the false match as a prefix). This change actually simplifies the logic of tokenize_interpolated_string somewhat.
* Fix #4238 - if should match undef as ''Brice Figureau2010-07-184-32/+79
| | | | | | | | | | | | | | The comparisons operator (and more particularly == and !=) were not treating the undef value as '', like case and selector did since #2818. This patch makes sure comparison operator uses AST leaf matching. Unfortunately, doing this introduces a behavior change compared to the previous versions: Numbers embedded in strings will now be matched as numbers in case and selector statements instead of string matching. Signed-off-by: Brice Figureau <brice-puppet@daysofwonder.com>
* Minimal fix for #4243 -- import isn't thread safeMarkus Roberts2010-07-183-29/+27
| | | | | | | | The import function was calling type_loader#import directly so that it could pass in the current file name, but by doing so it was thwarting the thread- safety locking level. This patch rearanges things so that all imports go through the same (thread safe) code path while retaining the current_file passing, error handling, etc. from the old structure.
* [#4247] storeconfigs was calling Puppet::Parser::Resource.new with the wrong ↵Jesse Wolfe2010-07-184-3/+28
| | | | | | | | | | | | | arguments When the interface to Puppet::Resource changed, its subclass Puppet::Parser::Resource was also affected. One case of initializing those objects did not get updated when the code changed, causing storeconfigs to break. Also, this patch adds a error message that would have made it easier to catch this problem (as puppet could consume all memory and die trying to print the old error message)
* [#4256] External nodes parameters can now be assigned to nodesMatt Robinson2010-07-182-6/+7
| | | | | | | | | | | | | | | | | | Node parameters were made a reader instead of an accessor in commit b82b4ef04282ca0006931562f60459a1591b6268 Author: Luke Kanies <luke@reductivelabs.com> Date: Wed Jan 6 17:42:42 2010 -0800 All non-transient parser references are gone but external nodes needs to be able to assign to parameters. The fix is just to change that back to an accessor. There may have been concern over nodes replacing the hash object instead of the values could have bad consequences, but that's not a concern since the node object being created in this case is new also. Paired with: Nick Lewis
* Fix for #4257 -- problems resolving ::-prefixed classesMarkus Roberts2010-07-181-5/+1
| | | | | | While find_fully_qualified expects (and gets) fully qualified class names it does not always get absolute names (with the ::-prefix); test in the global scope refers to the same thing as ::test.
* Fix #4262 - Puppetmaster used to log compilation timeBrice Figureau2010-07-182-2/+12
| | | | | | | It looks like a merge went wrong and we were returning abruptely from a benchmark block, thus jumping over a precious log information. Signed-off-by: Brice Figureau <brice-puppet@daysofwonder.com>
* Fix for #4255 -- misleading diagnostic messageMarkus Roberts2010-07-181-2/+0
| | | | A diagnostic message was left in the code durring development. Now it's gone.
* Partial fix for #4278 -- the performance aspectsMarkus Roberts2010-07-185-34/+10
| | | | | | | | | unevaluated_resources was a performance bottleneck and was doing a great deal of unneeded work, such as searching for the type of evaluated resources before ignoring them because only unevaluated resources were wanted. This patch is behaviour neutral but gives a 2-3x speedup for compiles with many defined resources.
* Fixed #4249 - Updated SUSE packaging specificationsJames Turnbull2010-07-163-20/+26
|
* New man pages for 2.6.0James Turnbull2010-07-1511-316/+373
|
* Fixes errant Trac references in documentationJames Turnbull2010-07-1520-20/+20
|
* Updated CHANGELOG for 2.6.0rc3James Turnbull2010-07-141-0/+12
|
* [#4219] Install misses command_line dir, puppet $app --help failsTodd Zullinger2010-07-131-1/+1
|
* conf/redhat: Consistently pass pidfile option to daemon, killproc, and statusTodd Zullinger2010-07-132-11/+20
| | | | | | | | | In Red Hat bug #531116 Ruben Kerkhof noted that we weren't using the --pidfile $pidfile option to daemon. This caused 'service puppet start' to fail if puppet had already been started. To be consistent, we now pass the pidfile option to daemon, killproc, and status when those functions provide such an option. And we only test for the availability of the -p/--pidfile option in one place.
* conf/redhat: Update conf/init files for single binaryTodd Zullinger2010-07-133-3/+3
|
* conf/redhat: Rebase rundir-perms patchTodd Zullinger2010-07-131-13/+13
|
* [#4213] -o option for setting onetime now works properlyNick Lewis2010-07-133-44/+26
| | | | | | | | When onetime was moved to global defaults, it broke the option handler using it in agent to manage waitforcert length. Additionally, it caused --onetime and -o to behave differently. This patch removes the ordinary option handler defined in agent and moves the logic for waitforcert to the one location it's used.
* [#3656] Serializing arrays of referencesJesse Wolfe2010-07-132-5/+19
| | | | | | My previous fix for #3656 missed the case where a "require" attribute (or other graph-ish attribute) had multiple values. This patch generalizes that fix to the multiple-value case.
* [#4215] Have rundir depend on vardirMatt Robinson2010-07-132-9/+60
| | | | | | | | | | | | This came up because if you ran puppetd with a specific vardir, then when rundir got set to a hardcoded value its parent directory might not exist and the whole thing would fail. This change came about with the concept of run_mode, and this fix is restoring the behaviour that was in 0.25.x Reviewed-by: Jesse Wolfe Signed-off-by: Matt Robinson <matt@puppetlabs.com>
* Fix for #4220 -- modules not implicitly loading their init filesMarkus Roberts2010-07-131-1/+1
| | | | | | The module init loading was broken in 7504f1e..b938edf and then gradually removed as dead code. This is a minimal (and mildly ugly) reinsertion os it with the addition of .rb support.
* Updated CHANGELOG for 2.6.0rc2James Turnbull2010-07-121-0/+10
|
* [#4209] catalog.resources should return resourcesJesse Wolfe2010-07-111-0/+4
| | | | | | | | | | | | type/user.rb was assuming that catalog.resources would return resources. In 0.25.x, it (confusingly) returns strings. type/user ignored this, and the codepath was a no-op. In 2.6, the method was renamed to something less confusing, causing the codepath in type/user to fail outright. This patch added a catalog.resources method that returns resource objects. As a side effect, user resources will now autorequire group resources again.
* Fix for #4210 -- missing require in CAMarkus Roberts2010-07-111-1/+1
| | | | Added the require.
* Minimal fix for #4205 -- incorrect Import loop messagesMarkus Roberts2010-07-111-2/+4
| | | | | | | | | | | | | | | | | | | | | This patch fixes the narrow problem of #4205, wherein type_loader would reparse a file each time it was imported (causing the parser to incorrectly think that it was in a loop) by checking @imported inside the existing check on the thread-guarded @loaded. (@imported was being set but never checked). This works (and is thread safe) because all of this is going on inside a giant synchronize care of @loaded. But it, like the fix for #4208, does nothing about the global lock. Areas for future research: 1) Why is the looping inside of import? 2) Why are there separate @loaded and @imported tables? 3) Why is the parsing treated like a function (called deep in the structure) yet coded like a thread-savvy pseudo state monad (e.g. raising errors that presume it knows/owns what's going on outside the whole process)? These and many other exciting questions are deferred to #4211
* Fix #4206 - import "path/*" tries to import files twiceBrice Figureau2010-07-112-1/+7
| | | | | | | | | Due to the glob pattern used, we are trying to import manifests twice. Since it isn't possible (see #4205), it is not possible to use a pattern in an import statement. This patch makes sure manifests are returned only once. Signed-off-by: Brice Figureau <brice-puppet@daysofwonder.com>
* Alt fix for #4207 -- serialize environments as their namesMarkus Roberts2010-07-111-0/+7
| | | | | | | | | | Environments contain a deal of transitory information and references to other objects, none of which is wanted when they are serialized. Rather than having this serialization concern propogate through the code by replacing environments by their names prior to serialization (which would be one way to address the problem) this patch changes environments so they only serialize their identity (name) and not their contents.
* [#4208] Missing parameter breaks multithread compilationJesse Wolfe2010-07-101-3/+3
| | | | | | | import_if_possible calls itself recursively, but it was failing to pass its block parameter to its younger self. Thus when the inner call reached the un-blocked case, it raised an exception rather than doing something useful.
* Updated CHANGELOG for 2.6.0rc1James Turnbull2010-07-101-0/+622
|
* Code smell: Two space indentationMarkus Roberts2010-07-091014-111266/+111266
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Replaced 106806 occurances of ^( +)(.*$) with The ruby community almost universally (i.e. everyone but Luke, Markus, and the other eleven people who learned ruby in the 1900s) uses two-space indentation. 3 Examples: The code: end # Tell getopt which arguments are valid def test_get_getopt_args element = Setting.new :name => "foo", :desc => "anything", :settings => Puppet::Util::Settings.new assert_equal([["--foo", GetoptLong::REQUIRED_ARGUMENT]], element.getopt_args, "Did not produce appropriate getopt args") becomes: end # Tell getopt which arguments are valid def test_get_getopt_args element = Setting.new :name => "foo", :desc => "anything", :settings => Puppet::Util::Settings.new assert_equal([["--foo", GetoptLong::REQUIRED_ARGUMENT]], element.getopt_args, "Did not produce appropriate getopt args") The code: assert_equal(str, val) assert_instance_of(Float, result) end # Now test it with a passed object becomes: assert_equal(str, val) assert_instance_of(Float, result) end # Now test it with a passed object The code: end assert_nothing_raised do klass[:Yay] = "boo" klass["Cool"] = :yayness end becomes: end assert_nothing_raised do klass[:Yay] = "boo" klass["Cool"] = :yayness end
* Code smell: Avoid needless decorationsMarkus Roberts2010-07-09229-713/+713
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * Replaced 704 occurances of (.*)\b([a-z_]+)\(\) with \1\2 3 Examples: The code: ctx = OpenSSL::SSL::SSLContext.new() becomes: ctx = OpenSSL::SSL::SSLContext.new The code: skip() becomes: skip The code: path = tempfile() becomes: path = tempfile * Replaced 31 occurances of ^( *)end *#.* with \1end 3 Examples: The code: becomes: The code: end # Dir.foreach becomes: end The code: end # def becomes: end
* Code smell: Don't restate results directly after assignmentMarkus Roberts2010-07-0929-33/+0
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Replaced 33 occurances of ([$@]?\w+)( +[|&+-]{0,2}= .+) \1 end with 3 Examples: The code: @sync ||= Sync.new @sync end becomes: @sync ||= Sync.new end The code: str += "\n" str end becomes: str += "\n" end The code: @indirection = Puppet::Indirector::Indirection.new(self, indirection, options) @indirection end becomes: @indirection = Puppet::Indirector::Indirection.new(self, indirection, options) end
* Code smell: Use &&= for dependent initializationMarkus Roberts2010-07-094-6/+6
| | | | | | | | | | | | | | | | | | | | | | | | | Replaced 6 occurances of ([$@]?\w+) += +(.*) +(if +\1|unless +\1.nil\?)$ with \1 &&= \2 3 Examples: The code: end becomes: end The code: becomes: The code: res becomes: res
* Code smell: Use ||= for conditional initializationMarkus Roberts2010-07-0943-55/+55
| | | | | | | | | | | | | | | | | | | | | | | | | Replaced 55 occurances of ([$@]?\w+) += +(.*) +(if +\1.nil\?|if +! *\1|unless +\1|unless +defined\?\(\1\))$ with \1 ||= \2 3 Examples: The code: @sync becomes: @sync The code: becomes: The code: if @yydebug becomes: if @yydebug
* Code smell: Omit needless checks on definedMarkus Roberts2010-07-0935-55/+55
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * Replaced 53 occurances of defined\?\((.+?)\) (?:and|&&) \1( |$) with \1\2 In code like: unless defined? @foo and @foo and bar("baz") "defined? @foo and @foo" can safely be replaced with "@foo": unless @foo and bar("baz") Because: * Both evaluate to false/nil when @foo is not defined * Both evaluate to @foo when @foo is defined 3 Examples: The code: @sync = Sync.new unless defined?(@sync) and @sync becomes: @sync = Sync.new unless @sync The code: unless defined?(@content) and @content becomes: unless @content The code: raise(ArgumentError, "Already handling indirection for #{@indirection.name}; cannot also handle #{indirection}") if defined?(@indirection) and @indirection becomes: raise(ArgumentError, "Already handling indirection for #{@indirection.name}; cannot also handle #{indirection}") if @indirection * Replaced 2 occurances of defined\?\((.+?)\) (?:and|&&) ! *\1.nil\? with !\1.nil? In code like: while defined? @foo and ! @foo.nil? ... "defined? @foo and ! @foo.nil?" can safely be replaced with "! @foo.nil?": while ! @foo.nil? ... Because: * Both evaluate to false/nil when @foo is not defined * Both evaluate to "! @foo.nil?" when @foo is defined 2 Examples: The code: !!(defined?(@value) and ! @value.nil?) becomes: !!(!@value.nil?) The code: self.init unless defined?(@@state) and ! @@state.nil? becomes: self.init unless !@@state.nil?
* Code smell: Avoid unneeded blocksMarkus Roberts2010-07-0935-135/+45
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Replaced 45 occurances of (DEF) begin (LINES) rescue(.*) (LINES) end end with 3 Examples: The code: def find(name) begin self.const_get(name.to_s.capitalize) rescue puts "Unable to find application '#{name.to_s}'." Kernel::exit(1) end end becomes: def find(name) self.const_get(name.to_s.capitalize) rescue puts "Unable to find application '#{name.to_s}'." Kernel::exit(1) end The code: def exit_on_fail(message, code = 1) begin yield rescue RuntimeError, NotImplementedError => detail puts detail.backtrace if Puppet[:trace] $stderr.puts "Could not #{message}: #{detail}" exit(code) end end becomes: def exit_on_fail(message, code = 1) yield rescue RuntimeError, NotImplementedError => detail puts detail.backtrace if Puppet[:trace] $stderr.puts "Could not #{message}: #{detail}" exit(code) end The code: def start begin case ssl when :tls @connection = LDAP::SSLConn.new(host, port, true) when true @connection = LDAP::SSLConn.new(host, port) else @connection = LDAP::Conn.new(host, port) end @connection.set_option(LDAP::LDAP_OPT_PROTOCOL_VERSION, 3) @connection.set_option(LDAP::LDAP_OPT_REFERRALS, LDAP::LDAP_OPT_ON) @connection.simple_bind(user, password) rescue => detail raise Puppet::Error, "Could not connect to LDAP: #{detail}" end end becomes: def start case ssl when :tls @connection = LDAP::SSLConn.new(host, port, true) when true @connection = LDAP::SSLConn.new(host, port) else @connection = LDAP::Conn.new(host, port) end @connection.set_option(LDAP::LDAP_OPT_PROTOCOL_VERSION, 3) @connection.set_option(LDAP::LDAP_OPT_REFERRALS, LDAP::LDAP_OPT_ON) @connection.simple_bind(user, password) rescue => detail raise Puppet::Error, "Could not connect to LDAP: #{detail}" end
* Code smell: Avoid explicit returnsMarkus Roberts2010-07-09256-583/+583
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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
* Code smell: Booleans are first class values.Markus Roberts2010-07-0965-388/+92
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * Replaced 2 occurances of def (.*) begin (.*) = Integer\((.*)\) return \2 rescue ArgumentError \2 = nil end if \2 = (.*) return \2 else return false end end with 2 Examples: The code: def validuser?(value) begin number = Integer(value) return number rescue ArgumentError number = nil end if number = uid(value) return number else return false end end becomes: def validuser?(value) Integer(value) rescue uid(value) || false end The code: def validgroup?(value) begin number = Integer(value) return number rescue ArgumentError number = nil end if number = gid(value) return number else return false end end becomes: def validgroup?(value) Integer(value) rescue gid(value) || false end * Replaced 28 occurances of return (.*?) if (.*) return (.*) with 3 Examples: The code: return send(options[:mode]) if [:rdoc, :trac, :markdown].include?(options[:mode]) return other becomes: return[:rdoc, :trac, :markdown].include?(options[:mode]) ? send(options[:mode]) : other The code: return true if known_resource_types.definition(name) return false becomes: return(known_resource_types.definition(name) ? true : false) The code: return :rest if request.protocol == 'https' return Puppet::FileBucket::File.indirection.terminus_class becomes: return(request.protocol == 'https' ? :rest : Puppet::FileBucket::File.indirection.terminus_class) * Replaced no occurances of return (.*?) unless (.*) return (.*) with * Replaced 7 occurances of if (.*) (.*[^:])false else \2true end with 3 Examples: The code: if RUBY_PLATFORM == "i386-mswin32" InstallOptions.ri = false else InstallOptions.ri = true end becomes: InstallOptions.ri = RUBY_PLATFORM != "i386-mswin32" The code: if options[:references].length > 1 with_contents = false else with_contents = true end becomes: with_contents = options[:references].length <= 1 The code: if value == false or value == "" or value == :undef return false else return true end becomes: return (value != false and value != "" and value != :undef) * Replaced 19 occurances of if (.*) (.*[^:])true else \2false end with 3 Examples: The code: if Puppet::Util::Log.level == :debug return true else return false end becomes: return Puppet::Util::Log.level == :debug The code: if satisfies?(*features) return true else return false end becomes: return !!satisfies?(*features) The code: if self.class.parsed_auth_db.has_key?(resource[:name]) return true else return false end becomes: return !!self.class.parsed_auth_db.has_key?(resource[:name]) * Replaced 1 occurance of if ([a-z_]) = (.*) (.*[^:])\1 else \3(.*) end with 1 Example: The code: if c = self.send(@subclassname, method) return c else return nil end becomes: return self.send(@subclassname, method) || nil * Replaced 2 occurances of if (.*) (.*[^:])\1 else \2false end with 2 Examples: The code: if hash[:Local] @local = hash[:Local] else @local = false end becomes: @local = hash[:Local] The code: if hash[:Local] @local = hash[:Local] else @local = false end becomes: @local = hash[:Local] * Replaced 10 occurances of if (.*) (.*[^:])(.*) else \2false end with 3 Examples: The code: if defined?(@isnamevar) return @isnamevar else return false end becomes: return defined?(@isnamevar) && @isnamevar The code: if defined?(@required) return @required else return false end becomes: return defined?(@required) && @required The code: if number = uid(value) return number else return false end becomes: return (number = uid(value)) && number * Replaced no occurances of if (.*) (.*[^:])nil else \2(true) end with * Replaced no occurances of if (.*) (.*[^:])true else \2nil end with * Replaced no occurances of if (.*) (.*[^:])\1 else \2nil end with * Replaced 23 occurances of if (.*) (.*[^:])(.*) else \2nil end with 3 Examples: The code: if node = Puppet::Node.find(hostname) env = node.environment else env = nil end becomes: env = (node = Puppet::Node.find(hostname)) ? node.environment : nil The code: if mod = Puppet::Node::Environment.new(env).module(module_name) and mod.files? return @mounts[MODULES].copy(mod.name, mod.file_directory) else return nil end becomes: return (mod = Puppet::Node::Environment.new(env).module(module_name) and mod.files?) ? @mounts[MODULES].copy(mod.name, mod.file_directory) : nil The code: if hash.include?(:CA) and hash[:CA] @ca = Puppet::SSLCertificates::CA.new() else @ca = nil end becomes: @ca = (hash.include?(:CA) and hash[:CA]) ? Puppet::SSLCertificates::CA.new() : nil
* Code smell: Line modifiers are preferred to one-line blocks.Markus Roberts2010-07-09279-2298/+782
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * Replaced 6 occurances of (while .*?) *do$ with The do is unneeded in the block header form and causes problems with the block-to-one-line transformation. 3 Examples: The code: while line = f.gets do becomes: while line = f.gets The code: while line = shadow.gets do becomes: while line = shadow.gets The code: while wrapper = zeros.pop do becomes: while wrapper = zeros.pop * Replaced 19 occurances of ((if|unless) .*?) *then$ with The then is unneeded in the block header form and causes problems with the block-to-one-line transformation. 3 Examples: The code: if f = test_files_for(failed).find { |f| failed_trace =~ Regexp.new(f) } then becomes: if f = test_files_for(failed).find { |f| failed_trace =~ Regexp.new(f) } The code: unless defined?(@spec_command) then becomes: unless defined?(@spec_command) The code: if c == ?\n then becomes: if c == ?\n * Replaced 758 occurances of ((?:if|unless|while|until) .*) (.*) end with The one-line form is preferable provided: * The condition is not used to assign a variable * The body line is not already modified * The resulting line is not too long 3 Examples: The code: if Puppet.features.libshadow? has_feature :manages_passwords end becomes: has_feature :manages_passwords if Puppet.features.libshadow? The code: unless (defined?(@current_pool) and @current_pool) @current_pool = process_zpool_data(get_pool_data) end becomes: @current_pool = process_zpool_data(get_pool_data) unless (defined?(@current_pool) and @current_pool) The code: if Puppet[:trace] puts detail.backtrace end becomes: puts detail.backtrace if Puppet[:trace]