cookstyle 6.6.9 → 6.11.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/config/cookstyle.yml +66 -6
- data/config/disable_all.yml +18 -0
- data/config/upstream.yml +128 -23
- data/lib/cookstyle.rb +2 -1
- data/lib/cookstyle/version.rb +2 -2
- data/lib/rubocop/cop/chef/correctness/incorrect_library_injection.rb +10 -0
- data/lib/rubocop/cop/chef/correctness/invalid_version_metadata.rb +1 -1
- data/lib/rubocop/cop/chef/correctness/lazy_eval_node_attribute_defaults.rb +3 -3
- data/lib/rubocop/cop/chef/deprecation/hwrp_without_provides.rb +141 -0
- data/lib/rubocop/cop/chef/deprecation/resource_uses_only_resource_name.rb +86 -0
- data/lib/rubocop/cop/chef/modernize/conditional_using_test.rb +56 -0
- data/lib/rubocop/cop/chef/modernize/includes_mixin_shellout.rb +24 -3
- data/lib/rubocop/cop/chef/modernize/node_init_package.rb +16 -8
- data/lib/rubocop/cop/chef/redundant/multiple_platform_checks.rb +60 -0
- data/lib/rubocop/cop/chef/redundant/ohai_attribute_to_string.rb +68 -0
- data/lib/rubocop/cop/chef/sharing/include_resource_examples.rb +59 -0
- data/lib/rubocop/cop/chef/sharing/invalid_license_string.rb +1 -1
- data/lib/rubocop/cop/chef/style/include_recipe_with_parentheses.rb +57 -0
- data/lib/rubocop/monkey_patches/registry_cop.rb +14 -0
- data/lib/rubocop/monkey_patches/team.rb +24 -0
- metadata +13 -6
- data/lib/rubocop/cop/chef/deprecation/resource_without_name_or_provides.rb +0 -81
- data/lib/rubocop/monkey_patches/commissioner.rb +0 -26
@@ -0,0 +1,60 @@
|
|
1
|
+
#
|
2
|
+
# Copyright:: 2020, 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
|
+
module ChefRedundantCode
|
22
|
+
# You can pass multiple values to the platform? and platform_family? helpers instead of calling the helpers multiple times.
|
23
|
+
#
|
24
|
+
# @example
|
25
|
+
#
|
26
|
+
# # bad
|
27
|
+
# platform?('redhat') || platform?('ubuntu')
|
28
|
+
# platform_family?('debian') || platform_family?('rhel')
|
29
|
+
#
|
30
|
+
# # good
|
31
|
+
# platform?('redhat', 'ubuntu')
|
32
|
+
# platform_family?('debian', 'rhel')
|
33
|
+
#
|
34
|
+
class MultiplePlatformChecks < Cop
|
35
|
+
MSG = 'You can pass multiple values to the platform? and platform_family? helpers instead of calling the helpers multiple times.'.freeze
|
36
|
+
|
37
|
+
def_node_matcher :or_platform_helpers?, <<-PATTERN
|
38
|
+
(or (send nil? ${:platform? :platform_family?} $_ )* )
|
39
|
+
PATTERN
|
40
|
+
|
41
|
+
def on_or(node)
|
42
|
+
or_platform_helpers?(node) do |helpers, _plats|
|
43
|
+
# if the helper types were the same it's an offense, but platform_family?('rhel') || platform?('ubuntu') is legit
|
44
|
+
add_offense(node, location: :expression, message: MSG, severity: :refactor) if helpers.uniq.size == 1
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def autocorrect(node)
|
49
|
+
or_platform_helpers?(node) do |type, plats|
|
50
|
+
lambda do |corrector|
|
51
|
+
new_string = "#{type.first}(#{plats.map(&:source).join(', ')})"
|
52
|
+
corrector.replace(node.loc.expression, new_string)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
@@ -0,0 +1,68 @@
|
|
1
|
+
#
|
2
|
+
# Copyright:: 2020, 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
|
+
module ChefRedundantCode
|
22
|
+
# Many Ohai node attributes are already strings and don't need to be cast to strings again
|
23
|
+
#
|
24
|
+
# @example
|
25
|
+
#
|
26
|
+
# # bad
|
27
|
+
# node['platform'].to_s
|
28
|
+
# node['platform_family'].to_s
|
29
|
+
# node['platform_version'].to_s
|
30
|
+
# node['fqdn'].to_s
|
31
|
+
# node['hostname'].to_s
|
32
|
+
# node['os'].to_s
|
33
|
+
# node['name'].to_s
|
34
|
+
#
|
35
|
+
# # good
|
36
|
+
# node['platform']
|
37
|
+
# node['platform_family']
|
38
|
+
# node['platform_version']
|
39
|
+
# node['fqdn']
|
40
|
+
# node['hostname']
|
41
|
+
# node['os']
|
42
|
+
# node['name']
|
43
|
+
#
|
44
|
+
class OhaiAttributeToString < Cop
|
45
|
+
MSG = "This Ohai node attribute is already a string and doesn't need to be converted".freeze
|
46
|
+
|
47
|
+
def_node_matcher :platform_to_s?, <<-PATTERN
|
48
|
+
(send (send (send nil? :node) :[] $(str {"platform" "platform_family" "platform_version" "fqdn" "hostname" "os" "name"}) ) :to_s )
|
49
|
+
PATTERN
|
50
|
+
|
51
|
+
def on_send(node)
|
52
|
+
platform_to_s?(node) do
|
53
|
+
add_offense(node, location: :expression, message: MSG, severity: :refactor)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
def autocorrect(node)
|
58
|
+
platform_to_s?(node) do |method|
|
59
|
+
lambda do |corrector|
|
60
|
+
corrector.replace(node.loc.expression, "node['#{method.value}']")
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
#
|
2
|
+
# Copyright:: Copyright 2020, 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 ChefSharing
|
21
|
+
# Resources should include examples field to allow automated documention. Requires Chef Infra Client 13.9 or later.
|
22
|
+
#
|
23
|
+
# @example
|
24
|
+
#
|
25
|
+
# # good
|
26
|
+
# examples <<~DOC
|
27
|
+
# **Specify a global domain value**
|
28
|
+
#
|
29
|
+
# ```ruby
|
30
|
+
# macos_userdefaults 'full keyboard access to all controls' do
|
31
|
+
# key 'AppleKeyboardUIMode'
|
32
|
+
# value '2'
|
33
|
+
# end
|
34
|
+
# ```
|
35
|
+
# DOC
|
36
|
+
#
|
37
|
+
class IncludeResourceExamples < Cop
|
38
|
+
include RangeHelp
|
39
|
+
extend TargetChefVersion
|
40
|
+
|
41
|
+
minimum_target_chef_version '13.9'
|
42
|
+
|
43
|
+
MSG = 'Resources should include examples field to allow automated documention. Requires Chef Infra Client 13.9 or later.'.freeze
|
44
|
+
|
45
|
+
def investigate(processed_source)
|
46
|
+
return if processed_source.blank?
|
47
|
+
|
48
|
+
# Using range similar to RuboCop::Cop::Naming::Filename (file_name.rb)
|
49
|
+
range = source_range(processed_source.buffer, 1, 0)
|
50
|
+
|
51
|
+
add_offense(nil, location: range, message: MSG, severity: :refactor) unless resource_examples(processed_source.ast).any?
|
52
|
+
end
|
53
|
+
|
54
|
+
def_node_search :resource_examples, '(send nil? :examples dstr ...)'
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
#
|
2
|
+
# Copyright:: 2020, 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
|
+
module ChefStyle
|
22
|
+
# There is no need to wrap the recipe in parentheses when using the include_recipe helper.
|
23
|
+
#
|
24
|
+
# @example
|
25
|
+
#
|
26
|
+
# # bad
|
27
|
+
# include_recipe('foo::bar')
|
28
|
+
#
|
29
|
+
# # good
|
30
|
+
# include_recipe 'foo::bar'
|
31
|
+
#
|
32
|
+
class IncludeRecipeWithParentheses < Base
|
33
|
+
extend RuboCop::Cop::AutoCorrector
|
34
|
+
|
35
|
+
MSG = 'There is no need to wrap the recipe in parentheses when using the include_recipe helper'.freeze
|
36
|
+
|
37
|
+
def_node_matcher :include_recipe?, <<-PATTERN
|
38
|
+
(send nil? :include_recipe $(str _))
|
39
|
+
PATTERN
|
40
|
+
|
41
|
+
def on_send(node)
|
42
|
+
include_recipe?(node) do |recipe|
|
43
|
+
return unless node.parenthesized?
|
44
|
+
|
45
|
+
# avoid chefspec: expect(chef_run).to include_recipe('foo')
|
46
|
+
return if node.parent&.send_type?
|
47
|
+
|
48
|
+
add_offense(node.loc.expression, message: MSG, severity: :refactor) do |corrector|
|
49
|
+
corrector.replace(node.loc.expression, "include_recipe #{recipe.source}")
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module RuboCop
|
2
|
+
module Cop
|
3
|
+
class Registry
|
4
|
+
# we monkeypatch this warning to replace rubocop with cookstyle
|
5
|
+
def print_warning(name, path)
|
6
|
+
message = "#{path}: Warning: no department given for #{name}."
|
7
|
+
if path.end_with?('.rb')
|
8
|
+
message += ' Run `cookstyle -a --only Migration/DepartmentName` to fix.'
|
9
|
+
end
|
10
|
+
warn message
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RuboCop
|
4
|
+
module Cop
|
5
|
+
class Team
|
6
|
+
def support_target_chef_version?(cop)
|
7
|
+
return true unless cop.class.respond_to?(:support_target_chef_version?)
|
8
|
+
|
9
|
+
cop.class.support_target_chef_version?(cop.target_chef_version)
|
10
|
+
end
|
11
|
+
|
12
|
+
### START COOKSTYLE MODIFICATION
|
13
|
+
def roundup_relevant_cops(filename)
|
14
|
+
cops.reject do |cop|
|
15
|
+
cop.excluded_file?(filename) ||
|
16
|
+
!support_target_ruby_version?(cop) ||
|
17
|
+
!support_target_chef_version?(cop) ||
|
18
|
+
!support_target_rails_version?(cop)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
### END COOKSTYLE MODIFICATION
|
22
|
+
end
|
23
|
+
end
|
24
|
+
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: 6.
|
4
|
+
version: 6.11.4
|
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: 2020-
|
12
|
+
date: 2020-07-09 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rubocop
|
@@ -17,14 +17,14 @@ dependencies:
|
|
17
17
|
requirements:
|
18
18
|
- - '='
|
19
19
|
- !ruby/object:Gem::Version
|
20
|
-
version: 0.
|
20
|
+
version: 0.87.1
|
21
21
|
type: :runtime
|
22
22
|
prerelease: false
|
23
23
|
version_requirements: !ruby/object:Gem::Requirement
|
24
24
|
requirements:
|
25
25
|
- - '='
|
26
26
|
- !ruby/object:Gem::Version
|
27
|
-
version: 0.
|
27
|
+
version: 0.87.1
|
28
28
|
description:
|
29
29
|
email:
|
30
30
|
- thom@chef.io
|
@@ -100,6 +100,7 @@ files:
|
|
100
100
|
- lib/rubocop/cop/chef/deprecation/eol_audit_mode.rb
|
101
101
|
- lib/rubocop/cop/chef/deprecation/epic_fail.rb
|
102
102
|
- lib/rubocop/cop/chef/deprecation/erl_call.rb
|
103
|
+
- lib/rubocop/cop/chef/deprecation/hwrp_without_provides.rb
|
103
104
|
- lib/rubocop/cop/chef/deprecation/inherits_compat_resource.rb
|
104
105
|
- lib/rubocop/cop/chef/deprecation/launchd_deprecated_hash_property.rb
|
105
106
|
- lib/rubocop/cop/chef/deprecation/legacy_notify_syntax.rb
|
@@ -119,9 +120,9 @@ files:
|
|
119
120
|
- lib/rubocop/cop/chef/deprecation/require_recipe.rb
|
120
121
|
- lib/rubocop/cop/chef/deprecation/resource_overrides_provides_method.rb
|
121
122
|
- lib/rubocop/cop/chef/deprecation/resource_uses_dsl_name_method.rb
|
123
|
+
- lib/rubocop/cop/chef/deprecation/resource_uses_only_resource_name.rb
|
122
124
|
- lib/rubocop/cop/chef/deprecation/resource_uses_provider_base_method.rb
|
123
125
|
- lib/rubocop/cop/chef/deprecation/resource_uses_updated_method.rb
|
124
|
-
- lib/rubocop/cop/chef/deprecation/resource_without_name_or_provides.rb
|
125
126
|
- lib/rubocop/cop/chef/deprecation/ruby_27_keyword_argument_warnings.rb
|
126
127
|
- lib/rubocop/cop/chef/deprecation/ruby_block_create_action.rb
|
127
128
|
- lib/rubocop/cop/chef/deprecation/run_command_helper.rb
|
@@ -148,6 +149,7 @@ files:
|
|
148
149
|
- lib/rubocop/cop/chef/modernize/chef_14_resources.rb
|
149
150
|
- lib/rubocop/cop/chef/modernize/chef_gem_nokogiri.rb
|
150
151
|
- lib/rubocop/cop/chef/modernize/compile_time_resources.rb
|
152
|
+
- lib/rubocop/cop/chef/modernize/conditional_using_test.rb
|
151
153
|
- lib/rubocop/cop/chef/modernize/cron_manage_resource.rb
|
152
154
|
- lib/rubocop/cop/chef/modernize/databag_helpers.rb
|
153
155
|
- lib/rubocop/cop/chef/modernize/default_action_initializer.rb
|
@@ -208,7 +210,9 @@ files:
|
|
208
210
|
- lib/rubocop/cop/chef/redundant/custom_resource_with_allowed_actions.rb
|
209
211
|
- lib/rubocop/cop/chef/redundant/grouping_metadata.rb
|
210
212
|
- lib/rubocop/cop/chef/redundant/long_description_metadata.rb
|
213
|
+
- lib/rubocop/cop/chef/redundant/multiple_platform_checks.rb
|
211
214
|
- lib/rubocop/cop/chef/redundant/name_property_and_required.rb
|
215
|
+
- lib/rubocop/cop/chef/redundant/ohai_attribute_to_string.rb
|
212
216
|
- lib/rubocop/cop/chef/redundant/property_splat_regex.rb
|
213
217
|
- lib/rubocop/cop/chef/redundant/property_with_default_and_required.rb
|
214
218
|
- lib/rubocop/cop/chef/redundant/provides_metadata.rb
|
@@ -225,6 +229,7 @@ files:
|
|
225
229
|
- lib/rubocop/cop/chef/sharing/empty_metadata_field.rb
|
226
230
|
- lib/rubocop/cop/chef/sharing/include_property_descriptions.rb
|
227
231
|
- lib/rubocop/cop/chef/sharing/include_resource_descriptions.rb
|
232
|
+
- lib/rubocop/cop/chef/sharing/include_resource_examples.rb
|
228
233
|
- lib/rubocop/cop/chef/sharing/insecure_cookbook_url.rb
|
229
234
|
- lib/rubocop/cop/chef/sharing/invalid_license_string.rb
|
230
235
|
- lib/rubocop/cop/chef/style/attribute_keys.rb
|
@@ -235,6 +240,7 @@ files:
|
|
235
240
|
- lib/rubocop/cop/chef/style/comments_format.rb
|
236
241
|
- lib/rubocop/cop/chef/style/file_mode.rb
|
237
242
|
- lib/rubocop/cop/chef/style/immediate_notification_timing.rb
|
243
|
+
- lib/rubocop/cop/chef/style/include_recipe_with_parentheses.rb
|
238
244
|
- lib/rubocop/cop/chef/style/negating_only_if.rb
|
239
245
|
- lib/rubocop/cop/chef/style/overly_complex_supports_depends_metadata.rb
|
240
246
|
- lib/rubocop/cop/chef/style/simplify_platform_major_version_check.rb
|
@@ -244,9 +250,10 @@ files:
|
|
244
250
|
- lib/rubocop/cop/chef/style/use_platform_helpers.rb
|
245
251
|
- lib/rubocop/cop/target_chef_version.rb
|
246
252
|
- lib/rubocop/monkey_patches/comment_config.rb
|
247
|
-
- lib/rubocop/monkey_patches/commissioner.rb
|
248
253
|
- lib/rubocop/monkey_patches/config.rb
|
249
254
|
- lib/rubocop/monkey_patches/cop.rb
|
255
|
+
- lib/rubocop/monkey_patches/registry_cop.rb
|
256
|
+
- lib/rubocop/monkey_patches/team.rb
|
250
257
|
homepage:
|
251
258
|
licenses:
|
252
259
|
- Apache-2.0
|
@@ -1,81 +0,0 @@
|
|
1
|
-
#
|
2
|
-
# Copyright:: 2020, 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
|
-
module ChefDeprecations
|
22
|
-
# In Chef Infra Client 16 and later a legacy HWRP resource must use either `resource_name` or `provides` to define the resource name.
|
23
|
-
#
|
24
|
-
# @example
|
25
|
-
#
|
26
|
-
# # bad
|
27
|
-
# class Chef
|
28
|
-
# class Resource
|
29
|
-
# class UlimitRule < Chef::Resource
|
30
|
-
# property :type, [Symbol, String], required: true
|
31
|
-
# property :item, [Symbol, String], required: true
|
32
|
-
#
|
33
|
-
# # additional resource code
|
34
|
-
# end
|
35
|
-
# end
|
36
|
-
# end
|
37
|
-
#
|
38
|
-
# # good
|
39
|
-
# class Chef
|
40
|
-
# class Resource
|
41
|
-
# class UlimitRule < Chef::Resource
|
42
|
-
# resource_name :ulimit_rule
|
43
|
-
#
|
44
|
-
# property :type, [Symbol, String], required: true
|
45
|
-
# property :item, [Symbol, String], required: true
|
46
|
-
#
|
47
|
-
# # additional resource code
|
48
|
-
# end
|
49
|
-
# end
|
50
|
-
# end
|
51
|
-
#
|
52
|
-
# # better
|
53
|
-
# Convert your legacy HWRPs to custom resources
|
54
|
-
#
|
55
|
-
class ResourceWithoutNameOrProvides < Cop
|
56
|
-
MSG = 'In Chef Infra Client 16 and later legacy HWRP resources must use either `resource_name` or `provides` to define the resource name.'.freeze
|
57
|
-
|
58
|
-
def_node_matcher :HWRP?, <<-PATTERN
|
59
|
-
(class
|
60
|
-
(const nil? :Chef) nil?
|
61
|
-
(class
|
62
|
-
(const nil? :Resource) nil?
|
63
|
-
$(class
|
64
|
-
(const nil? ... )
|
65
|
-
(const
|
66
|
-
(const nil? :Chef) :Resource)
|
67
|
-
(begin ... ))))
|
68
|
-
PATTERN
|
69
|
-
|
70
|
-
def_node_search :provides_or_resource_name?, '(send nil? {:provides :resource_name} ...)'
|
71
|
-
|
72
|
-
def on_class(node)
|
73
|
-
HWRP?(node) do |inherit|
|
74
|
-
add_offense(inherit, location: :expression, message: MSG, severity: :warning) if provides_or_resource_name?(processed_source.ast).nil?
|
75
|
-
end
|
76
|
-
end
|
77
|
-
end
|
78
|
-
end
|
79
|
-
end
|
80
|
-
end
|
81
|
-
end
|