Hello community, here is the log from the commit of package rubygem-puppet-lint for openSUSE:Factory checked in at 2016-09-21 18:46:54 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Comparing /work/SRC/openSUSE:Factory/rubygem-puppet-lint (Old) and /work/SRC/openSUSE:Factory/.rubygem-puppet-lint.new (New) ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Package is "rubygem-puppet-lint" Changes: -------- --- /work/SRC/openSUSE:Factory/rubygem-puppet-lint/rubygem-puppet-lint.changes 2014-11-28 08:44:52.000000000 +0100 +++ /work/SRC/openSUSE:Factory/.rubygem-puppet-lint.new/rubygem-puppet-lint.changes 2016-09-21 18:46:56.000000000 +0200 @@ -1,0 +2,6 @@ +Sat Jul 30 08:36:07 UTC 2016 - tampak...@opensuse.org + +- Version bump 2.0.0 + see https://github.com/rodjek/puppet-lint/blob/master/CHANGELOG.md#200-2016-06-22 + +------------------------------------------------------------------- Old: ---- puppet-lint-1.1.0.gem New: ---- puppet-lint-2.0.0.gem ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Other differences: ------------------ ++++++ rubygem-puppet-lint.spec ++++++ --- /var/tmp/diff_new_pack.yQrh13/_old 2016-09-21 18:46:58.000000000 +0200 +++ /var/tmp/diff_new_pack.yQrh13/_new 2016-09-21 18:46:58.000000000 +0200 @@ -1,7 +1,7 @@ # # spec file for package rubygem-puppet-lint # -# Copyright (c) 2014 SUSE LINUX Products GmbH, Nuernberg, Germany. +# Copyright (c) 2016 SUSE LINUX GmbH, Nuernberg, Germany. # # All modifications and additions to the file contributed by third parties # remain the property of their copyright owners, unless otherwise agreed @@ -16,7 +16,7 @@ # Name: rubygem-puppet-lint -Version: 1.1.0 +Version: 2.0.0 Release: 0 %define mod_name puppet-lint %define mod_full_name %{mod_name}-%{version} ++++++ puppet-lint-1.1.0.gem -> puppet-lint-2.0.0.gem ++++++ diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/.gitignore new/.gitignore --- old/.gitignore 1970-01-01 01:00:00.000000000 +0100 +++ new/.gitignore 1970-01-01 01:00:00.000000000 +0100 @@ -6,3 +6,4 @@ vendor/gems coverage/ *.swp +/_site/ diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/README.md new/README.md --- old/README.md 1970-01-01 01:00:00.000000000 +0100 +++ new/README.md 1970-01-01 01:00:00.000000000 +0100 @@ -38,7 +38,7 @@ config.ignore_paths = ['modules/apt', 'modules/stdlib'] # List of checks to disable - config.disable_checks = ['documentation', '80chars'] + config.disable_checks = ['documentation', '140chars'] # Should puppet-lint prefix it's output with the file being checked, # defaults to true @@ -59,6 +59,9 @@ # Show ignored problems in the output, defaults to false config.show_ignored = true + + # Compare module layout relative to the module root + config.relative = true end ## Implemented tests @@ -70,7 +73,7 @@ * Must use two-space soft tabs. * Must not use literal tab characters. * Must not contain trailing white space. - * Should not exceed an 80 character line width + * Should not exceed an 140 character line width * An exception has been made for `source => 'puppet://...'` lines as splitting these over multiple lines decreases the readability of the manifests. @@ -121,10 +124,10 @@ You can disable any of the checks when running the `puppet-lint` command by adding a `--no-<check name>-check` flag to the command. For example, if you -wanted to skip the 80 character check, you would run +wanted to skip the 140 character check, you would run ``` -puppet-lint --no-80chars-check /path/to/my/manifest.pp +puppet-lint --no-140chars-check /path/to/my/manifest.pp ``` puppet-lint will also check for a `.puppet-lint.rc` file in the current @@ -152,10 +155,10 @@ PuppetLint.configuration.send("disable_<check name>") ``` -So, to disable the 80 character check, you would add: +So, to disable the 140 character check, you would add: ``` ruby -PuppetLint.configuration.send("disable_80chars") +PuppetLint.configuration.send("disable_140chars") ``` The Rake task also supports ignoring certain paths Files old/checksums.yaml.gz and new/checksums.yaml.gz differ diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/lib/puppet-lint/checkplugin.rb new/lib/puppet-lint/checkplugin.rb --- old/lib/puppet-lint/checkplugin.rb 1970-01-01 01:00:00.000000000 +0100 +++ new/lib/puppet-lint/checkplugin.rb 1970-01-01 01:00:00.000000000 +0100 @@ -35,7 +35,7 @@ # # Returns an Array of problem Hashes. def fix_problems - @problems.each do |problem| + @problems.reject { |problem| problem[:kind] == :ignored }.each do |problem| if self.respond_to?(:fix) begin fix(problem) @@ -90,6 +90,14 @@ PuppetLint::Data.defined_type_indexes end + # Public: Provides positional information for any node definitions in the + # tokens array to the check plugins. + # + # Returns an Array of Hashes containing the position information. + def node_indexes + PuppetLint::Data.node_indexes + end + # Public: Provides the expanded path of the file being analysed to check # plugins. # diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/lib/puppet-lint/checks.rb new/lib/puppet-lint/checks.rb --- old/lib/puppet-lint/checks.rb 1970-01-01 01:00:00.000000000 +0100 +++ new/lib/puppet-lint/checks.rb 1970-01-01 01:00:00.000000000 +0100 @@ -20,7 +20,7 @@ def load_data(path, content) lexer = PuppetLint::Lexer.new PuppetLint::Data.path = path - PuppetLint::Data.manifest_lines = content.split("\n") + PuppetLint::Data.manifest_lines = content.split("\n", -1) begin PuppetLint::Data.tokens = lexer.tokenise(content) PuppetLint::Data.parse_control_comments diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/lib/puppet-lint/data.rb new/lib/puppet-lint/data.rb --- old/lib/puppet-lint/data.rb 1970-01-01 01:00:00.000000000 +0100 +++ new/lib/puppet-lint/data.rb 1970-01-01 01:00:00.000000000 +0100 @@ -25,13 +25,23 @@ @resource_indexes = nil @class_indexes = nil @defined_type_indexes = nil + @function_indexes = nil + @array_indexes = nil + @hash_indexes = nil + @defaults_indexes = nil end # Public: Get the tokenised manifest. # # Returns an Array of PuppetLint::Lexer::Token objects. def tokens - if caller[0][/`.*'/][1..-2] == 'check' + calling_method = begin + caller[0][/`.*'/][1..-2] + rescue NoMethodError + caller[1][/`.*'/][1..-2] + end + + if calling_method == 'check' @tokens.dup else @tokens @@ -100,7 +110,7 @@ if tokens[token_idx].type == :COLON next_token = tokens[token_idx].next_code_token depth = 1 - if next_token.type != :LBRACE + if next_token && next_token.type != :LBRACE tokens[(token_idx + 1)..-1].each_index do |idx| real_idx = token_idx + idx + 1 if tokens[real_idx].type == :LBRACE @@ -179,6 +189,20 @@ @defined_type_indexes ||= definition_indexes(:DEFINE) end + # Internal: Calculate the positions of all node definitions within the + # `tokens` Array. + # + # Returns an Array of Hashes, each containing: + # :start - An Integer position in the `tokens` Array pointing to the + # first Token of a defined type definition. + # :end - An Integer position in the `tokens` Array pointing to the last + # Token of a defined type definition. + # :tokens - An Array consisting of all the Token objects that make up the + # defined type. + def node_indexes + @node_indexes ||= definition_indexes(:NODE) + end + # Internal: Calculate the positions of all the specified defintion types # within the `tokens` Array. # @@ -232,6 +256,161 @@ result end + # Internal: Calculate the positions of all function calls within + # `tokens` Array. + # + # Returns an Array of Hashes, each containing: + # :start - An Integer position in the `tokens` Array pointing to the + # first Token of a function call + # :end - An Integer position in the `tokens` Array pointing to the last + # Token of a function call + # :tokens - An Array consisting of all the Token objects that make up the + # function call. + def function_indexes + @function_indexes ||= Proc.new do + functions = [] + tokens.each_with_index do |token, token_idx| + if token.type == :NAME && \ + (token_idx == 0 || (token_idx == 1 && tokens[0].type == :WHITESPACE) || token.prev_token.type == :NEWLINE || token.prev_token.type == :INDENT || \ + # function in a function + (token.prev_code_token && token.prev_code_token.type == :LPAREN)) + + # Hash key + next if token.next_code_token && token.next_code_token.type == :FARROW + + level = 0 + real_idx = 0 + in_paren = false + tokens[token_idx+1..-1].each_with_index do |cur_token, cur_token_idx| + break if level == 0 && in_paren + break if level == 0 && cur_token.type == :NEWLINE + + if cur_token.type == :LPAREN + level += 1 + in_paren = true + end + level -= 1 if cur_token.type == :RPAREN + real_idx = token_idx + 1 + cur_token_idx + end + + functions << { + :start => token_idx, + :end => real_idx, + :tokens => tokens[token_idx..real_idx], + } + end + end + functions + end.call + end + + # Internal: Calculate the positions of all array values within + # `tokens` Array. + # + # Returns an Array of Hashes, each containing: + # :start - An Integer position in the `tokens` Array pointing to the + # first Token of an array value + # :end - An Integer position in the `tokens` Array pointing to the last + # Token of an array value + # :tokens - An Array consisting of all the Token objects that make up the + # array value. + def array_indexes + @array_indexes ||= Proc.new do + arrays = [] + tokens.each_with_index do |token, token_idx| + if token.type == :LBRACK + real_idx = 0 + tokens[token_idx+1..-1].each_with_index do |cur_token, cur_token_idx| + real_idx = token_idx + 1 + cur_token_idx + break if cur_token.type == :RBRACK + end + + # Ignore resource references + next if token.prev_code_token && \ + token.prev_code_token.type == :CLASSREF + arrays << { + :start => token_idx, + :end => real_idx, + :tokens => tokens[token_idx..real_idx], + } + end + end + arrays + end.call + end + + # Internal: Calculate the positions of all hash values within + # `tokens` Array. + # + # Returns an Array of Hashes, each containing: + # :start - An Integer position in the `tokens` Array pointing to the + # first Token of an hash value + # :end - An Integer position in the `tokens` Array pointing to the last + # Token of an hash value + # :tokens - An Array consisting of all the Token objects that make up the + # hash value. + def hash_indexes + @hash_indexes ||= Proc.new do + hashes = [] + tokens.each_with_index do |token, token_idx| + next unless token.prev_code_token + next unless [:EQUALS, :ISEQUAL, :FARROW, :LPAREN].include? token.prev_code_token.type + if token.type == :LBRACE + level = 0 + real_idx = 0 + tokens[token_idx+1..-1].each_with_index do |cur_token, cur_token_idx| + real_idx = token_idx + 1 + cur_token_idx + + level += 1 if cur_token.type == :LBRACE + level -= 1 if cur_token.type == :RBRACE + break if level < 0 + end + + hashes << { + :start => token_idx, + :end => real_idx, + :tokens => tokens[token_idx..real_idx], + } + end + end + hashes + end.call + end + + # Internal: Calculate the positions of all defaults declarations within + # `tokens` Array. + # + # Returns an Array of Hashes, each containing: + # :start - An Integer position in the `tokens` Array pointing to the + # first Token of the defaults declaration + # :end - An Integer position in the `tokens` Array pointing to the last + # Token of the defaults declaration + # :tokens - An Array consisting of all the Token objects that make up the + # defaults declaration. + def defaults_indexes + @defaults_indexes ||= Proc.new do + defaults = [] + tokens.each_with_index do |token, token_idx| + if token.type == :CLASSREF && token.next_code_token && \ + token.next_code_token.type == :LBRACE + real_idx = 0 + + tokens[token_idx+1..-1].each_with_index do |cur_token, cur_token_idx| + real_idx = token_idx + 1 + cur_token_idx + break if cur_token.type == :RBRACE + end + + defaults << { + :start => token_idx, + :end => real_idx, + :tokens => tokens[token_idx..real_idx], + } + end + end + defaults + end.call + end + # Internal: Finds all the tokens that make up the defined type or class # definition parameters. # diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/lib/puppet-lint/lexer/token.rb new/lib/puppet-lint/lexer/token.rb --- old/lib/puppet-lint/lexer/token.rb 1970-01-01 01:00:00.000000000 +0100 +++ new/lib/puppet-lint/lexer/token.rb 1970-01-01 01:00:00.000000000 +0100 @@ -9,6 +9,9 @@ # Public: Returns the String value of the Token. attr_accessor :value + # Public: Returns the raw value of the Token. + attr_accessor :raw + # Public: Returns the Integer line number of the manifest text where # the Token can be found. attr_reader :line @@ -87,6 +90,8 @@ "##{@value}" when :REGEX "/#{@value}/" + when :MLCOMMENT + @raw else @value end diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/lib/puppet-lint/lexer.rb new/lib/puppet-lint/lexer.rb --- old/lib/puppet-lint/lexer.rb 1970-01-01 01:00:00.000000000 +0100 +++ new/lib/puppet-lint/lexer.rb 1970-01-01 01:00:00.000000000 +0100 @@ -195,11 +195,12 @@ elsif mlcomment = chunk[/\A(\/\*.*?\*\/)/m, 1] length = mlcomment.size + mlcomment_raw = mlcomment.dup mlcomment.sub!(/\A\/\* ?/, '') mlcomment.sub!(/ ?\*\/\Z/, '') - mlcomment.gsub!(/ *\* ?/, '') - mlcomment.strip! + mlcomment.gsub!(/^ *\*/, '') tokens << new_token(:MLCOMMENT, mlcomment, length) + tokens.last.raw = mlcomment_raw elsif chunk.match(/\A\/.*?\//) && possible_regex? str_content = StringScanner.new(code[i+1..-1]).scan_until(/(\A|[^\\])(\\\\)*\//m) diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/lib/puppet-lint/optparser.rb new/lib/puppet-lint/optparser.rb --- old/lib/puppet-lint/optparser.rb 1970-01-01 01:00:00.000000000 +0100 +++ new/lib/puppet-lint/optparser.rb 1970-01-01 01:00:00.000000000 +0100 @@ -58,6 +58,14 @@ load f end + opts.on('--load-from-puppet MODULEPATH', 'Load plugins from the given Puppet module path.') do |path| + path.split(':').each do |p| + Dir["#{p}/*/lib/puppet-lint/plugins/*.rb"].each do |file| + load file + end + end + end + opts.on('-f', '--fix', 'Attempt to automatically fix errors') do PuppetLint.configuration.fix = true end @@ -98,7 +106,12 @@ end opts.load('/etc/puppet-lint.rc') - opts.load(File.expand_path('~/.puppet-lint.rc')) if ENV['HOME'] + begin + opts.load(File.expand_path('~/.puppet-lint.rc')) if ENV['HOME'] + rescue Errno::EACCES + # silently skip loading this file if HOME is set to a directory that + # the user doesn't have read access to. + end opts.load('.puppet-lint.rc') end end diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/lib/puppet-lint/plugins/check_classes.rb new/lib/puppet-lint/plugins/check_classes.rb --- old/lib/puppet-lint/plugins/check_classes.rb 1970-01-01 01:00:00.000000000 +0100 +++ new/lib/puppet-lint/plugins/check_classes.rb 1970-01-01 01:00:00.000000000 +0100 @@ -45,7 +45,7 @@ end # Public: Check the manifest tokens for any classes or defined types that -# have a dash in their name and record a warning for each instance found. +# have a dash in their name and record an error for each instance found. PuppetLint.new_check(:names_containing_dash) do def check (class_indexes + defined_type_indexes).each do |class_idx| @@ -56,7 +56,7 @@ obj_type = 'defined type' end - notify :warning, { + notify :error, { :message => "#{obj_type} name containing a dash", :line => class_idx[:name_token].line, :column => class_idx[:name_token].column, @@ -263,17 +263,19 @@ msg = "top-scope variable being used without an explicit namespace" referenced_variables.each do |token| unless future_parser_scopes[token.line].nil? - next if future_parser_scopes[token.line].include?(token.value) + next if future_parser_scopes[token.line].include?(token.value.gsub(/\[.+\]\Z/, '')) end unless token.value.include? '::' - unless variables_in_scope.include? token.value.gsub(/\[.+\]\Z/, '') - unless token.value =~ /\A\d+\Z/ - notify :warning, { - :message => msg, - :line => token.line, - :column => token.column, - } + unless token.value =~ /^(facts|trusted)\[.+\]/ + unless variables_in_scope.include? token.value.gsub(/\[.+\]\Z/, '') + unless token.value =~ /\A\d+\Z/ + notify :warning, { + :message => msg, + :line => token.line, + :column => token.column, + } + end end end end diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/lib/puppet-lint/plugins/check_comments.rb new/lib/puppet-lint/plugins/check_comments.rb --- old/lib/puppet-lint/plugins/check_comments.rb 1970-01-01 01:00:00.000000000 +0100 +++ new/lib/puppet-lint/plugins/check_comments.rb 1970-01-01 01:00:00.000000000 +0100 @@ -36,7 +36,7 @@ end def fix(problem) - comment_lines = problem[:token].value.split("\n") + comment_lines = problem[:token].value.strip.split("\n").map(&:strip) first_line = comment_lines.shift problem[:token].type = :COMMENT problem[:token].value = " #{first_line}" diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/lib/puppet-lint/plugins/check_conditionals.rb new/lib/puppet-lint/plugins/check_conditionals.rb --- old/lib/puppet-lint/plugins/check_conditionals.rb 1970-01-01 01:00:00.000000000 +0100 +++ new/lib/puppet-lint/plugins/check_conditionals.rb 1970-01-01 01:00:00.000000000 +0100 @@ -46,9 +46,13 @@ end end - case_indexes.each do |kase| + case_indexes.each_with_index do |kase,kase_index| case_tokens = tokens[kase[:start]..kase[:end]] + case_indexes[(kase_index + 1)..-1].each do |successor_kase| + case_tokens -= tokens[successor_kase[:start]..successor_kase[:end]] + end + unless case_tokens.index { |r| r.type == :DEFAULT } notify :warning, { :message => 'case statement without a default case', diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/lib/puppet-lint/plugins/check_nodes.rb new/lib/puppet-lint/plugins/check_nodes.rb --- old/lib/puppet-lint/plugins/check_nodes.rb 1970-01-01 01:00:00.000000000 +0100 +++ new/lib/puppet-lint/plugins/check_nodes.rb 1970-01-01 01:00:00.000000000 +0100 @@ -5,7 +5,8 @@ node_tokens = tokens.select { |token| token.type == :NODE } node_tokens.each do |node| node_token_idx = tokens.index(node) - node_lbrace_idx = tokens.index(tokens.find { |token| token.type == :LBRACE }) + node_lbrace_tok = tokens[node_token_idx..-1].find { |token| token.type == :LBRACE } + node_lbrace_idx = tokens.index(node_lbrace_tok) tokens[node_token_idx..node_lbrace_idx].select { |token| token.type == :NAME diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/lib/puppet-lint/plugins/check_strings.rb new/lib/puppet-lint/plugins/check_strings.rb --- old/lib/puppet-lint/plugins/check_strings.rb 1970-01-01 01:00:00.000000000 +0100 +++ new/lib/puppet-lint/plugins/check_strings.rb 1970-01-01 01:00:00.000000000 +0100 @@ -155,15 +155,20 @@ PuppetLint.new_check(:puppet_url_without_modules) do def check tokens.select { |token| - token.type == :SSTRING && token.value.start_with?('puppet://') + (token.type == :SSTRING || token.type == :STRING || token.type == :DQPRE) && token.value.start_with?('puppet://') }.reject { |token| - token.value[/puppet:\/\/.*?\/(.+)/, 1].start_with?('modules/') + token.value[/puppet:\/\/.*?\/(.+)/, 1].start_with?('modules/') unless token.value[/puppet:\/\/.*?\/(.+)/, 1].nil? }.each do |token| notify :warning, { :message => 'puppet:// URL without modules/ found', :line => token.line, :column => token.column, + :token => token, } end end + + def fix(problem) + problem[:token].value.gsub!(/(puppet:\/\/.*?\/)/, '\1modules/') + end end diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/lib/puppet-lint/plugins/check_whitespace.rb new/lib/puppet-lint/plugins/check_whitespace.rb --- old/lib/puppet-lint/plugins/check_whitespace.rb 1970-01-01 01:00:00.000000000 +0100 +++ new/lib/puppet-lint/plugins/check_whitespace.rb 1970-01-01 01:00:00.000000000 +0100 @@ -26,7 +26,7 @@ PuppetLint.new_check(:trailing_whitespace) do def check tokens.select { |token| - token.type == :WHITESPACE + [:WHITESPACE, :INDENT].include?(token.type) }.select { |token| token.next_token.nil? || token.next_token.type == :NEWLINE }.each do |token| @@ -48,19 +48,19 @@ end end -# Public: Test the raw manifest string for lines containing more than 80 +# Public: Test the raw manifest string for lines containing more than 140 # characters and record a warning for each instance found. The only exceptions # to this rule are lines containing URLs and template() calls which would hurt # readability if split. -PuppetLint.new_check(:'80chars') do +PuppetLint.new_check(:'140chars') do def check manifest_lines.each_with_index do |line, idx| unless line =~ /:\/\// || line =~ /template\(/ - if line.scan(/./mu).size > 80 + if line.scan(/./mu).size > 140 notify :warning, { - :message => 'line has more than 80 characters', + :message => 'line has more than 140 characters', :line => idx + 1, - :column => 80, + :column => 140, } end end @@ -112,7 +112,8 @@ if token.type == :FARROW (level_tokens[indent_depth_idx] ||= []) << token prev_indent_token = resource_tokens[0..idx].rindex { |t| t.type == :INDENT } - indent_length = resource_tokens[prev_indent_token].to_manifest.length + token.prev_code_token.to_manifest.length + 2 + indent_token_length = prev_indent_token.nil? ? 0 : resource_tokens[prev_indent_token].to_manifest.length + indent_length = indent_token_length + token.prev_code_token.to_manifest.length + 2 if indent_depth[indent_depth_idx] < indent_length indent_depth[indent_depth_idx] = indent_length @@ -122,9 +123,9 @@ indent_depth_idx += 1 indent_depth << 0 level_tokens[indent_depth_idx] ||= [] - elsif token.type == :RBRACE + elsif token.type == :RBRACE || token.type == :SEMIC level_tokens[indent_depth_idx].each do |arrow_tok| - unless arrow_tok.column == indent_depth[indent_depth_idx] + unless arrow_tok.column == indent_depth[indent_depth_idx] || level_tokens[indent_depth_idx].size == 1 arrows_on_line = level_tokens[indent_depth_idx].select { |t| t.line == arrow_tok.line } notify :warning, { :message => 'indentation of => is not properly aligned', diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/lib/puppet-lint/tasks/puppet-lint.rb new/lib/puppet-lint/tasks/puppet-lint.rb --- old/lib/puppet-lint/tasks/puppet-lint.rb 1970-01-01 01:00:00.000000000 +0100 +++ new/lib/puppet-lint/tasks/puppet-lint.rb 1970-01-01 01:00:00.000000000 +0100 @@ -26,6 +26,7 @@ attr_accessor :with_context attr_accessor :fix attr_accessor :show_ignored + attr_accessor :relative # Public: Initialise a new PuppetLint::RakeTask. # @@ -49,6 +50,8 @@ task_block.call(*[self, args].slice(0, task_block.arity)) if task_block + # clear any (auto-)pre-existing task + Rake::Task[@name].clear if Rake::Task.task_defined?(@name) task @name do PuppetLint::OptParser.build @@ -56,11 +59,15 @@ PuppetLint.configuration.send("disable_#{check}") end - %w{with_filename fail_on_warnings error_level log_format with_context fix show_ignored}.each do |config| + %w{with_filename fail_on_warnings error_level log_format with_context fix show_ignored relative}.each do |config| value = instance_variable_get("@#{config}") PuppetLint.configuration.send("#{config}=".to_sym, value) unless value.nil? end + if PuppetLint.configuration.ignore_paths + @ignore_paths = PuppetLint.configuration.ignore_paths + end + RakeFileUtils.send(:verbose, true) do linter = PuppetLint.new matched_files = FileList[@pattern] diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/lib/puppet-lint/version.rb new/lib/puppet-lint/version.rb --- old/lib/puppet-lint/version.rb 1970-01-01 01:00:00.000000000 +0100 +++ new/lib/puppet-lint/version.rb 1970-01-01 01:00:00.000000000 +0100 @@ -1,3 +1,3 @@ class PuppetLint - VERSION = '1.1.0' + VERSION = '2.0.0' end diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/lib/puppet-lint.rb new/lib/puppet-lint.rb --- old/lib/puppet-lint.rb 1970-01-01 01:00:00.000000000 +0100 +++ new/lib/puppet-lint.rb 1970-01-01 01:00:00.000000000 +0100 @@ -164,6 +164,12 @@ raise PuppetLint::NoCodeError end + if @code.empty? + @problems = [] + @manifest = [] + return + end + linter = PuppetLint::Checks.new @problems = linter.run(@path, @code) @problems.each { |problem| @statistics[problem[:kind]] += 1 } diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/metadata new/metadata --- old/metadata 1970-01-01 01:00:00.000000000 +0100 +++ new/metadata 1970-01-01 01:00:00.000000000 +0100 @@ -1,94 +1,80 @@ ---- !ruby/object:Gem::Specification +--- !ruby/object:Gem::Specification name: puppet-lint -version: !ruby/object:Gem::Version - hash: 19 - prerelease: - segments: - - 1 - - 1 - - 0 - version: 1.1.0 +version: !ruby/object:Gem::Version + version: 2.0.0 platform: ruby -authors: +authors: - Tim Sharpe autorequire: bindir: bin cert_chain: [] - -date: 2014-09-23 00:00:00 -07:00 -default_executable: -dependencies: -- !ruby/object:Gem::Dependency +date: 2016-06-22 00:00:00.000000000 Z +dependencies: +- !ruby/object:Gem::Dependency name: rake - prerelease: false - requirement: &id001 !ruby/object:Gem::Requirement - none: false - requirements: - - - ~> - - !ruby/object:Gem::Version - hash: 35 - segments: - - 10 - - 0 - version: "10.0" + requirement: !ruby/object:Gem::Requirement + requirements: + - - ~> + - !ruby/object:Gem::Version + version: '10.0' type: :development - version_requirements: *id001 -- !ruby/object:Gem::Dependency - name: rspec prerelease: false - requirement: &id002 !ruby/object:Gem::Requirement - none: false - requirements: - - - ~> - - !ruby/object:Gem::Version - hash: 7 - segments: - - 3 - - 0 - version: "3.0" + version_requirements: !ruby/object:Gem::Requirement + requirements: + - - ~> + - !ruby/object:Gem::Version + version: '10.0' +- !ruby/object:Gem::Dependency + name: rspec + requirement: !ruby/object:Gem::Requirement + requirements: + - - ~> + - !ruby/object:Gem::Version + version: '3.0' type: :development - version_requirements: *id002 -- !ruby/object:Gem::Dependency - name: rspec-its prerelease: false - requirement: &id003 !ruby/object:Gem::Requirement - none: false - requirements: - - - ~> - - !ruby/object:Gem::Version - hash: 15 - segments: - - 1 - - 0 - version: "1.0" + version_requirements: !ruby/object:Gem::Requirement + requirements: + - - ~> + - !ruby/object:Gem::Version + version: '3.0' +- !ruby/object:Gem::Dependency + name: rspec-its + requirement: !ruby/object:Gem::Requirement + requirements: + - - ~> + - !ruby/object:Gem::Version + version: '1.0' type: :development - version_requirements: *id003 -- !ruby/object:Gem::Dependency - name: rspec-collection_matchers prerelease: false - requirement: &id004 !ruby/object:Gem::Requirement - none: false - requirements: - - - ~> - - !ruby/object:Gem::Version - hash: 15 - segments: - - 1 - - 0 - version: "1.0" + version_requirements: !ruby/object:Gem::Requirement + requirements: + - - ~> + - !ruby/object:Gem::Version + version: '1.0' +- !ruby/object:Gem::Dependency + name: rspec-collection_matchers + requirement: !ruby/object:Gem::Requirement + requirements: + - - ~> + - !ruby/object:Gem::Version + version: '1.0' type: :development - version_requirements: *id004 + prerelease: false + version_requirements: !ruby/object:Gem::Requirement + requirements: + - - ~> + - !ruby/object:Gem::Version + version: '1.0' description: |- Checks your Puppet manifests against the Puppetlabs style guide and alerts you to any discrepancies. email: t...@sharpe.id.au -executables: +executables: - puppet-lint extensions: [] - extra_rdoc_files: [] - -files: +files: - .gitignore - .travis.yml - Gemfile @@ -128,6 +114,7 @@ - spec/fixtures/test/manifests/ignore_reason.pp - spec/fixtures/test/manifests/init.pp - spec/fixtures/test/manifests/malformed.pp +- spec/fixtures/test/manifests/url_interpolation.pp - spec/fixtures/test/manifests/warning.pp - spec/puppet-lint/bin_spec.rb - spec/puppet-lint/configuration_spec.rb @@ -161,48 +148,37 @@ - spec/puppet-lint/plugins/check_strings/single_quote_string_with_variables_spec.rb - spec/puppet-lint/plugins/check_strings/variables_not_enclosed_spec.rb - spec/puppet-lint/plugins/check_variables/variable_contains_dash_spec.rb +- spec/puppet-lint/plugins/check_whitespace/140chars_spec.rb - spec/puppet-lint/plugins/check_whitespace/2sp_soft_tabs_spec.rb -- spec/puppet-lint/plugins/check_whitespace/80chars_spec.rb - spec/puppet-lint/plugins/check_whitespace/arrow_alignment_spec.rb - spec/puppet-lint/plugins/check_whitespace/hard_tabs_spec.rb - spec/puppet-lint/plugins/check_whitespace/trailing_whitespace_spec.rb - spec/puppet-lint_spec.rb - spec/spec_helper.rb -has_rdoc: true homepage: https://github.com/rodjek/puppet-lint/ licenses: [] - +metadata: {} post_install_message: rdoc_options: [] - -require_paths: +require_paths: - lib -required_ruby_version: !ruby/object:Gem::Requirement - none: false - requirements: - - - ">=" - - !ruby/object:Gem::Version - hash: 3 - segments: - - 0 - version: "0" -required_rubygems_version: !ruby/object:Gem::Requirement - none: false - requirements: - - - ">=" - - !ruby/object:Gem::Version - hash: 3 - segments: - - 0 - version: "0" +required_ruby_version: !ruby/object:Gem::Requirement + requirements: + - - '>=' + - !ruby/object:Gem::Version + version: '0' +required_rubygems_version: !ruby/object:Gem::Requirement + requirements: + - - '>=' + - !ruby/object:Gem::Version + version: '0' requirements: [] - rubyforge_project: -rubygems_version: 1.6.2 +rubygems_version: 2.0.14 signing_key: -specification_version: 3 +specification_version: 4 summary: Ensure your Puppet manifests conform with the Puppetlabs style guide -test_files: +test_files: - spec/fixtures/test/manifests/fail.pp - spec/fixtures/test/manifests/ignore.pp - spec/fixtures/test/manifests/ignore_multiple_block.pp @@ -210,6 +186,7 @@ - spec/fixtures/test/manifests/ignore_reason.pp - spec/fixtures/test/manifests/init.pp - spec/fixtures/test/manifests/malformed.pp +- spec/fixtures/test/manifests/url_interpolation.pp - spec/fixtures/test/manifests/warning.pp - spec/puppet-lint/bin_spec.rb - spec/puppet-lint/configuration_spec.rb @@ -243,10 +220,11 @@ - spec/puppet-lint/plugins/check_strings/single_quote_string_with_variables_spec.rb - spec/puppet-lint/plugins/check_strings/variables_not_enclosed_spec.rb - spec/puppet-lint/plugins/check_variables/variable_contains_dash_spec.rb +- spec/puppet-lint/plugins/check_whitespace/140chars_spec.rb - spec/puppet-lint/plugins/check_whitespace/2sp_soft_tabs_spec.rb -- spec/puppet-lint/plugins/check_whitespace/80chars_spec.rb - spec/puppet-lint/plugins/check_whitespace/arrow_alignment_spec.rb - spec/puppet-lint/plugins/check_whitespace/hard_tabs_spec.rb - spec/puppet-lint/plugins/check_whitespace/trailing_whitespace_spec.rb - spec/puppet-lint_spec.rb - spec/spec_helper.rb +has_rdoc: diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/spec/fixtures/test/manifests/url_interpolation.pp new/spec/fixtures/test/manifests/url_interpolation.pp --- old/spec/fixtures/test/manifests/url_interpolation.pp 1970-01-01 01:00:00.000000000 +0100 +++ new/spec/fixtures/test/manifests/url_interpolation.pp 1970-01-01 01:00:00.000000000 +0100 @@ -0,0 +1,12 @@ +file { 'test1': + source => 'puppet:///foo' +} +file { 'test2': + source => "puppet:///foo/${::fqdn}" +} +file { 'test3': + source => "puppet:///${::fqdn}/foo" +} +file { 'test4': + source => "puppet:///foo/${::fqdn}/bar" +} diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/spec/puppet-lint/lexer_spec.rb new/spec/puppet-lint/lexer_spec.rb --- old/spec/puppet-lint/lexer_spec.rb 1970-01-01 01:00:00.000000000 +0100 +++ new/spec/puppet-lint/lexer_spec.rb 1970-01-01 01:00:00.000000000 +0100 @@ -687,7 +687,7 @@ it 'should match comments on multiple lines' do token = @lexer.tokenise("/* foo\n * bar\n*/").first expect(token.type).to eq(:MLCOMMENT) - expect(token.value).to eq("foo\nbar") + expect(token.value).to eq("foo\n bar\n") end end diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/spec/puppet-lint/plugins/check_classes/names_containing_dash_spec.rb new/spec/puppet-lint/plugins/check_classes/names_containing_dash_spec.rb --- old/spec/puppet-lint/plugins/check_classes/names_containing_dash_spec.rb 1970-01-01 01:00:00.000000000 +0100 +++ new/spec/puppet-lint/plugins/check_classes/names_containing_dash_spec.rb 1970-01-01 01:00:00.000000000 +0100 @@ -12,8 +12,8 @@ expect(problems).to have(1).problem end - it 'should create a warning' do - expect(problems).to contain_warning(class_msg).on_line(1).in_column(7) + it 'should create an error' do + expect(problems).to contain_error(class_msg).on_line(1).in_column(7) end end @@ -25,8 +25,8 @@ expect(problems).to have(1).problem end - it 'should create a warning' do - expect(problems).to contain_warning(define_msg).on_line(1).in_column(8) + it 'should create an error' do + expect(problems).to contain_error(define_msg).on_line(1).in_column(8) end end @@ -38,8 +38,8 @@ expect(problems).to have(1).problem end - it 'should create a warning' do - expect(problems).to contain_warning(class_msg).on_line(1).in_column(7) + it 'should create an error' do + expect(problems).to contain_error(class_msg).on_line(1).in_column(7) end end end diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/spec/puppet-lint/plugins/check_classes/variable_scope_spec.rb new/spec/puppet-lint/plugins/check_classes/variable_scope_spec.rb --- old/spec/puppet-lint/plugins/check_classes/variable_scope_spec.rb 1970-01-01 01:00:00.000000000 +0100 +++ new/spec/puppet-lint/plugins/check_classes/variable_scope_spec.rb 1970-01-01 01:00:00.000000000 +0100 @@ -147,16 +147,19 @@ context 'future parser blocks' do let(:code) { " class foo() { - $foo = [1,2] + $foo = {1=>2, 3=>4} $foo.each |$a, $b| { - $a - $c + $a # should cause no warnings + $c # top-scope variable warning + } + $b # top-scope variable warning + $foo.each |$d| { + $d[1] # should cause no warnings } - $b } " } - it 'should only detect a single problem' do + it 'should only detect two problems' do expect(problems).to have(2).problem end @@ -179,4 +182,18 @@ end end end + + context 'support the use of facts and trusted facts for Puppet 3.5 onwards' do + let(:code) { " + class foo() { + if $facts['osfamily'] == 'redhat' or $trusted['osfamily'] == 'redhat' { + $redhat = true + } + } + " } + + it 'should not detect any problems' do + expect(problems).to have(0).problems + end + end end diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/spec/puppet-lint/plugins/check_conditionals/case_without_default_spec.rb new/spec/puppet-lint/plugins/check_conditionals/case_without_default_spec.rb --- old/spec/puppet-lint/plugins/check_conditionals/case_without_default_spec.rb 1970-01-01 01:00:00.000000000 +0100 +++ new/spec/puppet-lint/plugins/check_conditionals/case_without_default_spec.rb 1970-01-01 01:00:00.000000000 +0100 @@ -32,6 +32,48 @@ expect(problems).to contain_warning(msg).on_line(2).in_column(7) end end + + context 'nested case statements without a default case on the outermost' do + let(:code) { " + case $foo { + case $foop { + bar: {} + default: {} + } + }" + } + + it 'should only detect a single problem' do + expect(problems).to have(1).problem + end + + it 'should create a warning' do + expect(problems).to contain_warning(msg) + end + end + + context 'three nested case statements with two missing default cases' do + let(:code) { " + case $foo { + case $foop { + bar: {} + case $woop { + baz: {} + } + default: {} + } + }" + } + + it 'should detect two problems' do + expect(problems).to have(2).problems + end + + it 'should create two warnings' do + expect(problems).to contain_warning(msg).on_line(2).in_column(7) + expect(problems).to contain_warning(msg).on_line(5).in_column(4) + end + end context 'issue-117' do let(:code) { " diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/spec/puppet-lint/plugins/check_nodes/unquoted_node_name_spec.rb new/spec/puppet-lint/plugins/check_nodes/unquoted_node_name_spec.rb --- old/spec/puppet-lint/plugins/check_nodes/unquoted_node_name_spec.rb 1970-01-01 01:00:00.000000000 +0100 +++ new/spec/puppet-lint/plugins/check_nodes/unquoted_node_name_spec.rb 1970-01-01 01:00:00.000000000 +0100 @@ -66,6 +66,19 @@ expect(problems).to contain_warning(msg).on_line(1).in_column(18) end end + + context 'multiple node blocks' do + let(:code) { "node foo { } node bar { }" } + + it 'should detect 2 problems' do + expect(problems).to have(2).problems + end + + it 'should create 2 warnings' do + expect(problems).to contain_warning(msg).on_line(1).in_column(6) + expect(problems).to contain_warning(msg).on_line(1).in_column(19) + end + end end context 'with fix enabled' do diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/spec/puppet-lint/plugins/check_resources/duplicate_params_spec.rb new/spec/puppet-lint/plugins/check_resources/duplicate_params_spec.rb --- old/spec/puppet-lint/plugins/check_resources/duplicate_params_spec.rb 1970-01-01 01:00:00.000000000 +0100 +++ new/spec/puppet-lint/plugins/check_resources/duplicate_params_spec.rb 1970-01-01 01:00:00.000000000 +0100 @@ -89,4 +89,12 @@ expect(problems).to have(0).problems end end + + context 'colon as last token in file' do + let(:code) { "}:" } + + it 'should not detect any problems' do + expect(problems).to have(0).problems + end + end end diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/spec/puppet-lint/plugins/check_strings/puppet_url_without_modules_spec.rb new/spec/puppet-lint/plugins/check_strings/puppet_url_without_modules_spec.rb --- old/spec/puppet-lint/plugins/check_strings/puppet_url_without_modules_spec.rb 1970-01-01 01:00:00.000000000 +0100 +++ new/spec/puppet-lint/plugins/check_strings/puppet_url_without_modules_spec.rb 1970-01-01 01:00:00.000000000 +0100 @@ -11,15 +11,52 @@ end end - context 'puppet:// url without modules' do - let(:code) { "'puppet:///foo'" } + context 'with fix disabled' do + context 'puppet:// url without modules' do + let(:code) { "'puppet:///foo'" } - it 'should only detect a single problem' do - expect(problems).to have(1).problem + it 'should only detect a single problem' do + expect(problems).to have(1).problem + end + + it 'should create a warning' do + expect(problems).to contain_warning(msg).on_line(1).in_column(1) + end + end + end + + context 'with fix enabled' do + before do + PuppetLint.configuration.fix = true end - it 'should create a warning' do - expect(problems).to contain_warning(msg).on_line(1).in_column(1) + after do + PuppetLint.configuration.fix = false end + + context 'puppet:// url without modules' do + let(:code) { "'puppet:///foo'" } + + it 'should only detect a single problem' do + expect(problems).to have(1).problem + end + + it 'should fix the manifest' do + expect(problems).to contain_fixed(msg).on_line(1).in_column(1) + end + + it 'should insert modules into the path' do + expect(manifest).to eq("'puppet:///modules/foo'") + end + end + end + + context 'double string wrapped puppet:// urls' do + let(:code) { File.read('spec/fixtures/test/manifests/url_interpolation.pp') } + + it 'should detect several problems' do + expect(problems).to have(4).problem + end + end end diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/spec/puppet-lint/plugins/check_whitespace/140chars_spec.rb new/spec/puppet-lint/plugins/check_whitespace/140chars_spec.rb --- old/spec/puppet-lint/plugins/check_whitespace/140chars_spec.rb 1970-01-01 01:00:00.000000000 +0100 +++ new/spec/puppet-lint/plugins/check_whitespace/140chars_spec.rb 1970-01-01 01:00:00.000000000 +0100 @@ -0,0 +1,54 @@ +# encoding: utf-8 +require 'spec_helper' + +describe '140chars' do + let(:msg) { 'line has more than 140 characters' } + + context 'file resource with a source line > 140c' do + let(:code) { " + file { + source => 'puppet:///modules/certificates/etc/ssl/private/wildcard.example.com.crt', + }" + } + + it 'should not detect any problems' do + expect(problems).to have(0).problems + end + end + + context 'file resource with a template line > 140c' do + let(:code) { " + file { + content => template('mymodule/this/is/a/truely/absurdly/long/path/that/should/make/you/feel/bad'), + }" + } + + it 'should not detect any problems' do + expect(problems).to have(0).problems + end + end + + context 'length of lines with UTF-8 characters' do + let(:code) { " + # ┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓ + # ┃ Configuration ┃ + # ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛" + } + + it 'should not detect any problems' do + expect(problems).to have(0).problems + end + end + + context '141 character line' do + let(:code) { 'a' * 141 } + + it 'should only detect a single problem' do + expect(problems).to have(1).problem + end + + it 'should create a warning' do + expect(problems).to contain_warning(msg).on_line(1).in_column(140) + end + end +end diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/spec/puppet-lint/plugins/check_whitespace/80chars_spec.rb new/spec/puppet-lint/plugins/check_whitespace/80chars_spec.rb --- old/spec/puppet-lint/plugins/check_whitespace/80chars_spec.rb 1970-01-01 01:00:00.000000000 +0100 +++ new/spec/puppet-lint/plugins/check_whitespace/80chars_spec.rb 1970-01-01 01:00:00.000000000 +0100 @@ -1,54 +0,0 @@ -# encoding: utf-8 -require 'spec_helper' - -describe '80chars' do - let(:msg) { 'line has more than 80 characters' } - - context 'file resource with a source line > 80c' do - let(:code) { " - file { - source => 'puppet:///modules/certificates/etc/ssl/private/wildcard.example.com.crt', - }" - } - - it 'should not detect any problems' do - expect(problems).to have(0).problems - end - end - - context 'file resource with a template line > 80c' do - let(:code) { " - file { - content => template('mymodule/this/is/a/truely/absurdly/long/path/that/should/make/you/feel/bad'), - }" - } - - it 'should not detect any problems' do - expect(problems).to have(0).problems - end - end - - context 'length of lines with UTF-8 characters' do - let(:code) { " - # ┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓ - # ┃ Configuration ┃ - # ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛" - } - - it 'should not detect any problems' do - expect(problems).to have(0).problems - end - end - - context '81 character line' do - let(:code) { 'a' * 81 } - - it 'should only detect a single problem' do - expect(problems).to have(1).problem - end - - it 'should create a warning' do - expect(problems).to contain_warning(msg).on_line(1).in_column(80) - end - end -end diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/spec/puppet-lint/plugins/check_whitespace/arrow_alignment_spec.rb new/spec/puppet-lint/plugins/check_whitespace/arrow_alignment_spec.rb --- old/spec/puppet-lint/plugins/check_whitespace/arrow_alignment_spec.rb 1970-01-01 01:00:00.000000000 +0100 +++ new/spec/puppet-lint/plugins/check_whitespace/arrow_alignment_spec.rb 1970-01-01 01:00:00.000000000 +0100 @@ -126,6 +126,28 @@ end end + context 'single resource with a misaligned => and semicolon at the end' do + let(:code) { " + file { '/tmp/bar': + foo => 1, + bar => 2, + gronk => 3, + baz => 4, + meh => 5; + }" + } + + it 'should detect four problems' do + expect(problems).to have(4).problems + end + + it 'should create four warnings' do + expect(problems).to contain_warning(msg).on_line(3).in_column(15) + expect(problems).to contain_warning(msg).on_line(4).in_column(15) + expect(problems).to contain_warning(msg).on_line(6).in_column(16) + expect(problems).to contain_warning(msg).on_line(7).in_column(15) + end + end context 'complex resource with a misaligned =>' do let(:code) { " file { '/tmp/foo': @@ -171,6 +193,34 @@ end end + context 'multi-resource with a misaligned => and semicolons' do + let(:code) { " + file { + '/tmp/foo': + ensure => 'directory', + owner => 'root', + mode => '0755'; + '/tmp/bar': + ensure => 'directory'; + '/tmp/baz': + ensure => 'directory', + owner => 'root', + mode => '0755'; + }" + } + + it 'should only detect a single problem' do + expect(problems).to have(4).problem + end + + it 'should create a warning' do + expect(problems).to contain_warning(msg).on_line(5).in_column(19) + expect(problems).to contain_warning(msg).on_line(6).in_column(18) + expect(problems).to contain_warning(msg).on_line(11).in_column(19) + expect(problems).to contain_warning(msg).on_line(12).in_column(18) + end + end + context 'multiple single line resources' do let(:code) { " file { 'foo': ensure => file } @@ -268,6 +318,20 @@ expect(problems).to contain_warning(msg).on_line(3).in_column(26) end end + + context 'resource param containing a single-element same-line hash' do + let(:code) { " + foo { 'foo': + a => true, + b => { 'a' => 'b' } + } + "} + + it 'should not detect any problems' do + expect(problems).to have(0).problems + end + end + end context 'with fix enabled' do diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/spec/puppet-lint/plugins/check_whitespace/trailing_whitespace_spec.rb new/spec/puppet-lint/plugins/check_whitespace/trailing_whitespace_spec.rb --- old/spec/puppet-lint/plugins/check_whitespace/trailing_whitespace_spec.rb 1970-01-01 01:00:00.000000000 +0100 +++ new/spec/puppet-lint/plugins/check_whitespace/trailing_whitespace_spec.rb 1970-01-01 01:00:00.000000000 +0100 @@ -15,6 +15,22 @@ expect(problems).to contain_error(msg).on_line(1).in_column(4) end end + + context 'line without code and trailing whitespace' do + let(:code) { " +class { + +} +" } + + it 'should only detect a single problem' do + expect(problems).to have(1).problem + end + + it 'should create an error' do + expect(problems).to contain_error(msg).on_line(3).in_column(1) + end + end end context 'with fix enabled' do @@ -57,5 +73,29 @@ expect(manifest).to eq("foo\nbar") end end + + context 'line without code and trailing whitespace' do + let(:code) { " +class foo { + +} +" } + let(:fixed) { " +class foo { + +} +" } + it 'should only detect a single problem' do + expect(problems).to have(1).problem + end + + it 'should create an error' do + expect(problems).to contain_fixed(msg).on_line(3).in_column(1) + end + + it 'should remove the trailing whitespace' do + expect(manifest).to eq(fixed) + end + end end end