puppet-lint-trailing_comma-check 1.0.0 → 2.0.0

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: '018a77724925ca0bef3850617c749c009d3b83ae767eda4e87baf88de6f4cd80'
4
- data.tar.gz: ddc25465f0676f38b5d3c16640f811431bbf2864fbb2d2cb8c5027b906fcf17c
3
+ metadata.gz: 0e7a6a8ff103202893357daa1664954b496e65143f3aa7503f6079c92c9315c0
4
+ data.tar.gz: 1e61f4bb4b7d5c51624cdbd4085bd78d1d50d7afd84df5f37e0ff5657618411c
5
5
  SHA512:
6
- metadata.gz: 4fb19ce04aba821d695bf8590d31ae62f94511ec6caf2abe8c9f3937cc15974f40e90f3ab30f27cb8208eff7ea3ba3e149b8e15be7b6c635b2a03f03c385c510
7
- data.tar.gz: 0a2d39ccf3301764ed941a043ca4656cb083e3675a3b21f33d64f6621764f3c6441c86a87a30f4226606b1c3ba3fa6b9d3e0fd1c3d808e81189cf234d9b0bc88
6
+ metadata.gz: b4f0c05f6c2d99f8c586940ea50eb54004fbbaf58ea5094ac6567c5ba0cabe4d26130c479ca7018abcb65ffdf62f484b37bc27617ea7a9e65665bc8537ab3d5e
7
+ data.tar.gz: d32d65600370ab35154ba97e3d94b20b5125e5cac6cd17add0bc71255a017a85b449bdc5f881686f6b3981acdf7ab7cdc89cea4edc18086c708df41db36b19ed
data/CHANGELOG.md CHANGED
@@ -2,6 +2,14 @@
2
2
 
3
3
  All notable changes to this project will be documented in this file.
4
4
 
5
+ ## [2.0.0](https://github.com/voxpupuli/puppet-lint-trailing_comma-check/tree/2.0.0) (2023-04-21)
6
+
7
+ [Full Changelog](https://github.com/voxpupuli/puppet-lint-trailing_comma-check/compare/1.0.0...2.0.0)
8
+
9
+ **Breaking changes:**
10
+
11
+ - Drop Ruby \< 2.7; Add RuboCop [\#33](https://github.com/voxpupuli/puppet-lint-trailing_comma-check/pull/33) ([bastelfreak](https://github.com/bastelfreak))
12
+
5
13
  ## [1.0.0](https://github.com/voxpupuli/puppet-lint-trailing_comma-check/tree/1.0.0) (2022-11-29)
6
14
 
7
15
  [Full Changelog](https://github.com/voxpupuli/puppet-lint-trailing_comma-check/compare/0.4.3...1.0.0)
@@ -1,86 +1,87 @@
1
1
  PuppetLint.new_check(:trailing_comma) do
2
2
  def array_indexes
3
- @array_indexes ||= Proc.new do
3
+ @array_indexes ||= proc do
4
4
  arrays = []
5
5
  tokens.each_with_index do |token, token_idx|
6
- if token.type == :LBRACK
7
- real_idx = 0
8
- tokens[token_idx+1..-1].each_with_index do |cur_token, cur_token_idx|
9
- real_idx = token_idx + 1 + cur_token_idx
10
- break if cur_token.type == :RBRACK
11
- end
12
-
13
- # Ignore resource references
14
- next if token.prev_code_token && \
15
- token.prev_code_token.type == :CLASSREF
16
-
17
- # Ignore data types
18
- next if token.prev_code_token && \
19
- token.prev_code_token.type == :TYPE
20
-
21
- arrays << {
22
- :start => token_idx,
23
- :end => real_idx,
24
- :tokens => tokens[token_idx..real_idx],
25
- }
6
+ next unless token.type == :LBRACK
7
+
8
+ real_idx = 0
9
+ tokens[token_idx + 1..-1].each_with_index do |cur_token, cur_token_idx|
10
+ real_idx = token_idx + 1 + cur_token_idx
11
+ break if cur_token.type == :RBRACK
26
12
  end
13
+
14
+ # Ignore resource references
15
+ next if token.prev_code_token &&
16
+ token.prev_code_token.type == :CLASSREF
17
+
18
+ # Ignore data types
19
+ next if token.prev_code_token &&
20
+ token.prev_code_token.type == :TYPE
21
+
22
+ arrays << {
23
+ start: token_idx,
24
+ end: real_idx,
25
+ tokens: tokens[token_idx..real_idx],
26
+ }
27
27
  end
28
28
  arrays
29
29
  end.call
30
30
  end
31
31
 
32
32
  def hash_indexes
33
- @hash_indexes ||= Proc.new do
33
+ @hash_indexes ||= proc do
34
34
  hashes = []
35
35
  tokens.each_with_index do |token, token_idx|
36
36
  next unless token.prev_code_token
37
- next unless [:EQUALS, :ISEQUAL, :FARROW, :LPAREN].include? token.prev_code_token.type
38
- if token.type == :LBRACE
39
- level = 0
40
- real_idx = 0
41
- tokens[token_idx+1..-1].each_with_index do |cur_token, cur_token_idx|
42
- real_idx = token_idx + 1 + cur_token_idx
43
-
44
- level += 1 if cur_token.type == :LBRACE
45
- level -= 1 if cur_token.type == :RBRACE
46
- break if level < 0
47
- end
48
-
49
- hashes << {
50
- :start => token_idx,
51
- :end => real_idx,
52
- :tokens => tokens[token_idx..real_idx],
53
- }
37
+ next unless %i[EQUALS ISEQUAL FARROW LPAREN].include? token.prev_code_token.type
38
+
39
+ next unless token.type == :LBRACE
40
+
41
+ level = 0
42
+ real_idx = 0
43
+ tokens[token_idx + 1..-1].each_with_index do |cur_token, cur_token_idx|
44
+ real_idx = token_idx + 1 + cur_token_idx
45
+
46
+ level += 1 if cur_token.type == :LBRACE
47
+ level -= 1 if cur_token.type == :RBRACE
48
+ break if level < 0
54
49
  end
50
+
51
+ hashes << {
52
+ start: token_idx,
53
+ end: real_idx,
54
+ tokens: tokens[token_idx..real_idx],
55
+ }
55
56
  end
56
57
  hashes
57
58
  end.call
58
59
  end
59
60
 
60
61
  def defaults_indexes
61
- @defaults_indexes ||= Proc.new do
62
+ @defaults_indexes ||= proc do
62
63
  defaults = []
63
64
  tokens.each_with_index do |token, token_idx|
64
- if token.type == :CLASSREF && token.next_code_token && \
65
- token.next_code_token.type == :LBRACE && \
66
- token.prev_code_token && \
67
- # Ensure that we aren't matching a function return type:
68
- token.prev_code_token.type != :RSHIFT && \
69
- # Or a conditional matching a type:
70
- ! [:MATCH, :NOMATCH].include?(token.prev_code_token.type)
71
- real_idx = 0
72
-
73
- tokens[token_idx+1..-1].each_with_index do |cur_token, cur_token_idx|
74
- real_idx = token_idx + 1 + cur_token_idx
75
- break if cur_token.type == :RBRACE
76
- end
77
-
78
- defaults << {
79
- :start => token_idx,
80
- :end => real_idx,
81
- :tokens => tokens[token_idx..real_idx],
82
- }
65
+ next unless token.type == :CLASSREF && token.next_code_token &&
66
+ token.next_code_token.type == :LBRACE &&
67
+ token.prev_code_token &&
68
+ # Ensure that we aren't matching a function return type:
69
+ token.prev_code_token.type != :RSHIFT &&
70
+ # Or a conditional matching a type:
71
+ !%i[MATCH NOMATCH].include?(token.prev_code_token.type)
72
+
73
+ real_idx = 0
74
+
75
+ tokens[token_idx + 1..-1].each_with_index do |cur_token, cur_token_idx|
76
+ real_idx = token_idx + 1 + cur_token_idx
77
+ break if cur_token.type == :RBRACE
83
78
  end
79
+
80
+ defaults << {
81
+ start: token_idx,
82
+ end: real_idx,
83
+ tokens: tokens[token_idx..real_idx],
84
+ }
84
85
  end
85
86
  defaults
86
87
  end.call
@@ -92,21 +93,19 @@ PuppetLint.new_check(:trailing_comma) do
92
93
  # If we get a token indicating the end of a HEREDOC, backtrack
93
94
  # until we find HEREDOC_OPEN. That is the line which should
94
95
  # be examined for the comma.
95
- if lbo_token && [:HEREDOC, :HEREDOC_POST].include?(lbo_token.type)
96
- while lbo_token && lbo_token.type != :HEREDOC_OPEN do
97
- lbo_token = lbo_token.prev_code_token
98
- end
96
+ if lbo_token && %i[HEREDOC HEREDOC_POST].include?(lbo_token.type)
97
+ lbo_token = lbo_token.prev_code_token while lbo_token && lbo_token.type != :HEREDOC_OPEN
99
98
  end
100
99
 
101
- if lbo_token && lbo_token.type != except_type && \
102
- elem[:tokens][-1].type != :SEMIC && \
103
- lbo_token.type != :COMMA && \
104
- lbo_token.next_token.type == :NEWLINE
100
+ if lbo_token && lbo_token.type != except_type &&
101
+ elem[:tokens][-1].type != :SEMIC &&
102
+ lbo_token.type != :COMMA &&
103
+ lbo_token.next_token.type == :NEWLINE
105
104
  notify :warning, {
106
- :message => 'missing trailing comma after last element',
107
- :line => lbo_token.next_token.line,
108
- :column => lbo_token.next_token.column,
109
- :token => lbo_token.next_token,
105
+ message: 'missing trailing comma after last element',
106
+ line: lbo_token.next_token.line,
107
+ column: lbo_token.next_token.column,
108
+ token: lbo_token.next_token,
110
109
  }
111
110
  end
112
111
  end
@@ -138,7 +137,7 @@ PuppetLint.new_check(:trailing_comma) do
138
137
  :COMMA,
139
138
  ',',
140
139
  problem[:token].line,
141
- problem[:token].column
140
+ problem[:token].column,
142
141
  )
143
142
 
144
143
  idx = tokens.index(problem[:token])
@@ -1,11 +1,11 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe 'trailing_comma' do
4
- let (:msg) { 'missing trailing comma after last element' }
4
+ let(:msg) { 'missing trailing comma after last element' }
5
5
 
6
6
  context 'with fix disabled' do
7
7
  context 'trailing comma present' do
8
- let (:code) {
8
+ let(:code) do
9
9
  <<-EOS
10
10
  class { '::apache':
11
11
  timeout => '100',
@@ -82,15 +82,15 @@ describe 'trailing_comma' do
82
82
  'c',
83
83
  ],
84
84
  EOS
85
- }
85
+ end
86
86
 
87
- it 'should not detect any problems' do
87
+ it 'does not detect any problems' do
88
88
  expect(problems).to have(0).problems
89
89
  end
90
90
  end
91
91
 
92
92
  context 'trailing comma absent' do
93
- let (:code) {
93
+ let(:code) do
94
94
  <<-EOS
95
95
  class { '::apache':
96
96
  timeout => '100',
@@ -152,13 +152,13 @@ describe 'trailing_comma' do
152
152
  'c'
153
153
  ]
154
154
  EOS
155
- }
155
+ end
156
156
 
157
- it 'should detect 7 problems' do
157
+ it 'detects 7 problems' do
158
158
  expect(problems).to have(7).problems
159
159
  end
160
160
 
161
- it 'should create warnings' do
161
+ it 'creates warnings' do
162
162
  expect(problems).to contain_warning(msg).on_line(8).in_column(24)
163
163
  expect(problems).to contain_warning(msg).on_line(15).in_column(27)
164
164
  expect(problems).to contain_warning(msg).on_line(29).in_column(18)
@@ -171,7 +171,7 @@ describe 'trailing_comma' do
171
171
 
172
172
  context 'with heredoc' do
173
173
  context 'with trailing comma' do
174
- let(:code) {
174
+ let(:code) do
175
175
  <<-EOS
176
176
  file { '/tmp/test.txt':
177
177
  ensure => 'file',
@@ -190,15 +190,15 @@ describe 'trailing_comma' do
190
190
  | FRAGMENT
191
191
  }
192
192
  EOS
193
- }
193
+ end
194
194
 
195
- it 'should not detect any problems' do
195
+ it 'does not detect any problems' do
196
196
  expect(problems).to have(0).problems
197
197
  end
198
198
  end
199
199
 
200
200
  context 'without trailing comma' do
201
- let(:code) {
201
+ let(:code) do
202
202
  <<-EOS
203
203
  file { '/tmp/test.txt':
204
204
  ensure => 'file',
@@ -217,13 +217,13 @@ describe 'trailing_comma' do
217
217
  | FRAGMENT
218
218
  }
219
219
  EOS
220
- }
220
+ end
221
221
 
222
- it 'should detect a problem' do
222
+ it 'detects a problem' do
223
223
  expect(problems).to have(2).problems
224
224
  end
225
225
 
226
- it 'should create a warning' do
226
+ it 'creates a warning' do
227
227
  expect(problems).to contain_warning(msg).on_line(3).in_column(30)
228
228
  expect(problems).to contain_warning(msg).on_line(11).in_column(37)
229
229
  end
@@ -241,7 +241,7 @@ describe 'trailing_comma' do
241
241
  end
242
242
 
243
243
  context 'trailing comma present' do
244
- let (:code) {
244
+ let(:code) do
245
245
  <<-EOS
246
246
  class { '::apache':
247
247
  timeout => '100',
@@ -303,19 +303,19 @@ describe 'trailing_comma' do
303
303
  'c',
304
304
  ],
305
305
  EOS
306
- }
306
+ end
307
307
 
308
- it 'should not detect any problems' do
308
+ it 'does not detect any problems' do
309
309
  expect(problems).to have(0).problems
310
310
  end
311
311
 
312
- it 'should not modify the manifest' do
312
+ it 'does not modify the manifest' do
313
313
  expect(manifest).to eq(code)
314
314
  end
315
315
  end
316
316
 
317
317
  context 'trailing comma absent' do
318
- let (:code) {
318
+ let(:code) do
319
319
  <<-EOS
320
320
  class { '::apache':
321
321
  timeout => '100',
@@ -377,13 +377,13 @@ describe 'trailing_comma' do
377
377
  'c'
378
378
  ]
379
379
  EOS
380
- }
380
+ end
381
381
 
382
- it 'should detect 7 problems' do
382
+ it 'detects 7 problems' do
383
383
  expect(problems).to have(7).problems
384
384
  end
385
385
 
386
- it 'should create a warning' do
386
+ it 'creates a warning' do
387
387
  expect(problems).to contain_fixed(msg).on_line(8).in_column(24)
388
388
  expect(problems).to contain_fixed(msg).on_line(15).in_column(27)
389
389
  expect(problems).to contain_fixed(msg).on_line(29).in_column(18)
@@ -393,9 +393,9 @@ describe 'trailing_comma' do
393
393
  expect(problems).to contain_fixed(msg).on_line(58).in_column(14)
394
394
  end
395
395
 
396
- it 'should add trailing commas' do
396
+ it 'adds trailing commas' do
397
397
  expect(manifest).to eq(
398
- <<-EOS
398
+ <<-EOS,
399
399
  class { '::apache':
400
400
  timeout => '100',
401
401
  docroot => '/var/www',
@@ -462,7 +462,7 @@ describe 'trailing_comma' do
462
462
 
463
463
  context 'with heredoc' do
464
464
  context 'with trailing comma' do
465
- let(:code) {
465
+ let(:code) do
466
466
  <<-EOS
467
467
  file { '/tmp/test.txt':
468
468
  ensure => 'file',
@@ -481,19 +481,19 @@ describe 'trailing_comma' do
481
481
  | FRAGMENT
482
482
  }
483
483
  EOS
484
- }
484
+ end
485
485
 
486
- it 'should not detect any problems' do
486
+ it 'does not detect any problems' do
487
487
  expect(problems).to have(0).problems
488
488
  end
489
489
 
490
- it 'should not modify the manifest' do
490
+ it 'does not modify the manifest' do
491
491
  expect(manifest).to eq(code)
492
492
  end
493
493
  end
494
494
 
495
495
  context 'without trailing comma' do
496
- let(:code) {
496
+ let(:code) do
497
497
  <<-EOS
498
498
  file { '/tmp/test.txt':
499
499
  ensure => 'file',
@@ -512,20 +512,20 @@ describe 'trailing_comma' do
512
512
  | FRAGMENT
513
513
  }
514
514
  EOS
515
- }
515
+ end
516
516
 
517
- it 'should detect a problem' do
517
+ it 'detects a problem' do
518
518
  expect(problems).to have(2).problems
519
519
  end
520
520
 
521
- it 'should create a warning' do
521
+ it 'creates a warning' do
522
522
  expect(problems).to contain_fixed(msg).on_line(3).in_column(30)
523
523
  expect(problems).to contain_fixed(msg).on_line(11).in_column(37)
524
524
  end
525
525
 
526
- it 'should add trailing commas' do
526
+ it 'adds trailing commas' do
527
527
  expect(manifest).to eq(
528
- <<-EOS
528
+ <<-EOS,
529
529
  file { '/tmp/test.txt':
530
530
  ensure => 'file',
531
531
  content => @(EOT),
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: puppet-lint-trailing_comma-check
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Vox Pupuli
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-11-29 00:00:00.000000000 Z
11
+ date: 2023-04-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: puppet-lint
@@ -16,90 +16,20 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '1.0'
19
+ version: '3'
20
20
  - - "<"
21
21
  - !ruby/object:Gem::Version
22
- version: '4'
22
+ version: '5'
23
23
  type: :runtime
24
24
  prerelease: false
25
25
  version_requirements: !ruby/object:Gem::Requirement
26
26
  requirements:
27
27
  - - ">="
28
28
  - !ruby/object:Gem::Version
29
- version: '1.0'
29
+ version: '3'
30
30
  - - "<"
31
31
  - !ruby/object:Gem::Version
32
- version: '4'
33
- - !ruby/object:Gem::Dependency
34
- name: rspec
35
- requirement: !ruby/object:Gem::Requirement
36
- requirements:
37
- - - "~>"
38
- - !ruby/object:Gem::Version
39
- version: '3.0'
40
- type: :development
41
- prerelease: false
42
- version_requirements: !ruby/object:Gem::Requirement
43
- requirements:
44
- - - "~>"
45
- - !ruby/object:Gem::Version
46
- version: '3.0'
47
- - !ruby/object:Gem::Dependency
48
- name: rspec-its
49
- requirement: !ruby/object:Gem::Requirement
50
- requirements:
51
- - - "~>"
52
- - !ruby/object:Gem::Version
53
- version: '1.0'
54
- type: :development
55
- prerelease: false
56
- version_requirements: !ruby/object:Gem::Requirement
57
- requirements:
58
- - - "~>"
59
- - !ruby/object:Gem::Version
60
- version: '1.0'
61
- - !ruby/object:Gem::Dependency
62
- name: rspec-collection_matchers
63
- requirement: !ruby/object:Gem::Requirement
64
- requirements:
65
- - - "~>"
66
- - !ruby/object:Gem::Version
67
- version: '1.0'
68
- type: :development
69
- prerelease: false
70
- version_requirements: !ruby/object:Gem::Requirement
71
- requirements:
72
- - - "~>"
73
- - !ruby/object:Gem::Version
74
- version: '1.0'
75
- - !ruby/object:Gem::Dependency
76
- name: simplecov
77
- requirement: !ruby/object:Gem::Requirement
78
- requirements:
79
- - - ">="
80
- - !ruby/object:Gem::Version
81
- version: '0'
82
- type: :development
83
- prerelease: false
84
- version_requirements: !ruby/object:Gem::Requirement
85
- requirements:
86
- - - ">="
87
- - !ruby/object:Gem::Version
88
- version: '0'
89
- - !ruby/object:Gem::Dependency
90
- name: rake
91
- requirement: !ruby/object:Gem::Requirement
92
- requirements:
93
- - - ">="
94
- - !ruby/object:Gem::Version
95
- version: '0'
96
- type: :development
97
- prerelease: false
98
- version_requirements: !ruby/object:Gem::Requirement
99
- requirements:
100
- - - ">="
101
- - !ruby/object:Gem::Version
102
- version: '0'
32
+ version: '5'
103
33
  description: " A puppet-lint plugin to check for missing trailing commas.\n"
104
34
  email: voxpupuli@groups.io
105
35
  executables: []
@@ -124,7 +54,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
124
54
  requirements:
125
55
  - - ">="
126
56
  - !ruby/object:Gem::Version
127
- version: '2.0'
57
+ version: 2.7.0
128
58
  required_rubygems_version: !ruby/object:Gem::Requirement
129
59
  requirements:
130
60
  - - ">="
@@ -135,6 +65,4 @@ rubygems_version: 3.2.33
135
65
  signing_key:
136
66
  specification_version: 4
137
67
  summary: A puppet-lint plugin to check for missing trailing commas.
138
- test_files:
139
- - spec/puppet-lint/plugins/check_trailing_comma/check_trailing_comma_spec.rb
140
- - spec/spec_helper.rb
68
+ test_files: []