cookstyle 6.7.3 → 6.8.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.
- checksums.yaml +4 -4
- data/config/cookstyle.yml +3 -2
- data/lib/cookstyle/version.rb +2 -2
- data/lib/rubocop/cop/chef/deprecation/hwrp_without_provides.rb +141 -0
- data/lib/rubocop/cop/chef/deprecation/resource_uses_only_resource_name.rb +22 -13
- metadata +5 -5
- data/lib/rubocop/cop/chef/deprecation/resource_without_name_or_provides.rb +0 -81
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: df67335031d87f8782e6511ad4e1fbbf3dc40e5b9cfdec6f9cee45c6acd3cb38
|
4
|
+
data.tar.gz: 52a46161cd9e6d11643ae5b2b945347d69fac127f14878ebe1875d0cb1b34cd4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bb3a7a9c0cd62c6b664d659c565c0a48d3f496fa371e26349030539c8ddbfa6d30c4f7545d5c2b33f5bf268b7348867e4d010626488286c86b9bb1e720cb3ae1
|
7
|
+
data.tar.gz: 8af9e42d0f12bc1b0c262a341a60bee272831afb40cf3ff89ddbbf9865115c6d3162d4da4df85636e84c7391c8d75db776b5cd574c7c280aa09971d63674dd03
|
data/config/cookstyle.yml
CHANGED
@@ -946,11 +946,12 @@ ChefDeprecations/LogResourceNotifications:
|
|
946
946
|
- '**/metadata.rb'
|
947
947
|
- '**/Berksfile'
|
948
948
|
|
949
|
-
ChefDeprecations/
|
950
|
-
Description: In Chef Infra Client 16 and later legacy HWRP
|
949
|
+
ChefDeprecations/HWRPWithoutProvides:
|
950
|
+
Description: In Chef Infra Client 16 and later a legacy HWRP resource must use `provides` to define how the resource is called in recipes or other resources. To maintain compatibility with Chef Infra Client < 16 use both `resource_name` and `provides`.
|
951
951
|
StyleGuide: '#chefdeprecationsresourcewithoutnameorprovides'
|
952
952
|
Enabled: true
|
953
953
|
VersionAdded: '6.0.0'
|
954
|
+
VersionChanged: '6.8.0'
|
954
955
|
Include:
|
955
956
|
- '**/libraries/*.rb'
|
956
957
|
|
data/lib/cookstyle/version.rb
CHANGED
@@ -0,0 +1,141 @@
|
|
1
|
+
#
|
2
|
+
# Copyright:: Copyright (c) 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
|
+
# Chef Infra Client 16 and later a legacy HWRP resource must use `provides` to define how the resource is called in recipes or other resources. To maintain compatibility with Chef Infra Client < 16 use both `resource_name` and `provides`.
|
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
|
+
# # bad
|
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
|
+
# # good when Chef Infra Client < 15 (but compatible with 16+ as well)
|
53
|
+
# class Chef
|
54
|
+
# class Resource
|
55
|
+
# class UlimitRule < Chef::Resource
|
56
|
+
# resource_name :ulimit_rule
|
57
|
+
# provides :ulimit_rule
|
58
|
+
#
|
59
|
+
# property :type, [Symbol, String], required: true
|
60
|
+
# property :item, [Symbol, String], required: true
|
61
|
+
#
|
62
|
+
# # additional resource code
|
63
|
+
# end
|
64
|
+
# end
|
65
|
+
# end
|
66
|
+
#
|
67
|
+
# # good when Chef Infra Client 16+
|
68
|
+
# class Chef
|
69
|
+
# class Resource
|
70
|
+
# class UlimitRule < Chef::Resource
|
71
|
+
# provides :ulimit_rule
|
72
|
+
#
|
73
|
+
# property :type, [Symbol, String], required: true
|
74
|
+
# property :item, [Symbol, String], required: true
|
75
|
+
#
|
76
|
+
# # additional resource code
|
77
|
+
# end
|
78
|
+
# end
|
79
|
+
# end
|
80
|
+
#
|
81
|
+
# # better
|
82
|
+
# Convert your legacy HWRPs to custom resources
|
83
|
+
#
|
84
|
+
class HWRPWithoutProvides < Cop
|
85
|
+
MSG = 'In Chef Infra Client 16 and later a legacy HWRP resource must use `provides` to define how the resource is called in recipes or other resources. To maintain compatibility with Chef Infra Client < 16 use both `resource_name` and `provides`.'.freeze
|
86
|
+
|
87
|
+
def_node_matcher :HWRP?, <<-PATTERN
|
88
|
+
(class
|
89
|
+
(const nil? :Chef) nil?
|
90
|
+
(class
|
91
|
+
(const nil? :Resource) nil?
|
92
|
+
$(class
|
93
|
+
(const nil? ... )
|
94
|
+
(const
|
95
|
+
(const nil? :Chef) :Resource)
|
96
|
+
(begin ... ))))
|
97
|
+
PATTERN
|
98
|
+
|
99
|
+
def_node_search :provides, '(send nil? :provides (sym $_) ...)'
|
100
|
+
def_node_search :resource_name_ast, '$(send nil? :resource_name ...)'
|
101
|
+
def_node_search :resource_name, '(send nil? :resource_name (sym $_))'
|
102
|
+
|
103
|
+
def on_class(node)
|
104
|
+
HWRP?(node) do |inherit|
|
105
|
+
add_offense(inherit, location: :expression, message: MSG, severity: :warning) unless has_provides?
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
def has_provides?
|
110
|
+
provides_ast = provides(processed_source.ast)
|
111
|
+
return false if provides_ast.count == 0
|
112
|
+
|
113
|
+
resource_ast = resource_name(processed_source.ast)
|
114
|
+
|
115
|
+
if resource_ast.count == 0
|
116
|
+
true # no resource_name, but provides
|
117
|
+
else
|
118
|
+
# since we have a resource and provides make sure the there is a provides that
|
119
|
+
# matches the resource name
|
120
|
+
provides_ast.include?(resource_ast.first)
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
124
|
+
def indentation(node)
|
125
|
+
node.source_range.source_line =~ /\S/
|
126
|
+
end
|
127
|
+
|
128
|
+
def autocorrect(node)
|
129
|
+
lambda do |corrector|
|
130
|
+
resource_name_ast(node) do |ast_match|
|
131
|
+
# build a new string to add after that includes the new line and the proper indentation
|
132
|
+
new_string = "\n" + ast_match.source.dup.gsub('resource_name', 'provides').prepend(' ' * indentation(ast_match))
|
133
|
+
corrector.insert_after(ast_match.source_range, new_string)
|
134
|
+
end
|
135
|
+
end
|
136
|
+
end
|
137
|
+
end
|
138
|
+
end
|
139
|
+
end
|
140
|
+
end
|
141
|
+
end
|
@@ -1,5 +1,5 @@
|
|
1
1
|
#
|
2
|
-
# Copyright::
|
2
|
+
# Copyright:: Copyright (c) Chef Software Inc.
|
3
3
|
# Author:: Tim Smith (<tsmith@chef.io>)
|
4
4
|
#
|
5
5
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
@@ -18,7 +18,7 @@ module RuboCop
|
|
18
18
|
module Cop
|
19
19
|
module Chef
|
20
20
|
module ChefDeprecations
|
21
|
-
# Starting with Chef Infra Client 16, using `resource_name` without also using `provides` will result in resource failures.
|
21
|
+
# Starting with Chef Infra Client 16, using `resource_name` without also using `provides` will result in resource failures. Make sure to use both `resource_name` and `provides` to change the name of the resource. You can also omit `resource_name` entirely if the value set matches the name Chef Infra Client automatically assigns based on COOKBOOKNAME_FILENAME.
|
22
22
|
#
|
23
23
|
# @example
|
24
24
|
#
|
@@ -30,18 +30,17 @@ module RuboCop
|
|
30
30
|
include RuboCop::Chef::CookbookHelpers
|
31
31
|
include RangeHelp
|
32
32
|
|
33
|
-
MSG = 'Starting with Chef Infra Client 16, using `resource_name` without also using `provides` will result in resource failures.
|
33
|
+
MSG = 'Starting with Chef Infra Client 16, using `resource_name` without also using `provides` will result in resource failures. Make sure to use both `resource_name` and `provides` to change the name of the resource. You can also omit `resource_name` entirely if the value set matches the name Chef Infra Client automatically assigns based on COOKBOOKNAME_FILENAME.'.freeze
|
34
34
|
|
35
|
-
def_node_matcher :resource_name?,
|
36
|
-
(send nil? :resource_name (sym $_ ))
|
37
|
-
PATTERN
|
35
|
+
def_node_matcher :resource_name?, '(send nil? :resource_name (sym $_ ))'
|
38
36
|
|
39
|
-
def_node_search :cb_name_match,
|
40
|
-
(send nil? :name (str $_))
|
41
|
-
PATTERN
|
37
|
+
def_node_search :cb_name_match, '(send nil? :name (str $_))'
|
42
38
|
|
43
|
-
def_node_search :
|
39
|
+
def_node_search :provides, '(send nil? :provides (sym $_) ...)'
|
44
40
|
|
41
|
+
# determine the cookbook name either by parsing metdata.rb or by parsing metata.json
|
42
|
+
#
|
43
|
+
# @returns [String] the cookbook name
|
45
44
|
def cookbook_name
|
46
45
|
cb_path = File.expand_path(File.join(processed_source.file_path, '../..'))
|
47
46
|
|
@@ -53,9 +52,19 @@ module RuboCop
|
|
53
52
|
end
|
54
53
|
end
|
55
54
|
|
55
|
+
# given a resource name make sure there's a provides that matches that name
|
56
|
+
#
|
57
|
+
# @returns [TrueClass, FalseClass]
|
58
|
+
def valid_provides?(resource_name)
|
59
|
+
provides_ast = provides(processed_source.ast)
|
60
|
+
return false unless provides_ast
|
61
|
+
|
62
|
+
provides_ast.include?(resource_name)
|
63
|
+
end
|
64
|
+
|
56
65
|
def on_send(node)
|
57
|
-
resource_name?(node) do |
|
58
|
-
add_offense(node, location: :expression, message: MSG, severity: :warning) unless
|
66
|
+
resource_name?(node) do |r_name|
|
67
|
+
add_offense(node, location: :expression, message: MSG, severity: :warning) unless valid_provides?(r_name)
|
59
68
|
end
|
60
69
|
end
|
61
70
|
|
@@ -65,7 +74,7 @@ module RuboCop
|
|
65
74
|
if name.to_s == "#{cookbook_name}_#{File.basename(processed_source.path, '.rb')}"
|
66
75
|
corrector.remove(range_with_surrounding_space(range: node.loc.expression, side: :left))
|
67
76
|
else
|
68
|
-
corrector.
|
77
|
+
corrector.insert_after(node.source_range, "\n#{node.source.gsub('resource_name', 'provides')}")
|
69
78
|
end
|
70
79
|
end
|
71
80
|
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.8.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: 2020-06-
|
12
|
+
date: 2020-06-08 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.85.
|
20
|
+
version: 0.85.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.85.
|
27
|
+
version: 0.85.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
|
@@ -122,7 +123,6 @@ files:
|
|
122
123
|
- lib/rubocop/cop/chef/deprecation/resource_uses_only_resource_name.rb
|
123
124
|
- lib/rubocop/cop/chef/deprecation/resource_uses_provider_base_method.rb
|
124
125
|
- lib/rubocop/cop/chef/deprecation/resource_uses_updated_method.rb
|
125
|
-
- lib/rubocop/cop/chef/deprecation/resource_without_name_or_provides.rb
|
126
126
|
- lib/rubocop/cop/chef/deprecation/ruby_27_keyword_argument_warnings.rb
|
127
127
|
- lib/rubocop/cop/chef/deprecation/ruby_block_create_action.rb
|
128
128
|
- lib/rubocop/cop/chef/deprecation/run_command_helper.rb
|
@@ -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
|