puppet-lint 2.4.0 → 2.5.2

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 (34) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +15 -1014
  3. data/HISTORY.md +1130 -0
  4. data/lib/puppet-lint/data.rb +9 -9
  5. data/lib/puppet-lint/lexer/string_slurper.rb +21 -5
  6. data/lib/puppet-lint/lexer/token.rb +6 -0
  7. data/lib/puppet-lint/lexer.rb +16 -5
  8. data/lib/puppet-lint/plugins/check_classes/parameter_order.rb +12 -1
  9. data/lib/puppet-lint/plugins/check_documentation/documentation.rb +4 -0
  10. data/lib/puppet-lint/plugins/check_resources/ensure_first_param.rb +1 -1
  11. data/lib/puppet-lint/plugins/check_strings/double_quoted_strings.rb +1 -1
  12. data/lib/puppet-lint/tasks/puppet-lint.rb +14 -0
  13. data/lib/puppet-lint/tasks/release_test.rb +3 -1
  14. data/lib/puppet-lint/version.rb +1 -1
  15. data/lib/puppet-lint.rb +1 -1
  16. data/spec/puppet-lint/bin_spec.rb +8 -8
  17. data/spec/puppet-lint/lexer/string_slurper_spec.rb +68 -2
  18. data/spec/puppet-lint/lexer_spec.rb +56 -0
  19. data/spec/puppet-lint/plugins/check_classes/parameter_order_spec.rb +18 -0
  20. data/spec/puppet-lint/plugins/check_classes/variable_scope_spec.rb +14 -0
  21. data/spec/puppet-lint/plugins/check_documentation/documentation_spec.rb +18 -0
  22. data/spec/puppet-lint/plugins/check_strings/double_quoted_strings_spec.rb +6 -5
  23. data/spec/puppet-lint/plugins/check_variables/variable_is_lowercase_spec.rb +28 -0
  24. data/spec/spec_helper.rb +7 -5
  25. metadata +16 -18
  26. data/.gitignore +0 -12
  27. data/.rspec +0 -2
  28. data/.rubocop.yml +0 -74
  29. data/.rubocop_todo.yml +0 -89
  30. data/.travis.yml +0 -26
  31. data/Gemfile +0 -40
  32. data/Rakefile +0 -42
  33. data/appveyor.yml +0 -35
  34. data/puppet-lint.gemspec +0 -19
@@ -253,6 +253,47 @@ describe PuppetLint::Lexer do # rubocop:disable Metrics/BlockLength
253
253
  end
254
254
  end
255
255
 
256
+ context 'treats a variable named the same as the keyword as a variable' do
257
+ PuppetLint::Lexer::KEYWORDS.keys.each do |keyword|
258
+ context "for '#{keyword}'" do
259
+ let(:segments) do
260
+ [
261
+ [:STRING, ''],
262
+ [:INTERP, keyword],
263
+ [:STRING, ''],
264
+ ]
265
+ end
266
+
267
+ it 'creates a tokenised string' do
268
+ expect(tokens).to have(3).tokens
269
+
270
+ expect(tokens[0]).to have_attributes(
271
+ :type => :DQPRE,
272
+ :value => '',
273
+ :line => 1,
274
+ :column => 1
275
+ )
276
+ expect(tokens[1]).to have_attributes(
277
+ :type => :VARIABLE,
278
+ :value => keyword,
279
+ :line => 1,
280
+ :column => 4
281
+ )
282
+ expect(tokens[2]).to have_attributes(
283
+ :type => :DQPOST,
284
+ :value => '',
285
+ :line => 1,
286
+ :column => keyword.size + 4
287
+ )
288
+ end
289
+
290
+ it 'can render the result back into a manifest' do
291
+ expect(manifest).to eq("\"${#{keyword}}\"")
292
+ end
293
+ end
294
+ end
295
+ end
296
+
256
297
  context 'an interpolated variable with an unnecessary $' do
257
298
  let(:segments) do
258
299
  [
@@ -1590,6 +1631,21 @@ END
1590
1631
  expect(tokens[6].type).to eq(:HEREDOC)
1591
1632
  expect(tokens[6].value).to eq(" foo\n ")
1592
1633
  end
1634
+
1635
+ it 'should handle a heredoc with no indentation' do
1636
+ manifest = <<-END.gsub(%r{^ {6}}, '')
1637
+ $str = @(EOT)
1638
+ something
1639
+ EOT
1640
+ END
1641
+ tokens = @lexer.tokenise(manifest)
1642
+
1643
+ expect(tokens.length).to eq(8)
1644
+ expect(tokens[4].type).to eq(:HEREDOC_OPEN)
1645
+ expect(tokens[4].value).to eq('EOT')
1646
+ expect(tokens[6].type).to eq(:HEREDOC)
1647
+ expect(tokens[6].value).to eq('something')
1648
+ end
1593
1649
  end
1594
1650
 
1595
1651
  context ':HEREDOC with interpolation' do
@@ -147,5 +147,23 @@ describe 'parameter_order' do
147
147
 
148
148
  it { expect(problems).to have(0).problems }
149
149
  end
150
+
151
+ context "#{type} parameter with array operation" do
152
+ let(:code) do
153
+ <<-END
154
+ #{type} ntp (
155
+ # XXX: remove self from list
156
+ Array[String] $ntp_servers = [
157
+ 'foo',
158
+ 'bar',
159
+ 'baz',
160
+ ] - $::fqdn,
161
+ Array[String] $pools = [],
162
+ ) { }
163
+ END
164
+ end
165
+
166
+ it { expect(problems).to have(0).problems }
167
+ end
150
168
  end
151
169
  end
@@ -316,4 +316,18 @@ describe 'variable_scope' do
316
316
  expect(problems).to contain_warning(msg).on_line(2).in_column(14)
317
317
  end
318
318
  end
319
+
320
+ context 'assigning regex with multiple alternations to variable' do
321
+ let(:code) do
322
+ <<-END
323
+ class gh::issue859 {
324
+ $regex = /5|6|7/
325
+ }
326
+ END
327
+ end
328
+
329
+ it 'should not detect any problems' do
330
+ expect(problems).to have(0).problems
331
+ end
332
+ end
319
333
  end
@@ -29,6 +29,24 @@ describe 'documentation' do
29
29
  end
30
30
  end
31
31
 
32
+ describe 'incorrectly documented class' do
33
+ let(:code) do
34
+ <<-END
35
+ # foo
36
+
37
+ class test {}
38
+ END
39
+ end
40
+
41
+ it 'should only detect a single problem' do
42
+ expect(problems).to have(1).problem
43
+ end
44
+
45
+ it 'should create a warning' do
46
+ expect(problems).to contain_warning(class_msg).on_line(3).in_column(9)
47
+ end
48
+ end
49
+
32
50
  describe 'undocumented defined type' do
33
51
  let(:code) { 'define test {}' }
34
52
 
@@ -93,16 +93,17 @@ describe 'double_quoted_strings' do
93
93
  end
94
94
  end
95
95
 
96
- context 'double quoted stings containing supported escape patterns' do
96
+ context 'double quoted strings containing supported escape patterns' do
97
97
  let(:code) do
98
98
  <<-END
99
- $string1 = "this string contins \n newline"
100
- $string2 = "this string contains \ttab"
99
+ $string1 = "this string contains \n newline"
100
+ $string2 = "this string contains \t tab"
101
101
  $string3 = "this string contains \${escaped} var"
102
102
  $string4 = "this string contains \\"escaped \\" double quotes"
103
103
  $string5 = "this string contains \\'escaped \\' single quotes"
104
- $string6 = "this string contains \r line return"
104
+ $string6 = "this string contains \r carriage return"
105
105
  $string7 = "this string contains \\\\ an escaped backslash"
106
+ $string8 = "this string contains \\s"
106
107
  END
107
108
  end
108
109
 
@@ -112,7 +113,7 @@ describe 'double_quoted_strings' do
112
113
  end
113
114
 
114
115
  context 'double quoted string with random escape should be rejected' do
115
- let(:code) { %( $ztring = "this string contains \l random esape" ) }
116
+ let(:code) { %( $ztring = "this string contains \l random escape" ) }
116
117
 
117
118
  it 'should only detect a single problem' do
118
119
  expect(problems).to have(1).problem
@@ -22,4 +22,32 @@ describe 'variable_is_lowercase' do
22
22
  expect(problems).to have(0).problems
23
23
  end
24
24
  end
25
+
26
+ context 'when typecasting inside an interpolation' do
27
+ let(:code) { %("${Integer(fact('memory.system.total_bytes'))}") }
28
+
29
+ it 'should not detect any problems' do
30
+ expect(problems).to have(0).problems
31
+ end
32
+ end
33
+
34
+ context 'when an interpolated variable contains an uppercase letter' do
35
+ let(:code) { '"${fooBar}"' }
36
+
37
+ it 'should only detect a single problem' do
38
+ expect(problems).to have(1).problem
39
+ end
40
+
41
+ it 'should create a warning' do
42
+ expect(problems).to contain_warning(msg).on_line(1).in_column(4)
43
+ end
44
+ end
45
+
46
+ context 'when an interpolated variable only contains lowercase letters' do
47
+ let(:code) { '"${foobar}"' }
48
+
49
+ it 'should not detect any problems' do
50
+ expect(problems).to have(0).problems
51
+ end
52
+ end
25
53
  end
data/spec/spec_helper.rb CHANGED
@@ -1,8 +1,10 @@
1
- require 'simplecov'
2
- SimpleCov.start do
3
- add_filter('/spec/')
4
- add_filter('/vendor/')
5
- add_group('Checks', 'lib/puppet-lint/plugins')
1
+ if ENV['COVERAGE'] == 'yes' && RUBY_VERSION.start_with?('2.6.')
2
+ require 'simplecov'
3
+ SimpleCov.start do
4
+ add_filter('/spec/')
5
+ add_filter('/vendor/')
6
+ add_group('Checks', 'lib/puppet-lint/plugins')
7
+ end
6
8
  end
7
9
 
8
10
  require 'puppet-lint'
metadata CHANGED
@@ -1,35 +1,32 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: puppet-lint
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.4.0
4
+ version: 2.5.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tim Sharpe
8
- autorequire:
8
+ - Puppet, Inc.
9
+ - Community Contributors
10
+ autorequire:
9
11
  bindir: bin
10
12
  cert_chain: []
11
- date: 2019-10-08 00:00:00.000000000 Z
13
+ date: 2021-09-14 00:00:00.000000000 Z
12
14
  dependencies: []
13
15
  description: |-
14
16
  Checks your Puppet manifests against the Puppetlabs
15
17
  style guide and alerts you to any discrepancies.
16
- email: tim@sharpe.id.au
18
+ email:
19
+ - tim@sharpe.id.au
20
+ - modules-team@puppet.com
17
21
  executables:
18
22
  - puppet-lint
19
23
  extensions: []
20
24
  extra_rdoc_files: []
21
25
  files:
22
- - ".gitignore"
23
- - ".rspec"
24
- - ".rubocop.yml"
25
- - ".rubocop_todo.yml"
26
- - ".travis.yml"
27
26
  - CHANGELOG.md
28
- - Gemfile
27
+ - HISTORY.md
29
28
  - LICENSE
30
29
  - README.md
31
- - Rakefile
32
- - appveyor.yml
33
30
  - bin/puppet-lint
34
31
  - lib/puppet-lint.rb
35
32
  - lib/puppet-lint/bin.rb
@@ -84,7 +81,6 @@ files:
84
81
  - lib/puppet-lint/tasks/puppet-lint.rb
85
82
  - lib/puppet-lint/tasks/release_test.rb
86
83
  - lib/puppet-lint/version.rb
87
- - puppet-lint.gemspec
88
84
  - spec/fixtures/test/manifests/fail.pp
89
85
  - spec/fixtures/test/manifests/ignore.pp
90
86
  - spec/fixtures/test/manifests/ignore_multiple_block.pp
@@ -144,10 +140,11 @@ files:
144
140
  - spec/puppet-lint/plugins/check_whitespace/trailing_whitespace_spec.rb
145
141
  - spec/puppet-lint_spec.rb
146
142
  - spec/spec_helper.rb
147
- homepage: https://github.com/rodjek/puppet-lint/
148
- licenses: []
143
+ homepage: https://github.com/puppetlabs/puppet-lint/
144
+ licenses:
145
+ - MIT
149
146
  metadata: {}
150
- post_install_message:
147
+ post_install_message:
151
148
  rdoc_options: []
152
149
  require_paths:
153
150
  - lib
@@ -162,8 +159,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
162
159
  - !ruby/object:Gem::Version
163
160
  version: '0'
164
161
  requirements: []
165
- rubygems_version: 3.0.6
166
- signing_key:
162
+ rubyforge_project:
163
+ rubygems_version: 2.7.6.3
164
+ signing_key:
167
165
  specification_version: 4
168
166
  summary: Ensure your Puppet manifests conform with the Puppetlabs style guide
169
167
  test_files:
data/.gitignore DELETED
@@ -1,12 +0,0 @@
1
- *.gem
2
- .bundle/
3
- .rbenv-version
4
- .ruby-version
5
- Gemfile.lock
6
- vendor/
7
- coverage/
8
- *.swp
9
- /_site/
10
- .idea
11
- /*.pp
12
- /tmp/
data/.rspec DELETED
@@ -1,2 +0,0 @@
1
- --format documentation
2
- --color
data/.rubocop.yml DELETED
@@ -1,74 +0,0 @@
1
- ---
2
- inherit_from: './.rubocop_todo.yml'
3
- AllCops:
4
- TargetRubyVersion: 1.9
5
-
6
- Style/HashSyntax:
7
- EnforcedStyle: hash_rockets
8
-
9
- Layout/FirstArrayElementLineBreak:
10
- Enabled: true
11
- Layout/FirstHashElementLineBreak:
12
- Enabled: true
13
- Layout/FirstMethodArgumentLineBreak:
14
- Enabled: true
15
- Layout/FirstMethodParameterLineBreak:
16
- Enabled: true
17
- Layout/IndentArray:
18
- EnforcedStyle: consistent
19
- Layout/MultilineArrayBraceLayout:
20
- EnforcedStyle: new_line
21
- Layout/MultilineAssignmentLayout:
22
- Enabled: true
23
- EnforcedStyle: same_line
24
- Layout/MultilineHashBraceLayout:
25
- EnforcedStyle: new_line
26
- Layout/MultilineMethodDefinitionBraceLayout:
27
- EnforcedStyle: new_line
28
-
29
- Style/AutoResourceCleanup:
30
- Enabled: true
31
- Style/BlockDelimiters:
32
- EnforcedStyle: braces_for_chaining
33
- Style/BracesAroundHashParameters:
34
- EnforcedStyle: context_dependent
35
- Style/Encoding:
36
- Enabled: false
37
- Style/MethodCallWithArgsParentheses:
38
- Enabled: true
39
- IgnoreMacros: true
40
- IgnoredMethods:
41
- - puts
42
- - require
43
- - include
44
- - it
45
- - context
46
- - describe
47
- - to
48
- - to_not
49
- - raise
50
- - desc
51
- - task
52
- - exit
53
- - should
54
- - gem
55
- - group
56
- - attr_reader
57
- - attr_accessor
58
- - attr_writer
59
- - source
60
- Style/MethodCalledOnDoEndBlock:
61
- Enabled: true
62
- Style/RegexpLiteral:
63
- EnforcedStyle: percent_r
64
- Style/TrailingCommaInArguments:
65
- EnforcedStyleForMultiline: no_comma
66
- Style/TrailingCommaInLiteral:
67
- EnforcedStyleForMultiline: comma
68
- Style/FormatStringToken:
69
- Enabled: false
70
- Style/FileName:
71
- Exclude:
72
- - 'lib/puppet-lint.rb'
73
- - 'lib/puppet-lint/tasks/puppet-lint.rb'
74
- - 'spec/puppet-lint_spec.rb'
data/.rubocop_todo.yml DELETED
@@ -1,89 +0,0 @@
1
- # This configuration was generated by
2
- # `rubocop --auto-gen-config`
3
- # on 2017-08-28 12:57:58 +1000 using RuboCop version 0.49.1.
4
- # The point is for the user to remove these configuration records
5
- # one by one as the offenses are removed from the code base.
6
- # Note that changes in the inspected code, or installation of new
7
- # versions of RuboCop, may require this file to be generated again.
8
-
9
- # Offense count: 3
10
- # Configuration parameters: Include.
11
- # Include: **/Gemfile, **/gems.rb
12
- Bundler/DuplicatedGem:
13
- Exclude:
14
- - 'Gemfile'
15
-
16
- # Offense count: 2
17
- # Cop supports --auto-correct.
18
- # Configuration parameters: Include, TreatCommentsAsGroupSeparators.
19
- # Include: **/Gemfile, **/gems.rb
20
- Bundler/OrderedGems:
21
- Exclude:
22
- - 'Gemfile'
23
-
24
- # Offense count: 9
25
- # Configuration parameters: AllowSafeAssignment.
26
- Lint/AssignmentInCondition:
27
- Exclude:
28
- - 'lib/puppet-lint/lexer.rb'
29
- - 'lib/puppet-lint/plugins/check_classes/variable_scope.rb'
30
-
31
- # Offense count: 52
32
- Metrics/AbcSize:
33
- Max: 153
34
-
35
- # Offense count: 121
36
- # Configuration parameters: CountComments, ExcludedMethods.
37
- Metrics/BlockLength:
38
- Max: 1136
39
-
40
- # Offense count: 8
41
- # Configuration parameters: CountBlocks.
42
- Metrics/BlockNesting:
43
- Max: 5
44
-
45
- # Offense count: 2
46
- # Configuration parameters: CountComments.
47
- Metrics/ClassLength:
48
- Max: 384
49
-
50
- # Offense count: 20
51
- Metrics/CyclomaticComplexity:
52
- Max: 26
53
-
54
- # Offense count: 238
55
- # Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
56
- # URISchemes: http, https
57
- Metrics/LineLength:
58
- Max: 223
59
-
60
- # Offense count: 65
61
- # Configuration parameters: CountComments.
62
- Metrics/MethodLength:
63
- Max: 105
64
-
65
- # Offense count: 18
66
- Metrics/PerceivedComplexity:
67
- Max: 28
68
-
69
- # Offense count: 1
70
- # Cop supports --auto-correct.
71
- Performance/RedundantBlockCall:
72
- Exclude:
73
- - 'lib/puppet-lint/tasks/puppet-lint.rb'
74
-
75
- # Offense count: 7
76
- # Configuration parameters: EnforcedStyle, SupportedStyles.
77
- # SupportedStyles: nested, compact
78
- Style/ClassAndModuleChildren:
79
- Exclude:
80
- - 'lib/puppet-lint.rb'
81
- - 'lib/puppet-lint/bin.rb'
82
- - 'lib/puppet-lint/checkplugin.rb'
83
- - 'lib/puppet-lint/checks.rb'
84
- - 'lib/puppet-lint/data.rb'
85
- - 'lib/puppet-lint/optparser.rb'
86
-
87
- # Offense count: 20
88
- Style/MultilineBlockChain:
89
- Enabled: false