puppet-lint 3.0.1 → 4.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (68) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +28 -6
  3. data/lib/puppet-lint/bin.rb +9 -8
  4. data/lib/puppet-lint/checkplugin.rb +4 -8
  5. data/lib/puppet-lint/checks.rb +8 -10
  6. data/lib/puppet-lint/configuration.rb +2 -1
  7. data/lib/puppet-lint/data.rb +48 -39
  8. data/lib/puppet-lint/lexer/string_slurper.rb +2 -3
  9. data/lib/puppet-lint/lexer/token.rb +6 -5
  10. data/lib/puppet-lint/lexer.rb +35 -38
  11. data/lib/puppet-lint/monkeypatches.rb +4 -4
  12. data/lib/puppet-lint/optparser.rb +5 -1
  13. data/lib/puppet-lint/plugins/check_classes/arrow_on_right_operand_line.rb +1 -0
  14. data/lib/puppet-lint/plugins/check_classes/autoloader_layout.rb +2 -4
  15. data/lib/puppet-lint/plugins/check_classes/class_inherits_from_params_class.rb +2 -2
  16. data/lib/puppet-lint/plugins/check_classes/code_on_top_scope.rb +1 -1
  17. data/lib/puppet-lint/plugins/check_classes/nested_classes_or_defines.rb +5 -5
  18. data/lib/puppet-lint/plugins/check_classes/parameter_order.rb +8 -9
  19. data/lib/puppet-lint/plugins/check_classes/variable_scope.rb +32 -34
  20. data/lib/puppet-lint/plugins/check_conditionals/case_without_default.rb +2 -2
  21. data/lib/puppet-lint/plugins/check_documentation/documentation.rb +7 -6
  22. data/lib/puppet-lint/plugins/check_nodes/unquoted_node_name.rb +1 -1
  23. data/lib/puppet-lint/plugins/check_resources/ensure_first_param.rb +3 -5
  24. data/lib/puppet-lint/plugins/check_resources/ensure_not_symlink_target.rb +2 -2
  25. data/lib/puppet-lint/plugins/check_resources/file_mode.rb +6 -6
  26. data/lib/puppet-lint/plugins/check_resources/unquoted_file_mode.rb +4 -4
  27. data/lib/puppet-lint/plugins/check_strings/double_quoted_strings.rb +4 -4
  28. data/lib/puppet-lint/plugins/check_strings/only_variable_string.rb +4 -5
  29. data/lib/puppet-lint/plugins/check_strings/quoted_booleans.rb +4 -4
  30. data/lib/puppet-lint/plugins/check_strings/single_quote_string_with_variables.rb +2 -2
  31. data/lib/puppet-lint/plugins/check_strings/variables_not_enclosed.rb +8 -7
  32. data/lib/puppet-lint/plugins/check_variables/variable_contains_dash.rb +3 -3
  33. data/lib/puppet-lint/plugins/check_variables/variable_is_lowercase.rb +2 -2
  34. data/lib/puppet-lint/plugins/check_whitespace/140chars.rb +1 -0
  35. data/lib/puppet-lint/plugins/check_whitespace/80chars.rb +2 -1
  36. data/lib/puppet-lint/plugins/check_whitespace/arrow_alignment.rb +9 -9
  37. data/lib/puppet-lint/plugins/check_whitespace/hard_tabs.rb +2 -2
  38. data/lib/puppet-lint/plugins/check_whitespace/line_length.rb +6 -6
  39. data/lib/puppet-lint/plugins/check_whitespace/trailing_whitespace.rb +1 -1
  40. data/lib/puppet-lint/plugins/legacy_facts/legacy_facts.rb +196 -0
  41. data/lib/puppet-lint/plugins/top_scope_facts/top_scope_facts.rb +39 -0
  42. data/lib/puppet-lint/plugins.rb +3 -4
  43. data/lib/puppet-lint/report/codeclimate.rb +49 -0
  44. data/lib/puppet-lint/report/github.rb +1 -0
  45. data/lib/puppet-lint/tasks/puppet-lint.rb +12 -24
  46. data/lib/puppet-lint/tasks/release_test.rb +4 -4
  47. data/lib/puppet-lint/version.rb +1 -1
  48. data/lib/puppet-lint.rb +16 -10
  49. data/rubocop_baseline.yml +83 -0
  50. data/spec/fixtures/test/reports/code_climate.json +38 -0
  51. data/spec/spec_helper.rb +3 -2
  52. data/spec/spec_helper_acceptance_local.rb +1 -1
  53. data/spec/unit/puppet-lint/bin_spec.rb +38 -4
  54. data/spec/unit/puppet-lint/configuration_spec.rb +23 -13
  55. data/spec/unit/puppet-lint/data_spec.rb +36 -0
  56. data/spec/unit/puppet-lint/lexer/string_slurper_spec.rb +3 -5
  57. data/spec/unit/puppet-lint/lexer_spec.rb +10 -11
  58. data/spec/unit/puppet-lint/plugins/check_classes/parameter_order_spec.rb +2 -2
  59. data/spec/unit/puppet-lint/plugins/check_conditionals/case_without_default_spec.rb +5 -5
  60. data/spec/unit/puppet-lint/plugins/check_strings/double_quoted_strings_spec.rb +1 -1
  61. data/spec/unit/puppet-lint/plugins/check_strings/only_variable_string_spec.rb +1 -1
  62. data/spec/unit/puppet-lint/plugins/check_whitespace/140chars_spec.rb +0 -2
  63. data/spec/unit/puppet-lint/plugins/check_whitespace/80chars_spec.rb +1 -3
  64. data/spec/unit/puppet-lint/plugins/check_whitespace/trailing_whitespace_spec.rb +12 -0
  65. data/spec/unit/puppet-lint/plugins/legacy_facts/legacy_facts_spec.rb +463 -0
  66. data/spec/unit/puppet-lint/plugins/top_scope_facts/top_scope_facts_spec.rb +195 -0
  67. metadata +10 -4
  68. data/.rubocop.yml +0 -522
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 780fb18c627fc4498cfbd056762846a70b2240619c52a23121d522b56aaec062
4
- data.tar.gz: 59068f03812ef0d9b622fa6b9440567ba4e12f33a5349c1ddc9c642ac7dd51a5
3
+ metadata.gz: a7cd6dad7a05e7eefb19f4c9efedc5815b1f83376a77def6fd54b321945c520c
4
+ data.tar.gz: d82288ffc965a3f001269abdb42efe6bb71041575b1106e3331b4a70f2a0fe84
5
5
  SHA512:
6
- metadata.gz: 32fb18937f47636f80535bcc8db5884aa63a6af9a86f148ee25a37b65890d13f275094ab2a81012a5ef7385d696195c59632d234eca805c94a2bc2d3b4d77905
7
- data.tar.gz: 124a921b4ad50b3f923f7180d330a89f313f70c5b77d1dcf8060611a124171e1bf3ef06f8b3d4b27421cad4157c69699c12bc8acc8dd63461a61fb1aecacc14c
6
+ metadata.gz: b1571f76174d7afaca3da45f692b681aedb4e99a52563c3f3a0171d6db9bbddb9c409f5f21223fbfe249b7254f2d41edb01331b9c154afafb35572f3fdff7e7c
7
+ data.tar.gz: e594e8917a7ce55bab177449d1a6db41454dbbaacb37eb4a4f1b0ec9a8cf4e82f5ee023d112ca629d83bceceaba413d281d242f45388207a4c707e7380afc3ab
data/README.md CHANGED
@@ -1,15 +1,13 @@
1
1
  # Puppet Lint
2
2
 
3
- [![Build
4
- Status](https://secure.travis-ci.org/rodjek/puppet-lint.png)](http://travis-ci.org/rodjek/puppet-lint)
5
- [![Inline docs](http://inch-ci.org/github/rodjek/puppet-lint.png?branch=master)](http://inch-ci.org/github/rodjek/puppet-lint)
6
-
7
3
  Puppet Lint tests Puppet code against the recommended [Puppet language style
8
4
  guide](http://puppet.com/docs/puppet/latest/style_guide.html). Puppet Lint validates only code style; it does not validate syntax. To test syntax, use Puppet's `puppet parser validate` command.
9
5
 
10
6
  ## Compatibility warning
11
7
 
12
- Puppet Lint version 2 is the last planned version with support for Puppet 3 and Ruby 1.8.7. The next major version of Puppet Lint will drop support for these versions.
8
+ Version 3.0.0 and above will no longer support Puppet 6 environments.
9
+
10
+ In cases where Puppet Lint is required in an environment with Puppet 6, we recommend pinning to version 2.5.2.
13
11
 
14
12
  ## Installation
15
13
 
@@ -213,6 +211,30 @@ There is a GitHub Actions action available to get linter feedback in workflows:
213
211
 
214
212
  * [puppet-lint-action](https://github.com/marketplace/actions/puppet-lint-action)
215
213
 
214
+ ## Integration with GitLab Code Quality
215
+
216
+ [GitLab](https://gitlab.com/) users can use the `--codeclimate-report-file` configuration option to generate a report for use with the
217
+ [Code Quality](https://docs.gitlab.com/ee/ci/testing/code_quality.html) feature.
218
+
219
+ The easiest way to set this option, (and without having to modify rake tasks), is with the `CODECLIMATE_REPORT_FILE` environment variable.
220
+
221
+ For example, the following GitLab job sets the environment variable and
222
+ [archives the report](https://docs.gitlab.com/ee/ci/yaml/artifacts_reports.html#artifactsreportscodequality) produced.
223
+ ```yaml
224
+ validate lint check rubocop-Ruby 2.7.2-Puppet ~> 7:
225
+ stage: syntax
226
+ image: ruby:2.7.2
227
+ script:
228
+ - bundle exec rake validate lint check rubocop
229
+ variables:
230
+ PUPPET_GEM_VERSION: '~> 7'
231
+ CODECLIMATE_REPORT_FILE: 'gl-code-quality-report.json'
232
+ artifacts:
233
+ reports:
234
+ codequality: gl-code-quality-report.json
235
+ expire_in: 1 week
236
+ ```
237
+
216
238
  ## Options
217
239
 
218
240
  See `puppet-lint --help` for a full list of command line options and checks.
@@ -268,7 +290,7 @@ For a complete list of checks, and how to resolve errors on each check, see the
268
290
  ## Reporting bugs or incorrect results
269
291
 
270
292
  If you find a bug in Puppet Lint or its results, please create an issue in the
271
- [repo issues tracker](https://github.com/rodjek/puppet-lint/issues/). Bonus
293
+ [repo issues tracker](https://github.com/puppetlabs/puppet-lint/issues/). Bonus
272
294
  points will be awarded if you also include a patch that fixes the issue.
273
295
 
274
296
  ## Thank you
@@ -1,6 +1,7 @@
1
1
  require 'pathname'
2
2
  require 'uri'
3
3
  require 'puppet-lint/optparser'
4
+ require 'puppet-lint/report/codeclimate'
4
5
 
5
6
  # Internal: The logic of the puppet-lint bin script, contained in a class for
6
7
  # ease of testing.
@@ -48,7 +49,7 @@ class PuppetLint::Bin
48
49
 
49
50
  begin
50
51
  path = @args[0]
51
- full_path = File.expand_path(path, ENV['PWD'])
52
+ full_path = File.expand_path(path, ENV.fetch('PWD', nil))
52
53
  full_base_path = if File.directory?(full_path)
53
54
  full_path
54
55
  else
@@ -78,19 +79,17 @@ class PuppetLint::Bin
78
79
 
79
80
  path.each do |f|
80
81
  next if ignore_paths.any? { |p| File.fnmatch(p, f) }
82
+
81
83
  l = PuppetLint.new
82
84
  l.file = f
83
85
  l.run
84
86
  all_problems << l.print_problems
85
87
 
86
- if l.errors? || (l.warnings? && PuppetLint.configuration.fail_on_warnings)
87
- return_val = 1
88
- end
88
+ return_val = 1 if l.errors? || (l.warnings? && PuppetLint.configuration.fail_on_warnings)
89
89
 
90
90
  next unless PuppetLint.configuration.fix && l.problems.none? { |r| r[:check] == :syntax }
91
- File.open(f, 'wb') do |fd|
92
- fd.write(l.manifest)
93
- end
91
+
92
+ File.binwrite(f, l.manifest)
94
93
  end
95
94
 
96
95
  if PuppetLint.configuration.sarif
@@ -104,6 +103,8 @@ class PuppetLint::Bin
104
103
  puts JSON.pretty_generate(all_problems)
105
104
  end
106
105
 
106
+ PuppetLint::Report::CodeClimateReporter.write_report_file(all_problems, PuppetLint.configuration.codeclimate_report_file) if PuppetLint.configuration.codeclimate_report_file
107
+
107
108
  return_val
108
109
  rescue PuppetLint::NoCodeError
109
110
  puts 'puppet-lint: no file specified or specified file does not exist'
@@ -143,7 +144,7 @@ class PuppetLint::Bin
143
144
  'ruleIndex' => rule_index,
144
145
  'message' => { 'text' => message[:message] },
145
146
  'locations' => [{ 'physicalLocation' => { 'artifactLocation' => { 'uri' => relative_path, 'uriBaseId' => 'ROOTPATH' },
146
- 'region' => { 'startLine' => message[:line], 'startColumn' => message[:column] } } }],
147
+ 'region' => { 'startLine' => message[:line], 'startColumn' => message[:column] } } }]
147
148
  }
148
149
  results << result
149
150
  end
@@ -179,10 +179,10 @@ class PuppetLint::CheckPlugin
179
179
  # Returns a Hash of default problem information.
180
180
  def default_info
181
181
  @default_info ||= {
182
- check: self.class.const_get('NAME'),
182
+ check: self.class.const_get(:NAME),
183
183
  fullpath: fullpath,
184
184
  path: path,
185
- filename: filename,
185
+ filename: filename
186
186
  }
187
187
  end
188
188
 
@@ -202,14 +202,10 @@ class PuppetLint::CheckPlugin
202
202
  problem[:kind] = kind
203
203
  problem.merge!(default_info) { |_key, v1, _v2| v1 }
204
204
 
205
- unless [:warning, :error, :fixed].include?(kind)
206
- raise ArgumentError, 'unknown value passed for kind'
207
- end
205
+ raise ArgumentError, 'unknown value passed for kind' unless [:warning, :error, :fixed].include?(kind)
208
206
 
209
207
  [:message, :line, :column, :check].each do |attr|
210
- unless problem.key?(attr)
211
- raise ArgumentError, "problem hash must contain #{attr.inspect}"
212
- end
208
+ raise ArgumentError, "problem hash must contain #{attr.inspect}" unless problem.key?(attr)
213
209
  end
214
210
 
215
211
  @problems << problem
@@ -39,7 +39,7 @@ class PuppetLint::Checks
39
39
  column: e.column,
40
40
  fullpath: PuppetLint::Data.fullpath,
41
41
  path: PuppetLint::Data.path,
42
- filename: PuppetLint::Data.filename,
42
+ filename: PuppetLint::Data.filename
43
43
  }
44
44
  PuppetLint::Data.tokens = []
45
45
  end
@@ -76,18 +76,18 @@ class PuppetLint::Checks
76
76
  kind: :error,
77
77
  check: :syntax,
78
78
  message: 'Syntax error',
79
- fullpath: File.expand_path(fileinfo, ENV['PWD']),
79
+ fullpath: File.expand_path(fileinfo, ENV.fetch('PWD', nil)),
80
80
  filename: File.basename(fileinfo),
81
81
  path: fileinfo,
82
82
  line: e.token.line,
83
- column: e.token.column,
83
+ column: e.token.column
84
84
  }
85
85
 
86
86
  @problems
87
- rescue => e
87
+ rescue StandardError => e
88
88
  $stdout.puts <<-END.gsub(%r{^ {6}}, '')
89
89
  Whoops! It looks like puppet-lint has encountered an error that it doesn't
90
- know how to handle. Please open an issue at https://github.com/rodjek/puppet-lint
90
+ know how to handle. Please open an issue at https://github.com/puppetlabs/puppet-lint
91
91
  and paste the following output into the issue description.
92
92
  ---
93
93
  puppet-lint version: #{PuppetLint::VERSION}
@@ -120,10 +120,8 @@ class PuppetLint::Checks
120
120
  #
121
121
  # Returns an Array of String check names.
122
122
  def enabled_checks
123
- @enabled_checks ||= begin
124
- PuppetLint.configuration.checks.select do |check|
125
- PuppetLint.configuration.send("#{check}_enabled?")
126
- end
123
+ @enabled_checks ||= PuppetLint.configuration.checks.select do |check|
124
+ PuppetLint.configuration.send("#{check}_enabled?")
127
125
  end
128
126
  end
129
127
 
@@ -131,6 +129,6 @@ class PuppetLint::Checks
131
129
  #
132
130
  # Returns the manifest as a String.
133
131
  def manifest
134
- PuppetLint::Data.tokens.map(&:to_manifest).join('')
132
+ PuppetLint::Data.tokens.map(&:to_manifest).join
135
133
  end
136
134
  end
@@ -18,7 +18,7 @@ class PuppetLint::Configuration
18
18
  #
19
19
  # Returns true if the check is enabled, otherwise return false.
20
20
  define_method("#{check}_enabled?") do
21
- settings["#{check}_disabled"] == true ? false : true
21
+ settings["#{check}_disabled"] != true
22
22
  end
23
23
 
24
24
  # Public: Disable the named check.
@@ -153,5 +153,6 @@ class PuppetLint::Configuration
153
153
  self.show_ignored = false
154
154
  self.ignore_paths = ['vendor/**/*.pp']
155
155
  self.github_actions = ENV.key?('GITHUB_ACTION')
156
+ self.codeclimate_report_file = ENV.fetch('CODECLIMATE_REPORT_FILE', nil)
156
157
  end
157
158
  end
@@ -72,7 +72,7 @@ class PuppetLint::Data
72
72
 
73
73
  unless formatting_tokens.include?(token.type)
74
74
  current_token.next_token.prev_code_token = token unless current_token.next_token.nil?
75
- next_nf_idx = tokens[index..-1].index { |r| !formatting_tokens.include?(r.type) }
75
+ next_nf_idx = tokens[index..].index { |r| !formatting_tokens.include?(r.type) }
76
76
  unless next_nf_idx.nil?
77
77
  next_nf_token = tokens[index + next_nf_idx]
78
78
  token.next_code_token = next_nf_token
@@ -92,9 +92,7 @@ class PuppetLint::Data
92
92
  end
93
93
 
94
94
  current_token.next_token = token
95
- unless formatting_tokens.include?(token.type)
96
- current_token.next_code_token = token
97
- end
95
+ current_token.next_code_token = token unless formatting_tokens.include?(token.type)
98
96
 
99
97
  tokens.insert(index, token)
100
98
  end
@@ -123,7 +121,7 @@ class PuppetLint::Data
123
121
  @fullpath = nil
124
122
  @filename = nil
125
123
  else
126
- @fullpath = File.expand_path(val, ENV['PWD'])
124
+ @fullpath = File.expand_path(val, ENV.fetch('PWD', nil))
127
125
  @filename = File.basename(val)
128
126
  end
129
127
  end
@@ -155,6 +153,18 @@ class PuppetLint::Data
155
153
  end
156
154
  end
157
155
 
156
+ # Internal: Determine if the given token contains a CLASSREF in
157
+ # the token chain..
158
+ #
159
+ # Returns a Boolean.
160
+ def classref?(token)
161
+ current_token = token
162
+ while (current_token = current_token.prev_code_token)
163
+ return true if current_token.type == :CLASSREF
164
+ return false if current_token.type == :NAME
165
+ end
166
+ end
167
+
158
168
  # Internal: Calculate the positions of all resource declarations within the
159
169
  # tokenised manifest. These positions only point to the content of the
160
170
  # resource declarations, they do not include resource types or titles.
@@ -170,13 +180,16 @@ class PuppetLint::Data
170
180
  result = []
171
181
  tokens.select { |t| t.type == :COLON }.each do |colon_token|
172
182
  next unless colon_token.next_code_token && colon_token.next_code_token.type != :LBRACE
183
+ next if classref?(colon_token)
173
184
 
174
- rel_start_idx = tokens[marker..-1].index(colon_token)
185
+ rel_start_idx = tokens[marker..].index(colon_token)
175
186
  break if rel_start_idx.nil?
187
+
176
188
  start_idx = rel_start_idx + marker
177
189
  end_token = colon_token.next_token_of([:SEMIC, :RBRACE])
178
- rel_end_idx = tokens[start_idx..-1].index(end_token)
190
+ rel_end_idx = tokens[start_idx..].index(end_token)
179
191
  raise PuppetLint::SyntaxError, colon_token if rel_end_idx.nil?
192
+
180
193
  marker = rel_end_idx + start_idx
181
194
 
182
195
  result << {
@@ -184,7 +197,7 @@ class PuppetLint::Data
184
197
  end: marker,
185
198
  tokens: tokens[start_idx..marker],
186
199
  type: find_resource_type_token(start_idx),
187
- param_tokens: find_resource_param_tokens(tokens[start_idx..marker]),
200
+ param_tokens: find_resource_param_tokens(tokens[start_idx..marker])
188
201
  }
189
202
  end
190
203
  result
@@ -224,9 +237,7 @@ class PuppetLint::Data
224
237
 
225
238
  break unless resource_tokens.include?(iter_token)
226
239
 
227
- if iter_token && iter_token.next_code_token.type == :FARROW
228
- param_tokens << iter_token
229
- end
240
+ param_tokens << iter_token if iter_token && iter_token.next_code_token.type == :FARROW
230
241
  end
231
242
 
232
243
  param_tokens
@@ -293,7 +304,7 @@ class PuppetLint::Data
293
304
  paren_depth = 0
294
305
  in_params = false
295
306
  inherited_class = nil
296
- tokens[i + 1..-1].each_with_index do |definition_token, j|
307
+ tokens[i + 1..].each_with_index do |definition_token, j|
297
308
  case definition_token.type
298
309
  when :INHERITS
299
310
  inherited_class = definition_token.next_code_token
@@ -307,19 +318,17 @@ class PuppetLint::Data
307
318
  brace_depth += 1
308
319
  when :RBRACE
309
320
  brace_depth -= 1
310
- if brace_depth.zero? && !in_params
311
- if token.next_code_token.type != :LBRACE
312
- result << {
313
- start: i,
314
- end: i + j + 1,
315
- tokens: tokens[i..(i + j + 1)],
316
- param_tokens: param_tokens(tokens[i..(i + j + 1)]),
317
- type: type,
318
- name_token: token.next_code_token,
319
- inherited_token: inherited_class,
320
- }
321
- break
322
- end
321
+ if brace_depth.zero? && !in_params && (token.next_code_token.type != :LBRACE)
322
+ result << {
323
+ start: i,
324
+ end: i + j + 1,
325
+ tokens: tokens[i..(i + j + 1)],
326
+ param_tokens: param_tokens(tokens[i..(i + j + 1)]),
327
+ type: type,
328
+ name_token: token.next_code_token,
329
+ inherited_token: inherited_class
330
+ }
331
+ break
323
332
  end
324
333
  end
325
334
  end
@@ -354,7 +363,7 @@ class PuppetLint::Data
354
363
  level = 0
355
364
  real_idx = 0
356
365
  in_paren = false
357
- tokens[token_idx + 1..-1].each_with_index do |cur_token, cur_token_idx|
366
+ tokens[token_idx + 1..].each_with_index do |cur_token, cur_token_idx|
358
367
  break if level.zero? && in_paren
359
368
  break if level.zero? && cur_token.type == :NEWLINE
360
369
 
@@ -369,7 +378,7 @@ class PuppetLint::Data
369
378
  functions << {
370
379
  start: token_idx,
371
380
  end: real_idx,
372
- tokens: tokens[token_idx..real_idx],
381
+ tokens: tokens[token_idx..real_idx]
373
382
  }
374
383
  end
375
384
  functions
@@ -393,7 +402,7 @@ class PuppetLint::Data
393
402
  next unless token.type == :LBRACK
394
403
 
395
404
  real_idx = 0
396
- tokens[token_idx + 1..-1].each_with_index do |cur_token, cur_token_idx|
405
+ tokens[token_idx + 1..].each_with_index do |cur_token, cur_token_idx|
397
406
  real_idx = token_idx + 1 + cur_token_idx
398
407
  break if cur_token.type == :RBRACK
399
408
  end
@@ -405,7 +414,7 @@ class PuppetLint::Data
405
414
  arrays << {
406
415
  start: token_idx,
407
416
  end: real_idx,
408
- tokens: tokens[token_idx..real_idx],
417
+ tokens: tokens[token_idx..real_idx]
409
418
  }
410
419
  end
411
420
  arrays
@@ -432,18 +441,18 @@ class PuppetLint::Data
432
441
 
433
442
  level = 0
434
443
  real_idx = 0
435
- tokens[token_idx + 1..-1].each_with_index do |cur_token, cur_token_idx|
444
+ tokens[token_idx + 1..].each_with_index do |cur_token, cur_token_idx|
436
445
  real_idx = token_idx + 1 + cur_token_idx
437
446
 
438
447
  level += 1 if cur_token.type == :LBRACE
439
448
  level -= 1 if cur_token.type == :RBRACE
440
- break if level < 0
449
+ break if level.negative?
441
450
  end
442
451
 
443
452
  hashes << {
444
453
  start: token_idx,
445
454
  end: real_idx,
446
- tokens: tokens[token_idx..real_idx],
455
+ tokens: tokens[token_idx..real_idx]
447
456
  }
448
457
  end
449
458
  hashes
@@ -469,7 +478,7 @@ class PuppetLint::Data
469
478
 
470
479
  real_idx = 0
471
480
 
472
- tokens[token_idx + 1..-1].each_with_index do |cur_token, cur_token_idx|
481
+ tokens[token_idx + 1..].each_with_index do |cur_token, cur_token_idx|
473
482
  real_idx = token_idx + 1 + cur_token_idx
474
483
  break if cur_token.type == :RBRACE
475
484
  end
@@ -477,7 +486,7 @@ class PuppetLint::Data
477
486
  defaults << {
478
487
  start: token_idx,
479
488
  end: real_idx,
480
- tokens: tokens[token_idx..real_idx],
489
+ tokens: tokens[token_idx..real_idx]
481
490
  }
482
491
  end
483
492
  defaults
@@ -551,7 +560,7 @@ class PuppetLint::Data
551
560
  comment_token_types.include?(token.type)
552
561
  end
553
562
  control_comment_tokens = comment_tokens.select do |token|
554
- token.value.strip =~ %r{\Alint\:(ignore\:[\w\d]+|endignore)}
563
+ token.value.strip =~ %r{\Alint:(ignore:[\w\d]+|endignore)}
555
564
  end
556
565
 
557
566
  stack = []
@@ -561,12 +570,12 @@ class PuppetLint::Data
561
570
 
562
571
  comment_words = token.value.strip.split(%r{\s+})
563
572
  comment_words.each_with_index do |word, i|
564
- if %r{\Alint\:(ignore|endignore)}.match?(word)
573
+ if %r{\Alint:(ignore|endignore)}.match?(word)
565
574
  comment_data << word
566
575
  else
567
576
  # Once we reach the first non-controlcomment word, assume the rest
568
577
  # of the words are the reason.
569
- reason = comment_words[i..-1]
578
+ reason = comment_words[i..]
570
579
  break
571
580
  end
572
581
  end
@@ -591,7 +600,7 @@ class PuppetLint::Data
591
600
  if top_override.nil?
592
601
  # TODO: refactor to provide a way to expose problems from
593
602
  # PuppetLint::Data via the normal problem reporting mechanism.
594
- $stderr.puts "WARNING: lint:endignore comment with no opening lint:ignore:<check> comment found on line #{token.line}"
603
+ warn "WARNING: lint:endignore comment with no opening lint:ignore:<check> comment found on line #{token.line}"
595
604
  else
596
605
  top_override.each do |start|
597
606
  next if start.nil?
@@ -607,7 +616,7 @@ class PuppetLint::Data
607
616
  end
608
617
 
609
618
  stack.each do |control|
610
- $stderr.puts "WARNING: lint:ignore:#{control[0][2]} comment on line #{control[0][0]} with no closing lint:endignore comment"
619
+ warn "WARNING: lint:ignore:#{control[0][2]} comment on line #{control[0][0]} with no closing lint:endignore comment"
611
620
  end
612
621
  end
613
622
  end
@@ -1,11 +1,10 @@
1
1
  require 'strscan'
2
2
 
3
+ # rubocop:disable Style/ClassAndModuleChildren
3
4
  class PuppetLint::Lexer
4
5
  # Internal: A class for slurping strings from a Puppet manifest.
5
6
  class StringSlurper
6
- attr_accessor :scanner
7
- attr_accessor :results
8
- attr_accessor :interp_stack
7
+ attr_accessor :scanner, :results, :interp_stack
9
8
 
10
9
  START_INTERP_PATTERN = %r{\$\{}.freeze
11
10
  END_INTERP_PATTERN = %r{\}}.freeze
@@ -1,3 +1,4 @@
1
+ # rubocop:disable Style/ClassAndModuleChildren
1
2
  class PuppetLint::Lexer
2
3
  # Public: Stores a fragment of the manifest and the information about its
3
4
  # location in the manifest.
@@ -175,12 +176,10 @@ class PuppetLint::Lexer
175
176
 
176
177
  token_iter = send("#{direction}_token".to_sym)
177
178
  until token_iter.nil?
178
- if to_find.include?(token_iter.type)
179
- return token_iter if opts[:value].nil? || token_iter.value == opts[:value]
180
- end
179
+ return token_iter if to_find.include?(token_iter.type) && (opts[:value].nil? || token_iter.value == opts[:value])
181
180
 
182
- opening_token = direction == :next ? 'L' : 'R'
183
- closing_token = direction == :next ? 'R' : 'L'
181
+ opening_token = (direction == :next) ? 'L' : 'R'
182
+ closing_token = (direction == :next) ? 'R' : 'L'
184
183
 
185
184
  if opts[:skip_blocks]
186
185
  case token_iter.type
@@ -194,6 +193,7 @@ class PuppetLint::Lexer
194
193
  end
195
194
 
196
195
  return nil if token_iter.nil?
196
+
197
197
  token_iter = token_iter.send("#{direction}_token".to_sym)
198
198
  end
199
199
  nil
@@ -202,6 +202,7 @@ class PuppetLint::Lexer
202
202
  def interpolated_variable?
203
203
  return false if type == :TYPE && value != 'type'
204
204
  return true if type == :NAME
205
+
205
206
  PuppetLint::Lexer::KEYWORDS.include?(type.to_s.downcase)
206
207
  end
207
208
  end