puppet-lint-trailing_comma-check 1.0.0 → 2.0.0
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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0e7a6a8ff103202893357daa1664954b496e65143f3aa7503f6079c92c9315c0
|
4
|
+
data.tar.gz: 1e61f4bb4b7d5c51624cdbd4085bd78d1d50d7afd84df5f37e0ff5657618411c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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 ||=
|
3
|
+
@array_indexes ||= proc do
|
4
4
|
arrays = []
|
5
5
|
tokens.each_with_index do |token, token_idx|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
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 ||=
|
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 [
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
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 ||=
|
62
|
+
@defaults_indexes ||= proc do
|
62
63
|
defaults = []
|
63
64
|
tokens.each_with_index do |token, token_idx|
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
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 && [
|
96
|
-
while lbo_token && lbo_token.type != :HEREDOC_OPEN
|
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
|
-
|
103
|
-
|
104
|
-
|
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
|
-
:
|
107
|
-
:
|
108
|
-
:
|
109
|
-
:
|
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
|
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
|
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 '
|
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
|
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 '
|
157
|
+
it 'detects 7 problems' do
|
158
158
|
expect(problems).to have(7).problems
|
159
159
|
end
|
160
160
|
|
161
|
-
it '
|
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 '
|
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 '
|
222
|
+
it 'detects a problem' do
|
223
223
|
expect(problems).to have(2).problems
|
224
224
|
end
|
225
225
|
|
226
|
-
it '
|
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
|
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 '
|
308
|
+
it 'does not detect any problems' do
|
309
309
|
expect(problems).to have(0).problems
|
310
310
|
end
|
311
311
|
|
312
|
-
it '
|
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
|
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 '
|
382
|
+
it 'detects 7 problems' do
|
383
383
|
expect(problems).to have(7).problems
|
384
384
|
end
|
385
385
|
|
386
|
-
it '
|
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 '
|
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 '
|
486
|
+
it 'does not detect any problems' do
|
487
487
|
expect(problems).to have(0).problems
|
488
488
|
end
|
489
489
|
|
490
|
-
it '
|
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 '
|
517
|
+
it 'detects a problem' do
|
518
518
|
expect(problems).to have(2).problems
|
519
519
|
end
|
520
520
|
|
521
|
-
it '
|
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 '
|
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:
|
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:
|
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: '
|
19
|
+
version: '3'
|
20
20
|
- - "<"
|
21
21
|
- !ruby/object:Gem::Version
|
22
|
-
version: '
|
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: '
|
29
|
+
version: '3'
|
30
30
|
- - "<"
|
31
31
|
- !ruby/object:Gem::Version
|
32
|
-
version: '
|
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:
|
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: []
|