cookstyle 5.6.5 → 5.7.0

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: ffca3b8387e0818808debc42526209312332b497559ed017b37f772187bca663
4
- data.tar.gz: 769bbde3f4becf66b92311d728b7d2b5d14924d18c2ebe4a77cc31c6bc95fbf0
3
+ metadata.gz: e79627357ca125484e3ab900401f64dfef191b650282118279129b9fc3e1e65c
4
+ data.tar.gz: c6633c204e5cf76711518d7f25cbb03c49814eb4a0534bf108fba69bd58c4f61
5
5
  SHA512:
6
- metadata.gz: 59ec17831658cb6712d866f71af9d1dcb59c2f81f98760f5966394cdf6e22c6e0b580a2e2cb8e069486d401dfdef7e0595769fd4c117c3d074270b72a7e2c8d5
7
- data.tar.gz: 8f062dd18cdb2e65b96285d5683397229109369db6f7d562af7e0d0ac61133cdbda34205ae340e37c5bc2589c8c8de7044204ab9625c45153e8d0df25d4ebf77
6
+ metadata.gz: 04db3d494e31f545987ee9a5d74b5b238fb22e5a3c46904cee0956f3903c5402a0cedb1f922270a54eec3fa44691af0e79767e0fa2cf643bdd727e5d28abf30b
7
+ data.tar.gz: b7459b727077fc0079872053a7f7dd4c07822e254a6c9476d99390d22dcf4b7c9284ca5aa1b908ba66673fd9f2116495eacfb19706b3cf69ce6d0c57d282f12b
@@ -412,6 +412,50 @@ ChefDeprecations/WindowsTaskChangeAction:
412
412
  Exclude:
413
413
  - '**/metadata.rb'
414
414
 
415
+ ChefDeprecations/ResourceOverridesProvidesMethod:
416
+ Description: Don't override the provides? method in a resource provider. Use provides :SOME_PROVIDER_NAME instead. This will cause failures in Chef Infra Client 13 and later.
417
+ Enabled: true
418
+ VersionAdded: '5.7.0'
419
+ Include:
420
+ - '**/libraries/*.rb'
421
+ - '**/providers/*.rb'
422
+ - '**/resources/*.rb'
423
+
424
+ ChefDeprecations/ResourceUsesDslNameMethod:
425
+ Description: Use resource_name instead of the dsl_name method in resources. This will cause failures in Chef Infra Client 13 and later.
426
+ Enabled: true
427
+ VersionAdded: '5.7.0'
428
+ Include:
429
+ - '**/libraries/*.rb'
430
+ - '**/providers/*.rb'
431
+ - '**/resources/*.rb'
432
+
433
+ ChefDeprecations/ResourceUsesUpdatedMethod:
434
+ Description: Don't use updated = true/false to update resource state. This will cause failures in Chef Infra Client 13 and later.
435
+ Enabled: false # has a high potential for false positives
436
+ VersionAdded: '5.7.0'
437
+ Include:
438
+ - '**/libraries/*.rb'
439
+ - '**/providers/*.rb'
440
+ - '**/resources/*.rb'
441
+
442
+ ChefDeprecations/NamePropertyWithDefaultValue:
443
+ Description: A resource property can't be marked as a name_property and also have a default value. This will fail in Chef Infra Client 13 or later.
444
+ Enabled: true
445
+ VersionAdded: '5.7.0'
446
+ Include:
447
+ - '**/libraries/*.rb'
448
+ - '**/providers/*.rb'
449
+ - '**/resources/*.rb'
450
+
451
+ ChefDeprecations/ResourceUsesProviderBaseMethod:
452
+ Description: Don't use the deprecated provider_base method in a resource to specify the provider module to use. Instead, the provider should call provides to register itself, or the resource should call provider to specify the provider to use. This will cause failures in Chef Infra Client 13 and later.
453
+ Enabled: true
454
+ VersionAdded: '5.7.0'
455
+ Include:
456
+ - '**/libraries/*.rb'
457
+ - '**/resources/*.rb'
458
+
415
459
  ###############################
416
460
  # ChefModernize: Cleaning up legacy code and using new built-in resources
417
461
  ###############################
@@ -1,4 +1,4 @@
1
1
  module Cookstyle
2
- VERSION = "5.6.5".freeze # rubocop: disable Style/StringLiterals
2
+ VERSION = "5.7.0".freeze # rubocop: disable Style/StringLiterals
3
3
  RUBOCOP_VERSION = '0.72.0'.freeze
4
4
  end
@@ -29,7 +29,7 @@ module RuboCop
29
29
  MSG = "Don't depend on the deprecated partial_search cookbook made obsolete by Chef 13".freeze
30
30
 
31
31
  def_node_matcher :depends_partial_search?, <<-PATTERN
32
- (send nil? :depends (str {"partial_search"}))
32
+ (send nil? :depends (str "partial_search"))
33
33
  PATTERN
34
34
 
35
35
  def on_send(node)
@@ -0,0 +1,67 @@
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
+ module ChefDeprecations
21
+ # A custom resource property can't be marked as a name_property and also have a default value. The name property is a special property that is derived from the name of the resource block in and thus always has a value passed to the resource. For example if you define `my_resource 'foo'` in recipe, then the name property of `my_resource` will automatically be set to `foo`. Setting a property to be both a name_property and have a default value will cause Chef Infra Client failures in 13.0 and later releases.
22
+ #
23
+ # @example
24
+ #
25
+ # # bad
26
+ # property :config_file, String, default: 'foo', name_property: true
27
+ #
28
+ # # good
29
+ # property :config_file, String, name_property: true
30
+ #
31
+ class NamePropertyWithDefaultValue < Cop
32
+ MSG = "A resource property can't be marked as a name_property and also have a default value. This will fail in Chef Infra Client 13 or later.".freeze
33
+
34
+ def on_send(node)
35
+ if default_value?(node) && property_is_name_property?(node)
36
+ add_offense(node, location: :expression, message: MSG, severity: :refactor)
37
+ end
38
+ end
39
+
40
+ private
41
+
42
+ def property_is_name_property?(node)
43
+ if node.method_name == :property
44
+ node.arguments.each do |arg|
45
+ if arg.type == :hash
46
+ return true if arg.source.match?(/name_property:\s*true/)
47
+ end
48
+ end
49
+ false # no required: true found
50
+ end
51
+ end
52
+
53
+ def default_value?(node)
54
+ if node.method_name == :property
55
+ node.arguments.each do |arg|
56
+ if arg.type == :hash
57
+ return true if arg.source.match?(/default:\s/)
58
+ end
59
+ end
60
+ false # no default: found
61
+ end
62
+ end
63
+ end
64
+ end
65
+ end
66
+ end
67
+ end
@@ -0,0 +1,47 @@
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
+ module ChefDeprecations
21
+ # Some providers in resources override the provides? method, used to check whether they are a valid provider on the current platform. In Chef Infra Client 13, this will cause an error. Instead use `provides :SOME_PROVIDER_NAME` to register the provider.
22
+ #
23
+ # @example
24
+ #
25
+ # # bad
26
+ # def provides?
27
+ # true
28
+ # end
29
+ #
30
+ # # good
31
+ # provides :SOME_PROVIDER_NAME
32
+ #
33
+ class ResourceOverridesProvidesMethod < Cop
34
+ MSG = "Don't override the provides? method in a resource provider. Use provides :SOME_PROVIDER_NAME instead. This will cause failures in Chef Infra Client 13 and later.".freeze
35
+
36
+ def_node_search :provides, '(send nil? :provides ...)'
37
+
38
+ def on_def(node)
39
+ if node.method_name == :provides?
40
+ add_offense(node, location: :expression, message: MSG, severity: :refactor) if provides(processed_source.ast).count == 0
41
+ end
42
+ end
43
+ end
44
+ end
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,44 @@
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
+ module ChefDeprecations
21
+ # Don't use the dsl_name method in a resource to find the name of the resource. Use the resource_name method instead. dsl_name was removed in Chef Infra Client 13 and will now result in an error.
22
+ #
23
+ # @example
24
+ #
25
+ # # bad
26
+ # my_resource = MyResource.dsl_name
27
+ #
28
+ # # good
29
+ # my_resource = MyResource.resource_name
30
+ #
31
+ class ResourceUsesDslNameMethod < Cop
32
+ MSG = 'Use resource_name instead of the dsl_name method in resources. This will cause failures in Chef Infra Client 13 and later.'.freeze
33
+
34
+ def on_send(node)
35
+ add_offense(node, location: :expression, message: MSG, severity: :refactor) if node.method_name == :dsl_name
36
+ end
37
+
38
+ # potential autocorrect is new_resource.updated_by_last_action true, but we need to actually see what class we were called from
39
+ # this might not be worth it yet based on the number of these we'd run into and the false auto correct potential
40
+ end
41
+ end
42
+ end
43
+ end
44
+ 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
+ module ChefDeprecations
21
+ # The Resource.provider_base allows the developer to specify within a resource a module to load the resource's provider from. Instead, the provider should call provides to register itself, or the resource should call provider to specify the provider to use.
22
+ #
23
+ # @example
24
+ #
25
+ # # bad
26
+ # provider_base ::Chef::Provider::SomethingSomething
27
+ #
28
+ class ResourceUsesProviderBaseMethod < Cop
29
+ MSG = "Don't use the deprecated provider_base method in a resource to specify the provider module to use. Instead, the provider should call provides to register itself, or the resource should call provider to specify the provider to use. This will cause failures in Chef Infra Client 13 and later.".freeze
30
+
31
+ def on_send(node)
32
+ add_offense(node, location: :expression, message: MSG, severity: :refactor) if node.method_name == :provider_base
33
+ end
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
+ module ChefDeprecations
21
+ # Don't call the deprecated updated= method in a resource to set the resource to updated. This method was removed from Chef Infra Client 13 and this will now cause an error. Instead wrap code that updated the state of the node in a converge_by block. Documentation on using the converge_by block can be found at https://docs.chef.io/custom_resources.html.
22
+ #
23
+ # @example
24
+ #
25
+ # # bad
26
+ # action :foo do
27
+ # updated = true
28
+ # end
29
+ #
30
+ # # good
31
+ # action :foo do
32
+ # converge_by('resource did something) do
33
+ # # code that causes the resource to converge
34
+ # end
35
+ #
36
+ class ResourceUsesUpdatedMethod < Cop
37
+ MSG = "Don't use updated = true/false to update resource state. This will cause failures in Chef Infra Client 13 and later.".freeze
38
+
39
+ def on_lvasgn(node)
40
+ add_offense(node, location: :expression, message: MSG, severity: :refactor) if node.node_parts.first == :updated
41
+ end
42
+
43
+ # potential autocorrect is new_resource.updated_by_last_action true, but we need to actually see what class we were called from
44
+ # this might not be worth it yet based on the number of these we'd run into and the false auto correct potential
45
+ end
46
+ end
47
+ end
48
+ end
49
+ end
@@ -18,8 +18,7 @@ module RuboCop
18
18
  module Cop
19
19
  module Chef
20
20
  module ChefModernize
21
- # Don't depend the zypper cookbook as the zypper_repository resource is built into
22
- # Chef Infra Client 13.3
21
+ # Don't depend the zypper cookbook as the zypper_repository resource is built into Chef Infra Client 13.3
23
22
  #
24
23
  # @example
25
24
  #
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.6.5
4
+ version: 5.7.0
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-10-02 00:00:00.000000000 Z
12
+ date: 2019-10-04 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rake
@@ -109,6 +109,7 @@ files:
109
109
  - lib/rubocop/cop/chef/deprecation/legacy_yum_cookbook_recipes.rb
110
110
  - lib/rubocop/cop/chef/deprecation/locale_lc_all_property.rb
111
111
  - lib/rubocop/cop/chef/deprecation/long_description_metadata.rb
112
+ - lib/rubocop/cop/chef/deprecation/name_property_and_default.rb
112
113
  - lib/rubocop/cop/chef/deprecation/node_methods_not_attributes.rb
113
114
  - lib/rubocop/cop/chef/deprecation/node_set.rb
114
115
  - lib/rubocop/cop/chef/deprecation/node_set_unless.rb
@@ -116,6 +117,10 @@ files:
116
117
  - lib/rubocop/cop/chef/deprecation/recipe_metadata.rb
117
118
  - lib/rubocop/cop/chef/deprecation/replaces_metadata.rb
118
119
  - lib/rubocop/cop/chef/deprecation/require_recipe.rb
120
+ - lib/rubocop/cop/chef/deprecation/resource_overrides_provides_method.rb
121
+ - lib/rubocop/cop/chef/deprecation/resource_uses_dsl_name_method.rb
122
+ - lib/rubocop/cop/chef/deprecation/resource_uses_provider_base_method.rb
123
+ - lib/rubocop/cop/chef/deprecation/resource_uses_updated_method.rb
119
124
  - lib/rubocop/cop/chef/deprecation/suggests_metadata.rb
120
125
  - lib/rubocop/cop/chef/deprecation/use_inline_resources.rb
121
126
  - lib/rubocop/cop/chef/deprecation/user_supports_property.rb