puppet-lint-manifest_whitespace-check 0.1.6 → 0.1.11

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: 8c2f9e366e644a2d8e44d200454971dbd137c8f5584a874a8b90778115066ef0
4
- data.tar.gz: af0b459243c84ff834246bbb00b96cb72fb6f24cc4636496d2e7b9d22fa51e84
3
+ metadata.gz: 7dd5e8776e914e8e269dba2e5fc7b10b344cdd8f2f0bb9e7b41b88ac0eb5b782
4
+ data.tar.gz: 69807b0aa0325654cabc75395b93494eb5375c7d53319c1163536da82f320466
5
5
  SHA512:
6
- metadata.gz: 24eb7bec7bc98a193b0c34e690723703f34b37903e5aadb3dd38a0b803dc743320a86f8f0312af44e7ebda6ec0c69847e16cd812fb3ec8e87319fce7c59a2d4d
7
- data.tar.gz: a8b40c6b1a020f1b70f1b7c75512a61f6514403efcaad9cd58abbf8fa0b515b73381d527cb1f2f7ee06b32c74266b7c81a7dc1e3c0939882b5aae4d60a3293fe
6
+ metadata.gz: ff95eac15ab930d9dfeabcfdfbb126288c7ef4d2b98a9ef6547e11202970190a0e3e2a0eb5d9595cb8228613446792c4547c8a68527e5c1ae087755547f45dcc
7
+ data.tar.gz: 11c9f07ca69106a3212813b0228d3215b41614cdc9c0526e1c141ed0399e156a2e0800b544b4f9886c4ff4bd7af22286417073b56142b235e3901a66bf9d8843
@@ -36,13 +36,13 @@ PuppetLint.new_check(:manifest_whitespace_class_name_single_space_after) do
36
36
  next unless name_token
37
37
 
38
38
  next_token = name_token.next_token
39
- brace_token = name_token.next_token_of(%i[LPAREN LBRACE])
40
- next unless tokens.index(name_token) != tokens.index(brace_token) - 2 ||
39
+ next_code_token = next_non_space_token(name_token)
40
+ next unless tokens.index(name_token) != tokens.index(next_code_token) - 2 ||
41
41
  !is_single_space(next_token)
42
42
 
43
43
  notify(
44
44
  :error,
45
- message: 'there should be a single space between the class or resource name and the first brace',
45
+ message: 'there should be a single space between the class or resource name and the next item',
46
46
  line: next_token.line,
47
47
  column: next_token.column,
48
48
  token: next_token,
@@ -52,22 +52,13 @@ PuppetLint.new_check(:manifest_whitespace_class_name_single_space_after) do
52
52
 
53
53
  def fix(problem)
54
54
  token = problem[:token]
55
- brace_token = token.prev_token.next_token_of(%i[LPAREN LBRACE])
56
-
57
- if token == brace_token
58
- add_token(tokens.index(brace_token), new_single_space)
59
- return
60
- end
61
-
62
- while token != brace_token
63
- unless %i[WHITESPACE INDENT NEWLINE].include?(token.type)
64
- raise PuppetLint::NoFix
65
- end
55
+ next_code_token = next_non_space_token(token.prev_token)
66
56
 
57
+ while token != next_code_token
67
58
  remove_token(token)
68
59
  token = token.next_token
69
60
  end
70
61
 
71
- add_token(tokens.index(brace_token), new_single_space)
62
+ add_token(tokens.index(next_code_token), new_single_space)
72
63
  end
73
64
  end
@@ -7,9 +7,9 @@ PuppetLint.new_check(:manifest_whitespace_closing_brace_before) do
7
7
  prev_code_token = prev_non_space_token(brace_token)
8
8
 
9
9
  next unless prev_token && prev_code_token
10
- next if %i[LBRACE RBRACK RBRACE].include?(prev_token.type)
10
+ next if %i[LBRACE].include?(prev_token.type)
11
11
 
12
- unless %i[LBRACE RBRACK RBRACE].include?(prev_code_token.type)
12
+ unless %i[LBRACE].include?(prev_code_token.type)
13
13
  if is_single_space(prev_token) && tokens.index(prev_code_token) == tokens.index(brace_token) - 2
14
14
  next
15
15
  end
@@ -73,7 +73,7 @@ PuppetLint.new_check(:manifest_whitespace_closing_brace_after) do
73
73
 
74
74
  notify(
75
75
  :error,
76
- message: 'there should be either a bracket, comma, colon, closing quote or a newline after a closing brace, or whitespace and none of the aforementioned',
76
+ message: 'there should be either a bracket, punctuation mark, closing quote or a newline after a closing brace, or whitespace and none of the aforementioned',
77
77
  line: next_token.line,
78
78
  column: next_token.column,
79
79
  token: next_token,
@@ -63,7 +63,7 @@ PuppetLint.new_check(:manifest_whitespace_closing_bracket_after) do
63
63
 
64
64
  notify(
65
65
  :error,
66
- message: 'there should be either a bracket, comma, colon, closing quote or a newline after a closing bracket, or whitespace and none of the aforementioned',
66
+ message: 'there should be either a bracket, punctuation mark, closing quote or a newline after a closing bracket, or whitespace and none of the aforementioned',
67
67
  line: next_token.line,
68
68
  column: next_token.column,
69
69
  token: next_token,
@@ -7,7 +7,9 @@ PuppetLint.new_check(:manifest_whitespace_opening_brace_before) do
7
7
  prev_code_token = prev_non_space_token(brace_token)
8
8
 
9
9
  next unless prev_token && prev_code_token
10
- next if %i[LBRACK LBRACE COMMA COMMENT].include?(prev_code_token.type)
10
+ if %i[LBRACK LBRACE COLON COMMA COMMENT].include?(prev_code_token.type)
11
+ next
12
+ end
11
13
  next unless tokens.index(prev_code_token) != tokens.index(brace_token) - 2 ||
12
14
  !is_single_space(prev_token)
13
15
 
@@ -9,6 +9,9 @@ PuppetLint.new_check(:manifest_whitespace_opening_bracket_before) do
9
9
  next unless prev_token && prev_code_token
10
10
  next if %i[LBRACK LBRACE COMMA SEMIC].include?(prev_code_token.type)
11
11
  next unless %i[WHITESPACE NEWLINE INDENT].include?(prev_token.type)
12
+ if prev_token.type == :NEWLINE && %i[RBRACK RBRACE].include?(prev_code_token.type)
13
+ next
14
+ end
12
15
  next unless tokens.index(prev_code_token) != tokens.index(bracket_token) - 2 ||
13
16
  !is_single_space(prev_token)
14
17
 
@@ -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 NEWLINE DQPOST LBRACK]
12
+ %i[RBRACE RBRACK RPAREN SEMIC COMMA COLON DOT NEWLINE DQMID DQPOST LBRACK]
13
13
  end
14
14
 
15
15
  def prev_non_space_token(token)
@@ -66,10 +66,34 @@ describe 'manifest_whitespace_class_name_single_space_before' do
66
66
  end
67
67
  end
68
68
  end
69
+
70
+ context 'with inherits' do
71
+ let(:code) do
72
+ 'class example inherits otherexample {'
73
+ end
74
+
75
+ it 'should detect no problems' do
76
+ expect(problems).to have(0).problem
77
+ end
78
+ end
69
79
  end
70
80
 
71
81
  describe 'manifest_whitespace_class_name_single_space_after' do
72
- let(:single_space_msg) { 'there should be a single space between the class or resource name and the first brace' }
82
+ let(:single_space_msg) { 'there should be a single space between the class or resource name and the next item' }
83
+
84
+ context 'with inherits' do
85
+ let(:code) do
86
+ <<~EOF
87
+ class example inherits otherexample {
88
+ assert_private()
89
+ }
90
+ EOF
91
+ end
92
+
93
+ it 'should detect no problems' do
94
+ expect(problems).to have(0).problem
95
+ end
96
+ end
73
97
 
74
98
  context 'with parameters and no spaces' do
75
99
  let(:code) do
@@ -405,32 +429,8 @@ describe 'manifest_whitespace_class_name_single_space_after' do
405
429
  EOF
406
430
  end
407
431
 
408
- context 'with fix disabled' do
409
- it 'should detect a single problem' do
410
- expect(problems).to have(1).problem
411
- end
412
-
413
- it 'should create a error' do
414
- expect(problems).to contain_error(single_space_msg).on_line(6).in_column(14)
415
- end
416
- end
417
-
418
- context 'with fix enabled' do
419
- before do
420
- PuppetLint.configuration.fix = true
421
- end
422
-
423
- after do
424
- PuppetLint.configuration.fix = false
425
- end
426
-
427
- it 'should detect a single problem' do
428
- expect(problems).to have(1).problem
429
- end
430
-
431
- it 'should not fix the manifest' do
432
- expect(problems).to contain_error(single_space_msg).on_line(6).in_column(14)
433
- end
432
+ it 'should detect no problem' do
433
+ expect(problems).to have(0).problems
434
434
  end
435
435
  end
436
436
  end
@@ -5,6 +5,34 @@ require 'spec_helper'
5
5
  describe 'manifest_whitespace_closing_brace_before' do
6
6
  let(:closing_brace_msg) { 'there should be a bracket or a single newline before a closing brace' }
7
7
 
8
+ context 'with nested hash' do
9
+ let(:code) do
10
+ <<~EOF
11
+ Hash $instances = { 'localhost' => { 'url' => 'http://localhost/mod_status?auto' } },
12
+ EOF
13
+ end
14
+
15
+ it 'should detect no problems' do
16
+ expect(problems).to have(0).problem
17
+ end
18
+ end
19
+
20
+ context 'with iterator' do
21
+ let(:code) do
22
+ <<~EOF
23
+ ['ib0', 'ib1', 'ib2', 'ib3', 'pub', 'oob', '0', '184'].each |String $name| {
24
+ }
25
+
26
+ ['ib0', 'ib1', 'ib2', 'ib3', 'pub', 'oob', '0', '184'].each |String $name| {
27
+ }
28
+ EOF
29
+ end
30
+
31
+ it 'should detect no problems' do
32
+ expect(problems).to have(0).problem
33
+ end
34
+ end
35
+
8
36
  context 'with comment only' do
9
37
  let(:code) do
10
38
  <<~EOF
@@ -344,7 +372,20 @@ describe 'manifest_whitespace_closing_brace_before' do
344
372
  end
345
373
 
346
374
  describe 'manifest_whitespace_closing_brace_after' do
347
- let(:closing_brace_msg) { 'there should be either a bracket, comma, colon, closing quote or a newline after a closing brace, or whitespace and none of the aforementioned' }
375
+ let(:closing_brace_msg) { 'there should be either a bracket, punctuation mark, closing quote or a newline after a closing brace, or whitespace and none of the aforementioned' }
376
+
377
+ context 'with iterator' do
378
+ let(:code) do
379
+ <<~EOF
380
+ ['ib0', 'ib1', 'ib2', 'ib3', 'pub', 'oob', '0', '184'].each |String $name| {
381
+ }
382
+ EOF
383
+ end
384
+
385
+ it 'should detect no problems' do
386
+ expect(problems).to have(0).problem
387
+ end
388
+ end
348
389
 
349
390
  context 'with spaces' do
350
391
  let(:code) do
@@ -153,7 +153,23 @@ describe 'manifest_whitespace_closing_bracket_before' do
153
153
  end
154
154
 
155
155
  describe 'manifest_whitespace_closing_bracket_after' do
156
- let(:closing_bracket_msg) { 'there should be either a bracket, comma, colon, closing quote or a newline after a closing bracket, or whitespace and none of the aforementioned' }
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
+
158
+ context 'with iterator' do
159
+ let(:code) do
160
+ <<~EOF
161
+ ['ib0', 'ib1', 'ib2', 'ib3', 'pub', 'oob', '0', '184'].each |String $name| {
162
+ }
163
+
164
+ ['ib0', 'ib1', 'ib2', 'ib3', 'pub', 'oob', '0', '184'].each |String $name| {
165
+ }
166
+ EOF
167
+ end
168
+
169
+ it 'should detect no problems' do
170
+ expect(problems).to have(0).problem
171
+ end
172
+ end
157
173
 
158
174
  context 'with spaces' do
159
175
  let(:code) do
@@ -19,6 +19,21 @@ describe 'manifest_whitespace_opening_brace_before' do
19
19
  end
20
20
  end
21
21
 
22
+ context 'with cases' do
23
+ let(:code) do
24
+ <<~EOF
25
+ case $facts['kernel'] {
26
+ 'OpenBSD': { $has_wordexp = false }
27
+ default: { $has_wordexp = true }
28
+ }
29
+ EOF
30
+ end
31
+
32
+ it 'should detect no problems' do
33
+ expect(problems).to have(0).problem
34
+ end
35
+ end
36
+
22
37
  context 'with no spaces' do
23
38
  let(:code) do
24
39
  <<~EOF
@@ -5,6 +5,22 @@ require 'spec_helper'
5
5
  describe 'manifest_whitespace_opening_bracket_before' do
6
6
  let(:opening_bracket_msg) { 'there should be a single space before an opening bracket' }
7
7
 
8
+ context 'with iterator' do
9
+ let(:code) do
10
+ <<~EOF
11
+ ['ib0', 'ib1', 'ib2', 'ib3', 'pub', 'oob', '0', '184'].each |String $name| {
12
+ }
13
+
14
+ ['ib0', 'ib1', 'ib2', 'ib3', 'pub', 'oob', '0', '184'].each |String $name| {
15
+ }
16
+ EOF
17
+ end
18
+
19
+ it 'should detect no problems' do
20
+ expect(problems).to have(0).problem
21
+ end
22
+ end
23
+
8
24
  context 'with no spaces' do
9
25
  let(:code) do
10
26
  <<~EOF
@@ -228,6 +244,22 @@ end
228
244
  describe 'manifest_whitespace_opening_bracket_after' do
229
245
  let(:opening_bracket_msg) { 'there should be no whitespace or a single newline after an opening bracket' }
230
246
 
247
+ context 'with iterator' do
248
+ let(:code) do
249
+ <<~EOF
250
+ ['ib0', 'ib1', 'ib2', 'ib3', 'pub', 'oob', '0', '184'].each |String $name| {
251
+ }
252
+
253
+ ['ib0', 'ib1', 'ib2', 'ib3', 'pub', 'oob', '0', '184'].each |String $name| {
254
+ }
255
+ EOF
256
+ end
257
+
258
+ it 'should detect no problems' do
259
+ expect(problems).to have(0).problem
260
+ end
261
+ end
262
+
231
263
  context 'with a single space' do
232
264
  let(:code) do
233
265
  <<~EOF
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.6
4
+ version: 0.1.11
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-23 00:00:00.000000000 Z
11
+ date: 2020-06-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: puppet-lint