cookstyle 5.22.6 → 5.23.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 +1 -3
- data/lib/cookstyle/version.rb +1 -1
- data/lib/rubocop/cop/chef/correctness/dnf_package_allow_downgrades.rb +8 -1
- data/lib/rubocop/cop/chef/correctness/incorrect_library_injection.rb +5 -11
- data/lib/rubocop/cop/chef/deprecation/depends_partial_search.rb +4 -0
- data/lib/rubocop/cop/chef/deprecation/deprecated_yum_repository_properties.rb +3 -0
- data/lib/rubocop/cop/chef/deprecation/launchd_deprecated_hash_property.rb +3 -0
- data/lib/rubocop/cop/chef/deprecation/verify_property_file_expansion.rb +3 -0
- data/lib/rubocop/cop/chef/deprecation/windows_task_change_action.rb +3 -0
- data/lib/rubocop/cop/chef/modernize/default_action_initializer.rb +6 -6
- data/lib/rubocop/cop/chef/modernize/powershell_install_windowsfeature.rb +3 -3
- data/lib/rubocop/cop/chef/modernize/respond_to_provides.rb +15 -5
- data/lib/rubocop/cop/chef/modernize/whyrun_supported_true.rb +9 -2
- data/lib/rubocop/cop/chef/redundant/sensitive_property_in_resource.rb +3 -3
- data/lib/rubocop/cop/chef/redundant/unnecessary_name_property.rb +26 -7
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b643382e9541a9d542bda66cde1aae0922ba3bb43318e21bc5f8abe3ebb37ce8
|
4
|
+
data.tar.gz: 4b7939a38dfa5d0065560a834c770bdde57ed58e5bfc86b4adeaaea622470ae7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 359c2d5b2b9112ce9d16e5ca8bbc76a4dd76db8076a9d5467fcdc9f69905997a67bbe8a6b869dc3099aab72ecdb6b2ca1cffacd1b2b378dbe9416430ecf10b8f
|
7
|
+
data.tar.gz: 971d8d6472462ce60641d5c097670d212e071dd99ef5e0e6f8082ce5ab4592860ef71423eb94a853a8a3181ebc27d6c8081bd97435ec6a19638482f51b52fcf7
|
data/config/cookstyle.yml
CHANGED
@@ -129,7 +129,7 @@ ChefStyle/ChefWhaaat:
|
|
129
129
|
|
130
130
|
ChefStyle/UnnecessaryOSCheck:
|
131
131
|
Description: Use the platform_family?() helpers instead of node['os] == 'foo' for platform_families that match 1:1 with OS values. These helpers are easier to read and can accept multiple platform arguments, which greatly simplifies complex platform logic.
|
132
|
-
Enabled:
|
132
|
+
Enabled: true
|
133
133
|
VersionAdded: '5.21.0'
|
134
134
|
|
135
135
|
###############################
|
@@ -1553,8 +1553,6 @@ Style/PercentQLiterals:
|
|
1553
1553
|
Enabled: true
|
1554
1554
|
Style/PerlBackrefs:
|
1555
1555
|
Enabled: true
|
1556
|
-
Naming/PredicateName:
|
1557
|
-
Enabled: true
|
1558
1556
|
Style/Proc:
|
1559
1557
|
Enabled: true
|
1560
1558
|
Style/RaiseArgs:
|
data/lib/cookstyle/version.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
#
|
2
|
-
# Copyright:: Copyright 2019, Chef Software Inc.
|
2
|
+
# Copyright:: 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");
|
@@ -34,6 +34,7 @@ module RuboCop
|
|
34
34
|
# end
|
35
35
|
#
|
36
36
|
class DnfPackageAllowDowngrades < Cop
|
37
|
+
include RangeHelp
|
37
38
|
include RuboCop::Chef::CookbookHelpers
|
38
39
|
|
39
40
|
MSG = 'dnf_package does not support the allow_downgrades property'.freeze
|
@@ -43,6 +44,12 @@ module RuboCop
|
|
43
44
|
add_offense(prop, location: :expression, message: MSG, severity: :refactor)
|
44
45
|
end
|
45
46
|
end
|
47
|
+
|
48
|
+
def autocorrect(node)
|
49
|
+
lambda do |corrector|
|
50
|
+
corrector.remove(range_with_surrounding_space(range: node.loc.expression, side: :left))
|
51
|
+
end
|
52
|
+
end
|
46
53
|
end
|
47
54
|
end
|
48
55
|
end
|
@@ -1,5 +1,5 @@
|
|
1
1
|
#
|
2
|
-
# Copyright:: Copyright 2019, Chef Software Inc.
|
2
|
+
# Copyright:: 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,24 +18,22 @@ module RuboCop
|
|
18
18
|
module Cop
|
19
19
|
module Chef
|
20
20
|
module ChefCorrectness
|
21
|
-
# Libraries should be injected into the Chef::DSL::Recipe
|
21
|
+
# Libraries should be injected into the Chef::DSL::Recipe class and not Chef::Recipe or Chef::Provider classes directly.
|
22
22
|
#
|
23
23
|
# @example
|
24
24
|
#
|
25
25
|
# # bad
|
26
26
|
# ::Chef::Recipe.send(:include, Filebeat::Helpers)
|
27
27
|
# ::Chef::Provider.send(:include, Filebeat::Helpers)
|
28
|
-
# ::Chef::Resource.send(:include, Filebeat::Helpers)
|
29
28
|
#
|
30
29
|
# # good
|
31
30
|
# ::Chef::DSL::Recipe.send(:include, Filebeat::Helpers) # covers previous Recipe & Provider classes
|
32
|
-
# ::Chef::DSL::Resource.send(:include, Filebeat::Helpers)
|
33
31
|
#
|
34
32
|
class IncorrectLibraryInjection < Cop
|
35
|
-
MSG = 'Libraries should be injected into the Chef::DSL::Recipe
|
33
|
+
MSG = 'Libraries should be injected into the Chef::DSL::Recipe class and not Chef::Recipe or Chef::Provider classes directly.'.freeze
|
36
34
|
|
37
35
|
def_node_matcher :legacy_class_sends?, <<-PATTERN
|
38
|
-
(send (const (const (cbase) :Chef) {:Recipe :Provider
|
36
|
+
(send (const (const (cbase) :Chef) {:Recipe :Provider}) :send (sym :include) ... )
|
39
37
|
PATTERN
|
40
38
|
|
41
39
|
def on_send(node)
|
@@ -46,11 +44,7 @@ module RuboCop
|
|
46
44
|
|
47
45
|
def autocorrect(node)
|
48
46
|
lambda do |corrector|
|
49
|
-
|
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)
|
47
|
+
corrector.replace(node.loc.expression, node.source.gsub(/Chef::(Provider|Recipe)/, 'Chef::DSL::Recipe'))
|
54
48
|
end
|
55
49
|
end
|
56
50
|
end
|
@@ -26,6 +26,10 @@ module RuboCop
|
|
26
26
|
# depends 'partial_search'
|
27
27
|
#
|
28
28
|
class CookbookDependsOnPartialSearch < Cop
|
29
|
+
extend TargetChefVersion
|
30
|
+
|
31
|
+
minimum_target_chef_version '13.0'
|
32
|
+
|
29
33
|
MSG = "Don't depend on the deprecated partial_search cookbook made obsolete by Chef 13".freeze
|
30
34
|
|
31
35
|
def_node_matcher :depends_partial_search?, <<-PATTERN
|
@@ -42,6 +42,9 @@ module RuboCop
|
|
42
42
|
#
|
43
43
|
class DeprecatedYumRepositoryProperties < Cop
|
44
44
|
include RuboCop::Chef::CookbookHelpers
|
45
|
+
extend TargetChefVersion
|
46
|
+
|
47
|
+
minimum_target_chef_version '12.14'
|
45
48
|
|
46
49
|
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
50
|
|
@@ -34,6 +34,9 @@ module RuboCop
|
|
34
34
|
#
|
35
35
|
class LaunchdDeprecatedHashProperty < Cop
|
36
36
|
include RuboCop::Chef::CookbookHelpers
|
37
|
+
extend TargetChefVersion
|
38
|
+
|
39
|
+
minimum_target_chef_version '12.19'
|
37
40
|
|
38
41
|
MSG = "The launchd resource's hash property was renamed to plist_hash in Chef Infra Client 13+ to avoid conflicts with Ruby's hash class.".freeze
|
39
42
|
|
@@ -34,6 +34,9 @@ module RuboCop
|
|
34
34
|
#
|
35
35
|
class VerifyPropertyUsesFileExpansion < Cop
|
36
36
|
include RuboCop::Chef::CookbookHelpers
|
37
|
+
extend TargetChefVersion
|
38
|
+
|
39
|
+
minimum_target_chef_version '12.5'
|
37
40
|
|
38
41
|
MSG = "Use the 'path' variable in the verify property and not the 'file' variable which was removed in Chef Infra Client 13.".freeze
|
39
42
|
|
@@ -41,6 +41,9 @@ module RuboCop
|
|
41
41
|
#
|
42
42
|
class WindowsTaskChangeAction < Cop
|
43
43
|
include RuboCop::Chef::CookbookHelpers
|
44
|
+
extend TargetChefVersion
|
45
|
+
|
46
|
+
minimum_target_chef_version '13.0'
|
44
47
|
|
45
48
|
MSG = 'The :change action in the windows_task resource was removed when windows_task was added to Chef Infra Client 13+. The default action of :create should can now be used to create an update tasks.'.freeze
|
46
49
|
|
@@ -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");
|
@@ -42,17 +42,17 @@ module RuboCop
|
|
42
42
|
|
43
43
|
MSG = 'The default action of a resource can be set with the "default_action" helper instead of using the initialize method.'.freeze
|
44
44
|
|
45
|
-
def_node_matcher :
|
46
|
-
(
|
45
|
+
def_node_matcher :action_variable_assignment?, <<-PATTERN
|
46
|
+
(ivasgn {:@action :@default_action} $(...))
|
47
47
|
PATTERN
|
48
48
|
|
49
49
|
def_node_search :intialize_method, '(def :initialize ... )'
|
50
50
|
|
51
51
|
def_node_search :default_action_method?, '(send nil? :default_action ... )'
|
52
52
|
|
53
|
-
def
|
54
|
-
|
55
|
-
add_offense(
|
53
|
+
def on_ivasgn(node)
|
54
|
+
action_variable_assignment?(node) do
|
55
|
+
add_offense(node, location: :expression, message: MSG, severity: :refactor) if intialize_method(node.parent.parent)
|
56
56
|
end
|
57
57
|
end
|
58
58
|
|
@@ -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|
|
@@ -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,19 +18,20 @@ module RuboCop
|
|
18
18
|
module Cop
|
19
19
|
module Chef
|
20
20
|
module ChefModernize
|
21
|
-
#
|
22
|
-
# methods in Chef 11 and early versions of Chef 12.
|
21
|
+
# In Chef Infra Client 12+ is is no longer necessary to gate the use of the provides methods in resources with `if respond_to?(:provides)` or `if defined? provides`.
|
23
22
|
#
|
24
23
|
# @example
|
25
24
|
#
|
26
25
|
# # bad
|
27
26
|
# provides :foo if respond_to?(:provides)
|
28
27
|
#
|
28
|
+
# provides :foo if defined? provides
|
29
|
+
#
|
29
30
|
# # good
|
30
31
|
# provides :foo
|
31
32
|
#
|
32
33
|
class RespondToProvides < Cop
|
33
|
-
MSG = 'respond_to?(:provides) in resources is no longer necessary in Chef Infra Client 12
|
34
|
+
MSG = 'Using `respond_to?(:provides)` or `if defined? provides` in resources is no longer necessary in Chef Infra Client 12+.'.freeze
|
34
35
|
|
35
36
|
def on_if(node)
|
36
37
|
if_respond_to_provides?(node) do
|
@@ -39,7 +40,16 @@ module RuboCop
|
|
39
40
|
end
|
40
41
|
|
41
42
|
def_node_matcher :if_respond_to_provides?, <<~PATTERN
|
42
|
-
(if
|
43
|
+
(if
|
44
|
+
{
|
45
|
+
(send nil? :respond_to?
|
46
|
+
(sym :provides))
|
47
|
+
|
48
|
+
(:defined?
|
49
|
+
(send nil? :provides))
|
50
|
+
}
|
51
|
+
(send nil? :provides
|
52
|
+
(sym _)) ... )
|
43
53
|
PATTERN
|
44
54
|
|
45
55
|
def autocorrect(node)
|
@@ -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");
|
@@ -35,8 +35,15 @@ module RuboCop
|
|
35
35
|
|
36
36
|
MSG = 'whyrun_supported? no longer needs to be set to true as it is the default in Chef Infra Client 13+'.freeze
|
37
37
|
|
38
|
+
# match on both whyrun_supported? and the typo form why_run_supported?
|
39
|
+
def_node_matcher :whyrun_true?, <<-PATTERN
|
40
|
+
(def {:whyrun_supported? :why_run_supported?}
|
41
|
+
(args)
|
42
|
+
(true))
|
43
|
+
PATTERN
|
44
|
+
|
38
45
|
def on_def(node)
|
39
|
-
|
46
|
+
whyrun_true?(node) do
|
40
47
|
add_offense(node, location: :expression, message: MSG, severity: :refactor)
|
41
48
|
end
|
42
49
|
end
|
@@ -1,5 +1,5 @@
|
|
1
1
|
#
|
2
|
-
# Copyright:: Copyright 2019, Chef Software Inc.
|
2
|
+
# Copyright:: 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,13 +18,13 @@ module RuboCop
|
|
18
18
|
module Cop
|
19
19
|
module Chef
|
20
20
|
module ChefRedundantCode
|
21
|
-
# Every Chef Infra
|
21
|
+
# Every Chef Infra resource already includes a sensitive property with a default value of false.
|
22
22
|
#
|
23
23
|
# # bad
|
24
24
|
# property :sensitive, [true, false], default: false
|
25
25
|
#
|
26
26
|
class SensitivePropertyInResource < Cop
|
27
|
-
MSG = 'Every Chef Infra
|
27
|
+
MSG = 'Every Chef Infra resource already includes a sensitive property with a default value of false.'.freeze
|
28
28
|
|
29
29
|
def_node_matcher :sensitive_property?, <<-PATTERN
|
30
30
|
(send nil? {:property :attribute} (sym :sensitive) ... (hash (pair (sym :default) (false))))
|
@@ -1,5 +1,5 @@
|
|
1
1
|
#
|
2
|
-
# Copyright:: Copyright 2019, Chef Software Inc.
|
2
|
+
# Copyright:: 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");
|
@@ -25,23 +25,42 @@ module RuboCop
|
|
25
25
|
# # bad
|
26
26
|
# property :name, String
|
27
27
|
# property :name, String, name_property: true
|
28
|
-
# attribute :name, String
|
29
|
-
# attribute :name, String, name_attribute: true
|
28
|
+
# attribute :name, kind_of: String
|
29
|
+
# attribute :name, kind_of: String, name_attribute: true
|
30
30
|
#
|
31
31
|
class UnnecessaryNameProperty < Cop
|
32
32
|
MSG = 'There is no need to define a property or attribute named :name in a resource as Chef Infra defines this on all resources by default.'.freeze
|
33
33
|
|
34
|
-
|
35
|
-
|
36
|
-
|
34
|
+
def_node_matcher :name_attribute?, <<-PATTERN
|
35
|
+
(send nil? :attribute
|
36
|
+
(sym :name)
|
37
|
+
(hash
|
38
|
+
(pair
|
39
|
+
(sym :kind_of)
|
40
|
+
(const nil? :String))
|
41
|
+
(pair
|
42
|
+
(sym :name_attribute)
|
43
|
+
(true))?))
|
44
|
+
PATTERN
|
45
|
+
|
37
46
|
def_node_matcher :name_property?, <<-PATTERN
|
38
|
-
(send nil?
|
47
|
+
(send nil? :property
|
48
|
+
(sym :name)
|
49
|
+
(const nil? :String)
|
50
|
+
(hash
|
51
|
+
(pair
|
52
|
+
(sym :name_property)
|
53
|
+
(true)))?)
|
39
54
|
PATTERN
|
40
55
|
|
41
56
|
def on_send(node)
|
42
57
|
name_property?(node) do
|
43
58
|
add_offense(node, location: :expression, message: MSG, severity: :refactor)
|
44
59
|
end
|
60
|
+
|
61
|
+
name_attribute?(node) do
|
62
|
+
add_offense(node, location: :expression, message: MSG, severity: :refactor)
|
63
|
+
end
|
45
64
|
end
|
46
65
|
|
47
66
|
def autocorrect(node)
|
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.23.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-
|
12
|
+
date: 2020-04-20 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rubocop
|