puppet-lint-strict_indent-check 2.1.0 → 4.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ef74dd23e7f707cb92230b999f833b102a5069be9857a88e1500809ad57a8c20
4
- data.tar.gz: 5b4f48f0408cb5161c4d1cec7144c703399aa88d35fb319c7c2fe78e2e164075
3
+ metadata.gz: 1fb2ac311bc0d30ef09d5975e7160f31fa7ecbb67e8498a7359d6894c6816526
4
+ data.tar.gz: 66a1bbfc4c9e494a8923d19c18ed1905a58b2645b4d4d6a65844efda0b9e9897
5
5
  SHA512:
6
- metadata.gz: da47ec5cabfbb07a0b9cf4e50d2700f8a1f355791b950260b0dd8784d84a3569c2bd9bcb6dcd289ad431c298291f397e1f4218444ba1469dad828c0f9aadbc3d
7
- data.tar.gz: 90719145ab8fab866bacb471091bb4d8710b08a0c3627b18a3740bd0c92572ea584bb433de5fb765f4cfb55a03ccee42b8c6f65746d30b96ba5aa4ad897d199d
6
+ metadata.gz: b0ec808b887a1f2459be4d34ce2371210b990ffec3c78a58c4e5ce3c173bea8c267697e18c6d693acbcb4e7b5a0551496fc05d8f5c6762283e530716ad40d0d7
7
+ data.tar.gz: 493240b21f3ab3a1157851f3cb1377089a9ff60454200b7bf34c68fa22ba747dda05bd16f940254305460df78a276963a5cb31e40e5ae132afc79ebfa05baf6e
data/CHANGELOG.md CHANGED
@@ -2,6 +2,41 @@
2
2
 
3
3
  All notable changes to this project will be documented in this file.
4
4
 
5
+ ## [4.0.0](https://github.com/voxpupuli/puppet-lint-strict_indent-check/tree/4.0.0) (2025-08-06)
6
+
7
+ [Full Changelog](https://github.com/voxpupuli/puppet-lint-strict_indent-check/compare/3.0.0...4.0.0)
8
+
9
+ **Breaking changes:**
10
+
11
+ - Match the indent for a single semicolon with the Puppet documentation [\#48](https://github.com/voxpupuli/puppet-lint-strict_indent-check/pull/48) ([msalway](https://github.com/msalway))
12
+ - Only indent once for doubled brackets [\#44](https://github.com/voxpupuli/puppet-lint-strict_indent-check/pull/44) ([msalway](https://github.com/msalway))
13
+
14
+ **Fixed bugs:**
15
+
16
+ - Refactor heredoc indent calculations [\#47](https://github.com/voxpupuli/puppet-lint-strict_indent-check/pull/47) ([msalway](https://github.com/msalway))
17
+
18
+ **Closed issues:**
19
+
20
+ - Ruby 3.1 test fails due to double start of SimpleCov [\#45](https://github.com/voxpupuli/puppet-lint-strict_indent-check/issues/45)
21
+ - Test workflow fails [\#41](https://github.com/voxpupuli/puppet-lint-strict_indent-check/issues/41)
22
+ - Extra indent requested with two opens on same line. [\#21](https://github.com/voxpupuli/puppet-lint-strict_indent-check/issues/21)
23
+ - Update indent behaviour when semicolon is on a separate line [\#19](https://github.com/voxpupuli/puppet-lint-strict_indent-check/issues/19)
24
+
25
+ **Merged pull requests:**
26
+
27
+ - Update README for recent changes [\#49](https://github.com/voxpupuli/puppet-lint-strict_indent-check/pull/49) ([msalway](https://github.com/msalway))
28
+ - Remove SimpleCov.start as it is done by PuppetLint's spec\_helper [\#46](https://github.com/voxpupuli/puppet-lint-strict_indent-check/pull/46) ([msalway](https://github.com/msalway))
29
+ - fix rubocop [\#42](https://github.com/voxpupuli/puppet-lint-strict_indent-check/pull/42) ([paran1](https://github.com/paran1))
30
+ - Update voxpupuli-rubocop requirement from ~\> 1.1 to ~\> 2.0 [\#36](https://github.com/voxpupuli/puppet-lint-strict_indent-check/pull/36) ([dependabot[bot]](https://github.com/apps/dependabot))
31
+
32
+ ## [3.0.0](https://github.com/voxpupuli/puppet-lint-strict_indent-check/tree/3.0.0) (2023-04-21)
33
+
34
+ [Full Changelog](https://github.com/voxpupuli/puppet-lint-strict_indent-check/compare/2.1.0...3.0.0)
35
+
36
+ **Breaking changes:**
37
+
38
+ - Drop Ruby \< 2.7; Add RuboCop [\#34](https://github.com/voxpupuli/puppet-lint-strict_indent-check/pull/34) ([bastelfreak](https://github.com/bastelfreak))
39
+
5
40
  ## [2.1.0](https://github.com/voxpupuli/puppet-lint-strict_indent-check/tree/2.1.0) (2022-11-29)
6
41
 
7
42
  [Full Changelog](https://github.com/voxpupuli/puppet-lint-strict_indent-check/compare/2.0.8...2.1.0)
data/README.md CHANGED
@@ -35,12 +35,15 @@ puppet-lint -l chars_per_indent_4.rb puppet-mysql/manifests/init.pp
35
35
 
36
36
  ## Acceptable Identation
37
37
 
38
- * indent should increase by one step the line after each opened brace (square, curly, paren)
38
+ * indent should increase by one step the line after each opened brace (square, curly, paren).
39
39
  * indent should decrease by one step the line of every closed brace.
40
+ * if multiple pairs of braces are opened and closed on the same two lines the indent should only increase once.
40
41
  * indent should increase by one step the line after a resource title, unless it already increased due to a bracket.
41
42
  * indent should decrease by one step the line after the end of a resource due to semicolon, if it was indented for resource title.
43
+ * if the semicolon is the only element on the line then the indent decreases on the semicolon line instead of the line after.
42
44
  * indent should decrease by one step the line of the end of a resource due to right curly brace, if it was indented for resource title, and not ended by a semicolon.
43
45
  * indent should increase by one step the line after an equals `=` or farrow `=>` that ends a line, but only for that one line.
46
+ * heredoc contents should be indented by one step.
44
47
 
45
48
  see `spec/fixtures/pass/` for good indentation examples.
46
49
 
@@ -1,30 +1,27 @@
1
1
  # Public: Check the manifest tokens for correct indent levels and
2
2
  # record a warning for each instance found.
3
3
 
4
- PuppetLint.new_check(:'strict_indent') do
4
+ PuppetLint.new_check(:strict_indent) do
5
5
  def match(tokens)
6
6
  opening_token = {
7
- :RBRACE => :LBRACE,
8
- :RBRACK => :LBRACK,
9
- :RPAREN => :LPAREN,
10
- :HEREDOC => :HEREDOC_OPEN,
11
- :HEREDOC_POST => :HEREDOC_OPEN,
7
+ RBRACE: :LBRACE,
8
+ RBRACK: :LBRACK,
9
+ RPAREN: :LPAREN,
12
10
  }
13
11
  open = {
14
- :LBRACE => [],
15
- :LBRACK => [],
16
- :LPAREN => [],
17
- :HEREDOC_OPEN => [],
12
+ LBRACE: [],
13
+ LBRACK: [],
14
+ LPAREN: [],
18
15
  }
19
16
 
20
17
  matches = {}
21
18
 
22
19
  tokens.each do |token|
23
- if [:LBRACE, :LBRACK, :LPAREN, :HEREDOC_OPEN].include?(token.type)
20
+ if %i[LBRACE LBRACK LPAREN].include?(token.type)
24
21
  open[token.type] << token
25
- elsif [:RBRACE, :RBRACK, :RPAREN, :HEREDOC, :HEREDOC_POST].include?(token.type)
22
+ elsif %i[RBRACE RBRACK RPAREN].include?(token.type)
26
23
  match = open[opening_token[token.type]].pop
27
- if not match.nil?
24
+ unless match.nil?
28
25
  matches[token] = match
29
26
  matches[match] = token
30
27
  end
@@ -41,25 +38,27 @@ PuppetLint.new_check(:'strict_indent') do
41
38
 
42
39
  matches = match(tokens)
43
40
 
44
- tokens.select { |token|
41
+ tokens.select do |token|
45
42
  token.type == :NEWLINE
46
- }.reject { |token|
43
+ end.reject do |token|
47
44
  # ignore newline at end of code
48
45
  token.next_token.nil?
49
- }.each do |token|
46
+ end.each do |token|
50
47
  temp_indent = 0
51
48
 
49
+ matched_open_lines = []
52
50
  # indent for open groups in the previous line
53
51
  open_groups = 0
54
52
  prev_token = token.prev_token
55
- while not prev_token.nil? and prev_token.type != :NEWLINE
56
- if prev_token.type == :HEREDOC_OPEN
57
- temp_indent += 1
58
- end
59
- if [:LBRACE, :LBRACK, :LPAREN].include?(prev_token.type)
60
- if matches[prev_token].nil? or matches[prev_token].line > prev_token.line
61
- # left braces not matched in the same line increase indent
53
+ while !prev_token.nil? and prev_token.type != :NEWLINE
54
+ temp_indent += 1 if prev_token.type == :HEREDOC_OPEN
55
+ if %i[LBRACE LBRACK LPAREN].include?(prev_token.type)
56
+ if matches[prev_token].nil?
57
+ open_groups += 1
58
+ elsif matches[prev_token].line > prev_token.line and !matched_open_lines.include?(matches[prev_token].line)
59
+ # increase indent for left braces not matched in the same line or in a line we have already matched a brace to
62
60
  open_groups += 1
61
+ matched_open_lines << matches[prev_token].line
63
62
  end
64
63
  end
65
64
  prev_token = prev_token.prev_token
@@ -68,7 +67,7 @@ PuppetLint.new_check(:'strict_indent') do
68
67
 
69
68
  # reset prev_token to last non-whitespace token on previous line
70
69
  prev_token = token.prev_token
71
- while not prev_token.nil? and (prev_token.type == :WHITESPACE or prev_token.type == :COMMENT)
70
+ while !prev_token.nil? and (prev_token.type == :WHITESPACE or prev_token.type == :COMMENT)
72
71
  prev_token = prev_token.prev_token
73
72
  end
74
73
 
@@ -88,7 +87,7 @@ PuppetLint.new_check(:'strict_indent') do
88
87
  end
89
88
  end
90
89
  when :SEMIC
91
- if not colon_indent.nil?
90
+ unless colon_indent.nil?
92
91
  # only unindent for a semicolon when we've indented for a colon
93
92
  colon_indent = nil
94
93
  indent -= 1
@@ -99,19 +98,27 @@ PuppetLint.new_check(:'strict_indent') do
99
98
 
100
99
  # unindent for closing brackets in the current line
101
100
  next_token = token.next_token
102
- while not next_token.nil? and next_token.type != :NEWLINE
103
- if [:RBRACE, :RBRACK, :RPAREN].include?(next_token.type)
104
- if not matches[next_token].nil? and matches[next_token].line < next_token.line
105
- # right braces matched in a previous line decrease indent
101
+ matched_close_lines = []
102
+ while !next_token.nil? and next_token.type != :NEWLINE
103
+ if %i[RBRACE RBRACK RPAREN].include?(next_token.type)
104
+ if !matches[next_token].nil? and
105
+ matches[next_token].line < next_token.line and
106
+ !matched_close_lines.include?(matches[next_token].line)
107
+ # right braces matched in a previous line decrease indent unless we already matched a brace in the same line
106
108
  indent -= 1
109
+ matched_close_lines << matches[next_token].line
107
110
  end
108
- if next_token.type == :RBRACE and not colon_indent.nil?
109
- if not matches[next_token].nil? and matches[next_token].line < colon_indent
110
- # unindent at the end of resources if needed
111
- indent -= 1
112
- colon_indent = nil
113
- end
111
+ if next_token.type == :RBRACE and !colon_indent.nil? && (!matches[next_token].nil? and matches[next_token].line < colon_indent)
112
+ # unindent at the end of resources if needed
113
+ indent -= 1
114
+ colon_indent = nil
114
115
  end
116
+ elsif next_token.type == :SEMIC and !colon_indent.nil? and
117
+ %i[INDENT NEWLINE].include?(next_token.prev_token.type) and
118
+ (next_token.next_token.nil? or next_token.next_token.type == :NEWLINE)
119
+ # For a lone semicolon within a block decrement immediately. Use temp_indent because
120
+ # indent will be decremented in the next line by the prev_token logic above.
121
+ temp_indent -= 1
115
122
  end
116
123
  next_token = next_token.next_token
117
124
  end
@@ -119,54 +126,112 @@ PuppetLint.new_check(:'strict_indent') do
119
126
  # obviously we have a problem
120
127
  if indent < 0
121
128
  notify :error, {
122
- :message => 'Error calculating indent. Please file an issue at https://github.com/relud/puppet-lint-indent-check/issues',
123
- :line => token.next_token.line,
124
- :column => token.next_token.column,
129
+ message: 'Error calculating indent. Please file an issue at https://github.com/relud/puppet-lint-indent-check/issues',
130
+ line: token.next_token.line,
131
+ column: token.next_token.column,
125
132
  }
126
133
  # stop parsing indent
127
134
  break
128
135
  end
129
136
 
130
137
  # get actual indent
131
- actual = 0
132
- if token.next_token.type == :INDENT
133
- actual = token.next_token.value.length
134
- elsif !token.prev_token.nil? and token.prev_token.type == :HEREDOC
135
- actual = token.prev_token.value.split("\n").last.length
136
- elsif !token.prev_token.nil? and token.prev_token.type == :HEREDOC_OPEN
137
- actual = next_token.prev_token.value.split("\n").last.length
138
- else
139
- actual = 0
140
- end
138
+ actual = case token.next_token.type
139
+ when :INDENT
140
+ token.next_token.value.length
141
+ when :HEREDOC
142
+ # Lines containing heredocs have no indent token as the indent is consumed by the heredoc token.
143
+ # However the last line of the token value is the whitespace before the pipe in the termination line.
144
+ # We use the length of this to get the indent.
145
+ if token.next_token.value.end_with?("\n")
146
+ 0
147
+ else
148
+ token.next_token.value.split("\n").last.length
149
+ end
150
+ when :HEREDOC_PRE
151
+ # For interpolated heredocs the pipe whitespace is in the HEREDOC_POST token so we need scan forward
152
+ # to this and get its length.
153
+ next_token = token.next_token
154
+ while !next_token.nil? and next_token.type != :NEWLINE and next_token.type != :HEREDOC_POST
155
+ next_token = next_token.next_token
156
+ end
157
+ if next_token.type == :HEREDOC_POST
158
+ next_token.value.split("\n").last.length
159
+ else
160
+ # Should never get here return zero if we do
161
+ 0
162
+ end
163
+ else
164
+ 0
165
+ end
141
166
 
142
167
  # expected indent
143
168
  expected = (indent + temp_indent) * chars_per_indent
144
169
 
145
170
  # oh no! incorrect indent!
146
- if actual != expected
147
- # no one cares if blank lines and comments are indented correctly
148
- if not [:COMMENT, :NEWLINE].include?(token.next_token.type)
149
- notify :warning, {
150
- :message => "indent should be #{expected} chars and is #{actual}",
151
- :line => token.next_token.line,
152
- :column => token.next_token.column,
153
- :token => token.next_token,
154
- :indent => expected,
155
- }
156
- end
157
- end
171
+ next unless actual != expected
172
+
173
+ # no one cares if blank lines and comments are indented correctly
174
+ next if %i[COMMENT NEWLINE].include?(token.next_token.type)
175
+
176
+ notify :warning, {
177
+ message: "indent should be #{expected} chars and is #{actual}",
178
+ line: token.next_token.line,
179
+ column: token.next_token.column,
180
+ token: token.next_token,
181
+ indent: expected,
182
+ actual: actual,
183
+ }
158
184
  end
159
185
  end
160
186
 
161
187
  def fix(problem)
162
188
  char_for_indent = ' '
163
- if [:INDENT,:WHITESPACE].include?(problem[:token].type)
189
+ if %i[INDENT WHITESPACE].include?(problem[:token].type)
164
190
  problem[:token].value = char_for_indent * problem[:indent]
191
+ elsif problem[:token].type == :HEREDOC
192
+ change = problem[:indent] - problem[:actual]
193
+ indent_heredoc(problem[:token], change)
194
+ elsif problem[:token].type == :HEREDOC_PRE
195
+ change = problem[:indent] - problem[:actual]
196
+ indent_heredoc(problem[:token], change)
197
+ next_token = problem[:token].next_token
198
+ while !next_token.nil? and next_token.type != :HEREDOC_POST
199
+ indent_heredoc(next_token, change) if next_token.type == :HEREDOC_MID
200
+ next_token = next_token.next_token
201
+ end
202
+ indent_heredoc(next_token, change) if next_token.type == :HEREDOC_POST
165
203
  else
166
204
  tokens.insert(
167
205
  tokens.find_index(problem[:token]),
168
- PuppetLint::Lexer::Token.new(:INDENT, char_for_indent * problem[:indent], problem[:line], problem[:column])
206
+ PuppetLint::Lexer::Token.new(:INDENT, char_for_indent * problem[:indent], problem[:line], problem[:column]),
169
207
  )
170
208
  end
171
209
  end
210
+
211
+ def map_heredoc_lines(value, change, skip)
212
+ char_for_indent = ' '
213
+ value.split("\n").map! do |line|
214
+ if skip or line.empty?
215
+ skip = false
216
+ line
217
+ elsif change < 0
218
+ line[-change..]
219
+ else
220
+ (char_for_indent * change) + line
221
+ end
222
+ end.join("\n")
223
+ end
224
+
225
+ def indent_heredoc(token, change)
226
+ case token.type
227
+ when :HEREDOC
228
+ token.raw = map_heredoc_lines(token.raw, change, false)
229
+ when :HEREDOC_PRE
230
+ token.value = map_heredoc_lines(token.value, change, false)
231
+ when :HEREDOC_MID
232
+ token.value = map_heredoc_lines(token.value, change, true)
233
+ when :HEREDOC_POST
234
+ token.raw = map_heredoc_lines(token.raw, change, true)
235
+ end
236
+ end
172
237
  end
@@ -0,0 +1,5 @@
1
+ $variable = @(EOT)
2
+ This is a multiline
3
+ with a ${variable}
4
+ heredoc string
5
+ | EOT
@@ -0,0 +1,5 @@
1
+ $variable = @(EOT)
2
+ This is a multiline
3
+ with a ${variable}
4
+ heredoc string
5
+ | EOT
@@ -0,0 +1,13 @@
1
+ $content = epp('file.epp',{
2
+ 'options' => '124',
3
+ })
4
+
5
+ $content = epp(
6
+ 'file.epp',{
7
+ 'options' => '124',
8
+ })
9
+
10
+ $content = epp('file.epp',{
11
+ 'options' => '124',
12
+ }
13
+ )
@@ -0,0 +1,31 @@
1
+ # Tests for heredocs within class
2
+ class 'heredocclass' {
3
+ file { '/heredoc/file/resource/without/comma':
4
+ content => @(HERE)
5
+ This is a here doc
6
+ with two lines
7
+ | HERE
8
+ }
9
+
10
+ file { '/heredoc/file/resource/with/comma':
11
+ content => @(HERE),
12
+ This is a here doc
13
+ with two lines
14
+ | HERE
15
+ }
16
+
17
+ file { '/heredoc/in/function/in/file/resource':
18
+ content => inlineepp(@(HERE)),
19
+ This is a here doc
20
+ with two lines
21
+ | HERE
22
+ }
23
+
24
+ $variable_with_interpolation = @("EOT")
25
+ Another example
26
+ ${variable}
27
+ with
28
+ ${variable}
29
+ with interpolation
30
+ | EOT
31
+ }
@@ -0,0 +1,15 @@
1
+ file {
2
+ default:
3
+ ensure => file,
4
+ owner => 'root',
5
+ group => 'wheel',
6
+ mode => '0600',
7
+ ;
8
+ ['ssh_host_dsa_key', 'ssh_host_key', 'ssh_host_rsa_key']:
9
+ # use all defaults
10
+ ;
11
+ ['ssh_config', 'ssh_host_dsa_key.pub', 'ssh_host_key.pub', 'ssh_host_rsa_key.pub', 'sshd_config']:
12
+ # override mode
13
+ mode => '0644',
14
+ ;
15
+ }
@@ -1,21 +1,24 @@
1
1
  require 'spec_helper'
2
+ # rubocop:disable Lint/RedundantRequireStatement
3
+ require 'pp'
4
+ # rubocop:enable Lint/RedundantRequireStatement
2
5
 
3
6
  describe 'strict_indent' do
4
7
  before do
5
8
  # disable all other checks
6
- PuppetLint.configuration.checks.reject{ |check|
9
+ PuppetLint.configuration.checks.reject do |check|
7
10
  check == :indent
8
- }.each do |check|
9
- PuppetLint.configuration.send("disable_#{check}")
11
+ end.each do |check|
12
+ PuppetLint.configuration.send(:"disable_#{check}")
10
13
  end
11
14
  end
12
15
 
13
16
  after do
14
17
  # re-enable other checks
15
- PuppetLint.configuration.checks.reject{ |check|
18
+ PuppetLint.configuration.checks.reject do |check|
16
19
  check == :indent
17
- }.each do |check|
18
- PuppetLint.configuration.send("enable_#{check}")
20
+ end.each do |check|
21
+ PuppetLint.configuration.send(:"enable_#{check}")
19
22
  end
20
23
  end
21
24
 
@@ -24,7 +27,7 @@ describe 'strict_indent' do
24
27
  context manifest do
25
28
  let(:code) { File.read(manifest) }
26
29
 
27
- it 'should detect no problems' do
30
+ it 'detects no problems' do
28
31
  expect(problems).to have(0).problems
29
32
  end
30
33
  end
@@ -34,7 +37,7 @@ describe 'strict_indent' do
34
37
  context manifest do
35
38
  let(:code) { File.read(manifest) }
36
39
 
37
- it 'should detect problems' do
40
+ it 'detects problems' do
38
41
  expect(problems).to have(1).problems
39
42
  end
40
43
  end
@@ -42,7 +45,7 @@ describe 'strict_indent' do
42
45
  end
43
46
 
44
47
  context 'comment after resource title.' do
45
- let(:code) {
48
+ let(:code) do
46
49
  <<-EOF.gsub(/^ {8}/, '')
47
50
  class (
48
51
  ) {
@@ -52,15 +55,15 @@ describe 'strict_indent' do
52
55
  }
53
56
  }
54
57
  EOF
55
- }
58
+ end
56
59
 
57
- it 'should detect 0 problems' do
60
+ it 'detects 0 problems' do
58
61
  expect(problems).to have(0).problems
59
62
  end
60
63
  end
61
64
 
62
65
  context 'invalid array indent' do
63
- let(:code) {
66
+ let(:code) do
64
67
  <<-EOF.gsub(/^ {8}/, '')
65
68
  class (
66
69
  ) {
@@ -71,23 +74,215 @@ describe 'strict_indent' do
71
74
  }
72
75
  }
73
76
  EOF
74
- }
77
+ end
75
78
 
76
- it 'should detect 1 problems' do
79
+ it 'detects 1 problems' do
77
80
  expect(problems).to have(1).problems
78
81
  end
79
82
  end
80
83
 
81
84
  context 'blank line at beginning of file' do
82
- let(:code) {
85
+ let(:code) do
83
86
  <<-EOF.gsub(/^ {8}/, '')
84
87
 
85
88
  class () {}
86
89
  EOF
87
- }
90
+ end
88
91
 
89
- it 'should detect 0 problems' do
92
+ it 'detects 0 problems' do
90
93
  expect(problems).to have(0).problems
91
94
  end
92
95
  end
96
+
97
+ context 'misplaced resource semicolons' do
98
+ before do
99
+ PuppetLint.configuration.fix = true
100
+ end
101
+
102
+ after do
103
+ PuppetLint.configuration.fix = false
104
+ end
105
+
106
+ let(:code) do
107
+ <<~EOF
108
+ file {
109
+ default:
110
+ ensure => file,
111
+ owner => 'root',
112
+ group => 'wheel',
113
+ mode => '0600',
114
+ ;
115
+ ['ssh_host_dsa_key', 'ssh_host_key', 'ssh_host_rsa_key']:
116
+ # use all defaults
117
+ ;
118
+ ['ssh_config', 'ssh_host_dsa_key.pub', 'ssh_host_key.pub', 'ssh_host_rsa_key.pub', 'sshd_config']:
119
+ # override mode
120
+ mode => '0644',
121
+ ;
122
+ }
123
+ EOF
124
+ end
125
+
126
+ let(:fixed) do
127
+ <<~EOF
128
+ file {
129
+ default:
130
+ ensure => file,
131
+ owner => 'root',
132
+ group => 'wheel',
133
+ mode => '0600',
134
+ ;
135
+ ['ssh_host_dsa_key', 'ssh_host_key', 'ssh_host_rsa_key']:
136
+ # use all defaults
137
+ ;
138
+ ['ssh_config', 'ssh_host_dsa_key.pub', 'ssh_host_key.pub', 'ssh_host_rsa_key.pub', 'sshd_config']:
139
+ # override mode
140
+ mode => '0644',
141
+ ;
142
+ }
143
+ EOF
144
+ end
145
+
146
+ it 'detects three problems' do
147
+ expect(problems).to have(3).problem
148
+ end
149
+
150
+ it 'fixes the first problem' do
151
+ expect(problems).to contain_fixed('indent should be 2 chars and is 4').on_line(7).in_column(1)
152
+ end
153
+
154
+ it 'fixes the second problem' do
155
+ expect(problems).to contain_fixed('indent should be 2 chars and is 4').on_line(10).in_column(1)
156
+ end
157
+
158
+ it 'fixes the third problem' do
159
+ expect(problems).to contain_fixed('indent should be 2 chars and is 0').on_line(14).in_column(1)
160
+ end
161
+
162
+ it 'moves the semicolons' do
163
+ expect(manifest).to eq fixed
164
+ end
165
+ end
166
+
167
+ context 'misaligned heredocs' do
168
+ before do
169
+ PuppetLint.configuration.fix = true
170
+ end
171
+
172
+ after do
173
+ PuppetLint.configuration.fix = false
174
+ end
175
+
176
+ let(:code) do
177
+ <<~EOF
178
+ $over_indented = @(HERE)
179
+ This is a heredoc
180
+ that has been
181
+
182
+ indented 4 spaces
183
+ and has some
184
+ internal indenting
185
+ | HERE
186
+
187
+ $under_indented = @(HERE)
188
+ This is a heredoc
189
+
190
+ that has no
191
+ indent
192
+ and has some
193
+ internal indenting
194
+ | HERE
195
+
196
+ $over_indented_interpolated = @("HERE")
197
+ This is a heredoc
198
+ with a ${variable}
199
+ that has been
200
+
201
+ indented 4 spaces
202
+ and has some
203
+ internal indenting
204
+ and ${another} variable
205
+ | HERE
206
+
207
+ $under_indented_interpolated = @("HERE")
208
+ This is a heredoc
209
+ with a ${variable} with trailing text
210
+ that has been
211
+
212
+ indented 1 space
213
+ and has some
214
+ internal indenting
215
+ and ${another} variable
216
+ | HERE
217
+ EOF
218
+ end
219
+
220
+ let(:fixed) do
221
+ <<~EOF
222
+ $over_indented = @(HERE)
223
+ This is a heredoc
224
+ that has been
225
+
226
+ indented 4 spaces
227
+ and has some
228
+ internal indenting
229
+ | HERE
230
+
231
+ $under_indented = @(HERE)
232
+ This is a heredoc
233
+
234
+ that has no
235
+ indent
236
+ and has some
237
+ internal indenting
238
+ | HERE
239
+
240
+ $over_indented_interpolated = @("HERE")
241
+ This is a heredoc
242
+ with a ${variable}
243
+ that has been
244
+
245
+ indented 4 spaces
246
+ and has some
247
+ internal indenting
248
+ and ${another} variable
249
+ | HERE
250
+
251
+ $under_indented_interpolated = @("HERE")
252
+ This is a heredoc
253
+ with a ${variable} with trailing text
254
+ that has been
255
+
256
+ indented 1 space
257
+ and has some
258
+ internal indenting
259
+ and ${another} variable
260
+ | HERE
261
+ EOF
262
+ end
263
+
264
+ it 'detects four problems' do
265
+ expect(problems).to have(4).problem
266
+ end
267
+
268
+ it 'fixes the first problem' do
269
+ expect(problems).to contain_fixed('indent should be 2 chars and is 4').on_line(2).in_column(1)
270
+ end
271
+
272
+ it 'fixes the second problem' do
273
+ expect(problems).to contain_fixed('indent should be 2 chars and is 0').on_line(11).in_column(1)
274
+ end
275
+
276
+ it 'fixes the third problem' do
277
+ expect(problems).to contain_fixed('indent should be 2 chars and is 4').on_line(20).in_column(1)
278
+ end
279
+
280
+ it 'fixes the forth problem' do
281
+ expect(problems).to contain_fixed('indent should be 2 chars and is 1').on_line(31).in_column(1)
282
+ end
283
+
284
+ it 'moves the heredoc' do
285
+ expect(manifest).to eq fixed
286
+ end
287
+ end
93
288
  end
data/spec/spec_helper.rb CHANGED
@@ -1,29 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- begin
4
- require 'simplecov'
5
- require 'simplecov-console'
6
- require 'codecov'
7
- rescue LoadError
8
- else
9
- SimpleCov.start do
10
- track_files 'lib/**/*.rb'
11
-
12
- add_filter '/spec'
13
-
14
- enable_coverage :branch
15
-
16
- # do not track vendored files
17
- add_filter '/vendor'
18
- add_filter '/.vendor'
19
- end
20
-
21
- SimpleCov.formatters = [
22
- SimpleCov::Formatter::Console,
23
- SimpleCov::Formatter::Codecov,
24
- ]
25
- end
26
-
27
3
  require 'puppet-lint'
4
+ require 'rspec/collection_matchers'
28
5
 
29
6
  PuppetLint::Plugins.load_spec_helper
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: puppet-lint-strict_indent-check
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.0
4
+ version: 4.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Vox Pupuli
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-11-29 00:00:00.000000000 Z
11
+ date: 2025-08-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: puppet-lint
@@ -16,104 +16,20 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '1.0'
19
+ version: '3'
20
20
  - - "<"
21
21
  - !ruby/object:Gem::Version
22
- version: '4'
22
+ version: '5'
23
23
  type: :runtime
24
24
  prerelease: false
25
25
  version_requirements: !ruby/object:Gem::Requirement
26
26
  requirements:
27
27
  - - ">="
28
28
  - !ruby/object:Gem::Version
29
- version: '1.0'
29
+ version: '3'
30
30
  - - "<"
31
31
  - !ruby/object:Gem::Version
32
- version: '4'
33
- - !ruby/object:Gem::Dependency
34
- name: rspec
35
- requirement: !ruby/object:Gem::Requirement
36
- requirements:
37
- - - "~>"
38
- - !ruby/object:Gem::Version
39
- version: '3.0'
40
- type: :development
41
- prerelease: false
42
- version_requirements: !ruby/object:Gem::Requirement
43
- requirements:
44
- - - "~>"
45
- - !ruby/object:Gem::Version
46
- version: '3.0'
47
- - !ruby/object:Gem::Dependency
48
- name: rspec-its
49
- requirement: !ruby/object:Gem::Requirement
50
- requirements:
51
- - - "~>"
52
- - !ruby/object:Gem::Version
53
- version: '1.0'
54
- type: :development
55
- prerelease: false
56
- version_requirements: !ruby/object:Gem::Requirement
57
- requirements:
58
- - - "~>"
59
- - !ruby/object:Gem::Version
60
- version: '1.0'
61
- - !ruby/object:Gem::Dependency
62
- name: rspec-collection_matchers
63
- requirement: !ruby/object:Gem::Requirement
64
- requirements:
65
- - - "~>"
66
- - !ruby/object:Gem::Version
67
- version: '1.0'
68
- type: :development
69
- prerelease: false
70
- version_requirements: !ruby/object:Gem::Requirement
71
- requirements:
72
- - - "~>"
73
- - !ruby/object:Gem::Version
74
- version: '1.0'
75
- - !ruby/object:Gem::Dependency
76
- name: rspec-json_expectations
77
- requirement: !ruby/object:Gem::Requirement
78
- requirements:
79
- - - ">="
80
- - !ruby/object:Gem::Version
81
- version: '0'
82
- type: :development
83
- prerelease: false
84
- version_requirements: !ruby/object:Gem::Requirement
85
- requirements:
86
- - - ">="
87
- - !ruby/object:Gem::Version
88
- version: '0'
89
- - !ruby/object:Gem::Dependency
90
- name: rake
91
- requirement: !ruby/object:Gem::Requirement
92
- requirements:
93
- - - ">="
94
- - !ruby/object:Gem::Version
95
- version: '0'
96
- type: :development
97
- prerelease: false
98
- version_requirements: !ruby/object:Gem::Requirement
99
- requirements:
100
- - - ">="
101
- - !ruby/object:Gem::Version
102
- version: '0'
103
- - !ruby/object:Gem::Dependency
104
- name: simplecov
105
- requirement: !ruby/object:Gem::Requirement
106
- requirements:
107
- - - ">="
108
- - !ruby/object:Gem::Version
109
- version: '0'
110
- type: :development
111
- prerelease: false
112
- version_requirements: !ruby/object:Gem::Requirement
113
- requirements:
114
- - - ">="
115
- - !ruby/object:Gem::Version
116
- version: '0'
32
+ version: '5'
117
33
  description: " Extends puppet-lint to ensure that your manifests follow a strict
118
34
  indentation pattern.\n"
119
35
  email: voxpupuli@groups.io
@@ -127,16 +43,21 @@ files:
127
43
  - lib/puppet-lint/plugins/check_strict_indent.rb
128
44
  - spec/fixtures/fail/1.pp
129
45
  - spec/fixtures/fail/heredoc_extra.pp
46
+ - spec/fixtures/fail/heredoc_interpolated_extra.pp
47
+ - spec/fixtures/fail/heredoc_interpolated_insuficient.pp
130
48
  - spec/fixtures/fail/heredoc_unsuficient.pp
131
49
  - spec/fixtures/pass/1.pp
50
+ - spec/fixtures/pass/doubles.pp
132
51
  - spec/fixtures/pass/heredoc.pp
52
+ - spec/fixtures/pass/heredocclass.pp
53
+ - spec/fixtures/pass/semicolon.pp
133
54
  - spec/puppet-lint/plugins/check_strict_indent_spec.rb
134
55
  - spec/spec_helper.rb
135
56
  homepage: https://github.com/voxpupuli/puppet-lint-strict_indent-check
136
57
  licenses:
137
- - Mozilla 2.0
58
+ - MPL-2.0
138
59
  metadata: {}
139
- post_install_message:
60
+ post_install_message:
140
61
  rdoc_options: []
141
62
  require_paths:
142
63
  - lib
@@ -144,7 +65,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
144
65
  requirements:
145
66
  - - ">="
146
67
  - !ruby/object:Gem::Version
147
- version: '0'
68
+ version: 2.7.0
148
69
  required_rubygems_version: !ruby/object:Gem::Requirement
149
70
  requirements:
150
71
  - - ">="
@@ -152,14 +73,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
152
73
  version: '0'
153
74
  requirements: []
154
75
  rubygems_version: 3.2.33
155
- signing_key:
76
+ signing_key:
156
77
  specification_version: 4
157
78
  summary: puppet-lint strict indent check
158
- test_files:
159
- - spec/fixtures/fail/1.pp
160
- - spec/fixtures/fail/heredoc_extra.pp
161
- - spec/fixtures/fail/heredoc_unsuficient.pp
162
- - spec/fixtures/pass/1.pp
163
- - spec/fixtures/pass/heredoc.pp
164
- - spec/puppet-lint/plugins/check_strict_indent_spec.rb
165
- - spec/spec_helper.rb
79
+ test_files: []