puppet-lint-manifest_whitespace-check 0.1.4 → 0.1.9

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: 82fd48a0b533bc6357b7e250f945f8ab3f0ba80625a19fa060fde543bf854dae
4
- data.tar.gz: 5289f75f1e16b08fb0b18c6798326017625d6a9b71cb061e9f020e4267630a45
3
+ metadata.gz: deec283a984c69934edd2522701fd6e840fb15e5ebbaf5d836366e59a6f7d894
4
+ data.tar.gz: e4b9559d3d6f82ef25f362b1bcbf8d7e8268e2f54089398dfb22519f6529b289
5
5
  SHA512:
6
- metadata.gz: 4ff960cc339885dfbfa62823058381bb609ca8de39f1047837f2882efb325e176251dcec6f9786907b5fa14145e4f8ad0dfea52e942eadc6909ebc1f8f8f3dd1
7
- data.tar.gz: 9a4f2cd1929e5ca731efb25894730e0ec793d4f2ebc9f3a46baa045deb9d6891e092402afe42acdd8cb83e6cfa808d7033fdb515d60360a4be1a7452e83f54dd
6
+ metadata.gz: 4a49d305962a6ea8168b6deb0f3ec7baf47276d7c6aa56c3869f16f73ed3ade68c3ff63acea7a5ebdef71cab5388b67b5d5cfc898d2f2f2daaa3bb9d7867a4a2
7
+ data.tar.gz: 10217466afcdf5fcd832eb08a54d1031c1f88d417783bc77da4a035ee3dfa5cfacc020ee87bac0b030abe59d80f080f596ffa0c803cddaf73aa0f312a3ac7d1d
@@ -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
@@ -4,12 +4,12 @@ PuppetLint.new_check(:manifest_whitespace_closing_brace_before) do
4
4
  def check
5
5
  tokens.select { |token| token.type == :RBRACE }.each do |brace_token|
6
6
  prev_token = brace_token.prev_token
7
- prev_code_token = brace_token.prev_code_token
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
@@ -66,7 +66,7 @@ PuppetLint.new_check(:manifest_whitespace_closing_brace_after) do
66
66
  next if after_bracket_tokens.include?(next_token.type)
67
67
 
68
68
  if next_token.type == :WHITESPACE
69
- next_code_token = brace_token.next_code_token
69
+ next_code_token = next_non_space_token(brace_token)
70
70
  next unless next_code_token
71
71
  next unless after_bracket_tokens.include?(next_code_token.type)
72
72
  end
@@ -6,7 +6,7 @@ PuppetLint.new_check(:manifest_whitespace_closing_bracket_before) do
6
6
  prev_token = bracket_token.prev_token
7
7
  next unless prev_token
8
8
 
9
- prev_code_token = bracket_token.prev_code_token
9
+ prev_code_token = prev_non_space_token(bracket_token)
10
10
  next unless prev_code_token
11
11
 
12
12
  next unless %i[NEWLINE INDENT WHITESPACE].include?(prev_token.type)
@@ -56,7 +56,7 @@ PuppetLint.new_check(:manifest_whitespace_closing_bracket_after) do
56
56
  next if after_bracket_tokens.include?(next_token.type)
57
57
 
58
58
  if next_token.type == :WHITESPACE
59
- next_code_token = bracket_token.next_code_token
59
+ next_code_token = next_non_space_token(bracket_token)
60
60
  next unless next_code_token
61
61
  next unless after_bracket_tokens.include?(next_code_token.type)
62
62
  end
@@ -4,10 +4,12 @@ PuppetLint.new_check(:manifest_whitespace_opening_brace_before) do
4
4
  def check
5
5
  tokens.select { |token| token.type == :LBRACE }.each do |brace_token|
6
6
  prev_token = brace_token.prev_token
7
- prev_code_token = brace_token.prev_code_token
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].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
 
@@ -24,7 +26,7 @@ PuppetLint.new_check(:manifest_whitespace_opening_brace_before) do
24
26
  def fix(problem)
25
27
  token = problem[:token]
26
28
  prev_token = token.prev_token
27
- prev_code_token = token.prev_code_token
29
+ prev_code_token = prev_non_space_token(token)
28
30
 
29
31
  while prev_code_token != prev_token
30
32
  unless %i[WHITESPACE INDENT NEWLINE].include?(prev_token.type)
@@ -4,7 +4,7 @@ PuppetLint.new_check(:manifest_whitespace_opening_bracket_before) do
4
4
  def check
5
5
  tokens.select { |token| token.type == :LBRACK }.each do |bracket_token|
6
6
  prev_token = bracket_token.prev_token
7
- prev_code_token = bracket_token.prev_code_token
7
+ prev_code_token = prev_non_space_token(bracket_token)
8
8
 
9
9
  next unless prev_token && prev_code_token
10
10
  next if %i[LBRACK LBRACE COMMA SEMIC].include?(prev_code_token.type)
@@ -25,7 +25,7 @@ PuppetLint.new_check(:manifest_whitespace_opening_bracket_before) do
25
25
  def fix(problem)
26
26
  token = problem[:token]
27
27
  prev_token = token.prev_token
28
- prev_code_token = token.prev_code_token
28
+ prev_code_token = prev_non_space_token(token)
29
29
 
30
30
  while prev_code_token != prev_token
31
31
  unless %i[WHITESPACE INDENT NEWLINE].include?(prev_token.type)
@@ -9,5 +9,17 @@ 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]
12
+ %i[RBRACE RBRACK RPAREN SEMIC COMMA COLON NEWLINE DQMID DQPOST LBRACK]
13
+ end
14
+
15
+ def prev_non_space_token(token)
16
+ while token = token.prev_token
17
+ return token unless %i[WHITESPACE INDENT NEWLINE].include?(token.type)
18
+ end
19
+ end
20
+
21
+ def next_non_space_token(token)
22
+ while token = token.next_token
23
+ return token unless %i[WHITESPACE INDENT NEWLINE].include?(token.type)
24
+ end
13
25
  end
@@ -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,32 @@ 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 comment only' do
21
+ let(:code) do
22
+ <<~EOF
23
+ $value7 = {
24
+ # nothing
25
+ }
26
+ EOF
27
+ end
28
+
29
+ it 'should detect no problems' do
30
+ expect(problems).to have(0).problem
31
+ end
32
+ end
33
+
8
34
  context 'with no spaces' do
9
35
  let(:code) do
10
36
  <<~EOF
@@ -30,6 +56,9 @@ describe 'manifest_whitespace_closing_brace_before' do
30
56
  $value5 = []
31
57
  $value6 = {}
32
58
  $value7 = "x${server_facts['environment']}y"
59
+ $value8 = {
60
+ # nothing
61
+ }
33
62
 
34
63
  if someothercondition { include ::otherclass}
35
64
  if somecondition {
@@ -91,6 +120,9 @@ describe 'manifest_whitespace_closing_brace_before' do
91
120
  $value5 = []
92
121
  $value6 = {}
93
122
  $value7 = "x${server_facts['environment']}y"
123
+ $value8 = {
124
+ # nothing
125
+ }
94
126
 
95
127
  if someothercondition { include ::otherclass }
96
128
  if somecondition {
@@ -5,6 +5,35 @@ require 'spec_helper'
5
5
  describe 'manifest_whitespace_opening_brace_before' do
6
6
  let(:opening_brace_msg) { 'there should be a single space before an opening brace' }
7
7
 
8
+ context 'with comment only' do
9
+ let(:code) do
10
+ <<~EOF
11
+ $value7 = {
12
+ # nothing
13
+ }
14
+ EOF
15
+ end
16
+
17
+ it 'should detect no problems' do
18
+ expect(problems).to have(0).problem
19
+ end
20
+ end
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
+
8
37
  context 'with no spaces' do
9
38
  let(:code) do
10
39
  <<~EOF
@@ -29,6 +58,9 @@ describe 'manifest_whitespace_opening_brace_before' do
29
58
  $value4 = ['somekey']
30
59
  $value5 = []
31
60
  $value6 = {}
61
+ $value7 = {
62
+ # nothing
63
+ }
32
64
 
33
65
  if somecondition{
34
66
  class{ 'example2':
@@ -91,6 +123,9 @@ describe 'manifest_whitespace_opening_brace_before' do
91
123
  $value4 = ['somekey']
92
124
  $value5 = []
93
125
  $value6 = {}
126
+ $value7 = {
127
+ # nothing
128
+ }
94
129
 
95
130
  if somecondition {
96
131
  class { 'example2':
@@ -332,29 +367,7 @@ describe 'manifest_whitespace_opening_brace_before' do
332
367
 
333
368
  context 'with fix disabled' do
334
369
  it 'should detect a single problem' do
335
- expect(problems).to have(2).problem
336
- end
337
-
338
- it 'should create a error' do
339
- expect(problems).to contain_error(opening_brace_msg).on_line(9).in_column(1)
340
- end
341
- end
342
-
343
- context 'with fix enabled' do
344
- before do
345
- PuppetLint.configuration.fix = true
346
- end
347
-
348
- after do
349
- PuppetLint.configuration.fix = false
350
- end
351
-
352
- it 'should detect a single problem' do
353
- expect(problems).to have(2).problem
354
- end
355
-
356
- it 'should not fix the manifest' do
357
- expect(problems).to contain_error(opening_brace_msg).on_line(9).in_column(1)
370
+ expect(problems).to have(0).problem
358
371
  end
359
372
  end
360
373
  end
@@ -516,6 +529,9 @@ describe 'manifest_whitespace_opening_brace_after' do
516
529
  $value4 = ['somekey']
517
530
  $value5 = []
518
531
  $value6 = {}
532
+ $value7 = {
533
+ # nothing
534
+ }
519
535
 
520
536
  if somecondition {
521
537
  class { 'example2':
@@ -578,6 +594,9 @@ describe 'manifest_whitespace_opening_brace_after' do
578
594
  $value4 = ['somekey']
579
595
  $value5 = []
580
596
  $value6 = {}
597
+ $value7 = {
598
+ # nothing
599
+ }
581
600
 
582
601
  if somecondition {
583
602
  class { 'example2':
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.4
4
+ version: 0.1.9
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-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: puppet-lint