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.
Files changed (70) hide show
  1. data/.travis.yml +3 -4
  2. data/Gemfile +2 -5
  3. data/README.md +2 -149
  4. data/Rakefile +0 -5
  5. data/lib/puppet-lint.rb +74 -20
  6. data/lib/puppet-lint/bin.rb +20 -85
  7. data/lib/puppet-lint/checkplugin.rb +158 -12
  8. data/lib/puppet-lint/checks.rb +39 -222
  9. data/lib/puppet-lint/configuration.rb +12 -31
  10. data/lib/puppet-lint/data.rb +329 -0
  11. data/lib/puppet-lint/lexer.rb +37 -30
  12. data/lib/puppet-lint/lexer/token.rb +14 -16
  13. data/lib/puppet-lint/monkeypatches/string_prepend.rb +6 -0
  14. data/lib/puppet-lint/optparser.rb +105 -0
  15. data/lib/puppet-lint/plugins.rb +28 -9
  16. data/lib/puppet-lint/plugins/check_classes.rb +162 -238
  17. data/lib/puppet-lint/plugins/check_comments.rb +40 -25
  18. data/lib/puppet-lint/plugins/check_conditionals.rb +16 -20
  19. data/lib/puppet-lint/plugins/check_documentation.rb +14 -20
  20. data/lib/puppet-lint/plugins/check_nodes.rb +23 -0
  21. data/lib/puppet-lint/plugins/check_resources.rb +127 -141
  22. data/lib/puppet-lint/plugins/check_strings.rb +133 -107
  23. data/lib/puppet-lint/plugins/check_variables.rb +11 -11
  24. data/lib/puppet-lint/plugins/check_whitespace.rb +86 -92
  25. data/lib/puppet-lint/tasks/puppet-lint.rb +17 -1
  26. data/lib/puppet-lint/version.rb +1 -1
  27. data/puppet-lint.gemspec +4 -2
  28. data/spec/fixtures/test/manifests/ignore.pp +1 -0
  29. data/spec/fixtures/test/manifests/ignore_reason.pp +1 -0
  30. data/spec/puppet-lint/bin_spec.rb +104 -84
  31. data/spec/puppet-lint/configuration_spec.rb +19 -19
  32. data/spec/puppet-lint/ignore_overrides_spec.rb +97 -0
  33. data/spec/puppet-lint/lexer/token_spec.rb +9 -9
  34. data/spec/puppet-lint/lexer_spec.rb +352 -325
  35. data/spec/puppet-lint/plugins/check_classes/autoloader_layout_spec.rb +77 -23
  36. data/spec/puppet-lint/plugins/check_classes/class_inherits_from_params_class_spec.rb +14 -12
  37. data/spec/puppet-lint/plugins/check_classes/inherits_across_namespaces_spec.rb +18 -14
  38. data/spec/puppet-lint/plugins/check_classes/names_containing_dash_spec.rb +30 -30
  39. data/spec/puppet-lint/plugins/check_classes/nested_classes_or_defines_spec.rb +31 -26
  40. data/spec/puppet-lint/plugins/check_classes/parameter_order_spec.rb +34 -28
  41. data/spec/puppet-lint/plugins/check_classes/right_to_left_relationship_spec.rb +14 -12
  42. data/spec/puppet-lint/plugins/check_classes/variable_scope_spec.rb +74 -30
  43. data/spec/puppet-lint/plugins/check_comments/slash_comments_spec.rb +27 -20
  44. data/spec/puppet-lint/plugins/check_comments/star_comments_spec.rb +78 -13
  45. data/spec/puppet-lint/plugins/check_conditionals/case_without_default_spec.rb +17 -12
  46. data/spec/puppet-lint/plugins/check_conditionals/selector_inside_resource_spec.rb +13 -10
  47. data/spec/puppet-lint/plugins/check_documentation/documentation_spec.rb +21 -16
  48. data/spec/puppet-lint/plugins/check_nodes/unquoted_node_name_spec.rb +69 -0
  49. data/spec/puppet-lint/plugins/check_resources/duplicate_params_spec.rb +42 -38
  50. data/spec/puppet-lint/plugins/check_resources/ensure_first_param_spec.rb +22 -10
  51. data/spec/puppet-lint/plugins/check_resources/ensure_not_symlink_target_spec.rb +81 -18
  52. data/spec/puppet-lint/plugins/check_resources/file_mode_spec.rb +69 -112
  53. data/spec/puppet-lint/plugins/check_resources/unquoted_file_mode_spec.rb +27 -20
  54. data/spec/puppet-lint/plugins/check_resources/unquoted_resource_title_spec.rb +177 -171
  55. data/spec/puppet-lint/plugins/check_strings/double_quoted_strings_spec.rb +165 -88
  56. data/spec/puppet-lint/plugins/check_strings/only_variable_string_spec.rb +97 -22
  57. data/spec/puppet-lint/plugins/check_strings/puppet_url_without_modules_spec.rb +25 -0
  58. data/spec/puppet-lint/plugins/check_strings/quoted_booleans_spec.rb +97 -111
  59. data/spec/puppet-lint/plugins/check_strings/single_quote_string_with_variables_spec.rb +10 -9
  60. data/spec/puppet-lint/plugins/check_strings/variables_not_enclosed_spec.rb +53 -53
  61. data/spec/puppet-lint/plugins/check_variables/variable_contains_dash_spec.rb +26 -14
  62. data/spec/puppet-lint/plugins/check_whitespace/2sp_soft_tabs_spec.rb +10 -9
  63. data/spec/puppet-lint/plugins/check_whitespace/80chars_spec.rb +31 -15
  64. data/spec/puppet-lint/plugins/check_whitespace/arrow_alignment_spec.rb +340 -322
  65. data/spec/puppet-lint/plugins/check_whitespace/hard_tabs_spec.rb +30 -23
  66. data/spec/puppet-lint/plugins/check_whitespace/trailing_whitespace_spec.rb +42 -41
  67. data/spec/puppet-lint_spec.rb +3 -3
  68. data/spec/spec_helper.rb +109 -116
  69. metadata +109 -50
  70. data/spec/puppet-lint/plugins/check_classes/class_parameter_defaults_spec.rb +0 -60
@@ -1,75 +1,62 @@
1
- class PuppetLint::Plugins::CheckStrings < PuppetLint::CheckPlugin
2
- # Public: Check the manifest tokens for any double quoted strings that don't
3
- # contain any variables or common escape characters and record a warning for
4
- # each instance found.
5
- #
6
- # Returns nothing.
7
- check 'double_quoted_strings' do
8
- tokens.select { |r|
9
- r.type == :STRING
10
- }.each { |r|
11
- r.value.gsub!(' '*r.column, "\n")
12
- }.select { |r|
13
- r.value[/(\t|\\t|\n|\\n)/].nil?
14
- }.each do |token|
15
- if PuppetLint.configuration.fix
16
- token.type = :SSTRING
17
- notify_type = :fixed
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
- # Public: Check the manifest tokens for double quoted strings that contain
31
- # a single variable only and record a warning for each instance found.
32
- #
33
- # Returns nothing.
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
- tokens.delete_at(token_idx + 2)
50
- tokens.delete_at(token_idx)
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
- prev_token.next_token = var_token unless prev_token.nil?
53
- prev_code_token.next_code_token = var_token unless prev_code_token.nil?
54
- next_code_token.prev_code_token = var_token unless next_code_token.nil?
55
- next_token.prev_token = var_token unless next_token.nil?
56
- var_token.type = :VARIABLE
57
- var_token.next_token = next_token
58
- var_token.next_code_token = next_code_token
59
- var_token.prev_code_token = prev_code_token
60
- var_token.prev_token = prev_token
61
- notify_type = :fixed
62
- notify_token = var_token
63
- else
64
- notify_type = :warning
65
- notify_token = tokens[token_idx + 1]
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
- notify notify_type, {
69
- :message => 'string containing only a variable',
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
- # Public: Check the manifest tokens for any variables in a string that have
81
- # not been enclosed by braces ({}) and record a warning for each instance
82
- # found.
83
- #
84
- # Returns nothing.
85
- check 'variables_not_enclosed' do
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
- if PuppetLint.configuration.fix
90
- token.type = :VARIABLE
91
- notify_type = :fixed
92
- else
93
- notify_type = :warning
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
- # Public: Check the manifest tokens for any single quoted strings containing
105
- # a enclosed variable and record an error for each instance found.
106
- #
107
- # Returns nothing.
108
- check 'single_quote_string_with_variables' do
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 => 'single quoted string containing a variable found',
114
- :linenumber => token.line,
115
- :column => token.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
- # Public: Check the manifest tokens for any double or single quoted strings
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
- {:STRING => true, :SSTRING => true}.include?(r.type) && %w{true false}.include?(r.value)
136
+ STRING_TYPES.include?(r.type) && BOOLEANS.include?(r.value)
128
137
  }.each do |token|
129
- if PuppetLint.configuration.fix
130
- token.type = token.value.upcase.to_sym
131
- notify_type = :fixed
132
- else
133
- notify_type = :warning
134
- end
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
- notify notify_type, {
137
- :message => 'quoted boolean value found',
138
- :linenumber => token.line,
139
- :column => token.column,
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
- class PuppetLint::Plugins::CheckVariables < PuppetLint::CheckPlugin
2
- # Public: Test the manifest tokens for variables that contain a dash and
3
- # record a warning for each instance found.
4
- #
5
- # Returns nothing.
6
- check 'variable_contains_dash' do
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
- {:VARIABLE => true, :UNENC_VARIABLE => true}.include? r.type
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 => 'variable contains a dash',
13
- :linenumber => token.line,
14
- :column => token.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
- class PuppetLint::Plugins::CheckWhitespace < PuppetLint::CheckPlugin
2
- # Check the raw manifest string for lines containing hard tab characters and
3
- # record an error for each instance found.
4
- #
5
- # Returns nothing.
6
- check 'hard_tabs' do
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
- [:INDENT, :WHITESPACE].include?(r.type) && r.value.include?("\t")
8
+ WHITESPACE_TYPES.include?(r.type) && r.value.include?("\t")
9
9
  }.each do |token|
10
- if PuppetLint.configuration.fix
11
- token.value.gsub!("\t", ' ')
12
- notify_type = :fixed
13
- else
14
- notify_type = :error
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
- # Check the manifest tokens for lines ending with whitespace and record an
26
- # error for each instance found.
27
- #
28
- # Returns nothing.
29
- check 'trailing_whitespace' do
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
- if PuppetLint.configuration.fix
36
- notify_type = :fixed
37
- prev_token = token.prev_token
38
- next_token = token.next_token
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
- # Test the raw manifest string for lines containing more than 80 characters
59
- # and record a warning for each instance found. The only exception to this
60
- # rule is lines containing URLs which would hurt readability if split.
61
- #
62
- # Returns nothing.
63
- check '80chars' do
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 => 'line has more than 80 characters',
69
- :linenumber => idx + 1,
70
- :column => 80,
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
- # Check the manifest tokens for any indentation not using 2 space soft tabs
78
- # and record an error for each instance found.
79
- #
80
- # Returns nothing.
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 => 'two-space soft tabs not used',
89
- :linenumber => token.line,
90
- :column => token.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
- # Check the manifest tokens for any arrows (=>) in a grouping ({}) that are
96
- # not aligned with other arrows in that grouping.
97
- #
98
- # Returns nothing.
99
- check 'arrow_alignment' do
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
- resource_tokens = tokens[res_idx[:start]..res_idx[:end]]
98
+ level_tokens = []
99
+ resource_tokens = res_idx[:tokens]
104
100
  resource_tokens.reject! do |token|
105
- {:COMMENT => true, :SLASH_COMMENT => true, :MLCOMMENT => true}.include? token.type
101
+ COMMENT_TYPES.include? token.type
106
102
  end
107
103
 
108
104
  # If this is a single line resource, skip it
109
- next if resource_tokens.select { |r| r.type == :NEWLINE }.empty?
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
- indent_length = token.column
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 -= 1
124
- end
125
- end
126
-
127
- indent_depth_idx = 0
128
- resource_tokens.each_with_index do |token, idx|
129
- if token.type == :FARROW
130
- indent_length = token.column
131
- unless indent_depth[indent_depth_idx] == indent_length
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
- elsif token.type == :LBRACE
146
- indent_depth_idx += 1
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