puppet-lint 2.3.0 → 2.3.1

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 (107) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +74 -0
  3. data/.rubocop_todo.yml +89 -0
  4. data/.travis.yml +11 -9
  5. data/CHANGELOG.md +54 -0
  6. data/Gemfile +3 -0
  7. data/Rakefile +14 -3
  8. data/appveyor.yml +1 -4
  9. data/bin/puppet-lint +1 -1
  10. data/lib/puppet-lint.rb +25 -21
  11. data/lib/puppet-lint/bin.rb +15 -19
  12. data/lib/puppet-lint/checkplugin.rb +24 -17
  13. data/lib/puppet-lint/checks.rb +42 -31
  14. data/lib/puppet-lint/configuration.rb +11 -8
  15. data/lib/puppet-lint/data.rb +236 -164
  16. data/lib/puppet-lint/lexer.rb +225 -203
  17. data/lib/puppet-lint/lexer/token.rb +34 -18
  18. data/lib/puppet-lint/optparser.rb +33 -30
  19. data/lib/puppet-lint/plugins.rb +42 -38
  20. data/lib/puppet-lint/plugins/check_classes/arrow_on_right_operand_line.rb +26 -28
  21. data/lib/puppet-lint/plugins/check_classes/autoloader_layout.rb +21 -20
  22. data/lib/puppet-lint/plugins/check_classes/class_inherits_from_params_class.rb +8 -9
  23. data/lib/puppet-lint/plugins/check_classes/code_on_top_scope.rb +9 -8
  24. data/lib/puppet-lint/plugins/check_classes/inherits_across_namespaces.rb +12 -11
  25. data/lib/puppet-lint/plugins/check_classes/names_containing_dash.rb +13 -12
  26. data/lib/puppet-lint/plugins/check_classes/names_containing_uppercase.rb +14 -13
  27. data/lib/puppet-lint/plugins/check_classes/nested_classes_or_defines.rb +9 -10
  28. data/lib/puppet-lint/plugins/check_classes/parameter_order.rb +40 -31
  29. data/lib/puppet-lint/plugins/check_classes/right_to_left_relationship.rb +3 -2
  30. data/lib/puppet-lint/plugins/check_classes/variable_scope.rb +21 -24
  31. data/lib/puppet-lint/plugins/check_comments/slash_comments.rb +3 -2
  32. data/lib/puppet-lint/plugins/check_comments/star_comments.rb +6 -5
  33. data/lib/puppet-lint/plugins/check_conditionals/case_without_default.rb +21 -20
  34. data/lib/puppet-lint/plugins/check_conditionals/selector_inside_resource.rb +10 -13
  35. data/lib/puppet-lint/plugins/check_documentation/documentation.rb +26 -17
  36. data/lib/puppet-lint/plugins/check_nodes/unquoted_node_name.rb +11 -11
  37. data/lib/puppet-lint/plugins/check_resources/duplicate_params.rb +4 -3
  38. data/lib/puppet-lint/plugins/check_resources/ensure_first_param.rb +17 -18
  39. data/lib/puppet-lint/plugins/check_resources/ensure_not_symlink_target.rb +17 -16
  40. data/lib/puppet-lint/plugins/check_resources/file_mode.rb +22 -23
  41. data/lib/puppet-lint/plugins/check_resources/unquoted_file_mode.rb +14 -13
  42. data/lib/puppet-lint/plugins/check_resources/unquoted_resource_title.rb +9 -8
  43. data/lib/puppet-lint/plugins/check_strings/double_quoted_strings.rb +8 -8
  44. data/lib/puppet-lint/plugins/check_strings/only_variable_string.rb +29 -42
  45. data/lib/puppet-lint/plugins/check_strings/puppet_url_without_modules.rb +5 -4
  46. data/lib/puppet-lint/plugins/check_strings/quoted_booleans.rb +3 -2
  47. data/lib/puppet-lint/plugins/check_strings/single_quote_string_with_variables.rb +4 -3
  48. data/lib/puppet-lint/plugins/check_strings/variables_not_enclosed.rb +3 -2
  49. data/lib/puppet-lint/plugins/check_variables/variable_contains_dash.rb +9 -8
  50. data/lib/puppet-lint/plugins/check_variables/variable_is_lowercase.rb +9 -8
  51. data/lib/puppet-lint/plugins/check_whitespace/140chars.rb +9 -9
  52. data/lib/puppet-lint/plugins/check_whitespace/2sp_soft_tabs.rb +4 -3
  53. data/lib/puppet-lint/plugins/check_whitespace/80chars.rb +10 -10
  54. data/lib/puppet-lint/plugins/check_whitespace/arrow_alignment.rb +23 -22
  55. data/lib/puppet-lint/plugins/check_whitespace/hard_tabs.rb +3 -2
  56. data/lib/puppet-lint/plugins/check_whitespace/trailing_whitespace.rb +3 -2
  57. data/lib/puppet-lint/tasks/puppet-lint.rb +3 -3
  58. data/lib/puppet-lint/version.rb +1 -1
  59. data/puppet-lint.gemspec +4 -4
  60. data/spec/puppet-lint/bin_spec.rb +268 -140
  61. data/spec/puppet-lint/checks_spec.rb +229 -0
  62. data/spec/puppet-lint/configuration_spec.rb +10 -9
  63. data/spec/puppet-lint/data_spec.rb +84 -0
  64. data/spec/puppet-lint/ignore_overrides_spec.rb +71 -40
  65. data/spec/puppet-lint/lexer/token_spec.rb +1 -1
  66. data/spec/puppet-lint/lexer_spec.rb +306 -73
  67. data/spec/puppet-lint/plugins/check_classes/arrow_on_right_operand_line_spec.rb +12 -6
  68. data/spec/puppet-lint/plugins/check_classes/autoloader_layout_spec.rb +10 -10
  69. data/spec/puppet-lint/plugins/check_classes/class_inherits_from_params_class_spec.rb +15 -11
  70. data/spec/puppet-lint/plugins/check_classes/code_on_top_scope_spec.rb +26 -21
  71. data/spec/puppet-lint/plugins/check_classes/inherits_across_namespaces_spec.rb +3 -3
  72. data/spec/puppet-lint/plugins/check_classes/name_contains_uppercase_spec.rb +4 -5
  73. data/spec/puppet-lint/plugins/check_classes/names_containing_dash_spec.rb +13 -0
  74. data/spec/puppet-lint/plugins/check_classes/nested_classes_or_defines_spec.rb +33 -25
  75. data/spec/puppet-lint/plugins/check_classes/parameter_order_spec.rb +80 -55
  76. data/spec/puppet-lint/plugins/check_classes/right_to_left_relationship_spec.rb +2 -2
  77. data/spec/puppet-lint/plugins/check_classes/variable_scope_spec.rb +165 -130
  78. data/spec/puppet-lint/plugins/check_comments/slash_comments_spec.rb +2 -2
  79. data/spec/puppet-lint/plugins/check_comments/star_comments_spec.rb +53 -35
  80. data/spec/puppet-lint/plugins/check_conditionals/case_without_default_spec.rb +59 -49
  81. data/spec/puppet-lint/plugins/check_conditionals/selector_inside_resource_spec.rb +18 -14
  82. data/spec/puppet-lint/plugins/check_documentation/documentation_spec.rb +14 -10
  83. data/spec/puppet-lint/plugins/check_nodes/unquoted_node_name_spec.rb +7 -7
  84. data/spec/puppet-lint/plugins/check_resources/duplicate_params_spec.rb +54 -44
  85. data/spec/puppet-lint/plugins/check_resources/ensure_first_param_spec.rb +114 -89
  86. data/spec/puppet-lint/plugins/check_resources/ensure_not_symlink_target_spec.rb +41 -30
  87. data/spec/puppet-lint/plugins/check_resources/file_mode_spec.rb +46 -40
  88. data/spec/puppet-lint/plugins/check_resources/unquoted_file_mode_spec.rb +46 -40
  89. data/spec/puppet-lint/plugins/check_resources/unquoted_resource_title_spec.rb +95 -71
  90. data/spec/puppet-lint/plugins/check_strings/double_quoted_strings_spec.rb +28 -24
  91. data/spec/puppet-lint/plugins/check_strings/only_variable_string_spec.rb +11 -9
  92. data/spec/puppet-lint/plugins/check_strings/puppet_url_without_modules_spec.rb +1 -2
  93. data/spec/puppet-lint/plugins/check_strings/single_quote_string_with_variables_spec.rb +18 -14
  94. data/spec/puppet-lint/plugins/check_variables/variable_contains_dash_spec.rb +1 -1
  95. data/spec/puppet-lint/plugins/check_variables/variable_is_lowercase_spec.rb +1 -1
  96. data/spec/puppet-lint/plugins/check_whitespace/140chars_spec.rb +22 -15
  97. data/spec/puppet-lint/plugins/check_whitespace/2sp_soft_tabs_spec.rb +8 -6
  98. data/spec/puppet-lint/plugins/check_whitespace/80chars_spec.rb +23 -29
  99. data/spec/puppet-lint/plugins/check_whitespace/arrow_alignment_spec.rb +588 -494
  100. data/spec/puppet-lint/plugins/check_whitespace/hard_tabs_spec.rb +1 -1
  101. data/spec/puppet-lint/plugins/check_whitespace/trailing_whitespace_spec.rb +27 -19
  102. data/spec/puppet-lint_spec.rb +2 -12
  103. data/spec/spec_helper.rb +35 -30
  104. metadata +6 -5
  105. data/lib/puppet-lint/monkeypatches.rb +0 -2
  106. data/lib/puppet-lint/monkeypatches/string_percent.rb +0 -52
  107. data/lib/puppet-lint/monkeypatches/string_prepend.rb +0 -13
@@ -5,18 +5,19 @@
5
5
  PuppetLint.new_check(:inherits_across_namespaces) do
6
6
  def check
7
7
  class_indexes.each do |class_idx|
8
- unless class_idx[:inherited_token].nil?
9
- inherited_module_name = class_idx[:inherited_token].value.split('::').reject { |r| r.empty? }.first
10
- class_module_name = class_idx[:name_token].value.split('::').reject { |r| r.empty? }.first
8
+ next if class_idx[:inherited_token].nil?
11
9
 
12
- unless class_module_name == inherited_module_name
13
- notify :warning, {
14
- :message => "class inherits across module namespaces",
15
- :line => class_idx[:inherited_token].line,
16
- :column => class_idx[:inherited_token].column,
17
- }
18
- end
19
- end
10
+ inherited_module_name = class_idx[:inherited_token].value.split('::').reject(&:empty?).first
11
+ class_module_name = class_idx[:name_token].value.split('::').reject(&:empty?).first
12
+
13
+ next if class_module_name == inherited_module_name
14
+
15
+ notify(
16
+ :warning,
17
+ :message => 'class inherits across module namespaces',
18
+ :line => class_idx[:inherited_token].line,
19
+ :column => class_idx[:inherited_token].column,
20
+ )
20
21
  end
21
22
  end
22
23
  end
@@ -5,19 +5,20 @@
5
5
  PuppetLint.new_check(:names_containing_dash) do
6
6
  def check
7
7
  (class_indexes + defined_type_indexes).each do |class_idx|
8
- if class_idx[:name_token].value.include? '-'
9
- if class_idx[:type] == :CLASS
10
- obj_type = 'class'
11
- else
12
- obj_type = 'defined type'
13
- end
8
+ next unless class_idx[:name_token].value.include?('-')
14
9
 
15
- notify :error, {
16
- :message => "#{obj_type} name containing a dash",
17
- :line => class_idx[:name_token].line,
18
- :column => class_idx[:name_token].column,
19
- }
20
- end
10
+ obj_type = if class_idx[:type] == :CLASS
11
+ 'class'
12
+ else
13
+ 'defined type'
14
+ end
15
+
16
+ notify(
17
+ :error,
18
+ :message => "#{obj_type} name containing a dash",
19
+ :line => class_idx[:name_token].line,
20
+ :column => class_idx[:name_token].column,
21
+ )
21
22
  end
22
23
  end
23
24
  end
@@ -5,20 +5,21 @@
5
5
  PuppetLint.new_check(:names_containing_uppercase) do
6
6
  def check
7
7
  (class_indexes + defined_type_indexes).each do |class_idx|
8
- if class_idx[:name_token].value =~ /[A-Z]/
9
- if class_idx[:type] == :CLASS
10
- obj_type = 'class'
11
- else
12
- obj_type = 'defined type'
13
- end
8
+ next unless class_idx[:name_token].value =~ %r{[A-Z]}
14
9
 
15
- notify :error, {
16
- :message => "#{obj_type} '#{class_idx[:name_token].value}' contains illegal uppercase",
17
- :line => class_idx[:name_token].line,
18
- :column => class_idx[:name_token].column,
19
- :token => class_idx[:name_token],
20
- }
21
- end
10
+ obj_type = if class_idx[:type] == :CLASS
11
+ 'class'
12
+ else
13
+ 'defined type'
14
+ end
15
+
16
+ notify(
17
+ :error,
18
+ :message => "#{obj_type} '#{class_idx[:name_token].value}' contains illegal uppercase",
19
+ :line => class_idx[:name_token].line,
20
+ :column => class_idx[:name_token].column,
21
+ :token => class_idx[:name_token],
22
+ )
22
23
  end
23
24
  end
24
25
 
@@ -11,17 +11,16 @@ PuppetLint.new_check(:nested_classes_or_defines) do
11
11
  class_tokens = class_idx[:tokens][1..-1]
12
12
 
13
13
  class_tokens.each do |token|
14
- if TOKENS.include?(token.type)
15
- if token.next_code_token.type != :LBRACE
16
- type = token.type == :CLASS ? 'class' : 'defined type'
14
+ next unless TOKENS.include?(token.type)
15
+ next if token.next_code_token.type == :LBRACE
16
+ type = token.type == :CLASS ? 'class' : 'defined type'
17
17
 
18
- notify :warning, {
19
- :message => "#{type} defined inside a class",
20
- :line => token.line,
21
- :column => token.column,
22
- }
23
- end
24
- end
18
+ notify(
19
+ :warning,
20
+ :message => "#{type} defined inside a class",
21
+ :line => token.line,
22
+ :column => token.column,
23
+ )
25
24
  end
26
25
  end
27
26
  end
@@ -6,39 +6,48 @@
6
6
  PuppetLint.new_check(:parameter_order) do
7
7
  def check
8
8
  (class_indexes + defined_type_indexes).each do |class_idx|
9
- unless class_idx[:param_tokens].nil?
10
- paren_stack = []
11
- hash_or_array_stack = []
12
- class_idx[:param_tokens].each_with_index do |token, i|
13
- if token.type == :LPAREN
14
- paren_stack.push(true)
15
- elsif token.type == :RPAREN
16
- paren_stack.pop
17
- elsif token.type == :LBRACE || token.type == :LBRACK
18
- hash_or_array_stack.push(true)
19
- elsif token.type == :RBRACE || token.type == :RBRACK
20
- hash_or_array_stack.pop
21
- end
22
- next if (! hash_or_array_stack.empty?)
23
- next unless paren_stack.empty?
24
-
25
- if token.type == :VARIABLE
26
- if token.next_code_token.nil? || [:COMMA, :RPAREN].include?(token.next_code_token.type)
27
- prev_tokens = class_idx[:param_tokens][0..i]
28
- unless prev_tokens.rindex { |r| r.type == :EQUALS }.nil?
29
- unless token.prev_code_token.nil? or token.prev_code_token.type == :EQUALS
30
- msg = 'optional parameter listed before required parameter'
31
- notify :warning, {
32
- :message => msg,
33
- :line => token.line,
34
- :column => token.column,
35
- }
36
- end
37
- end
38
- end
39
- end
9
+ next if class_idx[:param_tokens].nil?
10
+
11
+ paren_stack = []
12
+ hash_or_array_stack = []
13
+ class_idx[:param_tokens].each_with_index do |token, i|
14
+ if token.type == :LPAREN
15
+ paren_stack.push(true)
16
+ elsif token.type == :RPAREN
17
+ paren_stack.pop
18
+ elsif token.type == :LBRACE || token.type == :LBRACK
19
+ hash_or_array_stack.push(true)
20
+ elsif token.type == :RBRACE || token.type == :RBRACK
21
+ hash_or_array_stack.pop
40
22
  end
23
+
24
+ next unless hash_or_array_stack.empty? && paren_stack.empty?
25
+ next unless required_parameter?(token)
26
+
27
+ prev_tokens = class_idx[:param_tokens][0..i]
28
+ next if prev_tokens.rindex { |r| r.type == :EQUALS }.nil?
29
+
30
+ msg = 'optional parameter listed before required parameter'
31
+ notify(
32
+ :warning,
33
+ :message => msg,
34
+ :line => token.line,
35
+ :column => token.column,
36
+ )
41
37
  end
42
38
  end
43
39
  end
40
+
41
+ def required_parameter?(token)
42
+ return false unless token.type == :VARIABLE
43
+
44
+ data_type = token.prev_token_of(:TYPE, :skip_blocks => true)
45
+ return false if data_type && data_type.value == 'Optional'
46
+
47
+ if token.next_code_token.nil? || [:COMMA, :RPAREN].include?(token.next_code_token.type)
48
+ return !(token.prev_code_token && token.prev_code_token.type == :EQUALS)
49
+ end
50
+
51
+ false
52
+ end
44
53
  end
@@ -5,11 +5,12 @@
5
5
  PuppetLint.new_check(:right_to_left_relationship) do
6
6
  def check
7
7
  tokens.select { |r| r.type == :OUT_EDGE }.each do |token|
8
- notify :warning, {
8
+ notify(
9
+ :warning,
9
10
  :message => 'right-to-left (<-) relationship',
10
11
  :line => token.line,
11
12
  :column => token.column,
12
- }
13
+ )
13
14
  end
14
15
  end
15
16
  end
@@ -43,11 +43,10 @@ PuppetLint.new_check(:variable_scope) do
43
43
 
44
44
  unless idx[:param_tokens].nil?
45
45
  idx[:param_tokens].each do |token|
46
- if token.type == :VARIABLE
47
- if POST_VAR_TOKENS.include? token.next_code_token.type
48
- variables_in_scope << token.value
49
- end
50
- end
46
+ next unless token.type == :VARIABLE
47
+ next unless POST_VAR_TOKENS.include?(token.next_code_token.type)
48
+
49
+ variables_in_scope << token.value
51
50
  end
52
51
  end
53
52
 
@@ -72,10 +71,10 @@ PuppetLint.new_check(:variable_scope) do
72
71
  brack_depth += 1
73
72
  when :LBRACK
74
73
  brack_depth -= 1
75
- break if brack_depth == 0
76
- when :COMMA
74
+ break if brack_depth.zero?
75
+ when :COMMA # rubocop:disable Lint/EmptyWhen
77
76
  # ignore
78
- else # unexpected
77
+ else # unexpected
79
78
  break
80
79
  end
81
80
  end
@@ -102,7 +101,7 @@ PuppetLint.new_check(:variable_scope) do
102
101
  brace_depth += 1
103
102
  when :RBRACE
104
103
  brace_depth -= 1
105
- if brace_depth == 0
104
+ if brace_depth.zero?
106
105
  end_token = sub_token
107
106
  break
108
107
  end
@@ -118,25 +117,23 @@ PuppetLint.new_check(:variable_scope) do
118
117
  end
119
118
  end
120
119
 
121
- msg = "top-scope variable being used without an explicit namespace"
120
+ msg = 'top-scope variable being used without an explicit namespace'
122
121
  referenced_variables.each do |token|
123
122
  unless future_parser_scopes[token.line].nil?
124
- next if future_parser_scopes[token.line].include?(token.value.gsub(/\[.+\]\Z/, ''))
123
+ next if future_parser_scopes[token.line].include?(token.value.gsub(%r{\[.+\]\Z}, ''))
125
124
  end
126
125
 
127
- unless token.value.include? '::'
128
- unless token.value =~ /^(facts|trusted)\[.+\]/
129
- unless variables_in_scope.include? token.value.gsub(/\[.+\]\Z/, '')
130
- unless token.value =~ /\A\d+\Z/
131
- notify :warning, {
132
- :message => msg,
133
- :line => token.line,
134
- :column => token.column,
135
- }
136
- end
137
- end
138
- end
139
- end
126
+ next if token.value.include?('::')
127
+ next if token.value =~ %r{^(facts|trusted)\[.+\]}
128
+ next if variables_in_scope.include?(token.value.gsub(%r{\[.+\]\Z}, ''))
129
+ next if token.value =~ %r{\A\d+\Z}
130
+
131
+ notify(
132
+ :warning,
133
+ :message => msg,
134
+ :line => token.line,
135
+ :column => token.column,
136
+ )
140
137
  end
141
138
  end
142
139
  end
@@ -7,12 +7,13 @@ PuppetLint.new_check(:slash_comments) do
7
7
  tokens.select { |token|
8
8
  token.type == :SLASH_COMMENT
9
9
  }.each do |token|
10
- notify :warning, {
10
+ notify(
11
+ :warning,
11
12
  :message => '// comment found',
12
13
  :line => token.line,
13
14
  :column => token.column,
14
15
  :token => token,
15
- }
16
+ )
16
17
  end
17
18
  end
18
19
 
@@ -7,12 +7,13 @@ PuppetLint.new_check(:star_comments) do
7
7
  tokens.select { |token|
8
8
  token.type == :MLCOMMENT
9
9
  }.each do |token|
10
- notify :warning, {
10
+ notify(
11
+ :warning,
11
12
  :message => '/* */ comment found',
12
13
  :line => token.line,
13
14
  :column => token.column,
14
15
  :token => token,
15
- }
16
+ )
16
17
  end
17
18
  end
18
19
 
@@ -26,9 +27,9 @@ PuppetLint.new_check(:star_comments) do
26
27
  index = tokens.index(problem[:token].next_token) || 1
27
28
  comment_lines.reverse.each do |line|
28
29
  indent = problem[:token].prev_token.nil? ? nil : problem[:token].prev_token.value.dup
29
- tokens.insert(index, PuppetLint::Lexer::Token.new(:COMMENT, " #{line}", 0, 0))
30
- tokens.insert(index, PuppetLint::Lexer::Token.new(:INDENT, indent, 0, 0)) if indent
31
- tokens.insert(index, PuppetLint::Lexer::Token.new(:NEWLINE, "\n", 0, 0))
30
+ add_token(index, PuppetLint::Lexer::Token.new(:COMMENT, " #{line}", 0, 0))
31
+ add_token(index, PuppetLint::Lexer::Token.new(:INDENT, indent, 0, 0)) if indent
32
+ add_token(index, PuppetLint::Lexer::Token.new(:NEWLINE, "\n", 0, 0))
32
33
  end
33
34
  end
34
35
  end
@@ -7,37 +7,38 @@ PuppetLint.new_check(:case_without_default) do
7
7
  case_indexes = []
8
8
 
9
9
  tokens.each_index do |token_idx|
10
- if tokens[token_idx].type == :CASE
11
- depth = 0
12
- tokens[(token_idx + 1)..-1].each_index do |case_token_idx|
13
- idx = case_token_idx + token_idx + 1
14
- if tokens[idx].type == :LBRACE
15
- depth += 1
16
- elsif tokens[idx].type == :RBRACE
17
- depth -= 1
18
- if depth == 0
19
- case_indexes << {:start => token_idx, :end => idx}
20
- break
21
- end
10
+ next unless tokens[token_idx].type == :CASE
11
+
12
+ depth = 0
13
+ tokens[(token_idx + 1)..-1].each_index do |case_token_idx|
14
+ idx = case_token_idx + token_idx + 1
15
+ if tokens[idx].type == :LBRACE
16
+ depth += 1
17
+ elsif tokens[idx].type == :RBRACE
18
+ depth -= 1
19
+ if depth.zero?
20
+ case_indexes << { :start => token_idx, :end => idx }
21
+ break
22
22
  end
23
23
  end
24
24
  end
25
25
  end
26
26
 
27
- case_indexes.each_with_index do |kase,kase_index|
27
+ case_indexes.each_with_index do |kase, kase_index|
28
28
  case_tokens = tokens[kase[:start]..kase[:end]]
29
29
 
30
30
  case_indexes[(kase_index + 1)..-1].each do |successor_kase|
31
31
  case_tokens -= tokens[successor_kase[:start]..successor_kase[:end]]
32
32
  end
33
33
 
34
- unless case_tokens.index { |r| r.type == :DEFAULT }
35
- notify :warning, {
36
- :message => 'case statement without a default case',
37
- :line => case_tokens.first.line,
38
- :column => case_tokens.first.column,
39
- }
40
- end
34
+ next if case_tokens.index { |r| r.type == :DEFAULT }
35
+
36
+ notify(
37
+ :warning,
38
+ :message => 'case statement without a default case',
39
+ :line => case_tokens.first.line,
40
+ :column => case_tokens.first.column,
41
+ )
41
42
  end
42
43
  end
43
44
  end
@@ -6,19 +6,16 @@ PuppetLint.new_check(:selector_inside_resource) do
6
6
  def check
7
7
  resource_indexes.each do |resource|
8
8
  resource[:tokens].each do |token|
9
- if token.type == :FARROW
10
- if token.next_code_token.type == :VARIABLE
11
- unless token.next_code_token.next_code_token.nil?
12
- if token.next_code_token.next_code_token.type == :QMARK
13
- notify :warning, {
14
- :message => 'selector inside resource block',
15
- :line => token.line,
16
- :column => token.column,
17
- }
18
- end
19
- end
20
- end
21
- end
9
+ next unless token.type == :FARROW && token.next_code_token.type == :VARIABLE
10
+ next if token.next_code_token.next_code_token.nil?
11
+ next unless token.next_code_token.next_code_token.type == :QMARK
12
+
13
+ notify(
14
+ :warning,
15
+ :message => 'selector inside resource block',
16
+ :line => token.line,
17
+ :column => token.column,
18
+ )
22
19
  end
23
20
  end
24
21
  end
@@ -9,25 +9,34 @@ PuppetLint.new_check(:documentation) do
9
9
 
10
10
  def check
11
11
  (class_indexes + defined_type_indexes).each do |item_idx|
12
- prev_token = item_idx[:tokens].first.prev_token
13
- while (!prev_token.nil?) && WHITESPACE_TOKENS.include?(prev_token.type)
14
- prev_token = prev_token.prev_token
15
- end
12
+ comment_token = find_comment_token(item_idx[:tokens].first)
16
13
 
17
- unless (!prev_token.nil?) && COMMENT_TOKENS.include?(prev_token.type)
18
- first_token = item_idx[:tokens].first
19
- if first_token.type == :CLASS
20
- type = 'class'
21
- else
22
- type = 'defined type'
23
- end
14
+ next unless comment_token.nil?
24
15
 
25
- notify :warning, {
26
- :message => "#{type} not documented",
27
- :line => first_token.line,
28
- :column => first_token.column,
29
- }
30
- end
16
+ first_token = item_idx[:tokens].first
17
+ type = if first_token.type == :CLASS
18
+ 'class'
19
+ else
20
+ 'defined type'
21
+ end
22
+
23
+ notify(
24
+ :warning,
25
+ :message => "#{type} not documented",
26
+ :line => first_token.line,
27
+ :column => first_token.column,
28
+ )
29
+ end
30
+ end
31
+
32
+ def find_comment_token(start_token)
33
+ prev_token = start_token.prev_token
34
+ while !prev_token.nil? && WHITESPACE_TOKENS.include?(prev_token.type)
35
+ prev_token = prev_token.prev_token
31
36
  end
37
+
38
+ return if prev_token.nil?
39
+
40
+ prev_token if COMMENT_TOKENS.include?(prev_token.type)
32
41
  end
33
42
  end