puppet-lint-manifest_whitespace-check 0.1.10 → 0.1.15

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: 490924a99a241b6362b189a9279316ace251905f99ff547f8c1f3a1801b196c0
4
- data.tar.gz: 425fbd3f5b29ea52822bcf76d93c50261b23991e1a37558f3a999f50152feedc
3
+ metadata.gz: 77f398dd3202270ca5034002bbc6e877189b134bc087cf6a2defbf796e82df2a
4
+ data.tar.gz: 6d60d6dbc0c287c12d499338277a33d591778abc87e01afc01b831ea849c21f5
5
5
  SHA512:
6
- metadata.gz: 73d1cb558a99dc97ce5e23f7d0ecde9f05016f830832e7ac534675a9a2b0cd0154c552b0df1acd0f77bd143ed90c6e7bbdf3e8ae015e382a4d2de75cf44cd5e0
7
- data.tar.gz: 67bf90d141158f7af8ab63f922eff6b98ffdbf36d69d3f489153c6d02c1823843c31e1ee7453a4d488e56c5f624ea766610f27e1760344d135b64970d1933d51
6
+ metadata.gz: 5e8a383cd0a51575c8ffd67bf3a01781b8774932fcc1d808e87c2043b402586272da2e1dee2f08da7e4a5765cf72c5bc3ed7cdf63dabb4cab1e47f85b00a5753
7
+ data.tar.gz: eaafaf5fe1a713aeb9d05665c924b87ee3afbd30e1a43fb0fab280a47850a53f89d4717272ca5071b40ca3216a66978dfea1a9b297fc789c3c894bb97d8ef720
@@ -25,7 +25,7 @@ PuppetLint.new_check(:manifest_whitespace_closing_brace_before) do
25
25
 
26
26
  notify(
27
27
  :error,
28
- message: 'there should be a bracket or a single newline before a closing brace',
28
+ message: 'there should be a single space or newline before a closing brace',
29
29
  line: prev_code_token.next_token.line,
30
30
  column: prev_code_token.next_token.column,
31
31
  token: prev_code_token.next_token,
@@ -51,7 +51,7 @@ PuppetLint.new_check(:manifest_whitespace_closing_brace_before) do
51
51
  next_token = next_token.next_token
52
52
  end
53
53
 
54
- if next_token.type == :RBRACE && !%i[LBRACE RBRACE RBRACK NEWLINE INDENT].include?(next_token.prev_token.type)
54
+ if next_token.type == :RBRACE && !%i[LBRACE NEWLINE INDENT].include?(next_token.prev_token.type)
55
55
  add_token(tokens.index(next_token), new_single_space)
56
56
  end
57
57
  end
@@ -55,8 +55,6 @@ PuppetLint.new_check(:manifest_whitespace_closing_bracket_after) do
55
55
  next unless next_token
56
56
  next if after_bracket_tokens.include?(next_token.type)
57
57
 
58
- warn next_token.inspect
59
-
60
58
  if next_token.type == :WHITESPACE
61
59
  next_code_token = next_non_space_token(bracket_token)
62
60
  next unless next_code_token
@@ -47,7 +47,7 @@ PuppetLint.new_check(:manifest_whitespace_opening_brace_after) do
47
47
  next_token = brace_token.next_token
48
48
 
49
49
  next unless next_token && !is_single_space(next_token)
50
- next if %i[LBRACK LBRACE RBRACE].include?(next_token.type)
50
+ next if %i[RBRACE].include?(next_token.type)
51
51
 
52
52
  if next_token.type == :NEWLINE
53
53
  next_token = next_token.next_token
@@ -9,6 +9,10 @@ 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
+
13
+ if %i[INDENT NEWLINE].include?(prev_token.type) && %i[RBRACK RBRACE].include?(prev_code_token.type)
14
+ next
15
+ end
12
16
  next unless tokens.index(prev_code_token) != tokens.index(bracket_token) - 2 ||
13
17
  !is_single_space(prev_token)
14
18
 
@@ -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 DOT NEWLINE DQMID DQPOST LBRACK]
12
+ %i[RBRACK RPAREN SEMIC COMMA COLON DOT NEWLINE DQMID DQPOST LBRACK]
13
13
  end
14
14
 
15
15
  def prev_non_space_token(token)
@@ -3,7 +3,37 @@
3
3
  require 'spec_helper'
4
4
 
5
5
  describe 'manifest_whitespace_closing_brace_before' do
6
- let(:closing_brace_msg) { 'there should be a bracket or a single newline before a closing brace' }
6
+ let(:closing_brace_msg) { 'there should be a single space or newline before a closing brace' }
7
+
8
+ context 'with plus' do
9
+ let(:code) do
10
+ <<~EOF
11
+ $my_images = { 'default' => {}}
12
+ EOF
13
+ end
14
+
15
+ context 'with fix enabled' do
16
+ before do
17
+ PuppetLint.configuration.fix = true
18
+ end
19
+
20
+ after do
21
+ PuppetLint.configuration.fix = false
22
+ end
23
+
24
+ it 'should fix a error' do
25
+ expect(problems).to contain_fixed(closing_brace_msg)
26
+ end
27
+
28
+ it 'should add spaces' do
29
+ expect(manifest).to eq(
30
+ <<~EOF,
31
+ $my_images = { 'default' => {} }
32
+ EOF
33
+ )
34
+ end
35
+ end
36
+ end
7
37
 
8
38
  context 'with nested hash' do
9
39
  let(:code) do
@@ -155,6 +155,18 @@ end
155
155
  describe 'manifest_whitespace_closing_bracket_after' do
156
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
157
 
158
+ context 'with many brackets' do
159
+ let(:code) do
160
+ <<~EOF
161
+ ensure_packages($spaceweather::packages, { require => Class['Mongodb::Globals'] })
162
+ EOF
163
+ end
164
+
165
+ it 'should detect no problems' do
166
+ expect(problems).to have(0).problem
167
+ end
168
+ end
169
+
158
170
  context 'with iterator' do
159
171
  let(:code) do
160
172
  <<~EOF
@@ -219,12 +231,12 @@ describe 'manifest_whitespace_closing_bracket_after' do
219
231
  end
220
232
 
221
233
  context 'with fix disabled' do
222
- it 'should detect 3 problems' do
223
- expect(problems).to have(3).problem
234
+ it 'should detect 2 problems' do
235
+ expect(problems).to have(2).problem
224
236
  end
225
237
 
226
238
  it 'should create a error' do
227
- expect(problems).to contain_error(closing_bracket_msg).on_line(9).in_column(32)
239
+ expect(problems).to contain_error(closing_bracket_msg).on_line(23).in_column(22)
228
240
  end
229
241
  end
230
242
 
@@ -252,7 +264,7 @@ describe 'manifest_whitespace_closing_bracket_after' do
252
264
  class example (
253
265
  String $content,
254
266
  ) {
255
- $value = { 'key' => ['value']}
267
+ $value = { 'key' => ['value'] }
256
268
  $value2 = [
257
269
  {
258
270
  'key' => 'value1',
@@ -5,6 +5,24 @@ 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
+ {
12
+ if condition {
13
+ }
14
+
15
+ ['ib0', 'ib1', 'ib2', 'ib3', 'pub', 'oob', '0', '184'].each |String $name| {
16
+ }
17
+ }
18
+ EOF
19
+ end
20
+
21
+ it 'should detect no problems' do
22
+ expect(problems).to have(0).problem
23
+ end
24
+ end
25
+
8
26
  context 'with no spaces' do
9
27
  let(:code) do
10
28
  <<~EOF
@@ -228,6 +246,22 @@ end
228
246
  describe 'manifest_whitespace_opening_bracket_after' do
229
247
  let(:opening_bracket_msg) { 'there should be no whitespace or a single newline after an opening bracket' }
230
248
 
249
+ context 'with iterator' do
250
+ let(:code) do
251
+ <<~EOF
252
+ ['ib0', 'ib1', 'ib2', 'ib3', 'pub', 'oob', '0', '184'].each |String $name| {
253
+ }
254
+
255
+ ['ib0', 'ib1', 'ib2', 'ib3', 'pub', 'oob', '0', '184'].each |String $name| {
256
+ }
257
+ EOF
258
+ end
259
+
260
+ it 'should detect no problems' do
261
+ expect(problems).to have(0).problem
262
+ end
263
+ end
264
+
231
265
  context 'with a single space' do
232
266
  let(:code) do
233
267
  <<~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.1.10
4
+ version: 0.1.15
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jo Vandeginste