cookstyle 5.9.3 → 5.10.11
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 +77 -1
- data/lib/cookstyle/version.rb +1 -1
- data/lib/rubocop/cop/chef/correctness/incorrect_library_injection.rb +60 -0
- data/lib/rubocop/cop/chef/correctness/node_normal.rb +1 -1
- data/lib/rubocop/cop/chef/correctness/node_normal_unless.rb +1 -1
- data/lib/rubocop/cop/chef/correctness/notifies_action_not_symbol.rb +56 -0
- data/lib/rubocop/cop/chef/deprecation/deprecated_yum_repository_properties.rb +65 -0
- data/lib/rubocop/cop/chef/deprecation/eol_audit_mode.rb +48 -0
- data/lib/rubocop/cop/chef/deprecation/inherits_compat_resource.rb +61 -0
- data/lib/rubocop/cop/chef/deprecation/node_set.rb +1 -1
- data/lib/rubocop/cop/chef/deprecation/node_set_unless.rb +1 -1
- data/lib/rubocop/cop/chef/deprecation/verify_property_file_expansion.rb +55 -0
- data/lib/rubocop/cop/chef/effortless/node_environment.rb +41 -0
- data/lib/rubocop/cop/chef/effortless/node_policygroup.rb +40 -0
- data/lib/rubocop/cop/chef/effortless/node_roles.rb +41 -0
- data/lib/rubocop/cop/chef/modernize/default_action_initializer.rb +66 -0
- data/lib/rubocop/cop/chef/modernize/resource_name_initializer.rb +66 -0
- data/lib/rubocop/cop/chef/modernize/resource_with_allowed_actions.rb +29 -9
- metadata +13 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f5b67cdd58b4a1b059bc220b84e9b61fc242690234cae85cdc06798c96926d39
|
4
|
+
data.tar.gz: c8c1f767761dffcdf81111e4886b566458bb1337cea63826addccc78341359c2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 396a689a645d364c225cdba6ec31380b77450d0336a1b3f9d4c3b146220a9ba0a723009892fba86ef82e02e3b88b024555a983ab7cd04df8ab5b5baaca388acc
|
7
|
+
data.tar.gz: bd65a338641f061e1e6bfaf935096e2b4dc4fec7789ade64421cf615ddf668b1f694e561f11105ddcf066bb8bb975a4b80728f10257425c146f7f7ac8e120570
|
data/config/cookstyle.yml
CHANGED
@@ -237,6 +237,20 @@ ChefCorrectness/InvalidVersionMetadata:
|
|
237
237
|
Include:
|
238
238
|
- '**/metadata.rb'
|
239
239
|
|
240
|
+
ChefCorrectness/NotifiesActionNotSymbol:
|
241
|
+
Description: When notifying an action within a resource the action should always be a symbol. In Chef Infra Client releases before 14.0 this may result in double notification.
|
242
|
+
Enabled: true
|
243
|
+
VersionAdded: '5.10.0'
|
244
|
+
Include:
|
245
|
+
- '**/metadata.rb'
|
246
|
+
|
247
|
+
ChefCorrectness/IncorrectLibraryInjection:
|
248
|
+
Description: Libraries should be injected into the Chef::DSL::Recipe or Chef::DSL::Resource classes and not Recipe/Resource/Provider classes directly.
|
249
|
+
Enabled: true
|
250
|
+
VersionAdded: '5.10.0'
|
251
|
+
Include:
|
252
|
+
- '**/metadata.rb'
|
253
|
+
|
240
254
|
###############################
|
241
255
|
# ChefDeprecations: Resolving Deprecations that block upgrading Chef Infra Client
|
242
256
|
###############################
|
@@ -514,6 +528,34 @@ ChefDeprecations/ChefHandlerUsesSupports:
|
|
514
528
|
Exclude:
|
515
529
|
- '**/metadata.rb'
|
516
530
|
|
531
|
+
ChefDeprecations/DeprecatedYumRepositoryProperties:
|
532
|
+
Description: With the release of Chef Infra Client 12.14 and the yum cookbook 3.0 several properties in the yum_repository resource were renamed. url -> baseurl, keyurl -> gpgkey, and mirrorexpire -> mirror_expire.
|
533
|
+
Enabled: true
|
534
|
+
VersionAdded: '5.10.0'
|
535
|
+
Exclude:
|
536
|
+
- '**/metadata.rb'
|
537
|
+
|
538
|
+
ChefDeprecations/EOLAuditModeUsage:
|
539
|
+
Description: The beta Audit Mode feature in Chef Infra Client was removed in Chef Infra Client 15.0. Users should instead use InSpec and the audit cookbook. See https://www.inspec.io/ for more informmation.
|
540
|
+
Enabled: true
|
541
|
+
VersionAdded: '5.10.0'
|
542
|
+
Exclude:
|
543
|
+
- '**/metadata.rb'
|
544
|
+
|
545
|
+
ChefDeprecations/ResourceInheritsFromCompatResource:
|
546
|
+
Description: HWRP style resource should inherit from the 'Chef::Resource' class and not the 'ChefCompat::Resource' class from the deprecated compat_resource cookbook.
|
547
|
+
Enabled: true
|
548
|
+
VersionAdded: '5.10.0'
|
549
|
+
Include:
|
550
|
+
- '**/libraries/*.rb'
|
551
|
+
|
552
|
+
ChefDeprecations/VerifyPropertyUsesFileExpansion:
|
553
|
+
Description: Use the 'path' variable in the verify property and not the 'file' variable which was removed in Chef Infra Client 13.
|
554
|
+
Enabled: true
|
555
|
+
VersionAdded: '5.10.0'
|
556
|
+
Exclude:
|
557
|
+
- '**/metadata.rb'
|
558
|
+
|
517
559
|
###############################
|
518
560
|
# ChefModernize: Cleaning up legacy code and using new built-in resources
|
519
561
|
###############################
|
@@ -580,11 +622,12 @@ ChefModernize/CustomResourceWithAttributes:
|
|
580
622
|
- '**/resources/*.rb'
|
581
623
|
|
582
624
|
ChefModernize/CustomResourceWithAllowedActions:
|
583
|
-
Description:
|
625
|
+
Description: Resources no longer need to define the allowed actions using the allowed_actions / actions helper methods or within an initialize method.
|
584
626
|
Enabled: true
|
585
627
|
VersionAdded: '5.2.0'
|
586
628
|
Include:
|
587
629
|
- '**/resources/*.rb'
|
630
|
+
- '**/libraries/*.rb'
|
588
631
|
|
589
632
|
ChefModernize/IncludingAptDefaultRecipe:
|
590
633
|
Description: Do not include the Apt default recipe to update package cache. Instead use the apt_update resource, which is built into Chef Infra Client 12.7 and later.
|
@@ -762,6 +805,24 @@ ChefModernize/PowerShellGuardInterpreter:
|
|
762
805
|
Exclude:
|
763
806
|
- '**/metadata.rb'
|
764
807
|
|
808
|
+
ChefModernize/DefaultActionFromInitialize:
|
809
|
+
Description: The default actions can now be specified using the `default_action` helper instead of using the @action variable in the resource provider initialize method.
|
810
|
+
Enabled: true
|
811
|
+
VersionAdded: '5.10.0'
|
812
|
+
Include:
|
813
|
+
- '**/resources/*.rb'
|
814
|
+
- '**/providers/*.rb'
|
815
|
+
- '**/libraries/*.rb'
|
816
|
+
|
817
|
+
ChefModernize/ResourceNameFromInitialize:
|
818
|
+
Description: The name of a resource can be set with the "resource_name" helper instead of using the initialize method.
|
819
|
+
Enabled: true
|
820
|
+
VersionAdded: '5.10.0'
|
821
|
+
Include:
|
822
|
+
- '**/resources/*.rb'
|
823
|
+
- '**/providers/*.rb'
|
824
|
+
- '**/libraries/*.rb'
|
825
|
+
|
765
826
|
###############################
|
766
827
|
# Migrating to new patterns
|
767
828
|
###############################
|
@@ -776,6 +837,21 @@ ChefEffortless/CookbookUsesDatabags:
|
|
776
837
|
Enabled: false
|
777
838
|
VersionAdded: '5.1.0'
|
778
839
|
|
840
|
+
ChefEffortless/CookbookUsesEnvironmments:
|
841
|
+
Description: Cookbook uses environments, which cannot be used in the Effortless Infra pattern
|
842
|
+
Enabled: false
|
843
|
+
VersionAdded: '5.10.0'
|
844
|
+
|
845
|
+
ChefEffortless/CookbookUsesPolicygroups:
|
846
|
+
Description: Cookbook uses Policy Groups, which cannot be used in the Effortless Infra pattern
|
847
|
+
Enabled: false
|
848
|
+
VersionAdded: '5.10.0'
|
849
|
+
|
850
|
+
ChefEffortless/CookbookUsesRoles:
|
851
|
+
Description: Cookbook uses Roles, which cannot be used in the Effortless Infra pattern
|
852
|
+
Enabled: false
|
853
|
+
VersionAdded: '5.10.0'
|
854
|
+
|
779
855
|
#### The base rubocop 0.37 enabled.yml file we started with ####
|
780
856
|
|
781
857
|
Layout/AccessModifierIndentation:
|
data/lib/cookstyle/version.rb
CHANGED
@@ -0,0 +1,60 @@
|
|
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 ChefCorrectness
|
21
|
+
# Libraries should be injected into the Chef::DSL::Recipe or Chef::DSL::Resource classes and not Recipe/Resource/Provider classes directly.
|
22
|
+
#
|
23
|
+
# @example
|
24
|
+
#
|
25
|
+
# # bad
|
26
|
+
# ::Chef::Recipe.send(:include, Filebeat::Helpers)
|
27
|
+
# ::Chef::Provider.send(:include, Filebeat::Helpers)
|
28
|
+
# ::Chef::Resource.send(:include, Filebeat::Helpers)
|
29
|
+
#
|
30
|
+
# # good
|
31
|
+
# ::Chef::DSL::Recipe.send(:include, Filebeat::Helpers) # covers previous Recipe & Provider classes
|
32
|
+
# ::Chef::DSL::Resource.send(:include, Filebeat::Helpers)
|
33
|
+
#
|
34
|
+
class IncorrectLibraryInjection < Cop
|
35
|
+
MSG = 'Libraries should be injected into the Chef::DSL::Recipe or Chef::DSL::Resource classes and not Recipe/Resource/Provider classes directly.'.freeze
|
36
|
+
|
37
|
+
def_node_matcher :legacy_class_sends?, <<-PATTERN
|
38
|
+
(send (const (const (cbase) :Chef) {:Recipe :Provider :Resource}) :send (sym :include) ... )
|
39
|
+
PATTERN
|
40
|
+
|
41
|
+
def on_send(node)
|
42
|
+
legacy_class_sends?(node) do
|
43
|
+
add_offense(node, location: :expression, message: MSG, severity: :refactor)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
def autocorrect(node)
|
48
|
+
lambda do |corrector|
|
49
|
+
new_val = node.source
|
50
|
+
new_val.gsub!(/Chef::(Provider|Recipe)/, 'Chef::DSL::Recipe')
|
51
|
+
new_val.gsub!(/Chef::Resource/, 'Chef::DSL::Resource')
|
52
|
+
|
53
|
+
corrector.replace(node.loc.expression, new_val)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
@@ -0,0 +1,56 @@
|
|
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
|
+
module ChefCorrectness
|
22
|
+
# When notifying an action within a resource the action should always be a symbol. In Chef Infra Client releases before 14.0 this may result in double notification.
|
23
|
+
#
|
24
|
+
# @example
|
25
|
+
#
|
26
|
+
# # bad
|
27
|
+
# execute 'some commmand' do
|
28
|
+
# notifies 'restart', 'service[httpd]', 'delayed'
|
29
|
+
# end
|
30
|
+
#
|
31
|
+
# # good
|
32
|
+
# execute 'some commmand' do
|
33
|
+
# notifies :restart, 'service[httpd]', 'delayed'
|
34
|
+
# end
|
35
|
+
#
|
36
|
+
class NotifiesActionNotSymbol < Cop
|
37
|
+
include RuboCop::Chef::CookbookHelpers
|
38
|
+
|
39
|
+
MSG = 'Resource notifcation actions should be symbols not strings.'.freeze
|
40
|
+
|
41
|
+
def on_block(node)
|
42
|
+
match_property_in_resource?(nil, 'notifies', node) do |notifies_property|
|
43
|
+
add_offense(notifies_property, location: :expression, message: MSG, severity: :refactor) if notifies_property.node_parts[2].str_type?
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
def autocorrect(node)
|
48
|
+
lambda do |corrector|
|
49
|
+
corrector.replace(node.first_argument.loc.expression, ":#{node.node_parts[2].value}")
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
@@ -0,0 +1,65 @@
|
|
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
|
+
# With the release of Chef Infra Client 12.14 and the yum cookbook 3.0 several properties in the yum_repository resource were renamed. url -> baseurl, keyurl -> gpgkey, and mirrorexpire -> mirror_expire.
|
22
|
+
#
|
23
|
+
# @example
|
24
|
+
#
|
25
|
+
# # bad
|
26
|
+
# yum_repository 'OurCo' do
|
27
|
+
# description 'OurCo yum repository'
|
28
|
+
# url 'http://artifacts.ourco.org/foo/bar'
|
29
|
+
# keyurl 'http://artifacts.ourco.org/pub/yum/RPM-GPG-KEY-OURCO-6'
|
30
|
+
# mirrorexpire 1440
|
31
|
+
# action :create
|
32
|
+
# end
|
33
|
+
#
|
34
|
+
# # good
|
35
|
+
# yum_repository 'OurCo' do
|
36
|
+
# description 'OurCo yum repository'
|
37
|
+
# baseurl 'http://artifacts.ourco.org/foo/bar'
|
38
|
+
# gpgkey 'http://artifacts.ourco.org/pub/yum/RPM-GPG-KEY-OURCO-6'
|
39
|
+
# mirror_expire 1440
|
40
|
+
# action :create
|
41
|
+
# end
|
42
|
+
#
|
43
|
+
class DeprecatedYumRepositoryProperties < Cop
|
44
|
+
include RuboCop::Chef::CookbookHelpers
|
45
|
+
|
46
|
+
MSG = 'With the release of Chef Infra Client 12.14 and the yum cookbook 3.0 several properties in the yum_repository resource were renamed. url -> baseurl, keyurl -> gpgkey, and mirrorexpire -> mirror_expire.'.freeze
|
47
|
+
|
48
|
+
def on_block(node)
|
49
|
+
%w(url keyurl mirrorexpire).each do |prop|
|
50
|
+
match_property_in_resource?(:yum_repository, prop, node) do |prop_node|
|
51
|
+
add_offense(prop_node, location: :expression, message: MSG, severity: :refactor)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
def autocorrect(node)
|
57
|
+
lambda do |corrector|
|
58
|
+
corrector.replace(node.loc.expression, node.loc.expression.source.gsub(/^url/, 'baseurl').gsub(/^keyurl/, 'gpgkey').gsub(/^mirrorexpire/, 'mirror_expire'))
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
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
|
+
module ChefDeprecations
|
21
|
+
# The beta Audit Mode for Chef Infra Client was removed in Chef Infra Client 15.0. Users should instead use InSpec and the audit cookbook. See https://www.inspec.io/ for more informmation.
|
22
|
+
#
|
23
|
+
# @example
|
24
|
+
#
|
25
|
+
# # bad
|
26
|
+
# control_group 'Baseline' do
|
27
|
+
# control 'SSH' do
|
28
|
+
# it 'should be listening on port 22' do
|
29
|
+
# expect(port(22)).to be_listening
|
30
|
+
# end
|
31
|
+
# end
|
32
|
+
# end
|
33
|
+
|
34
|
+
class EOLAuditModeUsage < Cop
|
35
|
+
MSG = 'The beta Audit Mode feature in Chef Infra Client was removed in Chef Infra Client 15.0. Users should instead use InSpec and the audit cookbook. See https://www.inspec.io/ for more informmation.'.freeze
|
36
|
+
|
37
|
+
def_node_matcher :control_group?, '(send nil? :control_group ...)'
|
38
|
+
|
39
|
+
def on_send(node)
|
40
|
+
control_group?(node) do
|
41
|
+
add_offense(node, location: :selector, message: MSG, severity: :refactor)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,61 @@
|
|
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
|
+
module ChefDeprecations
|
22
|
+
# Resources written in the class based HWRP style should inherit from the 'Chef::Resource' class and not the 'ChefCompat::Resource' class from the deprecated compat_resource cookbook.
|
23
|
+
#
|
24
|
+
# @example
|
25
|
+
#
|
26
|
+
# # bad
|
27
|
+
# class AptUpdate < ChefCompat::Resource
|
28
|
+
# # some resource code
|
29
|
+
# end
|
30
|
+
#
|
31
|
+
# # good
|
32
|
+
# class AptUpdate < Chef::Resource
|
33
|
+
# # some resource code
|
34
|
+
# end
|
35
|
+
#
|
36
|
+
# # better
|
37
|
+
# Write a custom resource using the custom resource DSL and avoid class based HWRPs entirely
|
38
|
+
#
|
39
|
+
class ResourceInheritsFromCompatResource < Cop
|
40
|
+
MSG = "HWRP style resource should inherit from the 'Chef::Resource' class and not the 'ChefCompat::Resource' class from the deprecated compat_resource cookbook.".freeze
|
41
|
+
|
42
|
+
def_node_matcher :inherits_from_compat_resource?, <<-PATTERN
|
43
|
+
(class (const nil? _ ) (const (const nil? :ChefCompat) :Resource) ... )
|
44
|
+
PATTERN
|
45
|
+
|
46
|
+
def on_class(node)
|
47
|
+
inherits_from_compat_resource?(node) do
|
48
|
+
add_offense(node, location: :expression, message: MSG, severity: :refactor)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
def autocorrect(node)
|
53
|
+
lambda do |corrector|
|
54
|
+
corrector.replace(node.loc.expression, node.loc.expression.source.gsub('ChefCompat', 'Chef'))
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
@@ -0,0 +1,55 @@
|
|
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
|
+
# In Chef Infra Client 13 the "file" variable for use within the verify property was replaced with the "path" variable.
|
22
|
+
#
|
23
|
+
# @example
|
24
|
+
#
|
25
|
+
# # bad
|
26
|
+
# file '/etc/nginx.conf' do
|
27
|
+
# verify 'nginx -t -c %{file}'
|
28
|
+
# end
|
29
|
+
#
|
30
|
+
# # good
|
31
|
+
# file '/etc/nginx.conf' do
|
32
|
+
# verify 'nginx -t -c %{path}'
|
33
|
+
# end
|
34
|
+
#
|
35
|
+
class VerifyPropertyUsesFileExpansion < Cop
|
36
|
+
include RuboCop::Chef::CookbookHelpers
|
37
|
+
|
38
|
+
MSG = "Use the 'path' variable in the verify property and not the 'file' variable which was removed in Chef Infra Client 13.".freeze
|
39
|
+
|
40
|
+
def on_block(node)
|
41
|
+
match_property_in_resource?(nil, 'verify', node) do |verify|
|
42
|
+
add_offense(verify, location: :expression, message: MSG, severity: :refactor) if verify.source.match?(/%{file}/)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def autocorrect(node)
|
47
|
+
lambda do |corrector|
|
48
|
+
corrector.replace(node.loc.expression, node.loc.expression.source.gsub('%{file}', '%{path}'))
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
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
|
+
module ChefEffortless
|
21
|
+
# Neither Policyfiles or Effortless Infra which is based on Policyfiles supports Chef Environments
|
22
|
+
#
|
23
|
+
# @example
|
24
|
+
#
|
25
|
+
# # bad
|
26
|
+
# node.environment == "production"
|
27
|
+
# node.chef_environment == "production"
|
28
|
+
#
|
29
|
+
class CookbookUsesEnvironmments < Cop
|
30
|
+
MSG = 'Cookbook uses environments, which cannot be used in Policyfiles or Effortless Infra'.freeze
|
31
|
+
|
32
|
+
def on_send(node)
|
33
|
+
if %i(environment chef_environment).include?(node.method_name) && node.receiver && node.receiver.send_type? && node.receiver.method_name == :node
|
34
|
+
add_offense(node, location: :expression, message: MSG, severity: :refactor)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,40 @@
|
|
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 ChefEffortless
|
21
|
+
# Effortless Infra does not support Policyfile's Policygroup feature
|
22
|
+
#
|
23
|
+
# @example
|
24
|
+
#
|
25
|
+
# # bad
|
26
|
+
# node.policy_group == "foo"
|
27
|
+
#
|
28
|
+
class CookbookUsesPolicygroups < Cop
|
29
|
+
MSG = 'Cookbook uses Policy Groups, which cannot be used with Effortless Infra'.freeze
|
30
|
+
|
31
|
+
def on_send(node)
|
32
|
+
if node.method_name == :policy_group && node.receiver && node.receiver.send_type? && node.receiver.method_name == :node
|
33
|
+
add_offense(node, location: :expression, message: MSG, severity: :refactor)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
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
|
+
module ChefEffortless
|
21
|
+
# Neither Policyfiles or Effortless Infra which is based on Policyfiles supports Chef Roles
|
22
|
+
#
|
23
|
+
# @example
|
24
|
+
#
|
25
|
+
# # bad
|
26
|
+
# node.role?('webserver')
|
27
|
+
# node.roles.include?('webserver')
|
28
|
+
#
|
29
|
+
class CookbookUsesRoles < Cop
|
30
|
+
MSG = 'Cookbook uses roles, which cannot be used in Policyfiles or Effortless Infra'.freeze
|
31
|
+
|
32
|
+
def on_send(node)
|
33
|
+
if %i(role? roles).include?(node.method_name) && node.receiver && node.receiver.send_type? && node.receiver.method_name == :node
|
34
|
+
add_offense(node, location: :expression, message: MSG, severity: :refactor)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,66 @@
|
|
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 ChefModernize
|
21
|
+
# The default actions can now be specified using the `default_action` helper instead of using the @action variable in the resource provider initialize method. In general we recommend against writing HWRPs, but if HWRPs are necessary you should utilize as much of the resource DSL as possible.
|
22
|
+
#
|
23
|
+
# @example
|
24
|
+
#
|
25
|
+
# # bad
|
26
|
+
# def initialize(*args)
|
27
|
+
# super
|
28
|
+
# @action = :create
|
29
|
+
# end
|
30
|
+
#
|
31
|
+
# # good
|
32
|
+
# default_action :create
|
33
|
+
|
34
|
+
class DefaultActionFromInitialize < Cop
|
35
|
+
include RangeHelp
|
36
|
+
|
37
|
+
MSG = 'The default action of a resource can be set with the "default_action" helper instead of using the initialize method.'.freeze
|
38
|
+
|
39
|
+
def on_def(node)
|
40
|
+
return unless node.method_name == :initialize
|
41
|
+
return if node.body.nil? # nil body is an empty initialize method
|
42
|
+
|
43
|
+
node.body.each_node do |x|
|
44
|
+
if x.assignment? && !x.node_parts.empty? && x.node_parts.first == :@action
|
45
|
+
add_offense(x, location: :expression, message: MSG, severity: :refactor)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
def_node_search :intialize_method, '(def :initialize ... )'
|
51
|
+
|
52
|
+
def autocorrect(node)
|
53
|
+
lambda do |corrector|
|
54
|
+
# insert the new default_action call above the initialize method
|
55
|
+
initialize_node = intialize_method(processed_source.ast).first
|
56
|
+
corrector.insert_before(initialize_node.source_range, "default_action #{node.asgn_rhs.source}\n\n")
|
57
|
+
|
58
|
+
# remove the variable from the initialize method
|
59
|
+
corrector.remove(range_with_surrounding_space(range: node.loc.expression, side: :left))
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
@@ -0,0 +1,66 @@
|
|
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 ChefModernize
|
21
|
+
# The resource name can now be specified using the `resource_name` helper instead of using the @resource_name variable in the resource provider initialize method. In general we recommend against writing HWRPs, but if HWRPs are necessary you should utilize as much of the resource DSL as possible.
|
22
|
+
#
|
23
|
+
# @example
|
24
|
+
#
|
25
|
+
# # bad
|
26
|
+
# def initialize(*args)
|
27
|
+
# super
|
28
|
+
# @resource_name = :foo
|
29
|
+
# end
|
30
|
+
#
|
31
|
+
# # good
|
32
|
+
# resource_name :create
|
33
|
+
|
34
|
+
class ResourceNameFromInitialize < Cop
|
35
|
+
include RangeHelp
|
36
|
+
|
37
|
+
MSG = 'The name of a resource can be set with the "resource_name" helper instead of using the initialize method.'.freeze
|
38
|
+
|
39
|
+
def on_def(node)
|
40
|
+
return unless node.method_name == :initialize
|
41
|
+
return if node.body.nil? # nil body is an empty initialize method
|
42
|
+
|
43
|
+
node.body.each_node do |x|
|
44
|
+
if x.assignment? && !x.node_parts.empty? && x.node_parts.first == :@resource_name
|
45
|
+
add_offense(x, location: :expression, message: MSG, severity: :refactor)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
def_node_search :intialize_method, '(def :initialize ... )'
|
51
|
+
|
52
|
+
def autocorrect(node)
|
53
|
+
lambda do |corrector|
|
54
|
+
# insert the new resource_name call above the initialize method
|
55
|
+
initialize_node = intialize_method(processed_source.ast).first
|
56
|
+
corrector.insert_before(initialize_node.source_range, "resource_name #{node.asgn_rhs.source}\n\n")
|
57
|
+
|
58
|
+
# remove the variable from the initialize method
|
59
|
+
corrector.remove(range_with_surrounding_space(range: node.loc.expression, side: :left))
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
@@ -19,25 +19,26 @@ module RuboCop
|
|
19
19
|
module Cop
|
20
20
|
module Chef
|
21
21
|
module ChefModernize
|
22
|
-
# In Chef Infra Client
|
22
|
+
# In Chef Infra Client 12.5 and later it is no longer necessary to set `actions` or `allowed_actions` as Chef Infra Client determines these automatically from the set of all actions defined in the resource.
|
23
23
|
#
|
24
24
|
# @example
|
25
25
|
#
|
26
26
|
# # bad
|
27
|
-
# property :something, String
|
28
|
-
#
|
29
27
|
# allowed_actions [:create, :remove]
|
30
28
|
#
|
31
29
|
# # also bad
|
32
|
-
# property :something, String
|
33
|
-
#
|
34
30
|
# actions [:create, :remove]
|
35
31
|
#
|
36
|
-
# #
|
37
|
-
#
|
32
|
+
# # don't do this either
|
33
|
+
# def initialize(*args)
|
34
|
+
# super
|
35
|
+
# @allowed_actions = [:create, :remove]
|
36
|
+
# end
|
38
37
|
#
|
39
38
|
class CustomResourceWithAllowedActions < Cop
|
40
|
-
|
39
|
+
include RangeHelp
|
40
|
+
|
41
|
+
MSG = 'Resources no longer need to define the allowed actions using the allowed_actions / actions helper methods or within an initialize method.'.freeze
|
41
42
|
|
42
43
|
def_node_matcher :allowed_actions?, <<-PATTERN
|
43
44
|
(send nil? {:allowed_actions :actions} ... )
|
@@ -49,9 +50,28 @@ module RuboCop
|
|
49
50
|
end
|
50
51
|
end
|
51
52
|
|
53
|
+
def on_def(node)
|
54
|
+
return unless node.method_name == :initialize
|
55
|
+
return if node.body.nil? # empty initialize methods
|
56
|
+
|
57
|
+
node.body.each_node do |x|
|
58
|
+
if allowed_actions_assignment?(x) || allowed_action_send?(x)
|
59
|
+
add_offense(x, location: :expression, message: MSG, severity: :refactor)
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
def allowed_actions_assignment?(node)
|
65
|
+
node.assignment? && node.node_parts.first == :@allowed_actions
|
66
|
+
end
|
67
|
+
|
68
|
+
def allowed_action_send?(node)
|
69
|
+
node.send_type? && node.receiver == s(:ivar, :@allowed_actions)
|
70
|
+
end
|
71
|
+
|
52
72
|
def autocorrect(node)
|
53
73
|
lambda do |corrector|
|
54
|
-
corrector.remove(node.loc.expression)
|
74
|
+
corrector.remove(range_with_surrounding_space(range: node.loc.expression, side: :left))
|
55
75
|
end
|
56
76
|
end
|
57
77
|
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.
|
4
|
+
version: 5.10.11
|
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-
|
12
|
+
date: 2019-10-24 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rubocop
|
@@ -51,6 +51,7 @@ files:
|
|
51
51
|
- lib/rubocop/cop/chef/correctness/cb_depends_on_self.rb
|
52
52
|
- lib/rubocop/cop/chef/correctness/default_maintainer_metadata.rb
|
53
53
|
- lib/rubocop/cop/chef/correctness/empty_metadata_field.rb
|
54
|
+
- lib/rubocop/cop/chef/correctness/incorrect_library_injection.rb
|
54
55
|
- lib/rubocop/cop/chef/correctness/insecure_cookbook_url.rb
|
55
56
|
- lib/rubocop/cop/chef/correctness/invalid_license_string.rb
|
56
57
|
- lib/rubocop/cop/chef/correctness/invalid_platform_metadata.rb
|
@@ -60,6 +61,7 @@ files:
|
|
60
61
|
- lib/rubocop/cop/chef/correctness/node_normal.rb
|
61
62
|
- lib/rubocop/cop/chef/correctness/node_normal_unless.rb
|
62
63
|
- lib/rubocop/cop/chef/correctness/node_save.rb
|
64
|
+
- lib/rubocop/cop/chef/correctness/notifies_action_not_symbol.rb
|
63
65
|
- lib/rubocop/cop/chef/correctness/ohai_default_recipe.rb
|
64
66
|
- lib/rubocop/cop/chef/correctness/property_with_default_and_required.rb
|
65
67
|
- lib/rubocop/cop/chef/correctness/property_with_name_attribute.rb
|
@@ -80,9 +82,12 @@ files:
|
|
80
82
|
- lib/rubocop/cop/chef/deprecation/depends_partial_search.rb
|
81
83
|
- lib/rubocop/cop/chef/deprecation/depends_poise.rb
|
82
84
|
- lib/rubocop/cop/chef/deprecation/deprecated_mixins.rb
|
85
|
+
- lib/rubocop/cop/chef/deprecation/deprecated_yum_repository_properties.rb
|
83
86
|
- lib/rubocop/cop/chef/deprecation/easy_install.rb
|
87
|
+
- lib/rubocop/cop/chef/deprecation/eol_audit_mode.rb
|
84
88
|
- lib/rubocop/cop/chef/deprecation/epic_fail.rb
|
85
89
|
- lib/rubocop/cop/chef/deprecation/erl_call.rb
|
90
|
+
- lib/rubocop/cop/chef/deprecation/inherits_compat_resource.rb
|
86
91
|
- lib/rubocop/cop/chef/deprecation/launchd_deprecated_hash_property.rb
|
87
92
|
- lib/rubocop/cop/chef/deprecation/legacy_yum_cookbook_recipes.rb
|
88
93
|
- lib/rubocop/cop/chef/deprecation/locale_lc_all_property.rb
|
@@ -103,16 +108,21 @@ files:
|
|
103
108
|
- lib/rubocop/cop/chef/deprecation/suggests_metadata.rb
|
104
109
|
- lib/rubocop/cop/chef/deprecation/use_inline_resources.rb
|
105
110
|
- lib/rubocop/cop/chef/deprecation/user_supports_property.rb
|
111
|
+
- lib/rubocop/cop/chef/deprecation/verify_property_file_expansion.rb
|
106
112
|
- lib/rubocop/cop/chef/deprecation/windows_task_change_action.rb
|
107
113
|
- lib/rubocop/cop/chef/deprecation/xml_ruby_recipe.rb
|
108
114
|
- lib/rubocop/cop/chef/deprecation/yum_dnf_compat_recipe.rb
|
109
115
|
- lib/rubocop/cop/chef/effortless/data_bags.rb
|
116
|
+
- lib/rubocop/cop/chef/effortless/node_environment.rb
|
117
|
+
- lib/rubocop/cop/chef/effortless/node_policygroup.rb
|
118
|
+
- lib/rubocop/cop/chef/effortless/node_roles.rb
|
110
119
|
- lib/rubocop/cop/chef/effortless/search_used.rb
|
111
120
|
- lib/rubocop/cop/chef/modernize/apt_default_recipe.rb
|
112
121
|
- lib/rubocop/cop/chef/modernize/berksfile_source.rb
|
113
122
|
- lib/rubocop/cop/chef/modernize/build_essential.rb
|
114
123
|
- lib/rubocop/cop/chef/modernize/chef_14_resources.rb
|
115
124
|
- lib/rubocop/cop/chef/modernize/cron_manage_resource.rb
|
125
|
+
- lib/rubocop/cop/chef/modernize/default_action_initializer.rb
|
116
126
|
- lib/rubocop/cop/chef/modernize/defines_chefspec_matchers.rb
|
117
127
|
- lib/rubocop/cop/chef/modernize/depends_zypper_cookbook.rb
|
118
128
|
- lib/rubocop/cop/chef/modernize/execute_apt_update.rb
|
@@ -128,6 +138,7 @@ files:
|
|
128
138
|
- lib/rubocop/cop/chef/modernize/powershell_guard_interpreter.rb
|
129
139
|
- lib/rubocop/cop/chef/modernize/powershell_install_package.rb
|
130
140
|
- lib/rubocop/cop/chef/modernize/powershell_install_windowsfeature.rb
|
141
|
+
- lib/rubocop/cop/chef/modernize/resource_name_initializer.rb
|
131
142
|
- lib/rubocop/cop/chef/modernize/resource_set_or_return.rb
|
132
143
|
- lib/rubocop/cop/chef/modernize/resource_with_allowed_actions.rb
|
133
144
|
- lib/rubocop/cop/chef/modernize/resource_with_attributes.rb
|