cookstyle 5.3.6 → 5.4.13

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e6af19177bab0492d840cc42ab0b2afffaaf31c1a16492a6235811d362390f2f
4
- data.tar.gz: '01748b9bfbfcc03c1d99d4e09c24db484b76fa1c12010c48d6cb37c5ed3416bc'
3
+ metadata.gz: 05b57a23cb7a0dec58366d56a682cde9739ec6ffbf9f38f29b122df6ecbfa32c
4
+ data.tar.gz: 3653be8038c0edfe6c554824f74be18727af1af7d43d20b7e6a3c9ee50b22b08
5
5
  SHA512:
6
- metadata.gz: 6c84f45e06ffb944c0990ebed2d03b6a19d99c78b09c5e01fd8e16d27719c82d074364805b9e936ff793f4da805edcd706d1da7f0a16507526478603d409767c
7
- data.tar.gz: 9a78e7d098beb29896f63861867766b7744bb4e5262a2aec903caed0399c9659c0c25d249a232e57795707200c0eba0bb2b5b9a7ec8b0d90fca1c66ee87f2606
6
+ metadata.gz: 32c2f00742dda59d0944b13a9a06b2eb0336c20d13be753781a794e23c6b2c454eb5d26e0eeaf94ea176ad6f3a25c2b6449acedc04ae2d4dc40dcdef231fcd7a
7
+ data.tar.gz: 432baebc8013ff191096edb735abc1a90c8f9550f60931d34e15acb8eef372141cb008c3183665925610732a933301e92f6489948e25fa0511017b7103d6536c
@@ -1,6 +1,7 @@
1
1
  AllCops:
2
2
  TargetRubyVersion: 2.4
3
3
  Exclude:
4
+ - files/**/*
4
5
  - vendor/**/*
5
6
  - Guardfile
6
7
  ChefAttributes:
@@ -37,6 +38,8 @@ Chef/AttributeKeys:
37
38
  SupportedStyles:
38
39
  - strings
39
40
  - symbols
41
+ Exclude:
42
+ - '**/metadata.rb'
40
43
 
41
44
  Chef/CopyrightCommentFormat:
42
45
  Description: Properly format copyright dates in comment blocks and ensure dates are up to date
@@ -53,6 +56,13 @@ Chef/CommentFormat:
53
56
  Enabled: true
54
57
  VersionAdded: '5.0.0'
55
58
 
59
+ Chef/DefaultMetadataMaintainer:
60
+ Description: Metadata contains default maintainer information from the cookbook generator. Add actual cookbook maintainer information to the metadata.rb.
61
+ Enabled: true
62
+ VersionAdded: '5.4.0'
63
+ Include:
64
+ - '**/metadata.rb'
65
+
56
66
  ###############################
57
67
  # Avoiding potential problems
58
68
  ###############################
@@ -61,26 +71,36 @@ Chef/FileMode:
61
71
  Description: Use strings to represent file modes in Chef resources
62
72
  Enabled: true
63
73
  VersionAdded: '5.0.0'
74
+ Exclude:
75
+ - '**/metadata.rb'
64
76
 
65
77
  Chef/ServiceResource:
66
78
  Description: Use a service resource to start and stop services instead of execute resources
67
79
  Enabled: true
68
80
  VersionAdded: '5.0.0'
81
+ Exclude:
82
+ - '**/metadata.rb'
69
83
 
70
84
  Chef/NodeNormal:
71
85
  Description: Do not use the node.normal method
72
86
  Enabled: true
73
87
  VersionAdded: '5.1.0'
88
+ Exclude:
89
+ - '**/metadata.rb'
74
90
 
75
91
  Chef/NodeNormalUnless:
76
92
  Description: Do not use the node.normal_unless method
77
93
  Enabled: true
78
94
  VersionAdded: '5.1.0'
95
+ Exclude:
96
+ - '**/metadata.rb'
79
97
 
80
98
  Chef/TmpPath:
81
99
  Description: Use file_cache_path rather than hard-coding tmp paths
82
100
  Enabled: true
83
101
  VersionAdded: '5.0.0'
102
+ Exclude:
103
+ - '**/metadata.rb'
84
104
 
85
105
  Chef/InsecureCookbookURL:
86
106
  Description: Insecure http Github or Gitlab URLs for metadata source_url/issues_url fields
@@ -116,16 +136,22 @@ Chef/NodeSet:
116
136
  Description: Do not use the deprecated node.set method
117
137
  Enabled: true
118
138
  VersionAdded: '5.0.0'
139
+ Exclude:
140
+ - '**/metadata.rb'
119
141
 
120
142
  Chef/NodeSetUnless:
121
143
  Description: Do not use the deprecated node.set_unless method
122
144
  Enabled: true
123
145
  VersionAdded: '5.1.0'
146
+ Exclude:
147
+ - '**/metadata.rb'
124
148
 
125
149
  Chef/EpicFail:
126
150
  Description: Use ignore_failure method instead of the deprecated epic_fail method
127
151
  Enabled: true
128
152
  VersionAdded: '5.1.0'
153
+ Exclude:
154
+ - '**/metadata.rb'
129
155
 
130
156
  Chef/CookbookDependsOnPoise:
131
157
  Description: Cookbooks should not depend on the deprecated Poise framework
@@ -194,16 +220,52 @@ Chef/EasyInstallResource:
194
220
  Description: Don't use the deprecated easy_install resource resource removed in Chef 13
195
221
  Enabled: true
196
222
  VersionAdded: '5.1.0'
223
+ Exclude:
224
+ - '**/metadata.rb'
197
225
 
198
226
  Chef/ErlCallResource:
199
227
  Description: Don't use the deprecated erl_call resource removed in Chef 13
200
228
  Enabled: true
201
229
  VersionAdded: '5.1.0'
230
+ Exclude:
231
+ - '**/metadata.rb'
202
232
 
203
233
  Chef/RequireRecipe:
204
234
  Description: Use include_recipe instead of the require_recipe method
205
235
  Enabled: true
206
236
  VersionAdded: '5.2.0'
237
+ Exclude:
238
+ - '**/metadata.rb'
239
+
240
+ Chef/NodeMethodsInsteadofAttributes:
241
+ Description: Use node attributes to access Ohai data instead of node methods, which were deprecated in Chef Infra Client 13.
242
+ Enabled: true
243
+ VersionAdded: '5.4.0'
244
+ Exclude:
245
+ - '**/metadata.rb'
246
+
247
+ Chef/UsesDeprecatedMixins:
248
+ Description: Don't use deprecated Mixins no longer included in Chef Infra Client 14 and later.
249
+ Enabled: true
250
+ VersionAdded: '5.4.0'
251
+ Include:
252
+ - '**/libraries/*.rb'
253
+ - '**/providers/*.rb'
254
+
255
+ Chef/IncludingMixinShelloutInResources:
256
+ Description: There is no need to include Chef::Mixin::ShellOut in resources or providers as this is already done by Chef Infra Client.
257
+ Enabled: true
258
+ VersionAdded: '5.4.0'
259
+ Include:
260
+ - '**/resources/*.rb'
261
+ - '**/providers/*.rb'
262
+
263
+ Chef/LegacyYumCookbookRecipes:
264
+ Description: The elrepo, epel, ius, remi, and repoforge recipes were split into their own cookbooks and the yum recipe was renamed to be default with the release of yum cookbook 3.0 (Dec 2013).
265
+ Enabled: true
266
+ VersionAdded: '5.4.0'
267
+ Exclude:
268
+ - '**/metadata.rb'
207
269
 
208
270
  ###############################
209
271
  # Cleaning up Legacy Code
@@ -217,7 +279,7 @@ Chef/LegacyBerksfileSource:
217
279
  - '**/Berksfile'
218
280
 
219
281
  Chef/WhyRunSupportedTrue:
220
- Description: why_run_supported? no longer needs to be set to true as it is the default in Chef 13+
282
+ Description: whyrun_supported? no longer needs to be set to true as it is the default in Chef 13+
221
283
  Enabled: true
222
284
  VersionAdded: '5.1.0'
223
285
  Include:
@@ -328,6 +390,50 @@ Chef/ExecuteAptUpdate:
328
390
  Exclude:
329
391
  - '**/metadata.rb'
330
392
 
393
+ Chef/WindowsZipfileUsage:
394
+ Description: Use the archive_file resource built into Chef Infra Client 15+ instead of the windows_zipfile from the Windows cookbook
395
+ Enabled: true
396
+ VersionAdded: '5.4.0'
397
+ Exclude:
398
+ - '**/metadata.rb'
399
+
400
+ Chef/WindowsVersionHelper:
401
+ Description: Use node['platform_version'] data instead of the Windows::VersionHelper helper from the Windows cookbook.
402
+ Enabled: true
403
+ VersionAdded: '5.4.0'
404
+ Exclude:
405
+ - '**/metadata.rb'
406
+
407
+ Chef/MinitestHandlerUsage:
408
+ Description: Use Chef InSpec for testing instead of the Minitest Handler cookbook pattern.
409
+ Enabled: true
410
+ VersionAdded: '5.4.0'
411
+ Include:
412
+ - '**/metadata.rb'
413
+
414
+ Chef/IncludingOhaiDefaultRecipe:
415
+ Description: Use the ohai_plugin resource to ship custom Ohai plugins instead of using the ohai::default recipe. If you're not shipping custom Ohai plugins, then you can remove this recipe entirely.
416
+ Enabled: true
417
+ VersionAdded: '5.4.0'
418
+ Exclude:
419
+ - '**/metadata.rb'
420
+
421
+ Chef/IncludingXMLRubyRecipe:
422
+ Description: The xml::ruby recipe installs nokogiri which is included in Chef Infra Client 12 and later.
423
+ Enabled: true
424
+ VersionAdded: '5.4.0'
425
+ Exclude:
426
+ - '**/metadata.rb'
427
+
428
+ Chef/UseInlineResourcesDefined:
429
+ Description: use_inline_resources is now the default for resources in Chef Infra Client 13+ and does not need to be specified.
430
+ Enabled: true
431
+ VersionAdded: '5.4.0'
432
+ Include:
433
+ - '**/libraries/*.rb'
434
+ - '**/providers/*.rb'
435
+ - '**/resources/*.rb'
436
+
331
437
  ###############################
332
438
  # Detecting code that breaks Chef
333
439
  ###############################
@@ -1,4 +1,4 @@
1
1
  module Cookstyle
2
- VERSION = "5.3.6".freeze # rubocop: disable Style/StringLiterals
2
+ VERSION = "5.4.13".freeze # rubocop: disable Style/StringLiterals
3
3
  RUBOCOP_VERSION = '0.72.0'.freeze
4
4
  end
@@ -18,7 +18,7 @@
18
18
  module RuboCop
19
19
  module Cop
20
20
  module Chef
21
- # Make sure a cookbook doesn't depend on itself
21
+ # Make sure a cookbook doesn't depend on itself. This will fail on Chef Infra Client 13+
22
22
  #
23
23
  # @example
24
24
  #
@@ -30,7 +30,7 @@ module RuboCop
30
30
  # name 'foo'
31
31
  #
32
32
  class CookbooksDependsOnSelf < Cop
33
- MSG = 'A cookbook cannot depend on itself'.freeze
33
+ MSG = 'A cookbook cannot depend on itself. This will fail on Chef Infra Client 13+'.freeze
34
34
 
35
35
  def_node_search :dependencies, '(send nil? :depends str ...)'
36
36
  def_node_matcher :cb_name?, '(send nil? :name str ...)'
@@ -0,0 +1,48 @@
1
+ #
2
+ # Copyright:: 2019, Chef Software Inc.
3
+ # Author:: Tim Smith (<tsmith@chef.io>)
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+ #
17
+
18
+ module RuboCop
19
+ module Cop
20
+ module Chef
21
+ # Metadata contains default maintainer information from the `chef generate cookbook`
22
+ # command. This should be updated to reflect that actual maintainer of the cookbook.
23
+ #
24
+ # @example
25
+ #
26
+ # # bad
27
+ # maintainer 'YOUR_COMPANY_NAME'
28
+ # maintainer_email 'YOUR_EMAIL'
29
+ #
30
+ # # good
31
+ # maintainer 'Bob Bobberson'
32
+ # maintainer_email 'bob@bobberson.com'
33
+ #
34
+
35
+ class DefaultMetadataMaintainer < Cop
36
+ MSG = 'Metadata contains default maintainer information from the cookbook generator. Add actual cookbook maintainer information to the metadata.rb.'.freeze
37
+
38
+ def_node_matcher :default_metadata?, '(send nil? {:maintainer :maintainer_email} (str {"YOUR_COMPANY_NAME" "YOUR_EMAIL"}))'
39
+
40
+ def on_send(node)
41
+ default_metadata?(node) do
42
+ add_offense(node, location: :expression, message: MSG, severity: :refactor)
43
+ end
44
+ end
45
+ end
46
+ end
47
+ end
48
+ end
@@ -40,6 +40,16 @@ module RuboCop
40
40
  end
41
41
 
42
42
  def_node_search :cb_name, '(send nil? :name str ...)'
43
+
44
+ def autocorrect(_node)
45
+ lambda do |_corrector|
46
+ path = processed_source.path
47
+ cb_name = File.basename(File.dirname(path))
48
+
49
+ metadata = IO.read(path)
50
+ IO.write(path, "name '#{cb_name}'\n" + metadata)
51
+ end
52
+ end
43
53
  end
44
54
  end
45
55
  end
@@ -19,7 +19,8 @@ module RuboCop
19
19
  module Chef
20
20
  # When using properties in a custom resource you shouldn't set a property to
21
21
  # required and then provide a default value. If a property is required the
22
- # user will always pass in a value and the default will never be used.
22
+ # user will always pass in a value and the default will never be used. In Chef
23
+ # Infra Client 13+ this became an error.
23
24
  #
24
25
  # @example
25
26
  #
@@ -30,7 +31,7 @@ module RuboCop
30
31
  # property :bob, String, required: true
31
32
  #
32
33
  class PropertyWithRequiredAndDefault < Cop
33
- MSG = 'Resource property should not be both required and have a default value'.freeze
34
+ MSG = 'Resource property should not be both required and have a default value. This will fail on Chef Infra Client 13+'.freeze
34
35
 
35
36
  def on_send(node)
36
37
  if required_property?(node) && property_has_default?(node)
@@ -0,0 +1,72 @@
1
+ #
2
+ # Copyright:: 2019, Chef Software Inc.
3
+ # Author:: Tim Smith (<tsmith@chef.io>)
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+ #
17
+
18
+ module RuboCop
19
+ module Cop
20
+ module Chef
21
+ # The long_description metadata.rb method is not used and is unnecessary in cookbooks
22
+ #
23
+ # @example
24
+ #
25
+ # # bad
26
+ # include Chef::Mixin::LanguageIncludeAttribute
27
+ # include Chef::Mixin::RecipeDefinitionDSLCore
28
+ # include Chef::Mixin::LanguageIncludeRecipe
29
+ # include Chef::Mixin::Language
30
+ # include Chef::DSL::Recipe::FullDSL
31
+ # require 'chef/mixin/language
32
+ # require 'chef/mixin/language_include_attribute
33
+ # require 'chef/mixin/language_include_recipe
34
+
35
+ class UsesDeprecatedMixins < Cop
36
+ MSG = "Don't use deprecated Mixins no longer included in Chef Infra Client 14 and later.".freeze
37
+
38
+ def_node_matcher :deprecated_mixin?, <<-PATTERN
39
+ (send nil? :include (const (const (const nil? :Chef) :Mixin) { :Language :LanguageIncludeAttribute :RecipeDefinitionDSLCore :LanguageIncludeRecipe }))
40
+ PATTERN
41
+
42
+ def_node_matcher :deprecated_dsl?, <<-PATTERN
43
+ (send nil? :include (const (const (const (const nil? :Chef) :DSL) :Recipe) :FullDSL))
44
+ PATTERN
45
+
46
+ def_node_matcher :dsl_mixin_require?, <<-PATTERN
47
+ (send nil? :require ( str {"chef/mixin/language" "chef/mixin/language_include_attribute" "chef/mixin/language_include_recipe"}))
48
+ PATTERN
49
+
50
+ def on_send(node)
51
+ deprecated_mixin?(node) do
52
+ add_offense(node, location: :expression, message: MSG, severity: :refactor)
53
+ end
54
+
55
+ deprecated_dsl?(node) do
56
+ add_offense(node, location: :expression, message: MSG, severity: :refactor)
57
+ end
58
+
59
+ dsl_mixin_require?(node) do
60
+ add_offense(node, location: :expression, message: MSG, severity: :refactor)
61
+ end
62
+ end
63
+
64
+ def autocorrect(node)
65
+ lambda do |corrector|
66
+ corrector.remove(node.loc.expression)
67
+ end
68
+ end
69
+ end
70
+ end
71
+ end
72
+ end
@@ -0,0 +1,49 @@
1
+ #
2
+ # Copyright:: 2019, Chef Software, Inc.
3
+ # Author:: Tim Smith (<tsmith@chef.io>)
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+ #
17
+ module RuboCop
18
+ module Cop
19
+ module Chef
20
+ # The Ohai default recipe previously allowed a user to ship custom Ohai plugins to a system by including them
21
+ # in a directory in the Ohai cookbook. This functionality was replaced with the ohai_plugin resource, which
22
+ # should be used instead as it doesn't require forking the ohai cookbook.
23
+ #
24
+ # @example
25
+ #
26
+ # # bad
27
+ # include_recipe 'yum::elrepo'
28
+ # include_recipe 'yum::epel'
29
+ # include_recipe 'yum::ius'
30
+ # include_recipe 'yum::remi'
31
+ # include_recipe 'yum::repoforge'
32
+ # include_recipe 'yum::yum'
33
+ #
34
+ class LegacyYumCookbookRecipes < Cop
35
+ MSG = 'The elrepo, epel, ius, remi, and repoforge recipes were split into their own cookbooks and the yum recipe was renamed to be default with the release of yum cookbook 3.0 (Dec 2013).'.freeze
36
+
37
+ def_node_matcher :old_yum_recipe?, <<-PATTERN
38
+ (send nil? :include_recipe (str {"yum::elrepo" "yum::epel" "yum::ius" "yum::remi" "yum::repoforge" "yum::yum"}))
39
+ PATTERN
40
+
41
+ def on_send(node)
42
+ old_yum_recipe?(node) do
43
+ add_offense(node, location: :expression, message: MSG, severity: :refactor)
44
+ end
45
+ end
46
+ end
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,84 @@
1
+ #
2
+ # Copyright:: 2019, Chef Software Inc.
3
+ # Author:: Tim Smith (<tsmith@chef.io>)
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+ #
17
+ module RuboCop
18
+ module Cop
19
+ module Chef
20
+ # Incorrectly using node methods for Ohai data when you really want node attributes
21
+ #
22
+ # @example
23
+ #
24
+ # # bad
25
+ # node.fqdn
26
+ # node.platform
27
+ # node.platform_family
28
+ # node.platform_version
29
+ # node.hostname
30
+ #
31
+ # # good
32
+ # node['fqdn']
33
+ # node['platform']
34
+ # node['platform_family']
35
+ # node['platform_version']
36
+ # node['hostname']
37
+ #
38
+ class NodeMethodsInsteadofAttributes < Cop
39
+ MSG = 'Use node attributes to access Ohai data instead of node methods, which were deprecated in Chef Infra Client 13.'.freeze
40
+
41
+ def_node_matcher :node_ohai_methods?, <<-PATTERN
42
+ (send (send nil? :node) #non_nested_ohai_attribute?)
43
+ PATTERN
44
+
45
+ def on_send(node)
46
+ node_ohai_methods?(node) do
47
+ add_offense(node, location: :selector, message: MSG, severity: :refactor)
48
+ end
49
+ end
50
+
51
+ def autocorrect(node)
52
+ lambda do |corrector|
53
+ corrector.replace(node.loc.expression, "node['#{node.method_name}']")
54
+ end
55
+ end
56
+
57
+ private
58
+
59
+ def non_nested_ohai_attribute?(attribute)
60
+ %i(
61
+ current_user
62
+ domain
63
+ fqdn
64
+ hostname
65
+ ip6address
66
+ ipaddress
67
+ macaddress
68
+ machinename
69
+ ohai_time
70
+ os
71
+ os_version
72
+ platform
73
+ platform_build
74
+ platform_family
75
+ platform_version
76
+ root_group
77
+ shard_seed
78
+ uptime
79
+ uptime_seconds).include?(attribute)
80
+ end
81
+ end
82
+ end
83
+ end
84
+ end
@@ -0,0 +1,41 @@
1
+ #
2
+ # Copyright:: Copyright 2019, Chef Software Inc.
3
+ # Author:: Tim Smith (<tsmith@chef.io>)
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+ #
17
+ module RuboCop
18
+ module Cop
19
+ module Chef
20
+ # Do not use node.save with effortless as there is no server to save node state back to
21
+ #
22
+ # @example
23
+ #
24
+ # # bad
25
+ # node.save
26
+ class CookbookUsesNodeSave < Cop
27
+ MSG = 'Do not use node.save with Effortless as there is no server to save node state back to'.freeze
28
+
29
+ def_node_matcher :node_save?, <<-PATTERN
30
+ (send (send nil? :node) :save)
31
+ PATTERN
32
+
33
+ def on_send(node)
34
+ node_save?(node) do
35
+ add_offense(node, location: :expression, message: MSG, severity: :refactor)
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,58 @@
1
+ #
2
+ # Copyright:: 2019, Chef Software Inc.
3
+ # Author:: Tim Smith (<tsmith@chef.io>)
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+ #
17
+
18
+ module RuboCop
19
+ module Cop
20
+ module Chef
21
+ # There is no need to include Chef::Mixin::ShellOut in resources or providers as this is already done by Chef Infra Client.
22
+ #
23
+ # @example
24
+ #
25
+ # # bad
26
+ # require 'chef/mixin/shell_out'
27
+ # include Chef::Mixin::ShellOut
28
+
29
+ class IncludingMixinShelloutInResources < Cop
30
+ MSG = 'There is no need to include Chef::Mixin::ShellOut in resources or providers as this is already done by Chef Infra Client.'.freeze
31
+
32
+ def_node_matcher :include_shellout?, <<-PATTERN
33
+ (send nil? :include (const (const (const nil? :Chef) :Mixin) :ShellOut))
34
+ PATTERN
35
+
36
+ def_node_matcher :require_shellout?, <<-PATTERN
37
+ (send nil? :require ( str "chef/mixin/shell_out"))
38
+ PATTERN
39
+
40
+ def on_send(node)
41
+ require_shellout?(node) do
42
+ add_offense(node, location: :expression, message: MSG, severity: :refactor)
43
+ end
44
+
45
+ include_shellout?(node) do
46
+ add_offense(node, location: :expression, message: MSG, severity: :refactor)
47
+ end
48
+ end
49
+
50
+ def autocorrect(node)
51
+ lambda do |corrector|
52
+ corrector.remove(node.loc.expression)
53
+ end
54
+ end
55
+ end
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,48 @@
1
+ #
2
+ # Copyright:: 2019, Chef Software, Inc.
3
+ # Author:: Tim Smith (<tsmith@chef.io>)
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+ #
17
+ module RuboCop
18
+ module Cop
19
+ module Chef
20
+ # Use Chef InSpec for testing instead of the Minitest Handler cookbook pattern.
21
+ #
22
+ # @example
23
+ #
24
+ # # bad
25
+ # depends 'minitest-handler'
26
+ #
27
+ class MinitestHandlerUsage < Cop
28
+ MSG = 'Use Chef InSpec for testing instead of the Minitest Handler cookbook pattern.'.freeze
29
+
30
+ def_node_matcher :minitest_depends?, <<-PATTERN
31
+ (send nil? :depends (str "minitest-handler"))
32
+ PATTERN
33
+
34
+ def on_send(node)
35
+ minitest_depends?(node) do
36
+ add_offense(node, location: :expression, message: MSG, severity: :refactor)
37
+ end
38
+ end
39
+
40
+ def autocorrect(node)
41
+ lambda do |corrector|
42
+ corrector.remove(node.loc.expression)
43
+ end
44
+ end
45
+ end
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,45 @@
1
+ #
2
+ # Copyright:: 2019, Chef Software, Inc.
3
+ # Author:: Tim Smith (<tsmith@chef.io>)
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+ #
17
+ module RuboCop
18
+ module Cop
19
+ module Chef
20
+ # The Ohai default recipe previously allowed a user to ship custom Ohai plugins to a system by including them
21
+ # in a directory in the Ohai cookbook. This functionality was replaced with the ohai_plugin resource, which
22
+ # should be used instead as it doesn't require forking the ohai cookbook.
23
+ #
24
+ # @example
25
+ #
26
+ # # bad
27
+ # include_recipe 'ohai::default'
28
+ # include_recipe 'ohai'
29
+ #
30
+ class IncludingOhaiDefaultRecipe < Cop
31
+ MSG = "Use the ohai_plugin resource to ship custom Ohai plugins instead of using the ohai::default recipe. If you're not shipping custom Ohai plugins, then you can remove this recipe entirely".freeze
32
+
33
+ def_node_matcher :ohai_recipe_usage?, <<-PATTERN
34
+ (send nil? :include_recipe (str {"ohai" "ohai::default"}))
35
+ PATTERN
36
+
37
+ def on_send(node)
38
+ ohai_recipe_usage?(node) do
39
+ add_offense(node, location: :expression, message: MSG, severity: :refactor)
40
+ end
41
+ end
42
+ end
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,54 @@
1
+ #
2
+ # Copyright:: 2019, Chef Software Inc.
3
+ # Author:: Tim Smith (<tsmith@chef.io>)
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+ #
17
+ module RuboCop
18
+ module Cop
19
+ module Chef
20
+ # use_inline_resources became the default in Chef Infra Client 13+ and no longer needs
21
+ # to be called in resources
22
+ #
23
+ # @example
24
+ #
25
+ # # bad
26
+ # use_inline_resources
27
+ # use_inline_resources if defined?(use_inline_resources)
28
+ #
29
+ class UseInlineResourcesDefined < Cop
30
+ MSG = 'use_inline_resources is now the default for resources in Chef Infra Client 13+ and does not need to be specified.'.freeze
31
+
32
+ def on_send(node)
33
+ if node.method_name == :use_inline_resources
34
+ # don't alert on the use_inline_resources within the defined? check
35
+ # that would result in 2 alerts on the same line and wouldn't be useful
36
+ return if node.parent && node.parent.defined_type?
37
+
38
+ # catch the full offense if the method is gated like this: use_inline_resources if defined?(use_inline_resources)
39
+ if node.parent && node.parent.if_type? && node.parent.children.first.method_name == :defined?
40
+ node = node.parent
41
+ end
42
+ add_offense(node, location: :expression, message: MSG, severity: :refactor)
43
+ end
44
+ end
45
+
46
+ def autocorrect(node)
47
+ lambda do |corrector|
48
+ corrector.remove(node.loc.expression)
49
+ end
50
+ end
51
+ end
52
+ end
53
+ end
54
+ end
@@ -17,20 +17,20 @@
17
17
  module RuboCop
18
18
  module Cop
19
19
  module Chef
20
- # why_run_supported? no longer needs to be set to true as that is the default in Chef 13+
20
+ # whyrun_supported? no longer needs to be set to true as that is the default in Chef Infra Client 13+
21
21
  #
22
22
  # @example
23
23
  #
24
24
  # # bad
25
- # def why_run_supported?
25
+ # def whyrun_supported?
26
26
  # true
27
27
  # end
28
28
  #
29
29
  class WhyRunSupportedTrue < Cop
30
- MSG = 'why_run_supported? no longer needs to be set to true as it is the default in Chef 13+'.freeze
30
+ MSG = 'whyrun_supported? no longer needs to be set to true as it is the default in Chef Infra Client 13+'.freeze
31
31
 
32
32
  def on_def(node)
33
- if node.method_name == :why_run_supported? && node.body == s(:true) # rubocop: disable Lint/BooleanSymbol
33
+ if node.method_name == :whyrun_supported? && node.body == s(:true) # rubocop: disable Lint/BooleanSymbol
34
34
  add_offense(node, location: :expression, message: MSG, severity: :refactor)
35
35
  end
36
36
  end
@@ -0,0 +1,45 @@
1
+ #
2
+ # Copyright:: 2019, Chef Software, Inc.
3
+ # Author:: Tim Smith (<tsmith@chef.io>)
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+ #
17
+ module RuboCop
18
+ module Cop
19
+ module Chef
20
+ # Use node['platform_version] data instead of the Windows::VersionHelper helper from the Windows cookbook.
21
+ #
22
+ # @example
23
+ #
24
+ # # bad
25
+ # Windows::VersionHelper.nt_version
26
+ #
27
+ # # good
28
+ # node['platform_version].to_i
29
+ #
30
+ class WindowsVersionHelper < Cop
31
+ MSG = "Use node['platform_version'] data instead of the Windows::VersionHelper helper from the Windows cookbook.".freeze
32
+
33
+ def_node_matcher :windows_helper?, <<-PATTERN
34
+ (send ( const ( const {nil? cbase} :Windows ) :VersionHelper ) ... )
35
+ PATTERN
36
+
37
+ def on_send(node)
38
+ windows_helper?(node) do
39
+ add_offense(node, location: :expression, message: MSG, severity: :refactor)
40
+ end
41
+ end
42
+ end
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,38 @@
1
+ #
2
+ # Copyright:: 2019, Chef Software, Inc.
3
+ # Author:: Tim Smith (<tsmith@chef.io>)
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+ #
17
+ module RuboCop
18
+ module Cop
19
+ module Chef
20
+ # Use the archive_file resource built into Chef Infra Client 15+ instead of the windows_zipfile from the Windows cookbook
21
+ #
22
+ # @example
23
+ #
24
+ # # bad
25
+ # windows_zipfile 'C:\\files\\' do
26
+ # source 'C:\\Temp\\file.zip'
27
+ # end
28
+ #
29
+ class WindowsZipfileUsage < Cop
30
+ MSG = 'Use the archive_file resource built into Chef Infra Client 15+ instead of the windows_zipfile from the Windows cookbook'.freeze
31
+
32
+ def on_send(node)
33
+ add_offense(node, location: :expression, message: MSG, severity: :refactor) if node.method_name == :windows_zipfile
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,49 @@
1
+ #
2
+ # Copyright:: 2019, Chef Software, Inc.
3
+ # Author:: Tim Smith (<tsmith@chef.io>)
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+ #
17
+ module RuboCop
18
+ module Cop
19
+ module Chef
20
+ # The xml::ruby recipe was used to install nokogiri into the Chef installation. Nokogiri is included
21
+ # in Chef Infra Client 12 and later so this recipe is no longer necessary.
22
+ #
23
+ # @example
24
+ #
25
+ # # bad
26
+ # include_recipe 'xml::ruby'
27
+ #
28
+ class IncludingXMLRubyRecipe < Cop
29
+ MSG = 'The xml::ruby recipe installs nokogiri which is included in Chef Infra Client 12 and later.'.freeze
30
+
31
+ def_node_matcher :xml_ruby_recipe?, <<-PATTERN
32
+ (send nil? :include_recipe (str "xml::ruby"))
33
+ PATTERN
34
+
35
+ def on_send(node)
36
+ xml_ruby_recipe?(node) do
37
+ add_offense(node, location: :expression, message: MSG, severity: :refactor)
38
+ end
39
+ end
40
+
41
+ def autocorrect(node)
42
+ lambda do |corrector|
43
+ corrector.remove(node.loc.expression)
44
+ end
45
+ end
46
+ end
47
+ end
48
+ end
49
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cookstyle
3
3
  version: !ruby/object:Gem::Version
4
- version: 5.3.6
4
+ version: 5.4.13
5
5
  platform: ruby
6
6
  authors:
7
7
  - Thom May
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2019-08-20 00:00:00.000000000 Z
12
+ date: 2019-08-29 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rake
@@ -76,6 +76,7 @@ files:
76
76
  - lib/rubocop/chef/cookbook_only.rb
77
77
  - lib/rubocop/cop/chef/correctness/block_guard_clause_string_only.rb
78
78
  - lib/rubocop/cop/chef/correctness/cb_depends_on_self.rb
79
+ - lib/rubocop/cop/chef/correctness/default_maintainer_metadata.rb
79
80
  - lib/rubocop/cop/chef/correctness/insecure_cookbook_url.rb
80
81
  - lib/rubocop/cop/chef/correctness/invalid_license_string.rb
81
82
  - lib/rubocop/cop/chef/correctness/invalid_platform_metadata.rb
@@ -92,10 +93,13 @@ files:
92
93
  - lib/rubocop/cop/chef/deprecation/depends_compat_resource.rb
93
94
  - lib/rubocop/cop/chef/deprecation/depends_partial_search.rb
94
95
  - lib/rubocop/cop/chef/deprecation/depends_poise.rb
96
+ - lib/rubocop/cop/chef/deprecation/deprecated_mixins.rb
95
97
  - lib/rubocop/cop/chef/deprecation/easy_install.rb
96
98
  - lib/rubocop/cop/chef/deprecation/epic_fail.rb
97
99
  - lib/rubocop/cop/chef/deprecation/erl_call.rb
100
+ - lib/rubocop/cop/chef/deprecation/legacy_yum_cookbook_recipes.rb
98
101
  - lib/rubocop/cop/chef/deprecation/long_description_metadata.rb
102
+ - lib/rubocop/cop/chef/deprecation/node_methods_not_attributes.rb
99
103
  - lib/rubocop/cop/chef/deprecation/node_set.rb
100
104
  - lib/rubocop/cop/chef/deprecation/node_set_unless.rb
101
105
  - lib/rubocop/cop/chef/deprecation/provides_metadata.rb
@@ -104,6 +108,7 @@ files:
104
108
  - lib/rubocop/cop/chef/deprecation/respond_to_metadata.rb
105
109
  - lib/rubocop/cop/chef/deprecation/suggests_metadata.rb
106
110
  - lib/rubocop/cop/chef/effortless/data_bags.rb
111
+ - lib/rubocop/cop/chef/effortless/node_save.rb
107
112
  - lib/rubocop/cop/chef/effortless/search_used.rb
108
113
  - lib/rubocop/cop/chef/modernize/apt_default_recipe.rb
109
114
  - lib/rubocop/cop/chef/modernize/berksfile_source.rb
@@ -111,13 +116,20 @@ files:
111
116
  - lib/rubocop/cop/chef/modernize/chef_14_resources.rb
112
117
  - lib/rubocop/cop/chef/modernize/defines_chefspec_matchers.rb
113
118
  - lib/rubocop/cop/chef/modernize/execute_apt_update.rb
119
+ - lib/rubocop/cop/chef/modernize/includes_mixin_shellout.rb
120
+ - lib/rubocop/cop/chef/modernize/minitest_handler_usage.rb
121
+ - lib/rubocop/cop/chef/modernize/ohai_default_recipe.rb
114
122
  - lib/rubocop/cop/chef/modernize/resource_set_or_return.rb
115
123
  - lib/rubocop/cop/chef/modernize/resource_with_allowed_action.rb
116
124
  - lib/rubocop/cop/chef/modernize/resource_with_attributes.rb
117
125
  - lib/rubocop/cop/chef/modernize/respond_to_provides.rb
118
126
  - lib/rubocop/cop/chef/modernize/respond_to_resource_name.rb
119
- - lib/rubocop/cop/chef/modernize/why_run_supported_true.rb
127
+ - lib/rubocop/cop/chef/modernize/use_inline_resources.rb
128
+ - lib/rubocop/cop/chef/modernize/whyrun_supported_true.rb
120
129
  - lib/rubocop/cop/chef/modernize/windows_default_recipe.rb
130
+ - lib/rubocop/cop/chef/modernize/windows_version_helper.rb
131
+ - lib/rubocop/cop/chef/modernize/windows_zipfile.rb
132
+ - lib/rubocop/cop/chef/modernize/xml_ruby_recipe.rb
121
133
  - lib/rubocop/cop/chef/modernize/yum_dnf_compat_recipe.rb
122
134
  - lib/rubocop/cop/chef/style/attribute_keys.rb
123
135
  - lib/rubocop/cop/chef/style/comment_sentence_spacing.rb