puppet-lint-manifest_whitespace-check 0.2.2 → 0.2.4

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: bd465f6f8f5fe07dc5de6b9a9c3eb36e8f99e5c647e3d48a6001cd0f32749cf9
4
- data.tar.gz: e0bb7d7f3ee60d7bfed54e28ee24b78dae5a8477b870e41b33902bb86b3a5407
3
+ metadata.gz: 1a7733009c47320dbae135031b97cd389cd2edab33095ef5a9c64d2b61375d8c
4
+ data.tar.gz: 5e356c323847a31282c948131d41cd6c9b4f40338818bf42f46b65d3320694b1
5
5
  SHA512:
6
- metadata.gz: 85069ac6a3e3c7a349eea0e102a35f737204b210d35caf451e71ccd04da54bc241061947be20a93dc2adfc4a0ca91bc429243c27b7d4c50cc2fe072971dfecfd
7
- data.tar.gz: a7bde6a55568780469a5576c2353d77108c86e5e6ca84a448992fb9549dd89530f140ca2a1aae1f268145c25321b3acc8467706215a16fd90093043016691459
6
+ metadata.gz: a8621832c8cf644f7ad467a1215d944ce2427ad97c127f2b60521bd6e6f743f9d37265a030dc11e9491455ab4ce50bab6db6cef1de0417d058c28fa8731fb110
7
+ data.tar.gz: 7bd64637bf4bde4a1e71c9dd50534a69a63bb698bda7097f68de2759da4bcd8e0b8f7146686c5dc6e38bd539a8e31c1c67708229127e3f4ea448dbbc80bc198e
@@ -8,12 +8,12 @@ PuppetLint.new_check(:manifest_whitespace_opening_brace_before) do
8
8
 
9
9
  next unless prev_token && prev_code_token
10
10
 
11
+ next if %i[COMMA].include?(prev_code_token.type) && %i[INDENT NEWLINE].include?(prev_token.type)
11
12
  next if %i[COMMENT COLON].include?(prev_code_token.type)
12
13
 
13
14
  if %i[LPAREN LBRACK LBRACE].include?(prev_code_token.type)
14
15
  next if tokens.index(prev_code_token) == tokens.index(brace_token) - 1
15
16
  next if tokens[tokens.index(prev_code_token)..tokens.index(brace_token)].collect(&:type).include?(:NEWLINE)
16
-
17
17
  else
18
18
  next unless tokens.index(prev_code_token) != tokens.index(brace_token) - 2 ||
19
19
  !is_single_space(prev_token)
@@ -35,10 +35,7 @@ PuppetLint.new_check(:manifest_whitespace_opening_brace_before) do
35
35
  prev_code_token = prev_non_space_token(token)
36
36
 
37
37
  while prev_code_token != prev_token
38
- if !%i[LPAREN LBRACK LBRACE].include?(prev_code_token.type) &&
39
- %i[WHITESPACE INDENT NEWLINE].include?(prev_token.type)
40
- raise PuppetLint::NoFix
41
- end
38
+ raise PuppetLint::NoFix unless %i[WHITESPACE INDENT NEWLINE].include?(prev_token.type)
42
39
 
43
40
  remove_token(prev_token)
44
41
  prev_token = prev_token.prev_token
@@ -6,13 +6,29 @@ PuppetLint.new_check(:manifest_whitespace_opening_bracket_before) do
6
6
  prev_token = bracket_token.prev_token
7
7
  prev_code_token = prev_non_space_token(bracket_token)
8
8
 
9
- next unless prev_token && prev_code_token
10
- next if %i[LBRACK LBRACE COMMA SEMIC COMMENT NAME].include?(prev_code_token.type)
11
- next unless %i[WHITESPACE NEWLINE INDENT].include?(prev_token.type)
9
+ next if %i[SEMIC COMMA COLON].include?(prev_code_token.type) && %i[INDENT NEWLINE].include?(prev_token.type)
10
+ next if %i[COMMENT].include?(prev_code_token.type)
11
+ next if %i[INDENT NEWLINE].include?(prev_token.type) && %i[NAME RBRACK RBRACE].include?(prev_code_token.type)
12
+ next if %i[CLASSREF VARIABLE].include?(prev_code_token.type) && (prev_code_token == prev_token)
12
13
 
13
- next if %i[INDENT NEWLINE].include?(prev_token.type) && %i[RBRACK RBRACE].include?(prev_code_token.type)
14
- next unless tokens.index(prev_code_token) != tokens.index(bracket_token) - 2 ||
15
- !is_single_space(prev_token)
14
+ if %i[RBRACK RBRACE RPAREN LPAREN LBRACK LBRACE TYPE].include?(prev_code_token.type)
15
+ next if prev_code_token == prev_token
16
+ next if %i[INDENT NEWLINE].include?(prev_token.type)
17
+ elsif %i[CLASSREF VARIABLE].include?(prev_code_token.type)
18
+ # not good
19
+ elsif tokens.index(prev_code_token) == tokens.index(bracket_token) - 2 &&
20
+ is_single_space(prev_token)
21
+ next
22
+ end
23
+
24
+ if prev_code_token.type == :LBRACE
25
+ ppct = prev_non_space_token(prev_code_token)
26
+
27
+ if ppct && ppct.type == :NAME
28
+ next if %i[INDENT NEWLINE].include?(prev_token.type)
29
+ next if tokens.index(prev_code_token) == tokens.index(bracket_token) - 2 && is_single_space(prev_token)
30
+ end
31
+ end
16
32
 
17
33
  notify(
18
34
  :error,
@@ -36,7 +52,7 @@ PuppetLint.new_check(:manifest_whitespace_opening_bracket_before) do
36
52
  prev_token = prev_token.prev_token
37
53
  end
38
54
 
39
- add_token(tokens.index(token), new_single_space)
55
+ add_token(tokens.index(token), new_single_space) unless %i[LPAREN LBRACK LBRACE].include?(prev_code_token.type)
40
56
  end
41
57
  end
42
58
 
@@ -38,6 +38,18 @@ describe 'manifest_whitespace_opening_bracket_before' do
38
38
  end
39
39
  end
40
40
 
41
+ context 'with array key in interpolation' do
42
+ let(:code) do
43
+ <<~EOF
44
+ "${my_array['keyname']}"
45
+ EOF
46
+ end
47
+
48
+ it 'should detect no problems' do
49
+ expect(problems).to be_empty
50
+ end
51
+ end
52
+
41
53
  context 'with multiline iterator' do
42
54
  let(:code) do
43
55
  <<~EOF
@@ -65,7 +77,8 @@ describe 'manifest_whitespace_opening_bracket_before' do
65
77
 
66
78
  class example (
67
79
  String $content,
68
- ){
80
+ Optional[String] $some_other_content,
81
+ ) {
69
82
  $value = [{ 'key' => 'value' }]
70
83
  $value2 = [
71
84
  {
@@ -80,11 +93,20 @@ describe 'manifest_whitespace_opening_bracket_before' do
80
93
  $value5 = []
81
94
  $value6 = {}
82
95
 
83
- if somecondition{
84
- class{ 'example2':
96
+ if somecondition {
97
+ class { 'example2':
85
98
  param1 => 'value1',
86
99
  require => File['somefile'],
87
100
  }
101
+ package { ['pack1', 'pack2']:
102
+ ensure => present,
103
+ }
104
+ package {
105
+ ['pack3', 'pack4']:
106
+ ensure => present;
107
+ ['pack5', 'pack6']:
108
+ ensure => present;
109
+ }
88
110
  }
89
111
  }
90
112
  EOF
@@ -97,6 +119,41 @@ describe 'manifest_whitespace_opening_bracket_before' do
97
119
  end
98
120
  end
99
121
 
122
+ context 'with resource inline' do
123
+ let(:code) do
124
+ <<~EOF
125
+ package { ['pack1', 'pack2']:
126
+ ensure => present,
127
+ }
128
+ EOF
129
+ end
130
+
131
+ context 'with fix disabled' do
132
+ it 'should detect 0 problems' do
133
+ expect(problems).to be_empty
134
+ end
135
+ end
136
+ end
137
+
138
+ context 'with resource next line' do
139
+ let(:code) do
140
+ <<~EOF
141
+ package {
142
+ ['pack3', 'pack4']:
143
+ ensure => present;
144
+ ['pack5', 'pack6']:
145
+ ensure => present;
146
+ }
147
+ EOF
148
+ end
149
+
150
+ context 'with fix disabled' do
151
+ it 'should detect 0 problems' do
152
+ expect(problems).to be_empty
153
+ end
154
+ end
155
+ end
156
+
100
157
  context 'with two spaces' do
101
158
  let(:code) do
102
159
  <<~EOF
metadata CHANGED
@@ -1,7 +1,7 @@
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.2
4
+ version: 0.2.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jo Vandeginste