cookstyle 6.13.3 → 6.14.7
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 +27 -30
- data/lib/cookstyle.rb +5 -5
- data/lib/cookstyle/version.rb +1 -1
- data/lib/rubocop/cop/chef/correctness/invalid_platform_family_helper.rb +26 -3
- data/lib/rubocop/cop/chef/correctness/macos_userdefaults_invalid_type.rb +68 -0
- data/lib/rubocop/cop/chef/correctness/notifies_action_not_symbol.rb +4 -4
- data/lib/rubocop/cop/chef/deprecation/cheffile.rb +2 -2
- data/lib/rubocop/cop/chef/deprecation/eol_audit_mode.rb +2 -2
- data/lib/rubocop/cop/chef/deprecation/macos_userdefaults_global_property.rb +61 -0
- data/lib/rubocop/cop/chef/deprecation/poise_archive.rb +2 -2
- data/lib/rubocop/cop/chef/deprecation/resource_uses_only_resource_name.rb +1 -1
- data/lib/rubocop/cop/chef/effortless/node_environment.rb +1 -1
- data/lib/rubocop/cop/chef/effortless/node_roles.rb +3 -3
- data/lib/rubocop/cop/chef/modernize/allowed_actions_initializer.rb +2 -2
- data/lib/rubocop/cop/chef/modernize/default_action_initializer.rb +3 -3
- data/lib/rubocop/cop/chef/modernize/definitions.rb +1 -1
- data/lib/rubocop/cop/chef/modernize/provides_initializer.rb +3 -3
- data/lib/rubocop/cop/chef/modernize/resource_name_initializer.rb +2 -2
- data/lib/rubocop/cop/chef/modernize/use_multipackage_installs.rb +3 -3
- data/lib/rubocop/cop/chef/redundant/ohai_attribute_to_string.rb +3 -3
- data/lib/rubocop/cop/chef/sharing/include_property_descriptions.rb +2 -2
- data/lib/rubocop/cop/chef/sharing/include_resource_descriptions.rb +2 -2
- data/lib/rubocop/cop/chef/sharing/include_resource_examples.rb +2 -2
- data/lib/rubocop/cop/chef/style/file_mode.rb +38 -19
- data/lib/rubocop/cop/chef/style/unnecessary_platform_case_statement.rb +1 -1
- data/lib/rubocop/monkey_patches/{cop.rb → base.rb} +1 -1
- metadata +5 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 07d286963f81d70ccc2e4eeb9b3c7fb557485877c5bb95ac2b8c2bf5aa79bd50
|
4
|
+
data.tar.gz: 73e58cae888fc04614c21a724257f5833b146afddc6339ae8b3dd969ea9b5f35
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: af409a2dbf43a42e874f8b8e40006c9b97450d8b1048b765a57774c999d0e3e3163cc391239c82e117fd1e7f5ae9de4435625994d6ef0516ba71c2716502fc87
|
7
|
+
data.tar.gz: 7118a2999c086064f8d0be2cea95d7b1bbe3ea00ceb7a1e0a018f683ff676d993d591127ed35450daddf402e75f84c5fecf4252d450f535b525966f0469f127c
|
data/config/cookstyle.yml
CHANGED
@@ -5,27 +5,6 @@ AllCops:
|
|
5
5
|
- '/**/files/**/*'
|
6
6
|
- '/**/vendor/**/*'
|
7
7
|
- Guardfile
|
8
|
-
ChefAttributes:
|
9
|
-
Patterns:
|
10
|
-
- attributes/.*\.rb
|
11
|
-
ChefDefinitions:
|
12
|
-
Patterns:
|
13
|
-
- definitions/.*\.rb
|
14
|
-
ChefLibraries:
|
15
|
-
Patterns:
|
16
|
-
- libraries/.*\.rb
|
17
|
-
ChefMetadata:
|
18
|
-
Patterns:
|
19
|
-
- metadata\.rb
|
20
|
-
ChefProviders:
|
21
|
-
Patterns:
|
22
|
-
- providers/.*\.rb
|
23
|
-
ChefRecipes:
|
24
|
-
Patterns:
|
25
|
-
- recipes/.*\.rb
|
26
|
-
ChefResources:
|
27
|
-
Patterns:
|
28
|
-
- resources/.*\.rb
|
29
8
|
|
30
9
|
###############################
|
31
10
|
# ChefStyle: Making cookbooks look better
|
@@ -67,7 +46,7 @@ ChefStyle/CommentFormat:
|
|
67
46
|
- '**/Berksfile'
|
68
47
|
|
69
48
|
ChefStyle/FileMode:
|
70
|
-
Description: Use strings to represent file modes
|
49
|
+
Description: Use strings to represent file modes to avoid confusion between octal and base 10 integer formats.
|
71
50
|
StyleGuide: '#chefstylefilemode'
|
72
51
|
Enabled: true
|
73
52
|
VersionAdded: '5.0.0'
|
@@ -471,6 +450,15 @@ ChefCorrectness/SupportsMustBeFloat:
|
|
471
450
|
Include:
|
472
451
|
- '**/metadata.rb'
|
473
452
|
|
453
|
+
ChefCorrectness/MacosUserdefaultsInvalidType:
|
454
|
+
Description: The macos_userdefaults resource prior to Chef Infra Client 16.3 would silently continue if invalid types were passed resulting in unexpected behavior. Valid values are 'array', 'bool', 'dict', 'float', 'int', and 'string'.
|
455
|
+
StyleGuide: '#chefcorrectnessmacosuserdefaultsinvalidtype'
|
456
|
+
Enabled: true
|
457
|
+
VersionAdded: '6.14.0'
|
458
|
+
Exclude:
|
459
|
+
- '**/metadata.rb'
|
460
|
+
- '**/Berksfile'
|
461
|
+
|
474
462
|
###############################
|
475
463
|
# ChefSharing: Issues that prevent sharing code with other teams or with the Chef community in general
|
476
464
|
###############################
|
@@ -515,7 +503,7 @@ ChefSharing/EmptyMetadataField:
|
|
515
503
|
- '**/metadata.rb'
|
516
504
|
|
517
505
|
ChefSharing/IncludePropertyDescriptions:
|
518
|
-
Description: Properties should include description fields to allow automated
|
506
|
+
Description: Properties should include description fields to allow automated documentation. Requires Chef Infra Client 13.9 or later.
|
519
507
|
StyleGuide: '#chefsharingincludepropetydescriptions'
|
520
508
|
Enabled: false
|
521
509
|
VersionAdded: '6.1.0'
|
@@ -524,7 +512,7 @@ ChefSharing/IncludePropertyDescriptions:
|
|
524
512
|
- '**/resources/*.rb'
|
525
513
|
|
526
514
|
ChefSharing/IncludeResourceDescriptions:
|
527
|
-
Description: Resources should include description fields to allow automated
|
515
|
+
Description: Resources should include description fields to allow automated documentation. Requires Chef Infra Client 13.9 or later.
|
528
516
|
StyleGuide: '#chefsharingincluderesourcedescriptions'
|
529
517
|
Enabled: false
|
530
518
|
VersionAdded: '6.1.0'
|
@@ -532,7 +520,7 @@ ChefSharing/IncludeResourceDescriptions:
|
|
532
520
|
- '**/resources/*.rb'
|
533
521
|
|
534
522
|
ChefSharing/IncludeResourceExamples:
|
535
|
-
Description: Resources should include examples field to allow automated
|
523
|
+
Description: Resources should include examples field to allow automated documentation. Requires Chef Infra Client 13.9 or later.
|
536
524
|
StyleGuide: '#chefsharingincluderesourceexamples'
|
537
525
|
Enabled: false
|
538
526
|
VersionAdded: '6.10.0'
|
@@ -1039,7 +1027,7 @@ ChefDeprecations/ResourceUsesOnlyResourceName:
|
|
1039
1027
|
|
1040
1028
|
ChefDeprecations/ChefDKGenerators:
|
1041
1029
|
Description: Chef Workstation 0.8 and later renamed the ChefDK module used when writing custom cookbook generators from ChefDK to ChefCLI. For compatibility with the latest Chef Workstation releases you'll need to reference the new class names.
|
1042
|
-
StyleGuide: '#
|
1030
|
+
StyleGuide: '#chefdeprecationschefdkgenerators'
|
1043
1031
|
Enabled: true
|
1044
1032
|
VersionAdded: '6.12.0'
|
1045
1033
|
Exclude:
|
@@ -1048,7 +1036,7 @@ ChefDeprecations/ChefDKGenerators:
|
|
1048
1036
|
|
1049
1037
|
ChefDeprecations/ChefHandlerRecipe:
|
1050
1038
|
Description: There is no need to include the empty and deprecated chef_handler::default recipe in order to use the chef_handler resource.
|
1051
|
-
StyleGuide: '#
|
1039
|
+
StyleGuide: '#chefdeprecationschefhandlerrecipe'
|
1052
1040
|
Enabled: true
|
1053
1041
|
VersionAdded: '6.12.0'
|
1054
1042
|
Exclude:
|
@@ -1057,13 +1045,22 @@ ChefDeprecations/ChefHandlerRecipe:
|
|
1057
1045
|
|
1058
1046
|
ChefDeprecations/UseAutomaticResourceName:
|
1059
1047
|
Description: The use_automatic_resource_name method was removed in Chef Infra Client 16. The resource name/provides should be set explicitly instead.
|
1060
|
-
StyleGuide: '#
|
1048
|
+
StyleGuide: '#chefdeprecationsuseautomaticresourcename'
|
1061
1049
|
Enabled: true
|
1062
1050
|
VersionAdded: '6.12.0'
|
1063
1051
|
Include:
|
1064
1052
|
- '**/libraries/*.rb'
|
1065
1053
|
- '**/resources/*.rb'
|
1066
1054
|
|
1055
|
+
ChefDeprecations/MacosUserdefaultsGlobalProperty:
|
1056
|
+
Description: The `global` property in the macos_userdefaults resource was deprecated in Chef Infra Client 16.3. Omitting the `domain` property will now set global defaults.
|
1057
|
+
StyleGuide: '#chefdeprecationsmacosuserdefaultsglobalproperty'
|
1058
|
+
Enabled: true
|
1059
|
+
VersionAdded: '6.14.0'
|
1060
|
+
Exclude:
|
1061
|
+
- '**/metadata.rb'
|
1062
|
+
- '**/Berksfile'
|
1063
|
+
|
1067
1064
|
###############################
|
1068
1065
|
# ChefModernize: Cleaning up legacy code and using new built-in resources
|
1069
1066
|
###############################
|
@@ -1540,7 +1537,7 @@ ChefModernize/WindowsRegistryUAC:
|
|
1540
1537
|
- '**/Berksfile'
|
1541
1538
|
|
1542
1539
|
ChefModernize/UseMultipackageInstalls:
|
1543
|
-
Description: Pass an array of packages to package resources instead of
|
1540
|
+
Description: Pass an array of packages to package resources instead of iterating over an array of packages when using multi-package capable package subsystem such as apt, yum, chocolatey, dnf, or zypper. Multi-package installs are faster and simplify logs.
|
1544
1541
|
StyleGuide: '#chefmodernizeusemultipackageinstalls'
|
1545
1542
|
Enabled: true
|
1546
1543
|
VersionAdded: '6.0.0'
|
@@ -1873,7 +1870,7 @@ ChefEffortless/CookbookUsesDatabags:
|
|
1873
1870
|
- '**/metadata.rb'
|
1874
1871
|
- '**/Berksfile'
|
1875
1872
|
|
1876
|
-
ChefEffortless/
|
1873
|
+
ChefEffortless/CookbookUsesEnvironments:
|
1877
1874
|
Description: Cookbook uses environments, which cannot be used in the Effortless Infra pattern
|
1878
1875
|
StyleGuide: '#chefeffortlesscookbookusesenvironments'
|
1879
1876
|
Enabled: false
|
data/lib/cookstyle.rb
CHANGED
@@ -7,13 +7,13 @@ require 'yaml'
|
|
7
7
|
# ensure the desired target version of RuboCop is gem activated
|
8
8
|
gem 'rubocop', "= #{Cookstyle::RUBOCOP_VERSION}"
|
9
9
|
require 'rubocop'
|
10
|
-
|
10
|
+
require_relative 'rubocop/monkey_patches/comment_config.rb'
|
11
11
|
|
12
12
|
# monkey patches needed for the TargetChefVersion config option
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
13
|
+
require_relative 'rubocop/monkey_patches/config.rb'
|
14
|
+
require_relative 'rubocop/monkey_patches/base.rb'
|
15
|
+
require_relative 'rubocop/monkey_patches/team.rb'
|
16
|
+
require_relative 'rubocop/monkey_patches/registry_cop.rb'
|
17
17
|
|
18
18
|
module RuboCop
|
19
19
|
class ConfigLoader
|
data/lib/cookstyle/version.rb
CHANGED
@@ -33,6 +33,7 @@ module RuboCop
|
|
33
33
|
#
|
34
34
|
class InvalidPlatformFamilyHelper < Cop
|
35
35
|
include ::RuboCop::Chef::PlatformHelpers
|
36
|
+
include RangeHelp
|
36
37
|
|
37
38
|
MSG = 'Pass valid platform families to the platform_family? helper.'
|
38
39
|
|
@@ -41,9 +42,31 @@ module RuboCop
|
|
41
42
|
PATTERN
|
42
43
|
|
43
44
|
def on_send(node)
|
44
|
-
platform_family_helper?(node) do |
|
45
|
-
|
46
|
-
|
45
|
+
platform_family_helper?(node) do |plats|
|
46
|
+
plats.to_a.each do |p|
|
47
|
+
next unless INVALID_PLATFORM_FAMILIES.key?(p.value)
|
48
|
+
add_offense(p, location: :expression, message: MSG, severity: :refactor)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
def autocorrect(node)
|
54
|
+
replacement_platform = INVALID_PLATFORM_FAMILIES[node.value]
|
55
|
+
all_passed_platforms = node.parent.arguments.map(&:value)
|
56
|
+
|
57
|
+
# see if we have a replacement platform in our hash. If not we can't autocorrect
|
58
|
+
if replacement_platform
|
59
|
+
# if the replacement platform was one of the other platforms passed we can just delete this bad platform
|
60
|
+
if all_passed_platforms.include?(replacement_platform)
|
61
|
+
all_passed_platforms.delete(node.value)
|
62
|
+
lambda do |corrector|
|
63
|
+
arg_range = node.parent.arguments.first.loc.expression.join(node.parent.arguments[-1].loc.expression.end)
|
64
|
+
corrector.replace(arg_range, all_passed_platforms.map { |x| "'#{x}'" }.join(', '))
|
65
|
+
end
|
66
|
+
else
|
67
|
+
lambda do |corrector|
|
68
|
+
corrector.replace(node.loc.expression, node.value.gsub(node.value, "'#{replacement_platform}'")) # gsub to retain quotes
|
69
|
+
end
|
47
70
|
end
|
48
71
|
end
|
49
72
|
end
|
@@ -0,0 +1,68 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
#
|
3
|
+
# Copyright:: Copyright 2020, Chef Software Inc.
|
4
|
+
# Author:: Tim Smith (<tsmith@chef.io>)
|
5
|
+
#
|
6
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
7
|
+
# you may not use this file except in compliance with the License.
|
8
|
+
# You may obtain a copy of the License at
|
9
|
+
#
|
10
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
11
|
+
#
|
12
|
+
# Unless required by applicable law or agreed to in writing, software
|
13
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
14
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
15
|
+
# See the License for the specific language governing permissions and
|
16
|
+
# limitations under the License.
|
17
|
+
#
|
18
|
+
module RuboCop
|
19
|
+
module Cop
|
20
|
+
module Chef
|
21
|
+
module ChefCorrectness
|
22
|
+
# The macos_userdefaults resource prior to Chef Infra Client 16.3 would silently continue if invalid types were passed resulting in unexpected behavior. Valid values are: "array", "bool", "dict", "float", "int", and "string".
|
23
|
+
#
|
24
|
+
# @example
|
25
|
+
#
|
26
|
+
# # bad
|
27
|
+
# macos_userdefaults 'set a value' do
|
28
|
+
# global true
|
29
|
+
# key 'key'
|
30
|
+
# type 'boolean'
|
31
|
+
# end
|
32
|
+
#
|
33
|
+
# # good
|
34
|
+
# macos_userdefaults 'set a value' do
|
35
|
+
# global true
|
36
|
+
# key 'key'
|
37
|
+
# type 'bool'
|
38
|
+
# end
|
39
|
+
#
|
40
|
+
class MacosUserdefaultsInvalidType < Base
|
41
|
+
include RuboCop::Chef::CookbookHelpers
|
42
|
+
extend RuboCop::Cop::AutoCorrector
|
43
|
+
|
44
|
+
VALID_VALUES = %w(array bool dict float int string).freeze
|
45
|
+
INVALID_VALUE_MAP = {
|
46
|
+
'boolean' => 'bool',
|
47
|
+
'str' => 'string',
|
48
|
+
'integer' => 'int',
|
49
|
+
}.freeze
|
50
|
+
|
51
|
+
MSG = 'The macos_userdefaults resource prior to Chef Infra Client 16.3 would silently continue if invalid types were passed resulting in unexpected behavior. Valid values are: "array", "bool", "dict", "float", "int", and "string".'
|
52
|
+
|
53
|
+
def on_block(node)
|
54
|
+
match_property_in_resource?(:macos_userdefaults, 'type', node) do |type|
|
55
|
+
type_val = method_arg_ast_to_string(type)
|
56
|
+
return if VALID_VALUES.include?(type_val)
|
57
|
+
add_offense(type.loc.expression, message: MSG, severity: :refactor) do |corrector|
|
58
|
+
if INVALID_VALUE_MAP[type_val]
|
59
|
+
corrector.replace(type.loc.expression, "type '#{INVALID_VALUE_MAP[type_val]}'")
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
@@ -25,20 +25,20 @@ module RuboCop
|
|
25
25
|
# @example
|
26
26
|
#
|
27
27
|
# # bad
|
28
|
-
# execute 'some
|
28
|
+
# execute 'some command' do
|
29
29
|
# notifies 'restart', 'service[httpd]', 'delayed'
|
30
30
|
# end
|
31
31
|
#
|
32
|
-
# execute 'some
|
32
|
+
# execute 'some command' do
|
33
33
|
# subscribes 'restart', 'service[httpd]', 'delayed'
|
34
34
|
# end
|
35
35
|
#
|
36
36
|
# # good
|
37
|
-
# execute 'some
|
37
|
+
# execute 'some command' do
|
38
38
|
# notifies :restart, 'service[httpd]', 'delayed'
|
39
39
|
# end
|
40
40
|
#
|
41
|
-
# execute 'some
|
41
|
+
# execute 'some command' do
|
42
42
|
# subscribes :restart, 'service[httpd]', 'delayed'
|
43
43
|
# end
|
44
44
|
#
|
@@ -19,13 +19,13 @@
|
|
19
19
|
module RuboCop
|
20
20
|
module Cop
|
21
21
|
module Chef
|
22
|
-
# The
|
22
|
+
# The Librarian-Chef depsolving project is no longer maintained and a Cheffile should not be used for cookbook depsolving. Consider using Policyfiles instead. If the Policyfiles model is not compatible with your workflow you may find Berkshelf offers a more similar, and still supported, experience to Librarian-Chef.
|
23
23
|
#
|
24
24
|
module ChefDeprecations
|
25
25
|
class Cheffile < Cop
|
26
26
|
include RangeHelp
|
27
27
|
|
28
|
-
MSG = 'The
|
28
|
+
MSG = 'The Librarian-Chef depsolving project is no longer maintained and a Cheffile should not be used for cookbook depsolving. Consider using Policyfiles instead.'
|
29
29
|
|
30
30
|
def investigate(processed_source)
|
31
31
|
return if processed_source.blank?
|
@@ -19,7 +19,7 @@ module RuboCop
|
|
19
19
|
module Cop
|
20
20
|
module Chef
|
21
21
|
module ChefDeprecations
|
22
|
-
# 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
|
22
|
+
# 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 information.
|
23
23
|
#
|
24
24
|
# @example
|
25
25
|
#
|
@@ -33,7 +33,7 @@ module RuboCop
|
|
33
33
|
# end
|
34
34
|
|
35
35
|
class EOLAuditModeUsage < Cop
|
36
|
-
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
|
36
|
+
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 information.'
|
37
37
|
|
38
38
|
def_node_matcher :control_group?, '(send nil? :control_group ...)'
|
39
39
|
|
@@ -0,0 +1,61 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
#
|
3
|
+
# Copyright:: Copyright 2020, Chef Software Inc.
|
4
|
+
# Author:: Tim Smith (<tsmith@chef.io>)
|
5
|
+
#
|
6
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
7
|
+
# you may not use this file except in compliance with the License.
|
8
|
+
# You may obtain a copy of the License at
|
9
|
+
#
|
10
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
11
|
+
#
|
12
|
+
# Unless required by applicable law or agreed to in writing, software
|
13
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
14
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
15
|
+
# See the License for the specific language governing permissions and
|
16
|
+
# limitations under the License.
|
17
|
+
#
|
18
|
+
|
19
|
+
module RuboCop
|
20
|
+
module Cop
|
21
|
+
module Chef
|
22
|
+
module ChefDeprecations
|
23
|
+
# The `global` property in the macos_userdefaults resource was deprecated in Chef Infra Client 16.3. This property was never properly implemented and caused failures under many conditions. Omitting the `domain` property will now set global defaults.
|
24
|
+
#
|
25
|
+
# @example
|
26
|
+
#
|
27
|
+
# # bad
|
28
|
+
# macos_userdefaults 'set a value' do
|
29
|
+
# global true
|
30
|
+
# key 'key'
|
31
|
+
# value 'value'
|
32
|
+
# end
|
33
|
+
#
|
34
|
+
# # good
|
35
|
+
# macos_userdefaults 'set a value' do
|
36
|
+
# key 'key'
|
37
|
+
# value 'value'
|
38
|
+
# end
|
39
|
+
#
|
40
|
+
class MacosUserdefaultsGlobalProperty < Base
|
41
|
+
extend TargetChefVersion
|
42
|
+
include RangeHelp
|
43
|
+
include RuboCop::Chef::CookbookHelpers
|
44
|
+
extend AutoCorrector
|
45
|
+
|
46
|
+
minimum_target_chef_version '16.3'
|
47
|
+
|
48
|
+
MSG = 'The `global` property in the macos_userdefaults resource was deprecated in Chef Infra Client 16.3. Omitting the `domain` property will now set global defaults.'
|
49
|
+
|
50
|
+
def on_block(node)
|
51
|
+
match_property_in_resource?(:macos_userdefaults, 'global', node) do |global|
|
52
|
+
add_offense(global.loc.expression, message: MSG, severity: :warning) do |corrector|
|
53
|
+
corrector.remove(range_with_surrounding_space(range: global.loc.expression, side: :left))
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
@@ -25,12 +25,12 @@ module RuboCop
|
|
25
25
|
#
|
26
26
|
# # bad
|
27
27
|
# poise_archive 'https://example.com/myapp.tgz' do
|
28
|
-
# destination '/opt/
|
28
|
+
# destination '/opt/my_app'
|
29
29
|
# end
|
30
30
|
#
|
31
31
|
# # good
|
32
32
|
# archive_file 'https://example.com/myapp.tgz' do
|
33
|
-
# destination '/opt/
|
33
|
+
# destination '/opt/my_app'
|
34
34
|
# end
|
35
35
|
#
|
36
36
|
class PoiseArchiveUsage < Cop
|
@@ -39,7 +39,7 @@ module RuboCop
|
|
39
39
|
|
40
40
|
def_node_search :provides, '(send nil? :provides (sym $_) ...)'
|
41
41
|
|
42
|
-
# determine the cookbook name either by parsing
|
42
|
+
# determine the cookbook name either by parsing metadata.rb or by parsing metadata.json
|
43
43
|
#
|
44
44
|
# @returns [String] the cookbook name
|
45
45
|
def cookbook_name
|
@@ -27,7 +27,7 @@ module RuboCop
|
|
27
27
|
# node.environment == "production"
|
28
28
|
# node.chef_environment == "production"
|
29
29
|
#
|
30
|
-
class
|
30
|
+
class CookbookUsesEnvironments < Cop
|
31
31
|
MSG = 'Cookbook uses environments, which cannot be used in Policyfiles or Effortless Infra'
|
32
32
|
|
33
33
|
def on_send(node)
|
@@ -19,13 +19,13 @@ module RuboCop
|
|
19
19
|
module Cop
|
20
20
|
module Chef
|
21
21
|
module ChefEffortless
|
22
|
-
# Neither Policyfiles or Effortless Infra which is based on Policyfiles supports Chef Roles
|
22
|
+
# Neither Policyfiles or Effortless Infra which is based on Policyfiles supports Chef Infra Roles
|
23
23
|
#
|
24
24
|
# @example
|
25
25
|
#
|
26
26
|
# # bad
|
27
|
-
# node.role?('
|
28
|
-
# node.roles.include?('
|
27
|
+
# node.role?('web_server')
|
28
|
+
# node.roles.include?('web_server')
|
29
29
|
#
|
30
30
|
class CookbookUsesRoles < Cop
|
31
31
|
MSG = 'Cookbook uses roles, which cannot be used in Policyfiles or Effortless Infra'
|
@@ -56,13 +56,13 @@ module RuboCop
|
|
56
56
|
|
57
57
|
def_node_search :action_methods?, '(send nil? {:actions :allowed_actions} ... )'
|
58
58
|
|
59
|
-
def_node_search :
|
59
|
+
def_node_search :initialize_method, '(def :initialize ... )'
|
60
60
|
|
61
61
|
def autocorrect(node)
|
62
62
|
lambda do |corrector|
|
63
63
|
# insert the new allowed_actions call above the initialize method, but not if one already exists (this is sadly common)
|
64
64
|
unless action_methods?(processed_source.ast)
|
65
|
-
initialize_node =
|
65
|
+
initialize_node = initialize_method(processed_source.ast).first
|
66
66
|
corrector.insert_before(initialize_node.source_range, "allowed_actions #{node.descendants.first.source}\n\n")
|
67
67
|
end
|
68
68
|
|
@@ -47,13 +47,13 @@ module RuboCop
|
|
47
47
|
(ivasgn {:@action :@default_action} $(...))
|
48
48
|
PATTERN
|
49
49
|
|
50
|
-
def_node_search :
|
50
|
+
def_node_search :initialize_method, '(def :initialize ... )'
|
51
51
|
|
52
52
|
def_node_search :default_action_method?, '(send nil? :default_action ... )'
|
53
53
|
|
54
54
|
def on_ivasgn(node)
|
55
55
|
action_variable_assignment?(node) do
|
56
|
-
add_offense(node, location: :expression, message: MSG, severity: :refactor) if
|
56
|
+
add_offense(node, location: :expression, message: MSG, severity: :refactor) if initialize_method(node.parent.parent)
|
57
57
|
end
|
58
58
|
end
|
59
59
|
|
@@ -61,7 +61,7 @@ module RuboCop
|
|
61
61
|
lambda do |corrector|
|
62
62
|
# insert the new default_action call above the initialize method, but not if one already exists (this is sadly common)
|
63
63
|
unless default_action_method?(processed_source.ast)
|
64
|
-
initialize_node =
|
64
|
+
initialize_node = initialize_method(processed_source.ast).first
|
65
65
|
corrector.insert_before(initialize_node.source_range, "default_action #{node.descendants.first.source}\n\n")
|
66
66
|
end
|
67
67
|
|
@@ -19,7 +19,7 @@ module RuboCop
|
|
19
19
|
module Cop
|
20
20
|
module Chef
|
21
21
|
module ChefModernize
|
22
|
-
# In 2016 with Chef Infra Client 12.5 Custom Resources were introduced as a way of writing reusable resource code that could be shipped in cookbooks. Custom Resources offer many advantages of legacy Definitions including unit testing with ChefSpec, input validation, actions,
|
22
|
+
# In 2016 with Chef Infra Client 12.5 Custom Resources were introduced as a way of writing reusable resource code that could be shipped in cookbooks. Custom Resources offer many advantages of legacy Definitions including unit testing with ChefSpec, input validation, actions, common properties like not_if/only_if, and resource reporting.
|
23
23
|
#
|
24
24
|
class Definitions < Cop
|
25
25
|
include RuboCop::Chef::CookbookHelpers
|
@@ -43,19 +43,19 @@ module RuboCop
|
|
43
43
|
|
44
44
|
def on_ivasgn(node)
|
45
45
|
provides_assignment?(node) do
|
46
|
-
add_offense(node, location: :expression, message: MSG, severity: :refactor) if
|
46
|
+
add_offense(node, location: :expression, message: MSG, severity: :refactor) if initialize_method(node.parent.parent).any?
|
47
47
|
end
|
48
48
|
end
|
49
49
|
|
50
50
|
def_node_search :provides_method?, '(send nil? :provides ... )'
|
51
51
|
|
52
|
-
def_node_search :
|
52
|
+
def_node_search :initialize_method, '(def :initialize ... )'
|
53
53
|
|
54
54
|
def autocorrect(node)
|
55
55
|
lambda do |corrector|
|
56
56
|
# insert the new provides call above the initialize method, but not if one already exists (this is sadly common)
|
57
57
|
unless provides_method?(processed_source.ast)
|
58
|
-
initialize_node =
|
58
|
+
initialize_node = initialize_method(processed_source.ast).first
|
59
59
|
corrector.insert_before(initialize_node.source_range, "provides #{node.descendants.first.source}\n\n")
|
60
60
|
end
|
61
61
|
|
@@ -48,12 +48,12 @@ module RuboCop
|
|
48
48
|
end
|
49
49
|
end
|
50
50
|
|
51
|
-
def_node_search :
|
51
|
+
def_node_search :initialize_method, '(def :initialize ... )'
|
52
52
|
|
53
53
|
def autocorrect(node)
|
54
54
|
lambda do |corrector|
|
55
55
|
# insert the new resource_name call above the initialize method
|
56
|
-
initialize_node =
|
56
|
+
initialize_node = initialize_method(processed_source.ast).first
|
57
57
|
corrector.insert_before(initialize_node.source_range, "resource_name #{node.descendants.first.source}\n\n")
|
58
58
|
|
59
59
|
# remove the variable from the initialize method
|
@@ -19,7 +19,7 @@ module RuboCop
|
|
19
19
|
module Cop
|
20
20
|
module Chef
|
21
21
|
module ChefModernize
|
22
|
-
# Pass an array of packages to package resources instead of
|
22
|
+
# Pass an array of packages to package resources instead of iterating over an array of packages when using multi-package capable package subsystem such as apt, yum, chocolatey, dnf, or zypper. Multi-package installs are faster and simplify logs.
|
23
23
|
#
|
24
24
|
# @example
|
25
25
|
#
|
@@ -34,7 +34,7 @@ module RuboCop
|
|
34
34
|
# package %w(bmon htop vim curl)
|
35
35
|
#
|
36
36
|
class UseMultipackageInstalls < Cop
|
37
|
-
MSG = 'Pass an array of packages to package resources instead of
|
37
|
+
MSG = 'Pass an array of packages to package resources instead of iterating over an array of packages when using multi-package capable package subsystem such as apt, yum, chocolatey, dnf, or zypper. Multi-package installs are faster and simplify logs.'
|
38
38
|
MULTIPACKAGE_PLATS = %w(debian redhat suse amazon fedora scientific oracle rhel ubuntu centos redhat).freeze
|
39
39
|
|
40
40
|
def_node_matcher :platform_or_platform_family?, <<-PATTERN
|
@@ -73,7 +73,7 @@ module RuboCop
|
|
73
73
|
(lvar _))})
|
74
74
|
PATTERN
|
75
75
|
|
76
|
-
# see if all platforms in the when condition are
|
76
|
+
# see if all platforms in the when condition are multi-package compliant
|
77
77
|
def multipackage_platforms?(condition_obj)
|
78
78
|
condition_obj.all? do |p|
|
79
79
|
MULTIPACKAGE_PLATS.include?(p.value)
|
@@ -45,18 +45,18 @@ module RuboCop
|
|
45
45
|
class OhaiAttributeToString < Cop
|
46
46
|
MSG = "This Ohai node attribute is already a string and doesn't need to be converted"
|
47
47
|
|
48
|
-
def_node_matcher :
|
48
|
+
def_node_matcher :attribute_to_s?, <<-PATTERN
|
49
49
|
(send (send (send nil? :node) :[] $(str {"platform" "platform_family" "platform_version" "fqdn" "hostname" "os" "name"}) ) :to_s )
|
50
50
|
PATTERN
|
51
51
|
|
52
52
|
def on_send(node)
|
53
|
-
|
53
|
+
attribute_to_s?(node) do
|
54
54
|
add_offense(node, location: :expression, message: MSG, severity: :refactor)
|
55
55
|
end
|
56
56
|
end
|
57
57
|
|
58
58
|
def autocorrect(node)
|
59
|
-
|
59
|
+
attribute_to_s?(node) do |method|
|
60
60
|
lambda do |corrector|
|
61
61
|
corrector.replace(node.loc.expression, "node['#{method.value}']")
|
62
62
|
end
|
@@ -19,7 +19,7 @@ module RuboCop
|
|
19
19
|
module Cop
|
20
20
|
module Chef
|
21
21
|
module ChefSharing
|
22
|
-
# Resource properties should include description fields to allow automated
|
22
|
+
# Resource properties should include description fields to allow automated documentation. Requires Chef Infra Client 13.9 or later.
|
23
23
|
#
|
24
24
|
# @example
|
25
25
|
#
|
@@ -34,7 +34,7 @@ module RuboCop
|
|
34
34
|
|
35
35
|
minimum_target_chef_version '13.9'
|
36
36
|
|
37
|
-
MSG = 'Resource properties should include description fields to allow automated
|
37
|
+
MSG = 'Resource properties should include description fields to allow automated documentation. Requires Chef Infra Client 13.9 or later.'
|
38
38
|
|
39
39
|
# any method named property being called with a symbol argument and anything else
|
40
40
|
def_node_matcher :property?, '(send nil? :property (sym _) ...)'
|
@@ -19,7 +19,7 @@ module RuboCop
|
|
19
19
|
module Cop
|
20
20
|
module Chef
|
21
21
|
module ChefSharing
|
22
|
-
# Resources should include description fields to allow automated
|
22
|
+
# Resources should include description fields to allow automated documentation. Requires Chef Infra Client 13.9 or later.
|
23
23
|
#
|
24
24
|
# @example
|
25
25
|
#
|
@@ -33,7 +33,7 @@ module RuboCop
|
|
33
33
|
|
34
34
|
minimum_target_chef_version '13.9'
|
35
35
|
|
36
|
-
MSG = 'Resources should include description fields to allow automated
|
36
|
+
MSG = 'Resources should include description fields to allow automated documentation. Requires Chef Infra Client 13.9 or later.'
|
37
37
|
|
38
38
|
def investigate(processed_source)
|
39
39
|
return if processed_source.blank?
|
@@ -19,7 +19,7 @@ module RuboCop
|
|
19
19
|
module Cop
|
20
20
|
module Chef
|
21
21
|
module ChefSharing
|
22
|
-
# Resources should include examples field to allow automated
|
22
|
+
# Resources should include examples field to allow automated documentation. Requires Chef Infra Client 13.9 or later.
|
23
23
|
#
|
24
24
|
# @example
|
25
25
|
#
|
@@ -41,7 +41,7 @@ module RuboCop
|
|
41
41
|
|
42
42
|
minimum_target_chef_version '13.9'
|
43
43
|
|
44
|
-
MSG = 'Resources should include examples field to allow automated
|
44
|
+
MSG = 'Resources should include examples field to allow automated documentation. Requires Chef Infra Client 13.9 or later.'
|
45
45
|
|
46
46
|
def investigate(processed_source)
|
47
47
|
return if processed_source.blank?
|
@@ -19,39 +19,58 @@ module RuboCop
|
|
19
19
|
module Cop
|
20
20
|
module Chef
|
21
21
|
module ChefStyle
|
22
|
-
#
|
22
|
+
# Use strings to represent file modes to avoid confusion between octal and base 10 integer formats.
|
23
23
|
#
|
24
24
|
# @example
|
25
25
|
#
|
26
26
|
# # bad
|
27
|
-
#
|
28
|
-
#
|
27
|
+
# remote_directory '/etc/my.conf' do
|
28
|
+
# content 'some content'
|
29
|
+
# mode 0600
|
30
|
+
# action :create
|
31
|
+
# end
|
32
|
+
#
|
33
|
+
# remote_directory 'handler' do
|
34
|
+
# source 'handlers'
|
35
|
+
# recursive true
|
36
|
+
# files_mode 644
|
37
|
+
# action :create
|
38
|
+
# end
|
29
39
|
#
|
30
40
|
# # good
|
31
|
-
#
|
41
|
+
# remote_directory '/etc/my.conf' do
|
42
|
+
# content 'some content'
|
43
|
+
# mode '600'
|
44
|
+
# action :create
|
45
|
+
# end
|
46
|
+
#
|
47
|
+
# remote_directory 'handler' do
|
48
|
+
# source 'handlers'
|
49
|
+
# recursive true
|
50
|
+
# files_mode '644'
|
51
|
+
# action :create
|
52
|
+
# end
|
32
53
|
#
|
33
|
-
class FileMode <
|
34
|
-
|
54
|
+
class FileMode < Base
|
55
|
+
extend RuboCop::Cop::AutoCorrector
|
56
|
+
|
57
|
+
MSG = 'Use strings to represent file modes to avoid confusion between octal and base 10 integer formats'
|
35
58
|
|
36
59
|
def_node_matcher :resource_mode?, <<-PATTERN
|
37
|
-
(send nil? :mode $int)
|
60
|
+
(send nil? {:mode :files_mode} $int)
|
38
61
|
PATTERN
|
39
62
|
|
40
63
|
def on_send(node)
|
41
64
|
resource_mode?(node) do |mode_int|
|
42
|
-
add_offense(mode_int
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
def autocorrect(node)
|
47
|
-
lambda do |corrector|
|
48
|
-
# If it was an octal literal, make sure we write out the right number.
|
49
|
-
replacement_base = octal?(node) ? 8 : 10
|
50
|
-
replacement_mode = node.children.first.to_s(replacement_base)
|
65
|
+
add_offense(mode_int.loc.expression, message: MSG, severity: :refactor) do |corrector|
|
66
|
+
# If it was an octal literal, make sure we write out the right number.
|
67
|
+
replacement_base = octal?(mode_int) ? 8 : 10
|
68
|
+
replacement_mode = mode_int.children.first.to_s(replacement_base)
|
51
69
|
|
52
|
-
|
53
|
-
|
54
|
-
|
70
|
+
# we build our own escaped string instead of using .inspect because that way
|
71
|
+
# we can use single quotes instead of the double quotes that .inspect adds
|
72
|
+
corrector.replace(mode_int.loc.expression, "\'#{replacement_mode}\'")
|
73
|
+
end
|
55
74
|
end
|
56
75
|
end
|
57
76
|
|
@@ -67,7 +67,7 @@ module RuboCop
|
|
67
67
|
condition_string = node.when_branches.first.conditions.map(&:source).join(', ')
|
68
68
|
|
69
69
|
# single line bodies without an else statement should be transformed into `X if platform?('ubuntu')` style statements
|
70
|
-
# while
|
70
|
+
# while multi-line statements should just have the case and when bits replace with `if platform?('ubuntu')`
|
71
71
|
if !node.else? && !node.when_branches.first.body.multiline?
|
72
72
|
new_source = "#{node.when_branches.first.body.source} if #{type.value}?(#{condition_string})"
|
73
73
|
corrector.replace(node.loc.expression, new_source)
|
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.14.7
|
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-07-
|
12
|
+
date: 2020-07-30 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rubocop
|
@@ -67,6 +67,7 @@ files:
|
|
67
67
|
- lib/rubocop/cop/chef/correctness/invalid_value_for_platform_helper.rb
|
68
68
|
- lib/rubocop/cop/chef/correctness/invalid_version_metadata.rb
|
69
69
|
- lib/rubocop/cop/chef/correctness/lazy_eval_node_attribute_defaults.rb
|
70
|
+
- lib/rubocop/cop/chef/correctness/macos_userdefaults_invalid_type.rb
|
70
71
|
- lib/rubocop/cop/chef/correctness/malformed_value_for_platform.rb
|
71
72
|
- lib/rubocop/cop/chef/correctness/metadata_missing_name.rb
|
72
73
|
- lib/rubocop/cop/chef/correctness/node_normal.rb
|
@@ -113,6 +114,7 @@ files:
|
|
113
114
|
- lib/rubocop/cop/chef/deprecation/legacy_yum_cookbook_recipes.rb
|
114
115
|
- lib/rubocop/cop/chef/deprecation/locale_lc_all_property.rb
|
115
116
|
- lib/rubocop/cop/chef/deprecation/log_resource_notifications.rb
|
117
|
+
- lib/rubocop/cop/chef/deprecation/macos_userdefaults_global_property.rb
|
116
118
|
- lib/rubocop/cop/chef/deprecation/name_property_and_default.rb
|
117
119
|
- lib/rubocop/cop/chef/deprecation/node_deep_fetch.rb
|
118
120
|
- lib/rubocop/cop/chef/deprecation/node_methods_not_attributes.rb
|
@@ -258,9 +260,9 @@ files:
|
|
258
260
|
- lib/rubocop/cop/chef/style/unnecessary_platform_case_statement.rb
|
259
261
|
- lib/rubocop/cop/chef/style/use_platform_helpers.rb
|
260
262
|
- lib/rubocop/cop/target_chef_version.rb
|
263
|
+
- lib/rubocop/monkey_patches/base.rb
|
261
264
|
- lib/rubocop/monkey_patches/comment_config.rb
|
262
265
|
- lib/rubocop/monkey_patches/config.rb
|
263
|
-
- lib/rubocop/monkey_patches/cop.rb
|
264
266
|
- lib/rubocop/monkey_patches/registry_cop.rb
|
265
267
|
- lib/rubocop/monkey_patches/team.rb
|
266
268
|
homepage:
|