puppet-lint-manifest_whitespace-check 0.2.3 → 0.2.4

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: 68ebf647e803e56c8a3fdb45055b756a31a8aad16ba5e2626d5f9c37b2cd3edf
4
- data.tar.gz: 9e982b6494eb4a85e9853374c65ac21dc68431d506254d3975244f2ca9b1a902
3
+ metadata.gz: 1a7733009c47320dbae135031b97cd389cd2edab33095ef5a9c64d2b61375d8c
4
+ data.tar.gz: 5e356c323847a31282c948131d41cd6c9b4f40338818bf42f46b65d3320694b1
5
5
  SHA512:
6
- metadata.gz: 7af1583cd0809ca34d8e6aa4fd63353873a326c1372cc757fa625c20a478cf6f0bf6a72af032b38038c6fe51f18f01035862d9f3c5b0e28518db503869758b58
7
- data.tar.gz: 9699d991b726203e67c2aac3c9c69aaa5a94888fb6196b2dfbdac402ae91db990a86b07ad16a83da2ec499aacbb1c3958be63d047afd1a86e679d571e9fa5980
6
+ metadata.gz: a8621832c8cf644f7ad467a1215d944ce2427ad97c127f2b60521bd6e6f743f9d37265a030dc11e9491455ab4ce50bab6db6cef1de0417d058c28fa8731fb110
7
+ data.tar.gz: 7bd64637bf4bde4a1e71c9dd50534a69a63bb698bda7097f68de2759da4bcd8e0b8f7146686c5dc6e38bd539a8e31c1c67708229127e3f4ea448dbbc80bc198e
@@ -14,7 +14,6 @@ PuppetLint.new_check(:manifest_whitespace_opening_brace_before) do
14
14
  if %i[LPAREN LBRACK LBRACE].include?(prev_code_token.type)
15
15
  next if tokens.index(prev_code_token) == tokens.index(brace_token) - 1
16
16
  next if tokens[tokens.index(prev_code_token)..tokens.index(brace_token)].collect(&:type).include?(:NEWLINE)
17
-
18
17
  else
19
18
  next unless tokens.index(prev_code_token) != tokens.index(brace_token) - 2 ||
20
19
  !is_single_space(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.3
4
+ version: 0.2.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jo Vandeginste