puppet-lint-class_alignment-check 0.3.4 → 0.3.5

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: d0263490e2b13cd13ec0f9cb4e3d569d4a004aa11b6caa63b51c4c0b4cb2a405
4
- data.tar.gz: aadc7259538098f01145ff841be78496c2ed04d9c799eb1a8d6d3a25d7df9ada
3
+ metadata.gz: 40fcbe1d19cc554f3b3a18fd44e8d252f8d4e7b39d5aea1ae14bb108b84d4ed5
4
+ data.tar.gz: 8909d0c354b917d2516ee7fd29078a2df9523a73b0e50d010eb6d36fb0fcff70
5
5
  SHA512:
6
- metadata.gz: eb63b8f785be3ee853cab31c262c169acaeafd21100833e467c1ee8ae7cb4921aa8b877e42f8fe4a242dbca0b104c51637bbd9d62cdec9a2c1fc85d190451200
7
- data.tar.gz: 49b6920703283013416902bfe3d28c0f57746127d2f20f07d21cd57aa29adc3bda5c6c12486c4639ab9a0997d0010007453e663ccf6fa4fd712eb3dda0e7e696
6
+ metadata.gz: aa23065a0ab5698aaef52a521279d871c68d594825fdf31cd1820b2e07fa4d7b427c205b2eb3004d79ad54c3a88b18c4ecc1190507ee02610bfa5aaa90e65799
7
+ data.tar.gz: f606316e9de223a83e1940daf2d5fca115eb6968116fbe7a5983ce43d7538dd368eb2b145becd227f6602260f58b57b5e9110c9cc2dbc6055d2789aa29b2d39c
@@ -3,92 +3,6 @@
3
3
  #
4
4
  # https://puppet.com/docs/puppet/7/style_guide.html#style_guide_classes-param-indentation-alignment
5
5
 
6
- def a_param?(token)
7
- if token&.prev_code_token&.type == :EQUALS
8
- false
9
- elsif token&.prev_code_token&.type == :FARROW
10
- false
11
- elsif %i[DQPRE DQMID].include?(token&.prev_code_token&.type)
12
- false
13
- elsif token&.type == :VARIABLE
14
- # first var in the class
15
- if token&.prev_token_of(:CLASS)&.next_token_of(:LPAREN)&.next_token_of(:VARIABLE) == token
16
- return true
17
- elsif token&.prev_token_of(:DEFINE)&.next_token_of(:LPAREN)&.next_token_of(:VARIABLE) == token
18
- return true
19
- end
20
-
21
- count = 0
22
- while token&.prev_token
23
- token = token.prev_token
24
- return false if token.type == :EQUALS
25
-
26
- if %i[RPAREN RBRACK RBRACE].include?(token.type)
27
- count += 1
28
- elsif %i[LPAREN LBRACK LBRACE].include?(token.type)
29
- count -= 1
30
- end
31
-
32
- return true if count.zero? && token.type == :COMMA
33
- end
34
- end
35
- end
36
-
37
- def first_on_the_line?(token, type)
38
- origin = token
39
- while token&.prev_token
40
- token = token.prev_token
41
-
42
- break if token.type == :NEWLINE
43
- end
44
-
45
- while token&.next_token
46
- token = token.next_token
47
-
48
- break if token.type == type
49
- end
50
-
51
- origin == token
52
- end
53
-
54
- def the_one?(token, character)
55
- case character
56
- when '='
57
- true if token.type == :EQUALS && first_on_the_line?(token, :EQUALS)
58
- when '$'
59
- true if a_param?(token) && first_on_the_line?(token, :VARIABLE)
60
- end
61
- end
62
-
63
- def get_the_first_param(token)
64
- while token&.prev_code_token
65
- token = token.prev_code_token
66
- break if token.type == :CLASS
67
- end
68
-
69
- while token&.next_code_token
70
- token = token.next_code_token
71
- return token if token.type == :VARIABLE
72
- end
73
- end
74
-
75
- def get_prev_code_token(token, character)
76
- case character
77
- when '='
78
- token.prev_code_token
79
- when '$'
80
- if token.prev_code_token
81
- if %i[CLASSREF RBRACK].include?(token.prev_code_token.type)
82
- token.prev_code_token
83
- elsif token.prev_code_token.type == :LPAREN
84
- token
85
- elsif token.prev_code_token.type == :COMMA
86
- get_the_first_param(token)
87
- end
88
- end
89
- end
90
- end
91
-
92
6
  # This function is copied & modified from puppet-lint arrow_alignment check
93
7
  # https://github.com/puppetlabs/puppet-lint/blob/020143b705b023946739eb44e7c7d99fcd087527/lib/puppet-lint/plugins/check_whitespace/arrow_alignment.rb#L8
94
8
  def check_for(character)
@@ -0,0 +1,89 @@
1
+ def a_param?(token)
2
+ if token&.prev_code_token&.type == :EQUALS
3
+ false
4
+ elsif token&.prev_code_token&.type == :FARROW
5
+ false
6
+ elsif %i[DQPRE DQMID].include?(token&.prev_code_token&.type)
7
+ false
8
+ elsif token&.type == :VARIABLE
9
+ # first var in the class
10
+ return true if token&.prev_token_of(:CLASS)&.next_token_of(:LPAREN)&.next_token_of(:VARIABLE) == token
11
+ return true if token&.prev_token_of(:DEFINE)&.next_token_of(:LPAREN)&.next_token_of(:VARIABLE) == token
12
+
13
+ count = 0
14
+ while token&.prev_token
15
+ token = token.prev_token
16
+ return false if token.type == :EQUALS
17
+
18
+ if %i[RPAREN RBRACK RBRACE].include?(token.type)
19
+ count += 1
20
+ elsif %i[LPAREN LBRACK LBRACE].include?(token.type)
21
+ count -= 1
22
+ end
23
+
24
+ return true if count.zero? && token.type == :COMMA
25
+ end
26
+ end
27
+ end
28
+
29
+ def first_on_the_line?(token, type)
30
+ origin = token
31
+ while token&.prev_token
32
+ token = token.prev_token
33
+
34
+ break if token.type == :NEWLINE
35
+ end
36
+
37
+ while token&.next_token
38
+ token = token.next_token
39
+
40
+ break if token.type == type
41
+ end
42
+
43
+ origin == token
44
+ end
45
+
46
+ def the_one?(token, character)
47
+ case character
48
+ when '='
49
+ true if token.type == :EQUALS && first_on_the_line?(token, :EQUALS)
50
+ when '$'
51
+ true if a_param?(token) && first_on_the_line?(token, :VARIABLE)
52
+ end
53
+ end
54
+
55
+ def get_the_first_param(token)
56
+ while token&.prev_code_token
57
+ token = token.prev_code_token
58
+ break if token.type == :CLASS
59
+ end
60
+
61
+ while token&.next_code_token
62
+ token = token.next_code_token
63
+ return token if token.type == :VARIABLE
64
+ end
65
+ end
66
+
67
+ def get_prev_code_token(token, character)
68
+ case character
69
+ when '='
70
+ token.prev_code_token
71
+ when '$'
72
+ if token.prev_code_token
73
+ if %i[CLASSREF RBRACK].include?(token.prev_code_token.type)
74
+ token.prev_code_token
75
+ elsif token.prev_code_token.type == :LPAREN
76
+ token
77
+ elsif token.prev_code_token.type == :COMMA
78
+ get_the_first_param(token)
79
+ end
80
+ end
81
+ end
82
+ end
83
+
84
+ def get_prev_param_token(token)
85
+ while token&.prev_code_token
86
+ token = token.prev_code_token
87
+ return token if a_param?(token)
88
+ end
89
+ end
@@ -1,11 +1,3 @@
1
- def prev_param_token(token)
2
- while token&.prev_code_token
3
- token = token.prev_code_token
4
- break if a_param?(token)
5
- end
6
- token
7
- end
8
-
9
1
  PuppetLint.new_check(:class_params_newline) do
10
2
  def check
11
3
  (class_indexes + defined_type_indexes).each do |item|
@@ -47,11 +39,10 @@ PuppetLint.new_check(:class_params_newline) do
47
39
 
48
40
  if token.prev_code_token.type == :LPAREN
49
41
  next if token.line != token.prev_code_token.line
50
- elsif token.line != prev_param_token(token).line
42
+ elsif token.line != get_prev_param_token(token).line
51
43
  next
52
44
  end
53
45
 
54
- # binding.break
55
46
  notify(
56
47
  :warning,
57
48
  message: "`#{token.to_manifest}` should be in a new line (expected in line #{token.line + 1}, but found it in line #{token.line})",
@@ -68,12 +59,13 @@ PuppetLint.new_check(:class_params_newline) do
68
59
  def fix(problem)
69
60
  token = problem[:token]
70
61
  if token.type == :VARIABLE
62
+ case token&.prev_code_token&.type
71
63
  # Integer $db_port
72
- if token&.prev_code_token&.type == :TYPE
64
+ when :TYPE
73
65
  token = token.prev_code_token
74
66
 
75
67
  # Variant[Undef, Enum['UNSET'], Stdlib::Port] $db_port
76
- elsif token&.prev_code_token&.type == :RBRACK
68
+ when :RBRACK
77
69
  count = 0
78
70
  while token&.prev_code_token
79
71
  token = token.prev_code_token
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.3.4
4
+ version: 0.3.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Anh Pham
@@ -123,6 +123,7 @@ files:
123
123
  - LICENSE
124
124
  - README.md
125
125
  - lib/puppet-lint/plugins/check_class_alignment.rb
126
+ - lib/puppet-lint/plugins/check_class_helper.rb
126
127
  - lib/puppet-lint/plugins/check_class_params_newline.rb
127
128
  - spec/puppet-lint/plugins/check_class_equals_alignment_spec.rb
128
129
  - spec/puppet-lint/plugins/check_class_params_alignment_spec.rb