puppet-lint 2.3.6 → 2.5.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 (44) hide show
  1. checksums.yaml +5 -5
  2. data/CHANGELOG.md +238 -87
  3. data/README.md +18 -0
  4. data/lib/puppet-lint.rb +1 -1
  5. data/lib/puppet-lint/data.rb +26 -11
  6. data/lib/puppet-lint/lexer.rb +97 -200
  7. data/lib/puppet-lint/lexer/string_slurper.rb +173 -0
  8. data/lib/puppet-lint/lexer/token.rb +8 -0
  9. data/lib/puppet-lint/optparser.rb +4 -5
  10. data/lib/puppet-lint/plugins/check_classes/parameter_order.rb +12 -1
  11. data/lib/puppet-lint/plugins/check_conditionals/case_without_default.rb +15 -1
  12. data/lib/puppet-lint/plugins/check_documentation/documentation.rb +4 -0
  13. data/lib/puppet-lint/plugins/check_resources/ensure_first_param.rb +5 -2
  14. data/lib/puppet-lint/plugins/check_strings/quoted_booleans.rb +1 -0
  15. data/lib/puppet-lint/plugins/check_strings/variables_not_enclosed.rb +71 -0
  16. data/lib/puppet-lint/plugins/check_whitespace/arrow_alignment.rb +1 -1
  17. data/lib/puppet-lint/tasks/puppet-lint.rb +14 -0
  18. data/lib/puppet-lint/tasks/release_test.rb +3 -1
  19. data/lib/puppet-lint/version.rb +1 -1
  20. data/spec/fixtures/test/manifests/two_warnings.pp +5 -0
  21. data/spec/puppet-lint/bin_spec.rb +47 -6
  22. data/spec/puppet-lint/data_spec.rb +12 -0
  23. data/spec/puppet-lint/lexer/string_slurper_spec.rb +473 -0
  24. data/spec/puppet-lint/lexer_spec.rb +1153 -590
  25. data/spec/puppet-lint/plugins/check_classes/parameter_order_spec.rb +18 -0
  26. data/spec/puppet-lint/plugins/check_classes/variable_scope_spec.rb +15 -1
  27. data/spec/puppet-lint/plugins/check_conditionals/case_without_default_spec.rb +39 -0
  28. data/spec/puppet-lint/plugins/check_documentation/documentation_spec.rb +18 -0
  29. data/spec/puppet-lint/plugins/check_resources/ensure_first_param_spec.rb +16 -0
  30. data/spec/puppet-lint/plugins/check_strings/double_quoted_strings_spec.rb +5 -5
  31. data/spec/puppet-lint/plugins/check_strings/only_variable_string_spec.rb +6 -6
  32. data/spec/puppet-lint/plugins/check_strings/variables_not_enclosed_spec.rb +32 -0
  33. data/spec/puppet-lint/plugins/check_variables/variable_is_lowercase_spec.rb +28 -0
  34. data/spec/spec_helper.rb +7 -5
  35. metadata +14 -17
  36. data/.gitignore +0 -12
  37. data/.rspec +0 -2
  38. data/.rubocop.yml +0 -74
  39. data/.rubocop_todo.yml +0 -89
  40. data/.travis.yml +0 -24
  41. data/Gemfile +0 -40
  42. data/Rakefile +0 -42
  43. data/appveyor.yml +0 -33
  44. data/puppet-lint.gemspec +0 -19
@@ -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
@@ -313,7 +313,21 @@ describe 'variable_scope' do
313
313
  end
314
314
 
315
315
  it 'should create one warning' do
316
- expect(problems).to contain_warning(msg).on_line(2).in_column(13)
316
+ expect(problems).to contain_warning(msg).on_line(2).in_column(14)
317
+ end
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
317
331
  end
318
332
  end
319
333
  end
@@ -105,4 +105,43 @@ describe 'case_without_default' do
105
105
  expect(problems).to have(0).problems
106
106
  end
107
107
  end
108
+
109
+ context 'issue-829 nested selector with default in case without default' do
110
+ let(:code) do
111
+ <<-END
112
+ case $::operatingsystem {
113
+ 'centos': {
114
+ $variable = $::operatingsystemmajrelease ? {
115
+ '7' => 'value1'
116
+ default => 'value2',
117
+ }
118
+ }
119
+ }
120
+ END
121
+ end
122
+
123
+ it 'should create one warning' do
124
+ expect(problems).to contain_warning(msg).on_line(1).in_column(9)
125
+ end
126
+ end
127
+
128
+ context 'issue-829 nested selector with default in case with default' do
129
+ let(:code) do
130
+ <<-END
131
+ case $::operatingsystem {
132
+ 'centos': {
133
+ $variable = $::operatingsystemmajrelease ? {
134
+ '7' => 'value1'
135
+ default => 'value2',
136
+ }
137
+ }
138
+ default: {}
139
+ }
140
+ END
141
+ end
142
+
143
+ it 'should not detect any problems' do
144
+ expect(problems).to have(0).problems
145
+ end
146
+ end
108
147
  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
 
@@ -80,6 +80,22 @@ describe 'ensure_first_param' do
80
80
  expect(problems).to have(0).problems
81
81
  end
82
82
  end
83
+
84
+ context 'ensure in nested hash' do
85
+ let(:code) do
86
+ <<-END
87
+ foo::bar { 'bar':
88
+ opts => {
89
+ ensure => present,
90
+ },
91
+ },
92
+ END
93
+ end
94
+
95
+ it 'should not detect any problems' do
96
+ expect(problems).to have(0).problems
97
+ end
98
+ end
83
99
  end
84
100
 
85
101
  context 'with fix enabled' do
@@ -93,15 +93,15 @@ 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
106
  END
107
107
  end
@@ -112,7 +112,7 @@ describe 'double_quoted_strings' do
112
112
  end
113
113
 
114
114
  context 'double quoted string with random escape should be rejected' do
115
- let(:code) { %( $ztring = "this string contains \l random esape" ) }
115
+ let(:code) { %( $ztring = "this string contains \l random escape" ) }
116
116
 
117
117
  it 'should only detect a single problem' do
118
118
  expect(problems).to have(1).problem
@@ -12,7 +12,7 @@ describe 'only_variable_string' do
12
12
  end
13
13
 
14
14
  it 'should create a warning' do
15
- expect(problems).to contain_warning(msg).on_line(1).in_column(3)
15
+ expect(problems).to contain_warning(msg).on_line(1).in_column(4)
16
16
  end
17
17
  end
18
18
 
@@ -24,7 +24,7 @@ describe 'only_variable_string' do
24
24
  end
25
25
 
26
26
  it 'should create a warning' do
27
- expect(problems).to contain_warning(msg).on_line(1).in_column(3)
27
+ expect(problems).to contain_warning(msg).on_line(1).in_column(4)
28
28
  end
29
29
  end
30
30
 
@@ -36,7 +36,7 @@ describe 'only_variable_string' do
36
36
  end
37
37
 
38
38
  it 'should create a warning' do
39
- expect(problems).to contain_warning(msg).on_line(1).in_column(3)
39
+ expect(problems).to contain_warning(msg).on_line(1).in_column(4)
40
40
  end
41
41
  end
42
42
 
@@ -73,7 +73,7 @@ describe 'only_variable_string' do
73
73
  end
74
74
 
75
75
  it 'should fix the manifest' do
76
- expect(problems).to contain_fixed(msg).on_line(1).in_column(3)
76
+ expect(problems).to contain_fixed(msg).on_line(1).in_column(4)
77
77
  end
78
78
 
79
79
  it 'should unquote the variable' do
@@ -89,7 +89,7 @@ describe 'only_variable_string' do
89
89
  end
90
90
 
91
91
  it 'should fix the manifest' do
92
- expect(problems).to contain_fixed(msg).on_line(1).in_column(3)
92
+ expect(problems).to contain_fixed(msg).on_line(1).in_column(4)
93
93
  end
94
94
 
95
95
  it 'should unquoted the variable' do
@@ -105,7 +105,7 @@ describe 'only_variable_string' do
105
105
  end
106
106
 
107
107
  it 'should fix the manifest' do
108
- expect(problems).to contain_fixed(msg).on_line(1).in_column(3)
108
+ expect(problems).to contain_fixed(msg).on_line(1).in_column(4)
109
109
  end
110
110
 
111
111
  it 'should unquote the variable' do
@@ -86,5 +86,37 @@ describe 'variables_not_enclosed' do
86
86
  expect(manifest).to eq('"${foo}-${bar}"')
87
87
  end
88
88
  end
89
+
90
+ context 'variable with a hash or array reference not enclosed' do
91
+ let(:code) { %("$foo['bar'][2]something") }
92
+
93
+ it 'should only detect a single problem' do
94
+ expect(problems).to have(1).problem
95
+ end
96
+
97
+ it 'should fix the manifest' do
98
+ expect(problems).to contain_fixed(msg).on_line(1).in_column(2)
99
+ end
100
+
101
+ it 'should enclose the variable with the references' do
102
+ expect(manifest).to eq(%("${foo['bar'][2]}something"))
103
+ end
104
+ end
105
+
106
+ context 'unenclosed variable followed by a dash and then text' do
107
+ let(:code) { '"$hostname-keystore"' }
108
+
109
+ it 'should only detect a single problem' do
110
+ expect(problems).to have(1).problem
111
+ end
112
+
113
+ it 'should fix the manifest' do
114
+ expect(problems).to contain_fixed(msg).on_line(1).in_column(2)
115
+ end
116
+
117
+ it 'should enclose the variable but not the text' do
118
+ expect(manifest).to eq('"${hostname}-keystore"')
119
+ end
120
+ end
89
121
  end
90
122
  end
@@ -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,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: puppet-lint
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.3.6
4
+ version: 2.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tim Sharpe
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-07-09 00:00:00.000000000 Z
11
+ date: 2021-07-26 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: |-
14
14
  Checks your Puppet manifests against the Puppetlabs
@@ -19,17 +19,9 @@ executables:
19
19
  extensions: []
20
20
  extra_rdoc_files: []
21
21
  files:
22
- - ".gitignore"
23
- - ".rspec"
24
- - ".rubocop.yml"
25
- - ".rubocop_todo.yml"
26
- - ".travis.yml"
27
22
  - CHANGELOG.md
28
- - Gemfile
29
23
  - LICENSE
30
24
  - README.md
31
- - Rakefile
32
- - appveyor.yml
33
25
  - bin/puppet-lint
34
26
  - lib/puppet-lint.rb
35
27
  - lib/puppet-lint/bin.rb
@@ -38,6 +30,7 @@ files:
38
30
  - lib/puppet-lint/configuration.rb
39
31
  - lib/puppet-lint/data.rb
40
32
  - lib/puppet-lint/lexer.rb
33
+ - lib/puppet-lint/lexer/string_slurper.rb
41
34
  - lib/puppet-lint/lexer/token.rb
42
35
  - lib/puppet-lint/monkeypatches.rb
43
36
  - lib/puppet-lint/optparser.rb
@@ -83,7 +76,6 @@ files:
83
76
  - lib/puppet-lint/tasks/puppet-lint.rb
84
77
  - lib/puppet-lint/tasks/release_test.rb
85
78
  - lib/puppet-lint/version.rb
86
- - puppet-lint.gemspec
87
79
  - spec/fixtures/test/manifests/fail.pp
88
80
  - spec/fixtures/test/manifests/ignore.pp
89
81
  - spec/fixtures/test/manifests/ignore_multiple_block.pp
@@ -92,6 +84,7 @@ files:
92
84
  - spec/fixtures/test/manifests/init.pp
93
85
  - spec/fixtures/test/manifests/malformed.pp
94
86
  - spec/fixtures/test/manifests/mismatched_control_comment.pp
87
+ - spec/fixtures/test/manifests/two_warnings.pp
95
88
  - spec/fixtures/test/manifests/unterminated_control_comment.pp
96
89
  - spec/fixtures/test/manifests/url_interpolation.pp
97
90
  - spec/fixtures/test/manifests/warning.pp
@@ -100,6 +93,7 @@ files:
100
93
  - spec/puppet-lint/configuration_spec.rb
101
94
  - spec/puppet-lint/data_spec.rb
102
95
  - spec/puppet-lint/ignore_overrides_spec.rb
96
+ - spec/puppet-lint/lexer/string_slurper_spec.rb
103
97
  - spec/puppet-lint/lexer/token_spec.rb
104
98
  - spec/puppet-lint/lexer_spec.rb
105
99
  - spec/puppet-lint/plugins/check_classes/arrow_on_right_operand_line_spec.rb
@@ -142,9 +136,10 @@ files:
142
136
  - spec/puppet-lint_spec.rb
143
137
  - spec/spec_helper.rb
144
138
  homepage: https://github.com/rodjek/puppet-lint/
145
- licenses: []
139
+ licenses:
140
+ - MIT
146
141
  metadata: {}
147
- post_install_message:
142
+ post_install_message:
148
143
  rdoc_options: []
149
144
  require_paths:
150
145
  - lib
@@ -159,9 +154,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
159
154
  - !ruby/object:Gem::Version
160
155
  version: '0'
161
156
  requirements: []
162
- rubyforge_project:
163
- rubygems_version: 2.6.13
164
- signing_key:
157
+ rubyforge_project:
158
+ rubygems_version: 2.7.6.2
159
+ signing_key:
165
160
  specification_version: 4
166
161
  summary: Ensure your Puppet manifests conform with the Puppetlabs style guide
167
162
  test_files:
@@ -173,6 +168,7 @@ test_files:
173
168
  - spec/fixtures/test/manifests/init.pp
174
169
  - spec/fixtures/test/manifests/malformed.pp
175
170
  - spec/fixtures/test/manifests/mismatched_control_comment.pp
171
+ - spec/fixtures/test/manifests/two_warnings.pp
176
172
  - spec/fixtures/test/manifests/unterminated_control_comment.pp
177
173
  - spec/fixtures/test/manifests/url_interpolation.pp
178
174
  - spec/fixtures/test/manifests/warning.pp
@@ -181,6 +177,7 @@ test_files:
181
177
  - spec/puppet-lint/configuration_spec.rb
182
178
  - spec/puppet-lint/data_spec.rb
183
179
  - spec/puppet-lint/ignore_overrides_spec.rb
180
+ - spec/puppet-lint/lexer/string_slurper_spec.rb
184
181
  - spec/puppet-lint/lexer/token_spec.rb
185
182
  - spec/puppet-lint/lexer_spec.rb
186
183
  - spec/puppet-lint/plugins/check_classes/arrow_on_right_operand_line_spec.rb
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'