puppet-lint-manifest_whitespace-check 0.1.0 → 0.1.2

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: 6bdb4da2f82834a517b3f17c513548157e9b09e316dc1ef23ce29f0deabd0874
4
- data.tar.gz: cfea1846383662116b388a3257708cf9e1c441c0c9eae86df6c4982442a062bc
3
+ metadata.gz: d6c95fdd92713473387e0cb780ba993b73aac14c1b8a31ac3605cb211cb34413
4
+ data.tar.gz: 51b93e74f8b2ce71082873f4023efabc673fd8a6144710341695efdc80c102cc
5
5
  SHA512:
6
- metadata.gz: 895dd3bc23d6deb63a6a1e9837dec0ae2ab735859ac50ecc6e5d93d1a594f5b6709a53f2b139e291e0ec82a27e1b71eaf158dd278ec2b773e671275e4ba0acff
7
- data.tar.gz: 8c1fed89f0a3e49872288f298a36847b561a4a0aaacee85aa0b30673c3ac4aceb92a4e9ee59f32a00a88965f5d51a0cae7ee793a5fc287fa6a4613f26de620fc
6
+ metadata.gz: 1940d7236fab0350b6cf217c41a88228f50de795f8e68ca3b3d0da03289578fc83ffc4708c86d37ffd71f9c8b0b254be75121c6c311e43aef7d4acfc89950170
7
+ data.tar.gz: e5cb33fa8ee74bb757fcab7cb333090b3e9770e909274ce313a51e5e1a382c60799893235f8a40d31fac1b21cf9c39b6ba4479765f75bd92e0a2563dc9e47bf9
data/README.md CHANGED
@@ -21,7 +21,7 @@ This plugin provides a number of new checks to `puppet-lint`.
21
21
 
22
22
  ### manifest_whitespace_class_opening_curly_brace
23
23
 
24
- > There should be a single space before the opening curly bracket of a class body.
24
+ > There should be a single space before the opening curly brace of a class body.
25
25
 
26
26
  Good examples:
27
27
 
@@ -113,7 +113,7 @@ class myclass (
113
113
 
114
114
  ### manifest_whitespace_class_name_single_space_after
115
115
 
116
- > There should be a single space between the class or resource name and the first bracket.
116
+ > There should be a single space between the class or resource name and the first brace.
117
117
 
118
118
  Good examples:
119
119
 
@@ -3,7 +3,7 @@
3
3
  PuppetLint.new_check(:manifest_whitespace_inherits_name_single_space_before) do
4
4
  def check
5
5
  tokens.select { |token| token.type == :INHERITS }.each do |inherits_token|
6
- name_token = inherits_token.next_token_of(:NAME)
6
+ name_token = inherits_token.next_token_of(%i[NAME FUNCTION_NAME])
7
7
  next unless name_token
8
8
 
9
9
  next_token = inherits_token.next_token
@@ -30,17 +30,17 @@ end
30
30
  PuppetLint.new_check(:manifest_whitespace_inherits_name_single_space_after) do
31
31
  def check
32
32
  tokens.select { |token| token.type == :INHERITS }.each do |inherits_token|
33
- name_token = inherits_token.next_token_of(:NAME)
33
+ name_token = inherits_token.next_token_of(%i[NAME FUNCTION_NAME])
34
34
  next unless name_token
35
35
 
36
36
  next_token = name_token.next_token
37
- bracket_token = name_token.next_token_of(%i[LPAREN LBRACE])
38
- next unless tokens.index(name_token) != tokens.index(bracket_token) - 2 ||
37
+ brace_token = name_token.next_token_of(%i[LPAREN LBRACE])
38
+ next unless tokens.index(name_token) != tokens.index(brace_token) - 2 ||
39
39
  !is_single_space(next_token)
40
40
 
41
41
  notify(
42
42
  :error,
43
- message: 'there should be a single space between the class or resource name and the first bracket',
43
+ message: 'there should be a single space between the class or resource name and the first brace',
44
44
  line: next_token.line,
45
45
  column: next_token.column,
46
46
  token: next_token,
@@ -50,14 +50,14 @@ PuppetLint.new_check(:manifest_whitespace_inherits_name_single_space_after) do
50
50
 
51
51
  def fix(problem)
52
52
  token = problem[:token]
53
- bracket_token = token.prev_token.next_token_of(%i[LPAREN LBRACE])
53
+ brace_token = token.prev_token.next_token_of(%i[LPAREN LBRACE])
54
54
 
55
- if token == bracket_token
56
- add_token(tokens.index(bracket_token), new_single_space)
55
+ if token == brace_token
56
+ add_token(tokens.index(brace_token), new_single_space)
57
57
  return
58
58
  end
59
59
 
60
- while token != bracket_token
60
+ while token != brace_token
61
61
  unless %i[WHITESPACE INDENT NEWLINE].include?(token.type)
62
62
  raise PuppetLint::NoFix
63
63
  end
@@ -66,6 +66,6 @@ PuppetLint.new_check(:manifest_whitespace_inherits_name_single_space_after) do
66
66
  token = token.next_token
67
67
  end
68
68
 
69
- add_token(tokens.index(bracket_token), new_single_space)
69
+ add_token(tokens.index(brace_token), new_single_space)
70
70
  end
71
71
  end
@@ -4,7 +4,7 @@ PuppetLint.new_check(:manifest_whitespace_class_name_single_space_before) do
4
4
  def check
5
5
  (class_indexes + defined_type_indexes).each do |class_idx|
6
6
  class_token = class_idx[:tokens].first
7
- name_token = class_token.next_token_of(:NAME)
7
+ name_token = class_token.next_token_of(%i[NAME FUNCTION_NAME])
8
8
  next unless name_token
9
9
 
10
10
  next_token = class_token.next_token
@@ -32,17 +32,17 @@ PuppetLint.new_check(:manifest_whitespace_class_name_single_space_after) do
32
32
  def check
33
33
  (class_indexes + defined_type_indexes).each do |class_idx|
34
34
  class_token = class_idx[:tokens].first
35
- name_token = class_token.next_token_of(:NAME)
35
+ name_token = class_token.next_token_of(%i[NAME FUNCTION_NAME])
36
36
  next unless name_token
37
37
 
38
38
  next_token = name_token.next_token
39
- bracket_token = name_token.next_token_of(%i[LPAREN LBRACE])
40
- next unless tokens.index(name_token) != tokens.index(bracket_token) - 2 ||
39
+ brace_token = name_token.next_token_of(%i[LPAREN LBRACE])
40
+ next unless tokens.index(name_token) != tokens.index(brace_token) - 2 ||
41
41
  !is_single_space(next_token)
42
42
 
43
43
  notify(
44
44
  :error,
45
- message: 'there should be a single space between the class or resource name and the first bracket',
45
+ message: 'there should be a single space between the class or resource name and the first brace',
46
46
  line: next_token.line,
47
47
  column: next_token.column,
48
48
  token: next_token,
@@ -52,14 +52,14 @@ PuppetLint.new_check(:manifest_whitespace_class_name_single_space_after) do
52
52
 
53
53
  def fix(problem)
54
54
  token = problem[:token]
55
- bracket_token = token.prev_token.next_token_of(%i[LPAREN LBRACE])
55
+ brace_token = token.prev_token.next_token_of(%i[LPAREN LBRACE])
56
56
 
57
- if token == bracket_token
58
- add_token(tokens.index(bracket_token), new_single_space)
57
+ if token == brace_token
58
+ add_token(tokens.index(brace_token), new_single_space)
59
59
  return
60
60
  end
61
61
 
62
- while token != bracket_token
62
+ while token != brace_token
63
63
  unless %i[WHITESPACE INDENT NEWLINE].include?(token.type)
64
64
  raise PuppetLint::NoFix
65
65
  end
@@ -68,6 +68,6 @@ PuppetLint.new_check(:manifest_whitespace_class_name_single_space_after) do
68
68
  token = token.next_token
69
69
  end
70
70
 
71
- add_token(tokens.index(bracket_token), new_single_space)
71
+ add_token(tokens.index(brace_token), new_single_space)
72
72
  end
73
73
  end
@@ -4,27 +4,27 @@ PuppetLint.new_check(:manifest_whitespace_class_opening_curly_brace) do
4
4
  def check
5
5
  (class_indexes + defined_type_indexes).each do |class_idx|
6
6
  class_token = class_idx[:tokens].first
7
- bracket_token = class_token.next_token_of(:LBRACE)
8
- prev_token = bracket_token.prev_token
9
- prev_code_token = bracket_token.prev_token_of(%i[RPAREN NAME])
7
+ brace_token = class_token.next_token_of(:LBRACE)
8
+ prev_token = brace_token.prev_token
9
+ prev_code_token = brace_token.prev_token_of(%i[RPAREN NAME FUNCTION_NAME])
10
10
 
11
11
  next unless prev_code_token
12
- next unless tokens.index(prev_code_token) != tokens.index(bracket_token) - 2 ||
12
+ next unless tokens.index(prev_code_token) != tokens.index(brace_token) - 2 ||
13
13
  !is_single_space(prev_token)
14
14
 
15
15
  notify(
16
16
  :error,
17
- message: 'there should be a single space before the opening curly bracket of a class body',
18
- line: bracket_token.line,
19
- column: bracket_token.column,
20
- token: bracket_token,
17
+ message: 'there should be a single space before the opening curly brace of a class body',
18
+ line: brace_token.line,
19
+ column: brace_token.column,
20
+ token: brace_token,
21
21
  )
22
22
  end
23
23
  end
24
24
 
25
25
  def fix(problem)
26
26
  token = problem[:token]
27
- prev_code_token = token.prev_token_of(%i[RPAREN NAME]).next_token
27
+ prev_code_token = token.prev_token_of(%i[RPAREN NAME FUNCTION_NAME]).next_token
28
28
 
29
29
  while token != prev_code_token
30
30
  unless %i[WHITESPACE INDENT NEWLINE].include?(prev_code_token.type)
@@ -69,7 +69,135 @@ describe 'manifest_whitespace_class_name_single_space_before' do
69
69
  end
70
70
 
71
71
  describe 'manifest_whitespace_class_name_single_space_after' do
72
- let(:single_space_msg) { 'there should be a single space between the class or resource name and the first bracket' }
72
+ let(:single_space_msg) { 'there should be a single space between the class or resource name and the first brace' }
73
+
74
+ context 'with parameters and no spaces' do
75
+ let(:code) do
76
+ <<~EOF
77
+ # example
78
+ #
79
+ # Main class, includes all other classes.
80
+ #
81
+
82
+ class myclass(
83
+ $param1,
84
+ ) {
85
+ class { 'example2':
86
+ param1 => 'value1',
87
+ }
88
+ }
89
+ EOF
90
+ end
91
+
92
+ context 'with fix disabled' do
93
+ it 'should detect a single problem' do
94
+ expect(problems).to have(1).problem
95
+ end
96
+
97
+ it 'should create a error' do
98
+ expect(problems).to contain_error(single_space_msg).on_line(6).in_column(14)
99
+ end
100
+ end
101
+
102
+ context 'with fix enabled' do
103
+ before do
104
+ PuppetLint.configuration.fix = true
105
+ end
106
+
107
+ after do
108
+ PuppetLint.configuration.fix = false
109
+ end
110
+
111
+ it 'should detect a single problem' do
112
+ expect(problems).to have(1).problem
113
+ end
114
+
115
+ it 'should fix the manifest' do
116
+ expect(problems).to contain_fixed(single_space_msg)
117
+ end
118
+
119
+ it 'should fix the newline' do
120
+ expect(manifest).to eq(
121
+ <<~EOF,
122
+ # example
123
+ #
124
+ # Main class, includes all other classes.
125
+ #
126
+
127
+ class myclass (
128
+ $param1,
129
+ ) {
130
+ class { 'example2':
131
+ param1 => 'value1',
132
+ }
133
+ }
134
+ EOF
135
+ )
136
+ end
137
+ end
138
+ end
139
+
140
+ context 'with scope and no spaces' do
141
+ let(:code) do
142
+ <<~EOF
143
+ # example
144
+ #
145
+ # Main class, includes all other classes.
146
+ #
147
+
148
+ class mymodule::example{
149
+ class { 'example2':
150
+ param1 => 'value1',
151
+ }
152
+ }
153
+ EOF
154
+ end
155
+
156
+ context 'with fix disabled' do
157
+ it 'should detect a single problem' do
158
+ expect(problems).to have(1).problem
159
+ end
160
+
161
+ it 'should create a error' do
162
+ expect(problems).to contain_error(single_space_msg).on_line(6).in_column(24)
163
+ end
164
+ end
165
+
166
+ context 'with fix enabled' do
167
+ before do
168
+ PuppetLint.configuration.fix = true
169
+ end
170
+
171
+ after do
172
+ PuppetLint.configuration.fix = false
173
+ end
174
+
175
+ it 'should detect a single problem' do
176
+ expect(problems).to have(1).problem
177
+ end
178
+
179
+ it 'should fix the manifest' do
180
+ expect(problems).to contain_fixed(single_space_msg)
181
+ end
182
+
183
+ it 'should fix the newline' do
184
+ expect(manifest).to eq(
185
+ <<~EOF,
186
+ # example
187
+ #
188
+ # Main class, includes all other classes.
189
+ #
190
+
191
+ class mymodule::example {
192
+ class { 'example2':
193
+ param1 => 'value1',
194
+ }
195
+ }
196
+ EOF
197
+ )
198
+ end
199
+ end
200
+ end
73
201
 
74
202
  context 'with no spaces' do
75
203
  let(:code) do
@@ -308,7 +436,7 @@ describe 'manifest_whitespace_class_name_single_space_after' do
308
436
  end
309
437
 
310
438
  describe 'manifest_whitespace_class_opening_curly_brace' do
311
- let(:opening_curly_brace_same_line_msg) { 'there should be a single space before the opening curly bracket of a class body' }
439
+ let(:opening_curly_brace_same_line_msg) { 'there should be a single space before the opening curly brace of a class body' }
312
440
 
313
441
  context 'with no spaces' do
314
442
  let(:code) do
@@ -69,7 +69,7 @@ describe 'manifest_whitespace_inherits_name_single_space_before' do
69
69
  end
70
70
 
71
71
  describe 'manifest_whitespace_inherits_name_single_space_after' do
72
- let(:single_space_msg) { 'there should be a single space between the class or resource name and the first bracket' }
72
+ let(:single_space_msg) { 'there should be a single space between the class or resource name and the first brace' }
73
73
 
74
74
  context 'with no spaces' do
75
75
  let(:code) do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: puppet-lint-manifest_whitespace-check
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jo Vandeginste