puppet-lint-manifest_whitespace-check 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 73d348cb4f0a000a02c631f97562527a401f7e61f2954e31e8841c9095b32a8f
4
- data.tar.gz: 7fbdd7c452078510f2ae545a93f492f3effd982775cfce706ed7d41219eaa282
3
+ metadata.gz: 2b3bc8cb98f4459ad929e160c0759c73e76fc6253c54061b4edea16370f8b38d
4
+ data.tar.gz: ddc62ccbc2c3537f6057c73d498a035dc4007f416a8b435140a207aa8c0380f5
5
5
  SHA512:
6
- metadata.gz: 1e5df8707c5cbbe5a05bac3b1f16542e1df5c02cc41f4ca5a4d2e97eda2508bb5aa25601bbce7e04a3f06c6803a96dbd69752cd43be33d6f7dd69f23ff1c54dc
7
- data.tar.gz: c0c670b007c1456d68a59635e3e29da5ffbc9bdc0e3ff3c0cc1623766180665ef2180b3fff0b584b7ae9bee29243e618b92a7b9030880c3d965b090ac802a790
6
+ metadata.gz: 59189f5b0b1922bfd04ef96b64f53662b5740ef3a20d8a34f44045fa90d194a4c94e41ca6440ada5b0ecb8b8ec3bb27631b85c02e61f59b4844a708665e417a2
7
+ data.tar.gz: 3547dfb1ab41289ef4ad92168bbc02a12b0ae717b9e97146c0fc2cb13314a972cc1d1c191c0d4feaf73ac7604deb7b272ac90616693f980d1be224a2d498ec26
@@ -9,19 +9,13 @@ PuppetLint.new_check(:manifest_whitespace_closing_brace_before) do
9
9
  next unless prev_token && prev_code_token
10
10
  next if %i[LBRACE].include?(prev_token.type)
11
11
 
12
- unless %i[LBRACE].include?(prev_code_token.type)
13
- if is_single_space(prev_token) && tokens.index(prev_code_token) == tokens.index(brace_token) - 2
14
- next
15
- end
12
+ if !%i[LBRACE].include?(prev_code_token.type) && (is_single_space(prev_token) && tokens.index(prev_code_token) == tokens.index(brace_token) - 2)
13
+ next
16
14
  end
17
15
 
18
- if prev_token.type == :INDENT
19
- next if tokens.index(prev_code_token) == tokens.index(brace_token) - 3
20
- end
16
+ next if prev_token.type == :INDENT && (tokens.index(prev_code_token) == tokens.index(brace_token) - 3)
21
17
 
22
- if prev_token.type == :NEWLINE
23
- next if tokens.index(prev_code_token) == tokens.index(brace_token) - 2
24
- end
18
+ next if prev_token.type == :NEWLINE && (tokens.index(prev_code_token) == tokens.index(brace_token) - 2)
25
19
 
26
20
  notify(
27
21
  :error,
@@ -39,13 +33,9 @@ PuppetLint.new_check(:manifest_whitespace_closing_brace_before) do
39
33
  next_token = token
40
34
 
41
35
  until next_token.type == :RBRACE
42
- if tokens[tokens.index(next_token)..-1].first(2).collect(&:type) == %i[NEWLINE RBRACE]
43
- break
44
- end
36
+ break if tokens[tokens.index(next_token)..-1].first(2).collect(&:type) == %i[NEWLINE RBRACE]
45
37
 
46
- if tokens[tokens.index(next_token)..-1].first(3).collect(&:type) == %i[NEWLINE INDENT RBRACE]
47
- break
48
- end
38
+ break if tokens[tokens.index(next_token)..-1].first(3).collect(&:type) == %i[NEWLINE INDENT RBRACE]
49
39
 
50
40
  remove_token(next_token)
51
41
  next_token = next_token.next_token
@@ -11,12 +11,8 @@ PuppetLint.new_check(:manifest_whitespace_closing_bracket_before) do
11
11
 
12
12
  next unless %i[NEWLINE INDENT WHITESPACE].include?(prev_token.type)
13
13
 
14
- if prev_token.type == :INDENT
15
- next if tokens.index(prev_code_token) == tokens.index(bracket_token) - 3
16
- end
17
- if prev_token.type == :NEWLINE
18
- next if tokens.index(prev_code_token) == tokens.index(bracket_token) - 2
19
- end
14
+ next if prev_token.type == :INDENT && (tokens.index(prev_code_token) == tokens.index(bracket_token) - 3)
15
+ next if prev_token.type == :NEWLINE && (tokens.index(prev_code_token) == tokens.index(bracket_token) - 2)
20
16
 
21
17
  notify(
22
18
  :error,
@@ -37,9 +33,7 @@ PuppetLint.new_check(:manifest_whitespace_closing_bracket_before) do
37
33
 
38
34
  next_token = token.next_token
39
35
  until next_token.type == :RBRACK
40
- if next_token.type == :INDENT && next_token.next_token.type == :RBRACK
41
- break
42
- end
36
+ break if next_token.type == :INDENT && next_token.next_token.type == :RBRACK
43
37
 
44
38
  remove_token(next_token)
45
39
  next_token = next_token.next_token
@@ -7,11 +7,17 @@ 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
- if %i[LPAREN LBRACK LBRACE COLON COMMA COMMENT].include?(prev_code_token.type)
11
- next
10
+
11
+ next if %i[COLON].include?(prev_code_token.type)
12
+
13
+ if %i[COMMENT COMMA LPAREN LBRACK LBRACE].include?(prev_code_token.type)
14
+ next if tokens.index(prev_code_token) == tokens.index(brace_token) - 1
15
+ next if tokens[tokens.index(prev_code_token)..tokens.index(brace_token)].collect(&:type).include?(:NEWLINE)
16
+
17
+ else
18
+ next unless tokens.index(prev_code_token) != tokens.index(brace_token) - 2 ||
19
+ !is_single_space(prev_token)
12
20
  end
13
- next unless tokens.index(prev_code_token) != tokens.index(brace_token) - 2 ||
14
- !is_single_space(prev_token)
15
21
 
16
22
  notify(
17
23
  :error,
@@ -29,9 +35,7 @@ PuppetLint.new_check(:manifest_whitespace_opening_brace_before) do
29
35
  prev_code_token = prev_non_space_token(token)
30
36
 
31
37
  while prev_code_token != prev_token
32
- unless %i[WHITESPACE INDENT NEWLINE].include?(prev_token.type)
33
- raise PuppetLint::NoFix
34
- end
38
+ raise PuppetLint::NoFix unless %i[WHITESPACE INDENT NEWLINE].include?(prev_token.type)
35
39
 
36
40
  remove_token(prev_token)
37
41
  prev_token = prev_token.prev_token
@@ -7,14 +7,10 @@ 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
- if %i[LBRACK LBRACE COMMA SEMIC COMMENT].include?(prev_code_token.type)
11
- next
12
- end
10
+ next if %i[LBRACK LBRACE COMMA SEMIC COMMENT NAME].include?(prev_code_token.type)
13
11
  next unless %i[WHITESPACE NEWLINE INDENT].include?(prev_token.type)
14
12
 
15
- if %i[INDENT NEWLINE].include?(prev_token.type) && %i[RBRACK RBRACE].include?(prev_code_token.type)
16
- next
17
- end
13
+ next if %i[INDENT NEWLINE].include?(prev_token.type) && %i[RBRACK RBRACE].include?(prev_code_token.type)
18
14
  next unless tokens.index(prev_code_token) != tokens.index(bracket_token) - 2 ||
19
15
  !is_single_space(prev_token)
20
16
 
@@ -34,9 +30,7 @@ PuppetLint.new_check(:manifest_whitespace_opening_bracket_before) do
34
30
  prev_code_token = prev_non_space_token(token)
35
31
 
36
32
  while prev_code_token != prev_token
37
- unless %i[WHITESPACE INDENT NEWLINE].include?(prev_token.type)
38
- raise PuppetLint::NoFix
39
- end
33
+ raise PuppetLint::NoFix unless %i[WHITESPACE INDENT NEWLINE].include?(prev_token.type)
40
34
 
41
35
  remove_token(prev_token)
42
36
  prev_token = prev_token.prev_token
@@ -3,7 +3,9 @@
3
3
  require 'spec_helper'
4
4
 
5
5
  describe 'manifest_whitespace_class_name_single_space_before' do
6
- let(:single_space_msg) { 'there should be a single space between the class or defined resource statement and the name' }
6
+ let(:single_space_msg) {
7
+ 'there should be a single space between the class or defined resource statement and the name'
8
+ }
7
9
 
8
10
  context 'with two spaces' do
9
11
  let(:code) do
@@ -402,7 +402,9 @@ describe 'manifest_whitespace_closing_brace_before' do
402
402
  end
403
403
 
404
404
  describe 'manifest_whitespace_closing_brace_after' do
405
- 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' }
405
+ let(:closing_brace_msg) do
406
+ 'there should be either a bracket, punctuation mark, closing quote or a newline after a closing brace, or whitespace and none of the aforementioned'
407
+ end
406
408
 
407
409
  context 'with iterator' do
408
410
  let(:code) do
@@ -417,6 +419,18 @@ describe 'manifest_whitespace_closing_brace_after' do
417
419
  end
418
420
  end
419
421
 
422
+ context 'inline with a function after' do
423
+ let(:code) do
424
+ <<~EOF
425
+ Hash({ $key => $return_value } )
426
+ EOF
427
+ end
428
+
429
+ it 'should detect 1 problem' do
430
+ expect(problems).to have(1).problem
431
+ end
432
+ end
433
+
420
434
  context 'with spaces' do
421
435
  let(:code) do
422
436
  <<~EOF
@@ -153,7 +153,9 @@ 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, punctuation mark, closing quote or a newline after a closing bracket, or whitespace and none of the aforementioned' }
156
+ let(:closing_bracket_msg) {
157
+ 'there should be either a bracket, punctuation mark, closing quote or a newline after a closing bracket, or whitespace and none of the aforementioned'
158
+ }
157
159
 
158
160
  context 'with many brackets' do
159
161
  let(:code) do
@@ -28,8 +28,8 @@ describe 'manifest_whitespace_double_newline_end_of_file' do
28
28
  context 'with 1 empty line at the end of a manifest' do
29
29
  let(:code) do
30
30
  <<~EOF
31
- class example {
32
- }
31
+ class example {
32
+ }
33
33
 
34
34
  EOF
35
35
  end
@@ -46,8 +46,8 @@ describe 'manifest_whitespace_double_newline_end_of_file' do
46
46
  context 'with 3 empty lines at the end of a manifest' do
47
47
  let(:code) do
48
48
  <<~EOF
49
- class example {
50
- }
49
+ class example {
50
+ }
51
51
 
52
52
 
53
53
 
@@ -78,8 +78,8 @@ describe 'manifest_whitespace_double_newline_end_of_file' do
78
78
  context 'with 1 empty line at the end of a manifest' do
79
79
  let(:code) do
80
80
  <<~EOF
81
- class example {
82
- }
81
+ class example {
82
+ }
83
83
 
84
84
  EOF
85
85
  end
@@ -95,8 +95,8 @@ describe 'manifest_whitespace_double_newline_end_of_file' do
95
95
  it 'should add the final newline' do
96
96
  expect(manifest).to eq(
97
97
  <<~EOF
98
- class example {
99
- }
98
+ class example {
99
+ }
100
100
  EOF
101
101
  )
102
102
  end
@@ -105,8 +105,8 @@ describe 'manifest_whitespace_double_newline_end_of_file' do
105
105
  context 'with 3 empty lines at the end of a manifest' do
106
106
  let(:code) do
107
107
  <<~EOF
108
- class example {
109
- }
108
+ class example {
109
+ }
110
110
 
111
111
 
112
112
 
@@ -126,8 +126,8 @@ describe 'manifest_whitespace_double_newline_end_of_file' do
126
126
  it 'should add the final newline' do
127
127
  expect(manifest).to eq(
128
128
  <<~EOF
129
- class example {
130
- }
129
+ class example {
130
+ }
131
131
  EOF
132
132
  )
133
133
  end
@@ -19,6 +19,42 @@ describe 'manifest_whitespace_opening_brace_before' do
19
19
  end
20
20
  end
21
21
 
22
+ context 'inside interpolation' do
23
+ let(:code) do
24
+ <<~EOF
25
+ my_define { "foo-${myvar}": }
26
+ EOF
27
+ end
28
+
29
+ it 'should detect no problems' do
30
+ expect(problems).to be_empty
31
+ end
32
+ end
33
+
34
+ context 'inline with a function before' do
35
+ let(:code) do
36
+ <<~EOF
37
+ Hash( { $key => $return_value })
38
+ EOF
39
+ end
40
+
41
+ it 'should detect 1 problem' do
42
+ expect(problems).to have(1).problem
43
+ end
44
+ end
45
+
46
+ context 'inline with a function' do
47
+ let(:code) do
48
+ <<~EOF
49
+ Hash({ $key => $return_value })
50
+ EOF
51
+ end
52
+
53
+ it 'should detect no problems' do
54
+ expect(problems).to be_empty
55
+ end
56
+ end
57
+
22
58
  context 'inside a function' do
23
59
  let(:code) do
24
60
  <<~EOF
@@ -51,7 +51,6 @@ describe 'manifest_whitespace_opening_bracket_before' do
51
51
  end
52
52
 
53
53
  it 'should detect no problems' do
54
- pending 'Fix the linter'
55
54
  expect(problems).to be_empty
56
55
  end
57
56
  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.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jo Vandeginste
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-10-06 00:00:00.000000000 Z
11
+ date: 2022-10-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: puppet-lint
@@ -151,7 +151,7 @@ licenses:
151
151
  - MIT
152
152
  metadata:
153
153
  rubygems_mfa_required: 'true'
154
- post_install_message:
154
+ post_install_message:
155
155
  rdoc_options: []
156
156
  require_paths:
157
157
  - lib
@@ -167,7 +167,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
167
167
  version: '0'
168
168
  requirements: []
169
169
  rubygems_version: 3.3.7
170
- signing_key:
170
+ signing_key:
171
171
  specification_version: 4
172
172
  summary: A puppet-lint check to validate whitespace in manifests
173
173
  test_files: []