From ab0278ec0e22b5e76284aaf585113e06deb2da75 Mon Sep 17 00:00:00 2001 From: Moritz Kraus Date: Thu, 7 Nov 2024 09:20:52 +0100 Subject: [PATCH 1/3] add tests for collectors --- spec/fixtures/fail/collectors.pp | 3 +++ spec/fixtures/pass/collectors.pp | 7 +++++++ 2 files changed, 10 insertions(+) create mode 100644 spec/fixtures/fail/collectors.pp create mode 100644 spec/fixtures/pass/collectors.pp diff --git a/spec/fixtures/fail/collectors.pp b/spec/fixtures/fail/collectors.pp new file mode 100644 index 0000000..9f313fb --- /dev/null +++ b/spec/fixtures/fail/collectors.pp @@ -0,0 +1,3 @@ +Ressource <| +$tag == 'foo' +|> diff --git a/spec/fixtures/pass/collectors.pp b/spec/fixtures/pass/collectors.pp new file mode 100644 index 0000000..06c55b1 --- /dev/null +++ b/spec/fixtures/pass/collectors.pp @@ -0,0 +1,7 @@ +Ressource <<| + $tag == 'foo' +|>> + +Ressource <| + $tag == 'foo' +|> From 1c7fb2bdd8c026274793f6dc7c7ac8d07f596a99 Mon Sep 17 00:00:00 2001 From: Moritz Kraus Date: Thu, 7 Nov 2024 09:21:29 +0100 Subject: [PATCH 2/3] include rspec collection matchers to support `have` --- spec/spec_helper.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 2871e8d..0a448e4 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,5 +1,7 @@ # frozen_string_literal: true +require 'rspec/collection_matchers' + begin require 'simplecov' require 'simplecov-console' From 8353c2171450e34b6a32783dfc605f1cd8062c8e Mon Sep 17 00:00:00 2001 From: Moritz Kraus Date: Thu, 7 Nov 2024 09:22:47 +0100 Subject: [PATCH 3/3] support indent in multi-line collector operators --- lib/puppet-lint/plugins/check_strict_indent.rb | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/lib/puppet-lint/plugins/check_strict_indent.rb b/lib/puppet-lint/plugins/check_strict_indent.rb index 7ca010d..e6b8383 100644 --- a/lib/puppet-lint/plugins/check_strict_indent.rb +++ b/lib/puppet-lint/plugins/check_strict_indent.rb @@ -9,20 +9,24 @@ def match(tokens) RPAREN: :LPAREN, HEREDOC: :HEREDOC_OPEN, HEREDOC_POST: :HEREDOC_OPEN, + RCOLLECT: :LCOLLECT, + RRCOLLECT: :LLCOLLECT, } open = { LBRACE: [], LBRACK: [], LPAREN: [], HEREDOC_OPEN: [], + LCOLLECT: [], + LLCOLLECT: [], } matches = {} tokens.each do |token| - if %i[LBRACE LBRACK LPAREN HEREDOC_OPEN].include?(token.type) + if %i[LBRACE LBRACK LPAREN HEREDOC_OPEN LCOLLECT LLCOLLECT].include?(token.type) open[token.type] << token - elsif %i[RBRACE RBRACK RPAREN HEREDOC HEREDOC_POST].include?(token.type) + elsif %i[RBRACE RBRACK RPAREN HEREDOC HEREDOC_POST RCOLLECT RRCOLLECT].include?(token.type) match = open[opening_token[token.type]].pop unless match.nil? matches[token] = match @@ -54,7 +58,7 @@ def check prev_token = token.prev_token while !prev_token.nil? and prev_token.type != :NEWLINE temp_indent += 1 if prev_token.type == :HEREDOC_OPEN - if %i[LBRACE LBRACK + if %i[LBRACE LBRACK LCOLLECT LLCOLLECT LPAREN].include?(prev_token.type) && (matches[prev_token].nil? or matches[prev_token].line > prev_token.line) # left braces not matched in the same line increase indent open_groups += 1 @@ -97,7 +101,7 @@ def check # unindent for closing brackets in the current line next_token = token.next_token while !next_token.nil? and next_token.type != :NEWLINE - if %i[RBRACE RBRACK RPAREN].include?(next_token.type) + if %i[RBRACE RBRACK RPAREN RCOLLECT RRCOLLECT].include?(next_token.type) if !matches[next_token].nil? and matches[next_token].line < next_token.line # right braces matched in a previous line decrease indent indent -= 1