puppet-lint 0.4.0.pre1 → 1.0.0
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.
- data/.travis.yml +3 -4
- data/Gemfile +2 -5
- data/README.md +2 -149
- data/Rakefile +0 -5
- data/lib/puppet-lint.rb +74 -20
- data/lib/puppet-lint/bin.rb +20 -85
- data/lib/puppet-lint/checkplugin.rb +158 -12
- data/lib/puppet-lint/checks.rb +39 -222
- data/lib/puppet-lint/configuration.rb +12 -31
- data/lib/puppet-lint/data.rb +329 -0
- data/lib/puppet-lint/lexer.rb +37 -30
- data/lib/puppet-lint/lexer/token.rb +14 -16
- data/lib/puppet-lint/monkeypatches/string_prepend.rb +6 -0
- data/lib/puppet-lint/optparser.rb +105 -0
- data/lib/puppet-lint/plugins.rb +28 -9
- data/lib/puppet-lint/plugins/check_classes.rb +162 -238
- data/lib/puppet-lint/plugins/check_comments.rb +40 -25
- data/lib/puppet-lint/plugins/check_conditionals.rb +16 -20
- data/lib/puppet-lint/plugins/check_documentation.rb +14 -20
- data/lib/puppet-lint/plugins/check_nodes.rb +23 -0
- data/lib/puppet-lint/plugins/check_resources.rb +127 -141
- data/lib/puppet-lint/plugins/check_strings.rb +133 -107
- data/lib/puppet-lint/plugins/check_variables.rb +11 -11
- data/lib/puppet-lint/plugins/check_whitespace.rb +86 -92
- data/lib/puppet-lint/tasks/puppet-lint.rb +17 -1
- data/lib/puppet-lint/version.rb +1 -1
- data/puppet-lint.gemspec +4 -2
- data/spec/fixtures/test/manifests/ignore.pp +1 -0
- data/spec/fixtures/test/manifests/ignore_reason.pp +1 -0
- data/spec/puppet-lint/bin_spec.rb +104 -84
- data/spec/puppet-lint/configuration_spec.rb +19 -19
- data/spec/puppet-lint/ignore_overrides_spec.rb +97 -0
- data/spec/puppet-lint/lexer/token_spec.rb +9 -9
- data/spec/puppet-lint/lexer_spec.rb +352 -325
- data/spec/puppet-lint/plugins/check_classes/autoloader_layout_spec.rb +77 -23
- data/spec/puppet-lint/plugins/check_classes/class_inherits_from_params_class_spec.rb +14 -12
- data/spec/puppet-lint/plugins/check_classes/inherits_across_namespaces_spec.rb +18 -14
- data/spec/puppet-lint/plugins/check_classes/names_containing_dash_spec.rb +30 -30
- data/spec/puppet-lint/plugins/check_classes/nested_classes_or_defines_spec.rb +31 -26
- data/spec/puppet-lint/plugins/check_classes/parameter_order_spec.rb +34 -28
- data/spec/puppet-lint/plugins/check_classes/right_to_left_relationship_spec.rb +14 -12
- data/spec/puppet-lint/plugins/check_classes/variable_scope_spec.rb +74 -30
- data/spec/puppet-lint/plugins/check_comments/slash_comments_spec.rb +27 -20
- data/spec/puppet-lint/plugins/check_comments/star_comments_spec.rb +78 -13
- data/spec/puppet-lint/plugins/check_conditionals/case_without_default_spec.rb +17 -12
- data/spec/puppet-lint/plugins/check_conditionals/selector_inside_resource_spec.rb +13 -10
- data/spec/puppet-lint/plugins/check_documentation/documentation_spec.rb +21 -16
- data/spec/puppet-lint/plugins/check_nodes/unquoted_node_name_spec.rb +69 -0
- data/spec/puppet-lint/plugins/check_resources/duplicate_params_spec.rb +42 -38
- data/spec/puppet-lint/plugins/check_resources/ensure_first_param_spec.rb +22 -10
- data/spec/puppet-lint/plugins/check_resources/ensure_not_symlink_target_spec.rb +81 -18
- data/spec/puppet-lint/plugins/check_resources/file_mode_spec.rb +69 -112
- data/spec/puppet-lint/plugins/check_resources/unquoted_file_mode_spec.rb +27 -20
- data/spec/puppet-lint/plugins/check_resources/unquoted_resource_title_spec.rb +177 -171
- data/spec/puppet-lint/plugins/check_strings/double_quoted_strings_spec.rb +165 -88
- data/spec/puppet-lint/plugins/check_strings/only_variable_string_spec.rb +97 -22
- data/spec/puppet-lint/plugins/check_strings/puppet_url_without_modules_spec.rb +25 -0
- data/spec/puppet-lint/plugins/check_strings/quoted_booleans_spec.rb +97 -111
- data/spec/puppet-lint/plugins/check_strings/single_quote_string_with_variables_spec.rb +10 -9
- data/spec/puppet-lint/plugins/check_strings/variables_not_enclosed_spec.rb +53 -53
- data/spec/puppet-lint/plugins/check_variables/variable_contains_dash_spec.rb +26 -14
- data/spec/puppet-lint/plugins/check_whitespace/2sp_soft_tabs_spec.rb +10 -9
- data/spec/puppet-lint/plugins/check_whitespace/80chars_spec.rb +31 -15
- data/spec/puppet-lint/plugins/check_whitespace/arrow_alignment_spec.rb +340 -322
- data/spec/puppet-lint/plugins/check_whitespace/hard_tabs_spec.rb +30 -23
- data/spec/puppet-lint/plugins/check_whitespace/trailing_whitespace_spec.rb +42 -41
- data/spec/puppet-lint_spec.rb +3 -3
- data/spec/spec_helper.rb +109 -116
- metadata +109 -50
- data/spec/puppet-lint/plugins/check_classes/class_parameter_defaults_spec.rb +0 -60
@@ -1,75 +1,62 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
}.
|
11
|
-
|
12
|
-
}.
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
token.
|
17
|
-
|
18
|
-
else
|
19
|
-
notify_type = :warning
|
20
|
-
end
|
21
|
-
|
22
|
-
notify notify_type, {
|
23
|
-
:message => 'double quoted string containing no variables',
|
24
|
-
:linenumber => token.line,
|
25
|
-
:column => token.column,
|
1
|
+
# Public: Check the manifest tokens for any double quoted strings that don't
|
2
|
+
# contain any variables or common escape characters and record a warning for
|
3
|
+
# each instance found.
|
4
|
+
PuppetLint.new_check(:double_quoted_strings) do
|
5
|
+
def check
|
6
|
+
tokens.select { |token|
|
7
|
+
token.type == :STRING
|
8
|
+
}.map { |token|
|
9
|
+
[token, token.value.gsub(' '*token.column, "\n")]
|
10
|
+
}.select { |token, sane_value|
|
11
|
+
sane_value[/(\\\$|\\"|\\'|'|\r|\t|\\t|\n|\\n)/].nil?
|
12
|
+
}.each do |token, sane_value|
|
13
|
+
notify :warning, {
|
14
|
+
:message => 'double quoted string containing no variables',
|
15
|
+
:line => token.line,
|
16
|
+
:column => token.column,
|
17
|
+
:token => token,
|
26
18
|
}
|
27
19
|
end
|
28
20
|
end
|
29
21
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
check 'only_variable_string' do
|
35
|
-
tokens.each_index do |token_idx|
|
36
|
-
token = tokens[token_idx]
|
37
|
-
|
38
|
-
if token.type == :DQPRE and token.value == ''
|
39
|
-
if {:VARIABLE => true, :UNENC_VARIABLE => true}.include? tokens[token_idx + 1].type
|
40
|
-
if tokens[token_idx + 2].type == :DQPOST
|
41
|
-
if tokens[token_idx + 2].value == ''
|
42
|
-
if PuppetLint.configuration.fix
|
43
|
-
prev_token = token.prev_token
|
44
|
-
prev_code_token = token.prev_code_token
|
45
|
-
next_token = token.next_token.next_token.next_token
|
46
|
-
next_code_token = token.next_token.next_token.next_code_token
|
47
|
-
var_token = token.next_token
|
22
|
+
def fix(problem)
|
23
|
+
problem[:token].type = :SSTRING
|
24
|
+
end
|
25
|
+
end
|
48
26
|
|
49
|
-
|
50
|
-
|
27
|
+
# Public: Check the manifest tokens for double quoted strings that contain
|
28
|
+
# a single variable only and record a warning for each instance found.
|
29
|
+
PuppetLint.new_check(:only_variable_string) do
|
30
|
+
VAR_TYPES = Set[:VARIABLE, :UNENC_VARIABLE]
|
51
31
|
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
32
|
+
def check
|
33
|
+
tokens.each_with_index do |start_token, start_token_idx|
|
34
|
+
if start_token.type == :DQPRE and start_token.value == ''
|
35
|
+
var_token = start_token.next_token
|
36
|
+
if VAR_TYPES.include? var_token.type
|
37
|
+
eos_offset = 2
|
38
|
+
loop do
|
39
|
+
eos_token = tokens[start_token_idx + eos_offset]
|
40
|
+
case eos_token.type
|
41
|
+
when :LBRACK
|
42
|
+
eos_offset += 3
|
43
|
+
when :DQPOST
|
44
|
+
if eos_token.value == ''
|
45
|
+
if eos_token.next_code_token && eos_token.next_code_token.type == :FARROW
|
46
|
+
break
|
47
|
+
end
|
48
|
+
notify :warning, {
|
49
|
+
:message => 'string containing only a variable',
|
50
|
+
:line => var_token.line,
|
51
|
+
:column => var_token.column,
|
52
|
+
:start_token => start_token,
|
53
|
+
:var_token => var_token,
|
54
|
+
:end_token => eos_token,
|
55
|
+
}
|
66
56
|
end
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
:linenumber => notify_token.line,
|
71
|
-
:column => notify_token.column,
|
72
|
-
}
|
57
|
+
break
|
58
|
+
else
|
59
|
+
break
|
73
60
|
end
|
74
61
|
end
|
75
62
|
end
|
@@ -77,66 +64,105 @@ class PuppetLint::Plugins::CheckStrings < PuppetLint::CheckPlugin
|
|
77
64
|
end
|
78
65
|
end
|
79
66
|
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
67
|
+
def fix(problem)
|
68
|
+
prev_token = problem[:start_token].prev_token
|
69
|
+
prev_code_token = problem[:start_token].prev_code_token
|
70
|
+
next_token = problem[:end_token].next_token
|
71
|
+
next_code_token = problem[:end_token].next_code_token
|
72
|
+
var_token = problem[:var_token]
|
73
|
+
|
74
|
+
tokens.delete(problem[:start_token])
|
75
|
+
tokens.delete(problem[:end_token])
|
76
|
+
|
77
|
+
prev_token.next_token = var_token unless prev_token.nil?
|
78
|
+
prev_code_token.next_code_token = var_token unless prev_code_token.nil?
|
79
|
+
next_code_token.prev_code_token = var_token unless next_code_token.nil?
|
80
|
+
next_token.prev_token = var_token unless next_token.nil?
|
81
|
+
var_token.type = :VARIABLE
|
82
|
+
var_token.next_token = next_token
|
83
|
+
var_token.next_code_token = next_code_token
|
84
|
+
var_token.prev_code_token = prev_code_token
|
85
|
+
var_token.prev_token = prev_token
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
# Public: Check the manifest tokens for any variables in a string that have
|
90
|
+
# not been enclosed by braces ({}) and record a warning for each instance
|
91
|
+
# found.
|
92
|
+
PuppetLint.new_check(:variables_not_enclosed) do
|
93
|
+
def check
|
86
94
|
tokens.select { |r|
|
87
95
|
r.type == :UNENC_VARIABLE
|
88
96
|
}.each do |token|
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
end
|
95
|
-
|
96
|
-
notify notify_type, {
|
97
|
-
:message => 'variable not enclosed in {}',
|
98
|
-
:linenumber => token.line,
|
99
|
-
:column => token.column,
|
97
|
+
notify :warning, {
|
98
|
+
:message => 'variable not enclosed in {}',
|
99
|
+
:line => token.line,
|
100
|
+
:column => token.column,
|
101
|
+
:token => token,
|
100
102
|
}
|
101
103
|
end
|
102
104
|
end
|
103
105
|
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
106
|
+
def fix(problem)
|
107
|
+
problem[:token].type = :VARIABLE
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
# Public: Check the manifest tokens for any single quoted strings containing
|
112
|
+
# a enclosed variable and record an error for each instance found.
|
113
|
+
PuppetLint.new_check(:single_quote_string_with_variables) do
|
114
|
+
def check
|
109
115
|
tokens.select { |r|
|
110
116
|
r.type == :SSTRING && r.value.include?('${')
|
111
117
|
}.each do |token|
|
112
118
|
notify :error, {
|
113
|
-
:message
|
114
|
-
:
|
115
|
-
:column
|
119
|
+
:message => 'single quoted string containing a variable found',
|
120
|
+
:line => token.line,
|
121
|
+
:column => token.column,
|
116
122
|
}
|
117
123
|
end
|
118
124
|
end
|
125
|
+
end
|
126
|
+
|
127
|
+
# Public: Check the manifest tokens for any double or single quoted strings
|
128
|
+
# containing only a boolean value and record a warning for each instance
|
129
|
+
# found.
|
130
|
+
PuppetLint.new_check(:quoted_booleans) do
|
131
|
+
STRING_TYPES = Set[:STRING, :SSTRING]
|
132
|
+
BOOLEANS = Set['true', 'false']
|
119
133
|
|
120
|
-
|
121
|
-
# containing only a boolean value and record a warning for each instance
|
122
|
-
# found.
|
123
|
-
#
|
124
|
-
# Returns nothing.
|
125
|
-
check 'quoted_booleans' do
|
134
|
+
def check
|
126
135
|
tokens.select { |r|
|
127
|
-
|
136
|
+
STRING_TYPES.include?(r.type) && BOOLEANS.include?(r.value)
|
128
137
|
}.each do |token|
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
138
|
+
notify :warning, {
|
139
|
+
:message => 'quoted boolean value found',
|
140
|
+
:line => token.line,
|
141
|
+
:column => token.column,
|
142
|
+
:token => token,
|
143
|
+
}
|
144
|
+
end
|
145
|
+
end
|
135
146
|
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
147
|
+
def fix(problem)
|
148
|
+
problem[:token].type = problem[:token].value.upcase.to_sym
|
149
|
+
end
|
150
|
+
end
|
151
|
+
|
152
|
+
# Public: Check the manifest tokens for any puppet:// URL strings where the
|
153
|
+
# path section doesn't start with modules/ and record a warning for each
|
154
|
+
# instance found.
|
155
|
+
PuppetLint.new_check(:puppet_url_without_modules) do
|
156
|
+
def check
|
157
|
+
tokens.select { |token|
|
158
|
+
token.type == :SSTRING && token.value.start_with?('puppet://')
|
159
|
+
}.reject { |token|
|
160
|
+
token.value[/puppet:\/\/.*?\/(.+)/, 1].start_with?('modules/')
|
161
|
+
}.each do |token|
|
162
|
+
notify :warning, {
|
163
|
+
:message => 'puppet:// URL without modules/ found',
|
164
|
+
:line => token.line,
|
165
|
+
:column => token.column,
|
140
166
|
}
|
141
167
|
end
|
142
168
|
end
|
@@ -1,17 +1,17 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
check
|
1
|
+
# Public: Test the manifest tokens for variables that contain a dash and
|
2
|
+
# record a warning for each instance found.
|
3
|
+
PuppetLint.new_check(:variable_contains_dash) do
|
4
|
+
VARIABLE_TYPES = Set[:VARIABLE, :UNENC_VARIABLE]
|
5
|
+
|
6
|
+
def check
|
7
7
|
tokens.select { |r|
|
8
|
-
|
8
|
+
VARIABLE_TYPES.include? r.type
|
9
9
|
}.each do |token|
|
10
|
-
if token.value.match(/-/)
|
10
|
+
if token.value.gsub(/\[.+?\]/, '').match(/-/)
|
11
11
|
notify :warning, {
|
12
|
-
:message
|
13
|
-
:
|
14
|
-
:column
|
12
|
+
:message => 'variable contains a dash',
|
13
|
+
:line => token.line,
|
14
|
+
:column => token.column,
|
15
15
|
}
|
16
16
|
end
|
17
17
|
end
|
@@ -1,116 +1,117 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
check
|
1
|
+
# Public: Check the raw manifest string for lines containing hard tab
|
2
|
+
# characters and record an error for each instance found.
|
3
|
+
PuppetLint.new_check(:hard_tabs) do
|
4
|
+
WHITESPACE_TYPES = Set[:INDENT, :WHITESPACE]
|
5
|
+
|
6
|
+
def check
|
7
7
|
tokens.select { |r|
|
8
|
-
|
8
|
+
WHITESPACE_TYPES.include?(r.type) && r.value.include?("\t")
|
9
9
|
}.each do |token|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
end
|
16
|
-
|
17
|
-
notify notify_type, {
|
18
|
-
:message => 'tab character found',
|
19
|
-
:linenumber => token.line,
|
20
|
-
:column => token.column,
|
10
|
+
notify :error, {
|
11
|
+
:message => 'tab character found',
|
12
|
+
:line => token.line,
|
13
|
+
:column => token.column,
|
14
|
+
:token => token,
|
21
15
|
}
|
22
16
|
end
|
23
17
|
end
|
24
18
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
19
|
+
def fix(problem)
|
20
|
+
problem[:token].value.gsub!("\t", ' ')
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
# Public: Check the manifest tokens for lines ending with whitespace and record
|
25
|
+
# an error for each instance found.
|
26
|
+
PuppetLint.new_check(:trailing_whitespace) do
|
27
|
+
def check
|
30
28
|
tokens.select { |token|
|
31
29
|
token.type == :WHITESPACE
|
32
30
|
}.select { |token|
|
33
31
|
token.next_token.nil? || token.next_token.type == :NEWLINE
|
34
32
|
}.each do |token|
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
tokens.delete(token)
|
41
|
-
prev_token.next_token = next_token
|
42
|
-
|
43
|
-
unless next_token.nil?
|
44
|
-
next_token.prev_token = prev_token
|
45
|
-
end
|
46
|
-
else
|
47
|
-
notify_type = :error
|
48
|
-
end
|
49
|
-
|
50
|
-
notify notify_type, {
|
51
|
-
:message => 'trailing whitespace found',
|
52
|
-
:linenumber => token.line,
|
53
|
-
:column => token.column,
|
33
|
+
notify :error, {
|
34
|
+
:message => 'trailing whitespace found',
|
35
|
+
:line => token.line,
|
36
|
+
:column => token.column,
|
37
|
+
:token => token,
|
54
38
|
}
|
55
39
|
end
|
56
40
|
end
|
57
41
|
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
42
|
+
def fix(problem)
|
43
|
+
prev_token = problem[:token].prev_token
|
44
|
+
next_token = problem[:token].next_token
|
45
|
+
prev_token.next_token = next_token
|
46
|
+
next_token.prev_token = prev_token unless next_token.nil?
|
47
|
+
tokens.delete(problem[:token])
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
# Public: Test the raw manifest string for lines containing more than 80
|
52
|
+
# characters and record a warning for each instance found. The only exceptions
|
53
|
+
# to this rule are lines containing URLs and template() calls which would hurt
|
54
|
+
# readability if split.
|
55
|
+
PuppetLint.new_check(:'80chars') do
|
56
|
+
def check
|
64
57
|
manifest_lines.each_with_index do |line, idx|
|
65
|
-
unless line =~ /:\/\//
|
58
|
+
unless line =~ /:\/\// || line =~ /template\(/
|
66
59
|
if line.scan(/./mu).size > 80
|
67
60
|
notify :warning, {
|
68
|
-
:message
|
69
|
-
:
|
70
|
-
:column
|
61
|
+
:message => 'line has more than 80 characters',
|
62
|
+
:line => idx + 1,
|
63
|
+
:column => 80,
|
71
64
|
}
|
72
65
|
end
|
73
66
|
end
|
74
67
|
end
|
75
68
|
end
|
69
|
+
end
|
76
70
|
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
check '2sp_soft_tabs' do
|
71
|
+
# Public: Check the manifest tokens for any indentation not using 2 space soft
|
72
|
+
# tabs and record an error for each instance found.
|
73
|
+
PuppetLint.new_check(:'2sp_soft_tabs') do
|
74
|
+
def check
|
82
75
|
tokens.select { |r|
|
83
76
|
r.type == :INDENT
|
84
77
|
}.reject { |r|
|
85
78
|
r.value.length % 2 == 0
|
86
79
|
}.each do |token|
|
87
80
|
notify :error, {
|
88
|
-
:message
|
89
|
-
:
|
90
|
-
:column
|
81
|
+
:message => 'two-space soft tabs not used',
|
82
|
+
:line => token.line,
|
83
|
+
:column => token.column,
|
91
84
|
}
|
92
85
|
end
|
93
86
|
end
|
87
|
+
end
|
94
88
|
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
89
|
+
# Public: Check the manifest tokens for any arrows (=>) in a grouping ({}) that
|
90
|
+
# are not aligned with other arrows in that grouping.
|
91
|
+
PuppetLint.new_check(:arrow_alignment) do
|
92
|
+
COMMENT_TYPES = Set[:COMMENT, :SLASH_COMMENT, :MLCOMMENT]
|
93
|
+
|
94
|
+
def check
|
100
95
|
resource_indexes.each do |res_idx|
|
101
96
|
indent_depth = [0]
|
102
97
|
indent_depth_idx = 0
|
103
|
-
|
98
|
+
level_tokens = []
|
99
|
+
resource_tokens = res_idx[:tokens]
|
104
100
|
resource_tokens.reject! do |token|
|
105
|
-
|
101
|
+
COMMENT_TYPES.include? token.type
|
106
102
|
end
|
107
103
|
|
108
104
|
# If this is a single line resource, skip it
|
109
|
-
|
105
|
+
first_arrow = resource_tokens.index { |r| r.type == :FARROW }
|
106
|
+
last_arrow = resource_tokens.rindex { |r| r.type == :FARROW }
|
107
|
+
next if first_arrow.nil?
|
108
|
+
next if last_arrow.nil?
|
109
|
+
next unless resource_tokens[first_arrow..last_arrow].any? { |r| r.type == :NEWLINE }
|
110
110
|
|
111
111
|
resource_tokens.each_with_index do |token, idx|
|
112
112
|
if token.type == :FARROW
|
113
|
-
|
113
|
+
(level_tokens[indent_depth_idx] ||= []) << token
|
114
|
+
indent_length = token.prev_token.column + 1
|
114
115
|
|
115
116
|
if indent_depth[indent_depth_idx] < indent_length
|
116
117
|
indent_depth[indent_depth_idx] = indent_length
|
@@ -120,34 +121,27 @@ class PuppetLint::Plugins::CheckWhitespace < PuppetLint::CheckPlugin
|
|
120
121
|
indent_depth_idx += 1
|
121
122
|
indent_depth << 0
|
122
123
|
elsif token.type == :RBRACE
|
123
|
-
indent_depth_idx
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
if PuppetLint.configuration.fix
|
133
|
-
offset = indent_depth[indent_depth_idx] - indent_length
|
134
|
-
token.prev_token.value = token.prev_token.value + (' ' * offset)
|
135
|
-
notify_type = :fixed
|
136
|
-
else
|
137
|
-
notify_type = :warning
|
124
|
+
level_tokens[indent_depth_idx].each do |arrow_tok|
|
125
|
+
unless arrow_tok.column == indent_depth[indent_depth_idx]
|
126
|
+
notify :warning, {
|
127
|
+
:message => 'indentation of => is not properly aligned',
|
128
|
+
:line => arrow_tok.line,
|
129
|
+
:column => arrow_tok.column,
|
130
|
+
:token => arrow_tok,
|
131
|
+
:indent_depth => indent_depth[indent_depth_idx],
|
132
|
+
}
|
138
133
|
end
|
139
|
-
notify notify_type, {
|
140
|
-
:message => 'indentation of => is not properly aligned',
|
141
|
-
:linenumber => token.line,
|
142
|
-
:column => token.column,
|
143
|
-
}
|
144
134
|
end
|
145
|
-
|
146
|
-
indent_depth_idx
|
147
|
-
elsif token.type == :RBRACE
|
135
|
+
indent_depth[indent_depth_idx] = 0
|
136
|
+
level_tokens[indent_depth_idx].clear
|
148
137
|
indent_depth_idx -= 1
|
149
138
|
end
|
150
139
|
end
|
151
140
|
end
|
152
141
|
end
|
142
|
+
|
143
|
+
def fix(problem)
|
144
|
+
new_indent = ' ' * (problem[:indent_depth] - problem[:token].prev_token.column)
|
145
|
+
problem[:token].prev_token.value = new_indent
|
146
|
+
end
|
153
147
|
end
|