puppet-lint-manifest_whitespace-check 0.1.12 → 0.1.17

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: 9e03f64681e0f77650a16f9cb6fdc2da2f02cdfcd7480070bab2c847de55088a
4
- data.tar.gz: 3a92cd24d10fbd164d6f08d3e8c5ef2777ddc9575658c4d49cba1e2719fcfcbf
3
+ metadata.gz: 242cfac889870bbdd8d1346f1adafb8348b868945e9cfbe9adebebf6c4468c59
4
+ data.tar.gz: 0fd2197f54e3f911e077d3315458a0e2c44e69230570757cf26a7fc26db0d89e
5
5
  SHA512:
6
- metadata.gz: ef768ef36782696c60b1e03ee44cf43916df55100415c84e0c636e9ea6eddadfe2536ab7e4c35bf514aba32e7861b8868f654a0b14b444cdafa507a71bad3d70
7
- data.tar.gz: 642d9a4ff1e10f056cd938b7206ffc0835ee479cdf7423beb7eb8c6d6cc8f923ae3478adb597c88903b9eb721d778275b33fc56a3d9563c91ad3af1d54a78fb8
6
+ metadata.gz: fc1eea7da122458e2cda3cad1820548774a57149ec6ae6061fd75e20388a82af98e4d93e740f15bfdb623e6f4ee5cd647d189e6c30285238712040eddbcc8f0f
7
+ data.tar.gz: 80b25a77380531e248bb146af17a010818e4782698fe85972cf97245a27ab2383fb8b2a3cc69875c56afd6a3ef3e3fe769d05a770bd858a45e5de4e55af5aecd
@@ -43,20 +43,22 @@ PuppetLint.new_check(:manifest_whitespace_class_name_single_space_after) do
43
43
  notify(
44
44
  :error,
45
45
  message: 'there should be a single space between the class or resource name and the next item',
46
- line: next_token.line,
47
- column: next_token.column,
48
- token: next_token,
46
+ line: name_token.line,
47
+ column: name_token.column,
48
+ token: name_token,
49
49
  )
50
50
  end
51
51
  end
52
52
 
53
53
  def fix(problem)
54
54
  token = problem[:token]
55
- next_code_token = next_non_space_token(token.prev_token)
56
55
 
57
- while token != next_code_token
58
- remove_token(token)
59
- token = token.next_token
56
+ next_token = token.next_token
57
+ next_code_token = next_non_space_token(token)
58
+
59
+ while next_token != next_code_token
60
+ remove_token(next_token)
61
+ next_token = next_token.next_token
60
62
  end
61
63
 
62
64
  add_token(tokens.index(next_code_token), new_single_space)
@@ -25,7 +25,7 @@ PuppetLint.new_check(:manifest_whitespace_closing_brace_before) do
25
25
 
26
26
  notify(
27
27
  :error,
28
- message: 'there should be a bracket or a single newline before a closing brace',
28
+ message: 'there should be a single space or newline before a closing brace',
29
29
  line: prev_code_token.next_token.line,
30
30
  column: prev_code_token.next_token.column,
31
31
  token: prev_code_token.next_token,
@@ -51,7 +51,7 @@ PuppetLint.new_check(:manifest_whitespace_closing_brace_before) do
51
51
  next_token = next_token.next_token
52
52
  end
53
53
 
54
- if next_token.type == :RBRACE && !%i[LBRACE RBRACE RBRACK NEWLINE INDENT].include?(next_token.prev_token.type)
54
+ if next_token.type == :RBRACE && !%i[LBRACE NEWLINE INDENT].include?(next_token.prev_token.type)
55
55
  add_token(tokens.index(next_token), new_single_space)
56
56
  end
57
57
  end
@@ -7,9 +7,12 @@ PuppetLint.new_check(:manifest_whitespace_opening_bracket_before) do
7
7
  prev_code_token = prev_non_space_token(bracket_token)
8
8
 
9
9
  next unless prev_token && prev_code_token
10
- next if %i[LBRACK LBRACE COMMA SEMIC].include?(prev_code_token.type)
10
+ if %i[LBRACK LBRACE COMMA SEMIC COMMENT].include?(prev_code_token.type)
11
+ next
12
+ end
11
13
  next unless %i[WHITESPACE NEWLINE INDENT].include?(prev_token.type)
12
- if prev_token.type == :NEWLINE && %i[RBRACK RBRACE].include?(prev_code_token.type)
14
+
15
+ if %i[INDENT NEWLINE].include?(prev_token.type) && %i[RBRACK RBRACE].include?(prev_code_token.type)
13
16
  next
14
17
  end
15
18
  next unless tokens.index(prev_code_token) != tokens.index(bracket_token) - 2 ||
@@ -9,7 +9,7 @@ def new_single_space
9
9
  end
10
10
 
11
11
  def after_bracket_tokens
12
- %i[RBRACE RBRACK RPAREN SEMIC COMMA COLON DOT NEWLINE DQMID DQPOST LBRACK]
12
+ %i[RBRACK RPAREN SEMIC COMMA COLON DOT NEWLINE DQMID DQPOST LBRACK]
13
13
  end
14
14
 
15
15
  def prev_non_space_token(token)
@@ -119,7 +119,7 @@ describe 'manifest_whitespace_class_name_single_space_after' do
119
119
  end
120
120
 
121
121
  it 'should create a error' do
122
- expect(problems).to contain_error(single_space_msg).on_line(6).in_column(14)
122
+ expect(problems).to contain_error(single_space_msg).on_line(6).in_column(7)
123
123
  end
124
124
  end
125
125
 
@@ -183,7 +183,7 @@ describe 'manifest_whitespace_class_name_single_space_after' do
183
183
  end
184
184
 
185
185
  it 'should create a error' do
186
- expect(problems).to contain_error(single_space_msg).on_line(6).in_column(24)
186
+ expect(problems).to contain_error(single_space_msg).on_line(6).in_column(7)
187
187
  end
188
188
  end
189
189
 
@@ -245,7 +245,7 @@ describe 'manifest_whitespace_class_name_single_space_after' do
245
245
  end
246
246
 
247
247
  it 'should create a error' do
248
- expect(problems).to contain_error(single_space_msg).on_line(6).in_column(14)
248
+ expect(problems).to contain_error(single_space_msg).on_line(6).in_column(7)
249
249
  end
250
250
  end
251
251
 
@@ -307,7 +307,7 @@ describe 'manifest_whitespace_class_name_single_space_after' do
307
307
  end
308
308
 
309
309
  it 'should create a error' do
310
- expect(problems).to contain_error(single_space_msg).on_line(6).in_column(14)
310
+ expect(problems).to contain_error(single_space_msg).on_line(6).in_column(7)
311
311
  end
312
312
  end
313
313
 
@@ -372,7 +372,7 @@ describe 'manifest_whitespace_class_name_single_space_after' do
372
372
  end
373
373
 
374
374
  it 'should create a error' do
375
- expect(problems).to contain_error(single_space_msg).on_line(6).in_column(14)
375
+ expect(problems).to contain_error(single_space_msg).on_line(6).in_column(7)
376
376
  end
377
377
  end
378
378
 
@@ -3,7 +3,37 @@
3
3
  require 'spec_helper'
4
4
 
5
5
  describe 'manifest_whitespace_closing_brace_before' do
6
- let(:closing_brace_msg) { 'there should be a bracket or a single newline before a closing brace' }
6
+ let(:closing_brace_msg) { 'there should be a single space or newline before a closing brace' }
7
+
8
+ context 'with plus' do
9
+ let(:code) do
10
+ <<~EOF
11
+ $my_images = { 'default' => {}}
12
+ EOF
13
+ end
14
+
15
+ context 'with fix enabled' do
16
+ before do
17
+ PuppetLint.configuration.fix = true
18
+ end
19
+
20
+ after do
21
+ PuppetLint.configuration.fix = false
22
+ end
23
+
24
+ it 'should fix a error' do
25
+ expect(problems).to contain_fixed(closing_brace_msg)
26
+ end
27
+
28
+ it 'should add spaces' do
29
+ expect(manifest).to eq(
30
+ <<~EOF,
31
+ $my_images = { 'default' => {} }
32
+ EOF
33
+ )
34
+ end
35
+ end
36
+ end
7
37
 
8
38
  context 'with nested hash' do
9
39
  let(:code) do
@@ -155,6 +155,18 @@ end
155
155
  describe 'manifest_whitespace_closing_bracket_after' do
156
156
  let(:closing_bracket_msg) { 'there should be either a bracket, punctuation mark, closing quote or a newline after a closing bracket, or whitespace and none of the aforementioned' }
157
157
 
158
+ context 'with many brackets' do
159
+ let(:code) do
160
+ <<~EOF
161
+ ensure_packages($spaceweather::packages, { require => Class['Mongodb::Globals'] })
162
+ EOF
163
+ end
164
+
165
+ it 'should detect no problems' do
166
+ expect(problems).to have(0).problem
167
+ end
168
+ end
169
+
158
170
  context 'with iterator' do
159
171
  let(:code) do
160
172
  <<~EOF
@@ -219,12 +231,12 @@ describe 'manifest_whitespace_closing_bracket_after' do
219
231
  end
220
232
 
221
233
  context 'with fix disabled' do
222
- it 'should detect 3 problems' do
223
- expect(problems).to have(3).problem
234
+ it 'should detect 2 problems' do
235
+ expect(problems).to have(2).problem
224
236
  end
225
237
 
226
238
  it 'should create a error' do
227
- expect(problems).to contain_error(closing_bracket_msg).on_line(9).in_column(32)
239
+ expect(problems).to contain_error(closing_bracket_msg).on_line(23).in_column(22)
228
240
  end
229
241
  end
230
242
 
@@ -252,7 +264,7 @@ describe 'manifest_whitespace_closing_bracket_after' do
252
264
  class example (
253
265
  String $content,
254
266
  ) {
255
- $value = { 'key' => ['value']}
267
+ $value = { 'key' => ['value'] }
256
268
  $value2 = [
257
269
  {
258
270
  'key' => 'value1',
@@ -34,6 +34,46 @@ describe 'manifest_whitespace_opening_brace_before' do
34
34
  end
35
35
  end
36
36
 
37
+ context 'with class no spaces' do
38
+ let(:code) do
39
+ <<~EOF
40
+ class example{
41
+ # some generic comment
42
+ }
43
+ EOF
44
+ end
45
+
46
+ context 'with fix disabled' do
47
+ it 'should detect a problem' do
48
+ expect(problems).to have(1).problem
49
+ end
50
+
51
+ it 'should create a error' do
52
+ expect(problems).to contain_error(opening_brace_msg).on_line(1).in_column(14)
53
+ end
54
+ end
55
+
56
+ context 'with fix enabled' do
57
+ before do
58
+ PuppetLint.configuration.fix = true
59
+ end
60
+
61
+ after do
62
+ PuppetLint.configuration.fix = false
63
+ end
64
+
65
+ it 'should add a space' do
66
+ expect(manifest).to eq(
67
+ <<~EOF,
68
+ class example {
69
+ # some generic comment
70
+ }
71
+ EOF
72
+ )
73
+ end
74
+ end
75
+ end
76
+
37
77
  context 'with no spaces' do
38
78
  let(:code) do
39
79
  <<~EOF
@@ -8,10 +8,27 @@ describe 'manifest_whitespace_opening_bracket_before' do
8
8
  context 'with iterator' do
9
9
  let(:code) do
10
10
  <<~EOF
11
- ['ib0', 'ib1', 'ib2', 'ib3', 'pub', 'oob', '0', '184'].each |String $name| {
11
+ {
12
+ # some generic comment
13
+ ['some', 'values']
12
14
  }
15
+ EOF
16
+ end
13
17
 
14
- ['ib0', 'ib1', 'ib2', 'ib3', 'pub', 'oob', '0', '184'].each |String $name| {
18
+ it 'should detect no problems' do
19
+ expect(problems).to have(0).problem
20
+ end
21
+ end
22
+
23
+ context 'with iterator' do
24
+ let(:code) do
25
+ <<~EOF
26
+ {
27
+ if condition {
28
+ }
29
+
30
+ ['ib0', 'ib1', 'ib2', 'ib3', 'pub', 'oob', '0', '184'].each |String $name| {
31
+ }
15
32
  }
16
33
  EOF
17
34
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: puppet-lint-manifest_whitespace-check
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.12
4
+ version: 0.1.17
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jo Vandeginste
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-06-26 00:00:00.000000000 Z
11
+ date: 2020-06-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: puppet-lint