puppet-lint-manifest_whitespace-check 0.0.1 → 0.1.6
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 +5 -5
- data/README.md +25 -3
- data/lib/puppet-lint/plugins/check_manifest_whitespace_class_inherits_single_space.rb +28 -0
- data/lib/puppet-lint/plugins/check_manifest_whitespace_class_name_single_space.rb +10 -10
- data/lib/puppet-lint/plugins/check_manifest_whitespace_closing_brace.rb +96 -0
- data/lib/puppet-lint/plugins/check_manifest_whitespace_closing_bracket.rb +86 -0
- data/lib/puppet-lint/plugins/check_manifest_whitespace_empty_lines.rb +35 -0
- data/lib/puppet-lint/plugins/check_manifest_whitespace_opening_brace.rb +83 -0
- data/lib/puppet-lint/plugins/check_manifest_whitespace_opening_bracket.rb +79 -0
- data/lib/puppet-lint/plugins/tools.rb +16 -0
- data/spec/puppet-lint/plugins/manifest_whitespace_class_header_spec.rb +35 -158
- data/spec/puppet-lint/plugins/manifest_whitespace_class_inherits_spec.rb +69 -0
- data/spec/puppet-lint/plugins/manifest_whitespace_closing_brace_spec.rb +460 -0
- data/spec/puppet-lint/plugins/manifest_whitespace_closing_bracket_spec.rb +277 -0
- data/spec/puppet-lint/plugins/manifest_whitespace_double_newline_spec.rb +60 -0
- data/spec/puppet-lint/plugins/manifest_whitespace_opening_brace_spec.rb +792 -0
- data/spec/puppet-lint/plugins/manifest_whitespace_opening_bracket_spec.rb +470 -0
- metadata +54 -37
- data/lib/puppet-lint/plugins/check_manifest_whitespace_class_opening_curly_brace.rb +0 -40
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 8c2f9e366e644a2d8e44d200454971dbd137c8f5584a874a8b90778115066ef0
|
4
|
+
data.tar.gz: af0b459243c84ff834246bbb00b96cb72fb6f24cc4636496d2e7b9d22fa51e84
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 24eb7bec7bc98a193b0c34e690723703f34b37903e5aadb3dd38a0b803dc743320a86f8f0312af44e7ebda6ec0c69847e16cd812fb3ec8e87319fce7c59a2d4d
|
7
|
+
data.tar.gz: a8b40c6b1a020f1b70f1b7c75512a61f6514403efcaad9cd58abbf8fa0b515b73381d527cb1f2f7ee06b32c74266b7c81a7dc1e3c0939882b5aae4d60a3293fe
|
data/README.md
CHANGED
@@ -19,9 +19,17 @@ gem 'puppet-lint-manifest_whitespace-check'
|
|
19
19
|
|
20
20
|
This plugin provides a number of new checks to `puppet-lint`.
|
21
21
|
|
22
|
-
###
|
22
|
+
### manifest_whitespace_opening_bracket_after
|
23
23
|
|
24
|
-
> There should be a single space
|
24
|
+
> There should be a single space or single newline after an opening curly brace
|
25
|
+
|
26
|
+
Exceptions: other brackets or comma's
|
27
|
+
|
28
|
+
### manifest_whitespace_opening_bracket_before
|
29
|
+
|
30
|
+
> There should be a single space before an opening bracket
|
31
|
+
|
32
|
+
Exceptions: other brackets
|
25
33
|
|
26
34
|
Good examples:
|
27
35
|
|
@@ -35,6 +43,14 @@ class myclass (
|
|
35
43
|
class myclass {
|
36
44
|
# the body
|
37
45
|
}
|
46
|
+
|
47
|
+
class myclass {
|
48
|
+
$value = [{ 'key' => 'value' }]
|
49
|
+
|
50
|
+
if somecondition {
|
51
|
+
class { 'someclass': }
|
52
|
+
}
|
53
|
+
}
|
38
54
|
```
|
39
55
|
|
40
56
|
Bad examples:
|
@@ -57,6 +73,12 @@ class myclass
|
|
57
73
|
{
|
58
74
|
# the body
|
59
75
|
}
|
76
|
+
|
77
|
+
class myclass {
|
78
|
+
if somecondition{
|
79
|
+
class{ 'someclass': }
|
80
|
+
}
|
81
|
+
}
|
60
82
|
```
|
61
83
|
|
62
84
|
### manifest_whitespace_missing_newline_end_of_file
|
@@ -113,7 +135,7 @@ class myclass (
|
|
113
135
|
|
114
136
|
### manifest_whitespace_class_name_single_space_after
|
115
137
|
|
116
|
-
> There should be a single space between the class or resource name and the first
|
138
|
+
> There should be a single space between the class or resource name and the first brace.
|
117
139
|
|
118
140
|
Good examples:
|
119
141
|
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
PuppetLint.new_check(:manifest_whitespace_inherits_name_single_space_before) do
|
4
|
+
def check
|
5
|
+
tokens.select { |token| token.type == :INHERITS }.each do |inherits_token|
|
6
|
+
name_token = inherits_token.next_token_of(%i[NAME FUNCTION_NAME])
|
7
|
+
next unless name_token
|
8
|
+
|
9
|
+
next_token = inherits_token.next_token
|
10
|
+
next unless tokens.index(name_token) != tokens.index(inherits_token) + 2 ||
|
11
|
+
!is_single_space(next_token)
|
12
|
+
|
13
|
+
notify(
|
14
|
+
:error,
|
15
|
+
message: 'there should be a single space between the inherits statement and the name',
|
16
|
+
line: next_token.line,
|
17
|
+
column: next_token.column,
|
18
|
+
token: next_token,
|
19
|
+
)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def fix(problem)
|
24
|
+
raise PuppetLint::NoFix if problem[:token].type != :WHITESPACE
|
25
|
+
|
26
|
+
problem[:token].value = ' '
|
27
|
+
end
|
28
|
+
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(
|
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(
|
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
|
-
|
40
|
-
next unless tokens.index(name_token) != tokens.index(
|
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
|
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
|
-
|
55
|
+
brace_token = token.prev_token.next_token_of(%i[LPAREN LBRACE])
|
56
56
|
|
57
|
-
if token ==
|
58
|
-
add_token(tokens.index(
|
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 !=
|
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(
|
71
|
+
add_token(tokens.index(brace_token), new_single_space)
|
72
72
|
end
|
73
73
|
end
|
@@ -0,0 +1,96 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
PuppetLint.new_check(:manifest_whitespace_closing_brace_before) do
|
4
|
+
def check
|
5
|
+
tokens.select { |token| token.type == :RBRACE }.each do |brace_token|
|
6
|
+
prev_token = brace_token.prev_token
|
7
|
+
prev_code_token = prev_non_space_token(brace_token)
|
8
|
+
|
9
|
+
next unless prev_token && prev_code_token
|
10
|
+
next if %i[LBRACE RBRACK RBRACE].include?(prev_token.type)
|
11
|
+
|
12
|
+
unless %i[LBRACE RBRACK RBRACE].include?(prev_code_token.type)
|
13
|
+
if is_single_space(prev_token) && tokens.index(prev_code_token) == tokens.index(brace_token) - 2
|
14
|
+
next
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
if prev_token.type == :INDENT
|
19
|
+
next if tokens.index(prev_code_token) == tokens.index(brace_token) - 3
|
20
|
+
end
|
21
|
+
|
22
|
+
if prev_token.type == :NEWLINE
|
23
|
+
next if tokens.index(prev_code_token) == tokens.index(brace_token) - 2
|
24
|
+
end
|
25
|
+
|
26
|
+
notify(
|
27
|
+
:error,
|
28
|
+
message: 'there should be a bracket or a single newline before a closing brace',
|
29
|
+
line: prev_code_token.next_token.line,
|
30
|
+
column: prev_code_token.next_token.column,
|
31
|
+
token: prev_code_token.next_token,
|
32
|
+
)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def fix(problem)
|
37
|
+
token = problem[:token]
|
38
|
+
|
39
|
+
next_token = token
|
40
|
+
|
41
|
+
until next_token.type == :RBRACE
|
42
|
+
if tokens[tokens.index(next_token)..-1].first(2).collect(&:type) == %i[NEWLINE RBRACE]
|
43
|
+
break
|
44
|
+
end
|
45
|
+
|
46
|
+
if tokens[tokens.index(next_token)..-1].first(3).collect(&:type) == %i[NEWLINE INDENT RBRACE]
|
47
|
+
break
|
48
|
+
end
|
49
|
+
|
50
|
+
remove_token(next_token)
|
51
|
+
next_token = next_token.next_token
|
52
|
+
end
|
53
|
+
|
54
|
+
if next_token.type == :RBRACE && !%i[LBRACE RBRACE RBRACK NEWLINE INDENT].include?(next_token.prev_token.type)
|
55
|
+
add_token(tokens.index(next_token), new_single_space)
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
PuppetLint.new_check(:manifest_whitespace_closing_brace_after) do
|
61
|
+
def check
|
62
|
+
tokens.select { |token| token.type == :RBRACE }.each do |brace_token|
|
63
|
+
next_token = brace_token.next_token
|
64
|
+
|
65
|
+
next unless next_token
|
66
|
+
next if after_bracket_tokens.include?(next_token.type)
|
67
|
+
|
68
|
+
if next_token.type == :WHITESPACE
|
69
|
+
next_code_token = next_non_space_token(brace_token)
|
70
|
+
next unless next_code_token
|
71
|
+
next unless after_bracket_tokens.include?(next_code_token.type)
|
72
|
+
end
|
73
|
+
|
74
|
+
notify(
|
75
|
+
:error,
|
76
|
+
message: 'there should be either a bracket, comma, colon, closing quote or a newline after a closing brace, or whitespace and none of the aforementioned',
|
77
|
+
line: next_token.line,
|
78
|
+
column: next_token.column,
|
79
|
+
token: next_token,
|
80
|
+
)
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
def fix(problem)
|
85
|
+
token = problem[:token]
|
86
|
+
|
87
|
+
next_token = token
|
88
|
+
|
89
|
+
until %i[RBRACE RBRACK RPAREN COMMA NEWLINE].include?(next_token.type)
|
90
|
+
raise PuppetLint::NoFix if next_token.type != :WHITESPACE
|
91
|
+
|
92
|
+
remove_token(next_token)
|
93
|
+
next_token = next_token.next_token
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
@@ -0,0 +1,86 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
PuppetLint.new_check(:manifest_whitespace_closing_bracket_before) do
|
4
|
+
def check
|
5
|
+
tokens.select { |token| token.type == :RBRACK }.each do |bracket_token|
|
6
|
+
prev_token = bracket_token.prev_token
|
7
|
+
next unless prev_token
|
8
|
+
|
9
|
+
prev_code_token = prev_non_space_token(bracket_token)
|
10
|
+
next unless prev_code_token
|
11
|
+
|
12
|
+
next unless %i[NEWLINE INDENT WHITESPACE].include?(prev_token.type)
|
13
|
+
|
14
|
+
if prev_token.type == :INDENT
|
15
|
+
next if tokens.index(prev_code_token) == tokens.index(bracket_token) - 3
|
16
|
+
end
|
17
|
+
if prev_token.type == :NEWLINE
|
18
|
+
next if tokens.index(prev_code_token) == tokens.index(bracket_token) - 2
|
19
|
+
end
|
20
|
+
|
21
|
+
notify(
|
22
|
+
:error,
|
23
|
+
message: 'there should be no whitespace or a single newline before a closing bracket',
|
24
|
+
line: prev_code_token.next_token.line,
|
25
|
+
column: prev_code_token.next_token.column,
|
26
|
+
token: prev_code_token.next_token,
|
27
|
+
)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def fix(problem)
|
32
|
+
token = problem[:token]
|
33
|
+
if token.type == :WHITESPACE
|
34
|
+
remove_token(token)
|
35
|
+
return
|
36
|
+
end
|
37
|
+
|
38
|
+
next_token = token.next_token
|
39
|
+
until next_token.type == :RBRACK
|
40
|
+
if next_token.type == :INDENT && next_token.next_token.type == :RBRACK
|
41
|
+
break
|
42
|
+
end
|
43
|
+
|
44
|
+
remove_token(next_token)
|
45
|
+
next_token = next_token.next_token
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
PuppetLint.new_check(:manifest_whitespace_closing_bracket_after) do
|
51
|
+
def check
|
52
|
+
tokens.select { |token| token.type == :RBRACK }.each do |bracket_token|
|
53
|
+
next_token = bracket_token.next_token
|
54
|
+
|
55
|
+
next unless next_token
|
56
|
+
next if after_bracket_tokens.include?(next_token.type)
|
57
|
+
|
58
|
+
if next_token.type == :WHITESPACE
|
59
|
+
next_code_token = next_non_space_token(bracket_token)
|
60
|
+
next unless next_code_token
|
61
|
+
next unless after_bracket_tokens.include?(next_code_token.type)
|
62
|
+
end
|
63
|
+
|
64
|
+
notify(
|
65
|
+
:error,
|
66
|
+
message: 'there should be either a bracket, comma, colon, closing quote or a newline after a closing bracket, or whitespace and none of the aforementioned',
|
67
|
+
line: next_token.line,
|
68
|
+
column: next_token.column,
|
69
|
+
token: next_token,
|
70
|
+
)
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
def fix(problem)
|
75
|
+
token = problem[:token]
|
76
|
+
|
77
|
+
next_token = token
|
78
|
+
|
79
|
+
until %i[RBRACE RBRACK RPAREN COMMA NEWLINE].include?(next_token.type)
|
80
|
+
raise PuppetLint::NoFix if next_token.type != :WHITESPACE
|
81
|
+
|
82
|
+
remove_token(next_token)
|
83
|
+
next_token = next_token.next_token
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
PuppetLint.new_check(:manifest_whitespace_two_empty_lines) do
|
4
|
+
def check
|
5
|
+
tokens.select { |token| token.type == :NEWLINE }.each do |token|
|
6
|
+
prev_newline = token.prev_token_of(:NEWLINE)
|
7
|
+
next unless prev_newline
|
8
|
+
|
9
|
+
prev_newline = prev_newline.prev_token_of(:NEWLINE)
|
10
|
+
next unless prev_newline
|
11
|
+
|
12
|
+
good_to_go = true
|
13
|
+
tokens.index(prev_newline).upto(tokens.index(token)).each do |between_token_idx|
|
14
|
+
unless %i[NEWLINE WHITESPACE INDENT].include?(tokens[between_token_idx].type)
|
15
|
+
good_to_go = false
|
16
|
+
break
|
17
|
+
end
|
18
|
+
end
|
19
|
+
next unless good_to_go
|
20
|
+
|
21
|
+
notify(
|
22
|
+
:error,
|
23
|
+
message: 'there should be no two consecutive empty lines',
|
24
|
+
line: token.line,
|
25
|
+
column: token.column,
|
26
|
+
token: token,
|
27
|
+
)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def fix(problem)
|
32
|
+
token = problem[:token]
|
33
|
+
remove_token(token)
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,83 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
PuppetLint.new_check(:manifest_whitespace_opening_brace_before) do
|
4
|
+
def check
|
5
|
+
tokens.select { |token| token.type == :LBRACE }.each do |brace_token|
|
6
|
+
prev_token = brace_token.prev_token
|
7
|
+
prev_code_token = prev_non_space_token(brace_token)
|
8
|
+
|
9
|
+
next unless prev_token && prev_code_token
|
10
|
+
next if %i[LBRACK LBRACE COMMA COMMENT].include?(prev_code_token.type)
|
11
|
+
next unless tokens.index(prev_code_token) != tokens.index(brace_token) - 2 ||
|
12
|
+
!is_single_space(prev_token)
|
13
|
+
|
14
|
+
notify(
|
15
|
+
:error,
|
16
|
+
message: 'there should be a single space before an opening brace',
|
17
|
+
line: brace_token.line,
|
18
|
+
column: brace_token.column,
|
19
|
+
token: brace_token,
|
20
|
+
)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def fix(problem)
|
25
|
+
token = problem[:token]
|
26
|
+
prev_token = token.prev_token
|
27
|
+
prev_code_token = prev_non_space_token(token)
|
28
|
+
|
29
|
+
while prev_code_token != prev_token
|
30
|
+
unless %i[WHITESPACE INDENT NEWLINE].include?(prev_token.type)
|
31
|
+
raise PuppetLint::NoFix
|
32
|
+
end
|
33
|
+
|
34
|
+
remove_token(prev_token)
|
35
|
+
prev_token = prev_token.prev_token
|
36
|
+
end
|
37
|
+
|
38
|
+
add_token(tokens.index(token), new_single_space)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
PuppetLint.new_check(:manifest_whitespace_opening_brace_after) do
|
43
|
+
def check
|
44
|
+
tokens.select { |token| token.type == :LBRACE }.each do |brace_token|
|
45
|
+
next_token = brace_token.next_token
|
46
|
+
|
47
|
+
next unless next_token && !is_single_space(next_token)
|
48
|
+
next if %i[LBRACK LBRACE RBRACE].include?(next_token.type)
|
49
|
+
|
50
|
+
if next_token.type == :NEWLINE
|
51
|
+
next_token = next_token.next_token
|
52
|
+
next if next_token.type != :NEWLINE
|
53
|
+
end
|
54
|
+
|
55
|
+
notify(
|
56
|
+
:error,
|
57
|
+
message: 'there should be a single space or single newline after an opening brace',
|
58
|
+
line: next_token.line,
|
59
|
+
column: next_token.column,
|
60
|
+
token: next_token,
|
61
|
+
)
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
def fix(problem)
|
66
|
+
token = problem[:token]
|
67
|
+
|
68
|
+
if token.type == :WHITESPACE
|
69
|
+
token.value = ' '
|
70
|
+
return
|
71
|
+
end
|
72
|
+
|
73
|
+
if token.type == :NEWLINE
|
74
|
+
while token && token.type == :NEWLINE
|
75
|
+
remove_token(token)
|
76
|
+
token = token.next_token
|
77
|
+
end
|
78
|
+
return
|
79
|
+
end
|
80
|
+
|
81
|
+
add_token(tokens.index(token), new_single_space)
|
82
|
+
end
|
83
|
+
end
|