puppet-lint-class_alignment-check 0.3.0 → 0.3.1

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: fe4a55df13a00eb32e3dab657bc0d1dc1e2982851d3992ec1329210b2642ccc5
4
- data.tar.gz: 0d227e2da3f0dfa710ee46a11c3a9bd0e6e4fbf05728e96b553ae28a018c305e
3
+ metadata.gz: e32258dfb55db44ee2f3f0a2057958463c3c5ea2bad429c9bc5d179b772d6a71
4
+ data.tar.gz: 40ddced7d67f62decc65e9e9b396d2e60b19508aecf40039524c7c635d38fd0f
5
5
  SHA512:
6
- metadata.gz: 4c33eb7910db84735f6baa86e020b604cdc272c18d726c7c53bb34b3995b6ca874fc5da985756df1f34f985cc80385f2477fe571756ff0c8da374ca0e1001de8
7
- data.tar.gz: 9d3122d562637f655b4fdb251e59256c3a29a42b6affecf78d26d9618cacacd81d3ae698541d5fda6b0e1aa1350d71807bfbd87b5f55213d671bb7ba0f010a41
6
+ metadata.gz: 3e6caecc7f1607637a851670b86f258e2e4da20f9c39d900aeb971216ffdade15d5d3e35d3b31094376dae4e57c3b6e5c6aa97da875d340f4dc0a9d63b795229
7
+ data.tar.gz: 4fc0dd184ce132b65f032a55bd2146cdc11ee8abb7b9457ef5d8dc0e6cd4d242dc88440e0c293da1c726d61bf122a646ffbb3ad5ab478d035a6e37358d8cbfa8
@@ -20,9 +20,37 @@ PuppetLint.new_check(:class_params_newline) do
20
20
  next if tokens[first_param] == tokens[last_param]
21
21
 
22
22
  tokens.each do |token|
23
+ if token == tokens[-1]
24
+ rparen = token
25
+ while rparen&.next_token
26
+ rparen = rparen.next_token
27
+ break if rparen.type == :RPAREN
28
+ end
29
+
30
+ last_code_token = token
31
+ while last_code_token&.prev_token
32
+ break unless %i[WHITESPACE INDENT NEWLINE].include?(last_code_token.type)
33
+
34
+ last_code_token = last_code_token.prev_token
35
+ end
36
+
37
+ next if rparen.line != last_code_token.line
38
+
39
+ notify(
40
+ :warning,
41
+ message: "`)` should be in a new line (expected in line #{token.line + 1}, but found it in line #{token.line})",
42
+ line: rparen.line,
43
+ column: rparen.column,
44
+ token: rparen,
45
+ newline: true,
46
+ newline_indent: item[:tokens][0].column - 1
47
+ )
48
+ break
49
+ end
50
+
23
51
  next unless a_param?(token)
24
52
 
25
- if token.prev_code_token == :LPAREN
53
+ if token.prev_code_token.type == :LPAREN
26
54
  next if token.line != token.prev_code_token.line
27
55
  elsif token.line != prev_param_token(token).line
28
56
  next
@@ -30,7 +58,7 @@ PuppetLint.new_check(:class_params_newline) do
30
58
 
31
59
  notify(
32
60
  :warning,
33
- message: "Parameter #{token.to_manifest} should have its own line (expected in line #{token.line + 1}, but found it in line #{token.line})",
61
+ message: "`#{token.to_manifest}` should be in a new line (expected in line #{token.line + 1}, but found it in line #{token.line})",
34
62
  line: token.line,
35
63
  column: token.column,
36
64
  token: token,
@@ -65,6 +93,13 @@ PuppetLint.new_check(:class_params_newline) do
65
93
  index = tokens.index(token.prev_code_token.next_token)
66
94
  tokens.insert(index, PuppetLint::Lexer::Token.new(:NEWLINE, "\n", 0, 0))
67
95
 
68
- token.prev_token.value = ' ' * problem[:newline_indent] if %i[WHITESPACE INDENT].include?(token.prev_token.type)
96
+ # When there's no space at the beginning of the param
97
+ # e.g. class foo($bar="aaa") {}
98
+ if token.prev_code_token.next_token == token
99
+ tokens.insert(index + 1, PuppetLint::Lexer::Token.new(:INDENT, ' ' * problem[:newline_indent], 0, 0))
100
+
101
+ elsif %i[WHITESPACE INDENT].include?(token.prev_token.type)
102
+ token.prev_token.value = ' ' * problem[:newline_indent]
103
+ end
69
104
  end
70
105
  end
@@ -1,7 +1,7 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe 'class_params_newline' do
4
- let(:msg) { 'Parameter %s should have its own line (expected in line %d, but found it in line %d)' }
4
+ let(:msg) { '`%s` should be in a new line (expected in line %d, but found it in line %d)' }
5
5
 
6
6
  context 'with fix disabled' do
7
7
  context 'tidy code' do
@@ -90,5 +90,51 @@ describe 'class_params_newline' do
90
90
  expect(manifest).to eq(fixed)
91
91
  end
92
92
  end
93
+
94
+ context 'in a single line' do
95
+ let(:code) do
96
+ <<-END
97
+ class foo ($foo = 1, $bar = $a) {}
98
+
99
+ class bar ($foo = 1, $bar = $a,) {}
100
+
101
+ class aaa ( $foo = 1, $bar = $a,) {}
102
+
103
+ class bbb ( $foo = 1, $bar = $a, ) {}
104
+
105
+ class ccc ($foo = 1) {}
106
+ END
107
+ end
108
+
109
+ let(:fixed) do
110
+ <<-END
111
+ class foo (
112
+ $foo = 1,
113
+ $bar = $a
114
+ ) {}
115
+
116
+ class bar (
117
+ $foo = 1,
118
+ $bar = $a,
119
+ ) {}
120
+
121
+ class aaa (
122
+ $foo = 1,
123
+ $bar = $a,
124
+ ) {}
125
+
126
+ class bbb (
127
+ $foo = 1,
128
+ $bar = $a,
129
+ ) {}
130
+
131
+ class ccc ($foo = 1) {}
132
+ END
133
+ end
134
+
135
+ it 'should fix the problems' do
136
+ expect(manifest).to eq(fixed)
137
+ end
138
+ end
93
139
  end
94
140
  end
metadata CHANGED
@@ -1,14 +1,14 @@
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.0
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Anh Pham
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-05-08 00:00:00.000000000 Z
11
+ date: 2022-05-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: puppet-lint