puppet-lint-class_alignment-check 0.2.4 → 0.2.5

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: ebf0e96bee2765a17143585f49c445c388612b1563ac6ec54513ee39989013ef
4
- data.tar.gz: 95d3539f4c25fd584610774c695394fb43b17ebb3881e0e73976f0a337eb6a57
3
+ metadata.gz: a097f4f616f220ca1061819f771b0e9553f89d91f2de912b271026d6a1be2640
4
+ data.tar.gz: 0db8265872341ec18239a51144d2ec7fd288f71488f1b5bf2174726c17bf279d
5
5
  SHA512:
6
- metadata.gz: 374133ecbc4fa790491148cc2f62bbe630584891a10df2d3cffec9ce289b2b63ab8bdd6fcd43477735f25fe52e246535017af0f59d27b75f60bd9bf3714bff3c
7
- data.tar.gz: d98666d602b2d846c5ad815d6f06b1dd15fa29ef7c896f6b507217d14e54f5536202aaef80127fc6b900b4ecd05b5183214641e55e45ae27a45dd7f28b0ba856
6
+ metadata.gz: a5d927d414770af9512912b5ee24eeedfafbfb1987984f0ad5806e6950c1f9efc56ed542114bb1933eb9920f4fbc9367ef9f9233c2ec6c20ed170857e204010b
7
+ data.tar.gz: 2dfa0a335795a1d5b21a35b9e68a01fcc19a2ef77efaa50a91c2460e12a7cae7e3fde92d772aa4fbc7f285bafbf5ceb98b62a7c146eb6cd140d9a748cdc02b97
@@ -4,16 +4,16 @@
4
4
  # https://puppet.com/docs/puppet/7/style_guide.html#style_guide_classes-param-indentation-alignment
5
5
 
6
6
  def a_param?(token)
7
- if token.prev_code_token.type == :EQUALS
7
+ if token&.prev_code_token&.type == :EQUALS
8
8
  false
9
- elsif token.prev_code_token.type == :FARROW
9
+ elsif token&.prev_code_token&.type == :FARROW
10
10
  false
11
- elsif token.type == :VARIABLE && !%i[DQPRE DQMID].include?(token.prev_code_token.type)
11
+ elsif token&.type == :VARIABLE && !%i[DQPRE DQMID].include?(token.prev_code_token.type)
12
12
  true
13
13
  end
14
14
  end
15
15
 
16
- def first_param_on_the_line?(token)
16
+ def first_on_the_line?(token, type)
17
17
  origin = token
18
18
  while token&.prev_token
19
19
  token = token.prev_token
@@ -24,7 +24,7 @@ def first_param_on_the_line?(token)
24
24
  while token&.next_token
25
25
  token = token.next_token
26
26
 
27
- break if token.type == :VARIABLE
27
+ break if token.type == type
28
28
  end
29
29
 
30
30
  origin == token
@@ -33,9 +33,9 @@ end
33
33
  def the_one?(token, character)
34
34
  case character
35
35
  when '='
36
- true if token.type == :EQUALS
36
+ true if token.type == :EQUALS && first_on_the_line?(token, :EQUALS)
37
37
  when '$'
38
- true if token.type == :VARIABLE && a_param?(token) && first_param_on_the_line?(token)
38
+ true if a_param?(token) && first_on_the_line?(token, :VARIABLE)
39
39
  end
40
40
  end
41
41
 
@@ -148,30 +148,14 @@ end
148
148
  # This function is copied & modified from puppet-lint arrow_alignment fix
149
149
  # https://github.com/puppetlabs/puppet-lint/blob/020143b705b023946739eb44e7c7d99fcd087527/lib/puppet-lint/plugins/check_whitespace/arrow_alignment.rb#L94
150
150
  def fix_for(problem)
151
- if problem[:newline]
152
- index = tokens.index(problem[:token].prev_code_token.prev_token)
153
-
154
- # insert newline
155
- tokens.insert(index, PuppetLint::Lexer::Token.new(:NEWLINE, "\n", 0, 0))
156
-
157
- # indent the parameter to the correct depth
158
- problem[:token].prev_code_token.prev_token.type = :INDENT
159
- problem[:token].prev_code_token.prev_token.value = ' ' * problem[:newline_indent]
160
-
161
- end_param_idx = tokens.index(problem[:token].prev_code_token)
162
- start_param_idx = tokens.index(problem[:token].prev_token_of(%i[INDENT NEWLINE]))
163
- param_length = tokens[start_param_idx..end_param_idx].map do |r|
164
- r.to_manifest.length
165
- end.reduce(0) { |sum, x| sum + x } + 1
166
- new_ws_len = problem[:arrow_column] - param_length
167
- else
168
- new_ws_len = if problem[:token].prev_token.type == :WHITESPACE
169
- problem[:token].prev_token.to_manifest.length
170
- else
171
- 0
172
- end
173
- new_ws_len += (problem[:arrow_column] - problem[:token].column)
174
- end
151
+ raise PuppetLint::NoFix if problem[:newline]
152
+
153
+ new_ws_len = if problem[:token].prev_token.type == :WHITESPACE
154
+ problem[:token].prev_token.to_manifest.length
155
+ else
156
+ 0
157
+ end
158
+ new_ws_len += (problem[:arrow_column] - problem[:token].column)
175
159
 
176
160
  if new_ws_len.negative?
177
161
  raise PuppetLint::NoFix if problem[:token].prev_token.type != :INDENT
@@ -241,13 +241,12 @@ describe 'class_equals_alignment' do
241
241
  END
242
242
  end
243
243
 
244
- it 'should detect 2 problems' do
245
- expect(problems).to have(2).problems
244
+ it 'should detect 1 problem' do
245
+ expect(problems).to have(1).problems
246
246
  end
247
247
 
248
- it 'should create 2 warnings' do
248
+ it 'should create 1 warning' do
249
249
  expect(problems).to contain_warning(format(msg, 18, 16)).on_line(2).in_column(16)
250
- expect(problems).to contain_warning(format(msg, 18, 29)).on_line(2).in_column(29)
251
250
  end
252
251
  end
253
252
  end
@@ -424,23 +423,21 @@ describe 'class_equals_alignment' do
424
423
  let(:fixed) do
425
424
  <<-END
426
425
  class test (
427
- $a = 'foo',
428
- $bb = 'bar',
426
+ $a = 'foo', $bb = 'bar',
429
427
  $ccc = 'baz',
430
428
  ) {}
431
429
  END
432
430
  end
433
431
 
434
- it 'should detect 2 problems' do
435
- expect(problems).to have(2).problems
432
+ it 'should detect 1 problem' do
433
+ expect(problems).to have(1).problems
436
434
  end
437
435
 
438
- it 'should fix 2 problems' do
436
+ it 'should fix 1 problem' do
439
437
  expect(problems).to contain_fixed(format(msg, 18, 16)).on_line(2).in_column(16)
440
- expect(problems).to contain_fixed(format(msg, 18, 29)).on_line(2).in_column(29)
441
438
  end
442
439
 
443
- it 'should move the extra param onto its own line and realign' do
440
+ it 'should not move the extra param onto its own line and realign' do
444
441
  expect(manifest).to eq(fixed)
445
442
  end
446
443
  end
@@ -458,24 +455,21 @@ describe 'class_equals_alignment' do
458
455
  let(:fixed) do
459
456
  <<-END
460
457
  class test (
461
- $a = 'foo',
462
- $bbccc = 'bar',
463
- $ccc = 'baz',
458
+ $a = 'foo', $bbccc = 'bar',
459
+ $ccc = 'baz',
464
460
  ) {}
465
461
  END
466
462
  end
467
463
 
468
- it 'should detect 2 problems' do
469
- expect(problems).to have(3).problems
464
+ it 'should detect 1 problem' do
465
+ expect(problems).to have(1).problems
470
466
  end
471
467
 
472
- it 'should fix 2 problems' do
473
- expect(problems).to contain_fixed(format(msg, 20, 16)).on_line(2).in_column(16)
474
- expect(problems).to contain_fixed(format(msg, 20, 32)).on_line(2).in_column(32)
475
- expect(problems).to contain_fixed(format(msg, 20, 18)).on_line(3).in_column(18)
468
+ it 'should fix 1 problem' do
469
+ expect(problems).to contain_fixed(format(msg, 18, 16)).on_line(2).in_column(16)
476
470
  end
477
471
 
478
- it 'should move the extra param onto its own line and realign' do
472
+ it 'should not move the extra param onto its own line and realign' do
479
473
  expect(manifest).to eq(fixed)
480
474
  end
481
475
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: puppet-lint-class_alignment-check
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.4
4
+ version: 0.2.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Anh Pham