cookstyle 6.0.19 → 6.1.6
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 +48 -7
- data/lib/cookstyle/version.rb +1 -1
- data/lib/rubocop/cop/chef/correctness/conditional_ruby_shellout.rb +72 -0
- data/lib/rubocop/cop/chef/deprecation/powershell_cookbook_helpers.rb +61 -0
- data/lib/rubocop/cop/chef/deprecation/windows_version_helpers.rb +74 -0
- data/lib/rubocop/cop/chef/effortless/berksfile.rb +2 -2
- data/lib/rubocop/cop/chef/modernize/depends_zypper_cookbook.rb +3 -3
- data/lib/rubocop/cop/chef/modernize/{windows_version_helper.rb → node_roles_include.rb} +21 -9
- data/lib/rubocop/cop/chef/modernize/powershell_install_windowsfeature.rb +3 -3
- data/lib/rubocop/cop/chef/sharing/include_property_descriptions.rb +53 -0
- data/lib/rubocop/cop/chef/sharing/include_resource_descriptions.rb +51 -0
- metadata +8 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2b60366fb42569f18aa8b379dff84bcceeb8ecb6b5feb52753cbd9c41575fd2c
|
4
|
+
data.tar.gz: '098c9ff5b266289457e5127b41eb1662191b4453dc0d31fb9a7955ea1774d995'
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 94a5cc1725f5264bc1d6abf84e5d8e8bc1e954609ea8ab5a080db7df7db0fc3333ba4d2a53199279f28e3b7567e2f22fe70c1c3564c1b11bd19e6d520790a02c
|
7
|
+
data.tar.gz: 113a4e827cd32b5c20e2fbc6ee561255d7a3f1508d930851f799aa6e8bc3d4ae850071fb3f302771cc5774ffec9d80bcd1e392e53e0f713d96acc0e41dee4bbb
|
data/config/cookstyle.yml
CHANGED
@@ -341,6 +341,15 @@ ChefCorrectness/PowershellScriptDeleteFile:
|
|
341
341
|
- '**/metadata.rb'
|
342
342
|
- '**/Berksfile'
|
343
343
|
|
344
|
+
ChefCorrectness/ConditionalRubyShellout:
|
345
|
+
Description: Don't use Ruby to shellout in an only_if / not_if conditional when you can shellout directly by wrapping the command in quotes.
|
346
|
+
Enabled: true
|
347
|
+
VersionAdded: '6.1.0'
|
348
|
+
Exclude:
|
349
|
+
- '**/attributes/*.rb'
|
350
|
+
- '**/metadata.rb'
|
351
|
+
- '**/Berksfile'
|
352
|
+
|
344
353
|
###############################
|
345
354
|
# ChefSharing: Issues that prevent sharing code with other teams or with the Chef community in general
|
346
355
|
###############################
|
@@ -377,6 +386,21 @@ ChefSharing/EmptyMetadataField:
|
|
377
386
|
Include:
|
378
387
|
- '**/metadata.rb'
|
379
388
|
|
389
|
+
ChefSharing/IncludePropertyDescriptions:
|
390
|
+
Description: Properties should include description fields to allow automated documention. Requires Chef Infra Client 13.9 or later.
|
391
|
+
Enabled: false
|
392
|
+
VersionAdded: '6.1.0'
|
393
|
+
Include:
|
394
|
+
- '**/libraries/*.rb'
|
395
|
+
- '**/resources/*.rb'
|
396
|
+
|
397
|
+
ChefSharing/IncludeResourceDescriptions:
|
398
|
+
Description: Resources should include description fields to allow automated documention. Requires Chef Infra Client 13.9 or later.
|
399
|
+
Enabled: false
|
400
|
+
VersionAdded: '6.1.0'
|
401
|
+
Include:
|
402
|
+
- '**/resources/*.rb'
|
403
|
+
|
380
404
|
###############################
|
381
405
|
# ChefDeprecations: Resolving Deprecations that block upgrading Chef Infra Client
|
382
406
|
###############################
|
@@ -774,6 +798,22 @@ ChefDeprecations/ResourceWithoutNameOrProvides:
|
|
774
798
|
Include:
|
775
799
|
- '**/libraries/*.rb'
|
776
800
|
|
801
|
+
ChefDeprecations/WindowsVersionHelpers:
|
802
|
+
Description: Use node['platform_version'] data instead of the Windows::VersionHelper helper from the Windows cookbook.
|
803
|
+
Enabled: true
|
804
|
+
VersionAdded: '5.4.0'
|
805
|
+
Exclude:
|
806
|
+
- '**/metadata.rb'
|
807
|
+
- '**/Berksfile'
|
808
|
+
|
809
|
+
ChefDeprecations/PowershellCookbookHelpers:
|
810
|
+
Description: Use node['powershell']['version'] or the new powershell_version helper available in Chef Infra Client 16+ instead of the deprecated PowerShell cookbook helpers.
|
811
|
+
Enabled: true
|
812
|
+
VersionAdded: '6.1.0'
|
813
|
+
Exclude:
|
814
|
+
- '**/metadata.rb'
|
815
|
+
- '**/Berksfile'
|
816
|
+
|
777
817
|
###############################
|
778
818
|
# ChefModernize: Cleaning up legacy code and using new built-in resources
|
779
819
|
###############################
|
@@ -867,13 +907,6 @@ ChefModernize/ExecuteAptUpdate:
|
|
867
907
|
Exclude:
|
868
908
|
- '**/metadata.rb'
|
869
909
|
|
870
|
-
ChefModernize/WindowsVersionHelper:
|
871
|
-
Description: Use node['platform_version'] data instead of the Windows::VersionHelper helper from the Windows cookbook.
|
872
|
-
Enabled: true
|
873
|
-
VersionAdded: '5.4.0'
|
874
|
-
Exclude:
|
875
|
-
- '**/metadata.rb'
|
876
|
-
|
877
910
|
ChefModernize/MinitestHandlerUsage:
|
878
911
|
Description: Use Chef InSpec for testing instead of the Minitest Handler cookbook pattern.
|
879
912
|
Enabled: true
|
@@ -1224,6 +1257,14 @@ ChefModernize/DatabagHelpers:
|
|
1224
1257
|
- '**/metadata.rb'
|
1225
1258
|
- '**/Berksfile'
|
1226
1259
|
|
1260
|
+
ChefModernize/NodeRolesInclude:
|
1261
|
+
Description: Use `node.role?('foo')` to check if a node includes a role instead of `node['roles'].include?('foo')`.
|
1262
|
+
Enabled: true
|
1263
|
+
VersionAdded: '6.1.0'
|
1264
|
+
Exclude:
|
1265
|
+
- '**/metadata.rb'
|
1266
|
+
- '**/Berksfile'
|
1267
|
+
|
1227
1268
|
###############################
|
1228
1269
|
# ChefRedundantCode: Cleanup unnecessary code in your cookbooks regardless of Chef Infra Client release
|
1229
1270
|
###############################
|
data/lib/cookstyle/version.rb
CHANGED
@@ -0,0 +1,72 @@
|
|
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
|
+
module RuboCop
|
18
|
+
module Cop
|
19
|
+
module Chef
|
20
|
+
module ChefCorrectness
|
21
|
+
# Don't use Ruby to shellout in a only_if / not_if conditional when you can just shellout directly. Any string value used with only_if / not_if is executed in your system's shell and the return code of the command is the result for the not_if / only_if determination.
|
22
|
+
#
|
23
|
+
# @example
|
24
|
+
#
|
25
|
+
# # bad
|
26
|
+
# cookbook_file '/logs/foo/error.log' do
|
27
|
+
# source 'error.log'
|
28
|
+
# only_if { system('wget https://www.bar.com/foobar.txt -O /dev/null') }
|
29
|
+
# end
|
30
|
+
#
|
31
|
+
# cookbook_file '/logs/foo/error.log' do
|
32
|
+
# source 'error.log'
|
33
|
+
# only_if { shell_out('wget https://www.bar.com/foobar.txt -O /dev/null').exitstatus == 0 }
|
34
|
+
# end
|
35
|
+
#
|
36
|
+
# # good
|
37
|
+
# cookbook_file '/logs/foo/error.log' do
|
38
|
+
# source 'error.log'
|
39
|
+
# only_if 'wget https://www.bar.com/foobar.txt -O /dev/null'
|
40
|
+
# end
|
41
|
+
#
|
42
|
+
class ConditionalRubyShellout < Cop
|
43
|
+
include RuboCop::Chef::CookbookHelpers
|
44
|
+
MSG = "Don't use Ruby to shellout in an only_if / not_if conditional when you can shellout directly by wrapping the command in quotes.".freeze
|
45
|
+
|
46
|
+
def_node_matcher :conditional_shellout?, <<-PATTERN
|
47
|
+
(block
|
48
|
+
(send nil? ${:only_if :not_if})
|
49
|
+
(args)
|
50
|
+
{(send nil? :system $(str ...))
|
51
|
+
(send (send (send nil? :shell_out $(str ...)) :exitstatus) :== (int 0))
|
52
|
+
})
|
53
|
+
PATTERN
|
54
|
+
|
55
|
+
def on_block(node)
|
56
|
+
conditional_shellout?(node) do
|
57
|
+
add_offense(node, location: :expression, message: MSG, severity: :refactor)
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
def autocorrect(node)
|
62
|
+
lambda do |corrector|
|
63
|
+
conditional_shellout?(node) do |type, val|
|
64
|
+
corrector.replace(node.loc.expression, "#{type} #{val.source}")
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
@@ -0,0 +1,61 @@
|
|
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
|
+
module RuboCop
|
18
|
+
module Cop
|
19
|
+
module Chef
|
20
|
+
module ChefDeprecations
|
21
|
+
# Use node['powershell']['version'] or the new powershell_version helper available in Chef Infra Client 16+ instead of the deprecated PowerShell cookbook helpers
|
22
|
+
#
|
23
|
+
# @example
|
24
|
+
#
|
25
|
+
# # bad
|
26
|
+
# Powershell::VersionHelper.powershell_version?('4.0')
|
27
|
+
#
|
28
|
+
# # good
|
29
|
+
# node['powershell']['version'].to_f == 4.0
|
30
|
+
#
|
31
|
+
# # good (Chef Infra Client 16+)
|
32
|
+
# powershell_version == 4.0
|
33
|
+
#
|
34
|
+
class PowershellCookbookHelpers < Cop
|
35
|
+
MSG = "Use node['powershell']['version'] or the new powershell_version helper available in Chef Infra Client 16+ instead of the deprecated PowerShell cookbook helpers.".freeze
|
36
|
+
|
37
|
+
def_node_matcher :ps_cb_helper?, <<-PATTERN
|
38
|
+
(send
|
39
|
+
(const
|
40
|
+
(const {cbase nil?} :Powershell) :VersionHelper) :powershell_version?
|
41
|
+
$(...))
|
42
|
+
PATTERN
|
43
|
+
|
44
|
+
def on_send(node)
|
45
|
+
ps_cb_helper?(node) do
|
46
|
+
add_offense(node, location: :expression, message: MSG, severity: :warning)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
def autocorrect(node)
|
51
|
+
lambda do |corrector|
|
52
|
+
ps_cb_helper?(node) do |ver|
|
53
|
+
corrector.replace(node.loc.expression, "node['powershell']['version'].to_f == #{ver.source}")
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
@@ -0,0 +1,74 @@
|
|
1
|
+
#
|
2
|
+
# Copyright:: 2019-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 ChefDeprecations
|
21
|
+
# Use node['platform_version'] and node['kernel'] data instead of the deprecated Windows::VersionHelper helpers from the Windows cookbook.
|
22
|
+
#
|
23
|
+
# @example
|
24
|
+
#
|
25
|
+
# # bad
|
26
|
+
# Windows::VersionHelper.nt_version
|
27
|
+
# Windows::VersionHelper.server_version?
|
28
|
+
# Windows::VersionHelper.core_version?
|
29
|
+
# Windows::VersionHelper.workstation_version?
|
30
|
+
#
|
31
|
+
# # good
|
32
|
+
# node['platform_version'].to_f
|
33
|
+
# node['kernel']['product_type'] == 'Server'
|
34
|
+
# node['kernel']['server_core']
|
35
|
+
# node['kernel']['product_type'] == 'Workstation'
|
36
|
+
#
|
37
|
+
class WindowsVersionHelpers < Cop
|
38
|
+
extend TargetChefVersion
|
39
|
+
|
40
|
+
minimum_target_chef_version '14.0'
|
41
|
+
|
42
|
+
MSG = "Use node['platform_version'] and node['kernel'] data introduced in Chef Infra Client 14 instead of the deprecated Windows::VersionHelper helpers from the Windows cookbook.".freeze
|
43
|
+
|
44
|
+
def_node_matcher :windows_helper?, <<-PATTERN
|
45
|
+
(send ( const ( const {nil? cbase} :Windows ) :VersionHelper ) $_ )
|
46
|
+
PATTERN
|
47
|
+
|
48
|
+
def on_send(node)
|
49
|
+
windows_helper?(node) do
|
50
|
+
add_offense(node, location: :expression, message: MSG, severity: :refactor)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
def autocorrect(node)
|
55
|
+
lambda do |corrector|
|
56
|
+
windows_helper?(node) do |method|
|
57
|
+
case method
|
58
|
+
when :nt_version
|
59
|
+
corrector.replace(node.loc.expression, 'node[\'platform_version\'].to_f')
|
60
|
+
when :server_version?
|
61
|
+
corrector.replace(node.loc.expression, 'node[\'kernel\'][\'product_type\'] == \'Server\'')
|
62
|
+
when :core_version?
|
63
|
+
corrector.replace(node.loc.expression, 'node[\'kernel\'][\'server_core\']')
|
64
|
+
when :workstation_version?
|
65
|
+
corrector.replace(node.loc.expression, 'node[\'kernel\'][\'product_type\'] == \'Workstation\'')
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
@@ -18,9 +18,9 @@
|
|
18
18
|
module RuboCop
|
19
19
|
module Cop
|
20
20
|
module Chef
|
21
|
-
# Policyfiles should be used for cookbook dependency solving instead of a Berkshelf Berksfile.
|
22
|
-
#
|
23
21
|
module ChefEffortless
|
22
|
+
# Policyfiles should be used for cookbook dependency solving instead of a Berkshelf Berksfile.
|
23
|
+
#
|
24
24
|
class Berksfile < Cop
|
25
25
|
include RangeHelp
|
26
26
|
|
@@ -1,5 +1,5 @@
|
|
1
1
|
#
|
2
|
-
# Copyright:: 2019, Chef Software, Inc.
|
2
|
+
# Copyright:: 2019-2020, 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 ChefModernize
|
21
|
-
# Don't depend the zypper cookbook as the zypper_repository resource is built into Chef Infra Client 13.3
|
21
|
+
# Don't depend on the zypper cookbook as the zypper_repository resource is built into Chef Infra Client 13.3+
|
22
22
|
#
|
23
23
|
# @example
|
24
24
|
#
|
@@ -31,7 +31,7 @@ module RuboCop
|
|
31
31
|
|
32
32
|
minimum_target_chef_version '13.3'
|
33
33
|
|
34
|
-
MSG = "Don't
|
34
|
+
MSG = "Don't depend on the zypper cookbook as the zypper_repository resource is built into Chef Infra Client 13.3+".freeze
|
35
35
|
|
36
36
|
def_node_matcher :zypper_depends?, <<-PATTERN
|
37
37
|
(send nil? :depends (str "zypper"))
|
@@ -1,5 +1,5 @@
|
|
1
1
|
#
|
2
|
-
# Copyright::
|
2
|
+
# Copyright:: 2020, 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,28 +18,40 @@ module RuboCop
|
|
18
18
|
module Cop
|
19
19
|
module Chef
|
20
20
|
module ChefModernize
|
21
|
-
# Use node
|
21
|
+
# Use `node.role?('foo')` to check if a node includes a role instead of `node['roles'].include?('foo')`.
|
22
22
|
#
|
23
23
|
# @example
|
24
24
|
#
|
25
25
|
# # bad
|
26
|
-
#
|
26
|
+
# node['roles'].include?('foo')
|
27
27
|
#
|
28
28
|
# # good
|
29
|
-
# node
|
29
|
+
# node.role?('foo')
|
30
30
|
#
|
31
|
-
class
|
32
|
-
MSG = "Use node
|
31
|
+
class NodeRolesInclude < Cop
|
32
|
+
MSG = "Use `node.role?('foo')` to check if a node includes a role instead of `node['roles'].include?('foo')`.".freeze
|
33
33
|
|
34
|
-
def_node_matcher :
|
35
|
-
|
34
|
+
def_node_matcher :node_role_include?, <<-PATTERN
|
35
|
+
(send
|
36
|
+
(send
|
37
|
+
(send nil? :node) :[]
|
38
|
+
(str "roles")) :include?
|
39
|
+
$(...))
|
36
40
|
PATTERN
|
37
41
|
|
38
42
|
def on_send(node)
|
39
|
-
|
43
|
+
node_role_include?(node) do
|
40
44
|
add_offense(node, location: :expression, message: MSG, severity: :refactor)
|
41
45
|
end
|
42
46
|
end
|
47
|
+
|
48
|
+
def autocorrect(node)
|
49
|
+
lambda do |corrector|
|
50
|
+
node_role_include?(node) do |val|
|
51
|
+
corrector.replace(node.loc.expression, "node.role?(#{val.source})")
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
43
55
|
end
|
44
56
|
end
|
45
57
|
end
|
@@ -18,7 +18,7 @@ module RuboCop
|
|
18
18
|
module Cop
|
19
19
|
module Chef
|
20
20
|
module ChefModernize
|
21
|
-
# Use the windows_feature resource built into Chef Infra Client
|
21
|
+
# Use the windows_feature resource built into Chef Infra Client 14+ instead of the powershell_script resource
|
22
22
|
# to run Install-WindowsFeature or Add-WindowsFeature
|
23
23
|
#
|
24
24
|
# @example
|
@@ -38,9 +38,9 @@ module RuboCop
|
|
38
38
|
include RuboCop::Chef::CookbookHelpers
|
39
39
|
extend TargetChefVersion
|
40
40
|
|
41
|
-
minimum_target_chef_version '
|
41
|
+
minimum_target_chef_version '14.0'
|
42
42
|
|
43
|
-
MSG = 'Use the windows_feature resource built into Chef Infra Client
|
43
|
+
MSG = 'Use the windows_feature resource built into Chef Infra Client 14+ instead of using Install-WindowsFeature or Add-WindowsFeature in a powershell_script resource'.freeze
|
44
44
|
|
45
45
|
def on_block(node)
|
46
46
|
match_property_in_resource?(:powershell_script, 'code', node) do |code_property|
|
@@ -0,0 +1,53 @@
|
|
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
|
+
# Resource properties should include description fields to allow automated documention. Requires Chef Infra Client 13.9 or later.
|
22
|
+
#
|
23
|
+
# @example
|
24
|
+
#
|
25
|
+
# # bad
|
26
|
+
# property :foo, String
|
27
|
+
#
|
28
|
+
# # good
|
29
|
+
# property :foo, String, description: "Set the important thing to..."
|
30
|
+
#
|
31
|
+
class IncludePropertyDescriptions < Cop
|
32
|
+
extend TargetChefVersion
|
33
|
+
|
34
|
+
minimum_target_chef_version '13.9'
|
35
|
+
|
36
|
+
MSG = 'Resource properties should include description fields to allow automated documention. Requires Chef Infra Client 13.9 or later.'.freeze
|
37
|
+
|
38
|
+
# any method named property being called with a symbol argument and anything else
|
39
|
+
def_node_matcher :property?, '(send nil? :property (sym _) ...)'
|
40
|
+
|
41
|
+
# hash that contains description in any order (that's the <> bit)
|
42
|
+
def_node_search :description_hash, '(hash <(pair (sym :description) ...) ...>)'
|
43
|
+
|
44
|
+
def on_send(node)
|
45
|
+
property?(node) do
|
46
|
+
add_offense(node, location: :expression, message: MSG, severity: :refactor) unless description_hash(processed_source.ast).any?
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
@@ -0,0 +1,51 @@
|
|
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 description fields to allow automated documention. Requires Chef Infra Client 13.9 or later.
|
22
|
+
#
|
23
|
+
# @example
|
24
|
+
#
|
25
|
+
# # good
|
26
|
+
# resource_name :foo
|
27
|
+
# description "The foo resource is used to do..."
|
28
|
+
#
|
29
|
+
class IncludeResourceDescriptions < Cop
|
30
|
+
include RangeHelp
|
31
|
+
extend TargetChefVersion
|
32
|
+
|
33
|
+
minimum_target_chef_version '13.9'
|
34
|
+
|
35
|
+
MSG = 'Resources should include description fields to allow automated documention. Requires Chef Infra Client 13.9 or later.'.freeze
|
36
|
+
|
37
|
+
def investigate(processed_source)
|
38
|
+
return if processed_source.blank?
|
39
|
+
|
40
|
+
# Using range similar to RuboCop::Cop::Naming::Filename (file_name.rb)
|
41
|
+
range = source_range(processed_source.buffer, 1, 0)
|
42
|
+
|
43
|
+
add_offense(nil, location: range, message: MSG, severity: :refactor) unless resource_description(processed_source.ast).any?
|
44
|
+
end
|
45
|
+
|
46
|
+
def_node_search :resource_description, '(send nil? :description str ...)'
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
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.1.6
|
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-03-
|
12
|
+
date: 2020-03-27 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rubocop
|
@@ -52,6 +52,7 @@ files:
|
|
52
52
|
- lib/rubocop/cop/chef/correctness/block_guard_clause_string_only.rb
|
53
53
|
- lib/rubocop/cop/chef/correctness/cb_depends_on_self.rb
|
54
54
|
- lib/rubocop/cop/chef/correctness/chef_application_fatal.rb
|
55
|
+
- lib/rubocop/cop/chef/correctness/conditional_ruby_shellout.rb
|
55
56
|
- lib/rubocop/cop/chef/correctness/dnf_package_allow_downgrades.rb
|
56
57
|
- lib/rubocop/cop/chef/correctness/incorrect_library_injection.rb
|
57
58
|
- lib/rubocop/cop/chef/correctness/invalid_notification_timing.rb
|
@@ -109,6 +110,7 @@ files:
|
|
109
110
|
- lib/rubocop/cop/chef/deprecation/partial_search_class_usage.rb
|
110
111
|
- lib/rubocop/cop/chef/deprecation/partial_search_helper_usage.rb
|
111
112
|
- lib/rubocop/cop/chef/deprecation/poise_archive.rb
|
113
|
+
- lib/rubocop/cop/chef/deprecation/powershell_cookbook_helpers.rb
|
112
114
|
- lib/rubocop/cop/chef/deprecation/require_recipe.rb
|
113
115
|
- lib/rubocop/cop/chef/deprecation/resource_overrides_provides_method.rb
|
114
116
|
- lib/rubocop/cop/chef/deprecation/resource_uses_dsl_name_method.rb
|
@@ -123,6 +125,7 @@ files:
|
|
123
125
|
- lib/rubocop/cop/chef/deprecation/verify_property_file_expansion.rb
|
124
126
|
- lib/rubocop/cop/chef/deprecation/windows_feature_servermanagercmd.rb
|
125
127
|
- lib/rubocop/cop/chef/deprecation/windows_task_change_action.rb
|
128
|
+
- lib/rubocop/cop/chef/deprecation/windows_version_helpers.rb
|
126
129
|
- lib/rubocop/cop/chef/deprecation/xml_ruby_recipe.rb
|
127
130
|
- lib/rubocop/cop/chef/deprecation/yum_dnf_compat_recipe.rb
|
128
131
|
- lib/rubocop/cop/chef/effortless/berksfile.rb
|
@@ -159,6 +162,7 @@ files:
|
|
159
162
|
- lib/rubocop/cop/chef/modernize/macos_user_defaults.rb
|
160
163
|
- lib/rubocop/cop/chef/modernize/minitest_handler_usage.rb
|
161
164
|
- lib/rubocop/cop/chef/modernize/node_init_package.rb
|
165
|
+
- lib/rubocop/cop/chef/modernize/node_roles_include.rb
|
162
166
|
- lib/rubocop/cop/chef/modernize/ohai_default_recipe.rb
|
163
167
|
- lib/rubocop/cop/chef/modernize/openssl_rsa_key_resource.rb
|
164
168
|
- lib/rubocop/cop/chef/modernize/openssl_x509_resource.rb
|
@@ -186,7 +190,6 @@ files:
|
|
186
190
|
- lib/rubocop/cop/chef/modernize/whyrun_supported_true.rb
|
187
191
|
- lib/rubocop/cop/chef/modernize/windows_default_recipe.rb
|
188
192
|
- lib/rubocop/cop/chef/modernize/windows_registry_uac.rb
|
189
|
-
- lib/rubocop/cop/chef/modernize/windows_version_helper.rb
|
190
193
|
- lib/rubocop/cop/chef/modernize/windows_zipfile.rb
|
191
194
|
- lib/rubocop/cop/chef/modernize/zipfile_resource.rb
|
192
195
|
- lib/rubocop/cop/chef/modernize/zypper_repo.rb
|
@@ -211,6 +214,8 @@ files:
|
|
211
214
|
- lib/rubocop/cop/chef/redundant/unnecessary_name_property.rb
|
212
215
|
- lib/rubocop/cop/chef/sharing/default_maintainer_metadata.rb
|
213
216
|
- lib/rubocop/cop/chef/sharing/empty_metadata_field.rb
|
217
|
+
- lib/rubocop/cop/chef/sharing/include_property_descriptions.rb
|
218
|
+
- lib/rubocop/cop/chef/sharing/include_resource_descriptions.rb
|
214
219
|
- lib/rubocop/cop/chef/sharing/insecure_cookbook_url.rb
|
215
220
|
- lib/rubocop/cop/chef/sharing/invalid_license_string.rb
|
216
221
|
- lib/rubocop/cop/chef/style/attribute_keys.rb
|