cookstyle 5.18.4 → 5.19.9
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 +18 -4
- data/lib/cookstyle/version.rb +1 -1
- data/lib/rubocop/cop/chef/correctness/cb_depends_on_self.rb +3 -1
- data/lib/rubocop/cop/chef/deprecation/chef_rewind.rb +3 -2
- data/lib/rubocop/cop/chef/deprecation/depends_compat_resource.rb +2 -1
- data/lib/rubocop/cop/chef/deprecation/deprecated_mixins.rb +3 -1
- data/lib/rubocop/cop/chef/deprecation/use_inline_resources.rb +3 -1
- data/lib/rubocop/cop/chef/deprecation/user_supports_property.rb +6 -2
- data/lib/rubocop/cop/chef/deprecation/yum_dnf_compat_recipe.rb +3 -1
- data/lib/rubocop/cop/chef/modernize/allowed_actions_initializer.rb +1 -1
- data/lib/rubocop/cop/chef/modernize/chef_14_resources.rb +2 -1
- data/lib/rubocop/cop/chef/modernize/chef_gem_nokogiri.rb +2 -1
- data/lib/rubocop/cop/chef/modernize/default_action_initializer.rb +9 -10
- data/lib/rubocop/cop/chef/modernize/defines_chefspec_matchers.rb +3 -1
- data/lib/rubocop/cop/chef/modernize/depends_zypper_cookbook.rb +2 -1
- data/lib/rubocop/cop/chef/modernize/empty_resource_initialize.rb +3 -1
- data/lib/rubocop/cop/chef/modernize/includes_mixin_shellout.rb +3 -1
- data/lib/rubocop/cop/chef/modernize/minitest_handler_usage.rb +3 -1
- data/lib/rubocop/cop/chef/modernize/unnecessary_mixlib_shellout_require.rb +3 -1
- data/lib/rubocop/cop/chef/modernize/whyrun_supported_true.rb +2 -1
- data/lib/rubocop/cop/chef/modernize/windows_default_recipe.rb +3 -1
- data/lib/rubocop/cop/chef/redundant/attribute_metadata.rb +3 -1
- data/lib/rubocop/cop/chef/redundant/conflicts_metadata.rb +3 -1
- data/lib/rubocop/cop/chef/redundant/grouping_metadata.rb +48 -0
- data/lib/rubocop/cop/chef/redundant/long_description_metadata.rb +6 -1
- data/lib/rubocop/cop/chef/redundant/provides_metadata.rb +3 -1
- data/lib/rubocop/cop/chef/redundant/recipe_metadata.rb +3 -1
- data/lib/rubocop/cop/chef/redundant/replaces_metadata.rb +3 -1
- data/lib/rubocop/cop/chef/redundant/resource_with_nothing_action.rb +3 -1
- data/lib/rubocop/cop/chef/redundant/suggests_metadata.rb +3 -1
- data/lib/rubocop/cop/chef/sharing/invalid_license_string.rb +1 -0
- data/lib/rubocop/cop/chef/style/file_mode.rb +4 -1
- data/lib/rubocop/cop/chef/style/overly_complex_supports_depends_metadata.rb +73 -0
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0f5cc0916309f625be3469422c3feb76f7e1340fca4ae99cc5110b0b80f857f6
|
4
|
+
data.tar.gz: 1c813c90c2bef8b8c869c4d9a826be958507a31db227c4b67ff1025192ab624c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0e8ae2b07a6b712889fa67ececde059ae3063fa89627fe6937668ed101a9874bfc98d2faaf5ac36cf99063fb14c9835595052213ffc299d5bc0b5aac28502153
|
7
|
+
data.tar.gz: 61747c1c26cf1708cfd82ca7945850c8fb2022a18d16c33145ed805741c313ee6bb0c0fc849ba90dad4a0a65ae53e10ea9d4b0291f5b14faaafc43ea18d7a8b0
|
data/config/cookstyle.yml
CHANGED
@@ -115,6 +115,13 @@ ChefStyle/TrueClassFalseClassResourceProperties:
|
|
115
115
|
- '**/libraries/*.rb'
|
116
116
|
- '**/resources/*.rb'
|
117
117
|
|
118
|
+
ChefStyle/OverlyComplexSupportsDependsMetadata:
|
119
|
+
Description: Don't loop over an array to set cookbook dependencies or supported platforms if you have fewer than three values to set.
|
120
|
+
Enabled: true
|
121
|
+
VersionAdded: '5.19.0'
|
122
|
+
Include:
|
123
|
+
- '**/metadata.rb'
|
124
|
+
|
118
125
|
###############################
|
119
126
|
# ChefCorrectness: Avoiding potential problems
|
120
127
|
###############################
|
@@ -1095,7 +1102,7 @@ ChefRedundantCode/ConflictsMetadata:
|
|
1095
1102
|
- '**/metadata.rb'
|
1096
1103
|
|
1097
1104
|
ChefRedundantCode/SuggestsMetadata:
|
1098
|
-
Description:
|
1105
|
+
Description: The suggests metadata.rb method is not used and is unnecessary in cookbooks.
|
1099
1106
|
Enabled: true
|
1100
1107
|
VersionAdded: '5.1.0'
|
1101
1108
|
VersionChanged: '5.15.0'
|
@@ -1103,7 +1110,7 @@ ChefRedundantCode/SuggestsMetadata:
|
|
1103
1110
|
- '**/metadata.rb'
|
1104
1111
|
|
1105
1112
|
ChefRedundantCode/ProvidesMetadata:
|
1106
|
-
Description:
|
1113
|
+
Description: The provides metadata.rb method is not used and is unnecessary in cookbooks.
|
1107
1114
|
Enabled: true
|
1108
1115
|
VersionAdded: '5.1.0'
|
1109
1116
|
VersionChanged: '5.15.0'
|
@@ -1111,7 +1118,7 @@ ChefRedundantCode/ProvidesMetadata:
|
|
1111
1118
|
- '**/metadata.rb'
|
1112
1119
|
|
1113
1120
|
ChefRedundantCode/ReplacesMetadata:
|
1114
|
-
Description:
|
1121
|
+
Description: The replaces metadata.rb method is not used and is unnecessary in cookbooks.
|
1115
1122
|
Enabled: true
|
1116
1123
|
VersionAdded: '5.1.0'
|
1117
1124
|
VersionChanged: '5.15.0'
|
@@ -1119,7 +1126,7 @@ ChefRedundantCode/ReplacesMetadata:
|
|
1119
1126
|
- '**/metadata.rb'
|
1120
1127
|
|
1121
1128
|
ChefRedundantCode/AttributeMetadata:
|
1122
|
-
Description:
|
1129
|
+
Description: The attribute metadata.rb method is not used and is unnecessary in cookbooks.
|
1123
1130
|
Enabled: true
|
1124
1131
|
VersionAdded: '5.1.0'
|
1125
1132
|
VersionChanged: '5.15.0'
|
@@ -1221,6 +1228,13 @@ ChefRedundantCode/AptRepositoryDistributionDefault:
|
|
1221
1228
|
- '**/attributes/*.rb'
|
1222
1229
|
- '**/Berksfile'
|
1223
1230
|
|
1231
|
+
ChefRedundantCode/GroupingMetadata:
|
1232
|
+
Description: The grouping metadata.rb method is not used and is unnecessary in cookbooks.
|
1233
|
+
Enabled: true
|
1234
|
+
VersionAdded: '5.19.0'
|
1235
|
+
Include:
|
1236
|
+
- '**/metadata.rb'
|
1237
|
+
|
1224
1238
|
###############################
|
1225
1239
|
# Migrating to new patterns
|
1226
1240
|
###############################
|
data/lib/cookstyle/version.rb
CHANGED
@@ -31,6 +31,8 @@ module RuboCop
|
|
31
31
|
#
|
32
32
|
module ChefCorrectness
|
33
33
|
class CookbooksDependsOnSelf < Cop
|
34
|
+
include RangeHelp
|
35
|
+
|
34
36
|
MSG = 'A cookbook cannot depend on itself. This will fail on Chef Infra Client 13+'.freeze
|
35
37
|
|
36
38
|
def_node_search :dependencies, '(send nil? :depends str ...)'
|
@@ -49,7 +51,7 @@ module RuboCop
|
|
49
51
|
|
50
52
|
def autocorrect(node)
|
51
53
|
lambda do |corrector|
|
52
|
-
corrector.remove(node.
|
54
|
+
corrector.remove(range_with_surrounding_space(range: node.loc.expression, side: :left))
|
53
55
|
end
|
54
56
|
end
|
55
57
|
end
|
@@ -36,6 +36,7 @@ module RuboCop
|
|
36
36
|
#
|
37
37
|
class ChefRewind < Cop
|
38
38
|
include RuboCop::Chef::CookbookHelpers
|
39
|
+
include RangeHelp
|
39
40
|
extend TargetChefVersion
|
40
41
|
|
41
42
|
minimum_target_chef_version '12.10'
|
@@ -83,12 +84,12 @@ module RuboCop
|
|
83
84
|
lambda do |corrector|
|
84
85
|
rewind_gem_install?(node) do
|
85
86
|
node = node.parent if node.parent&.block_type? # make sure we get the whole block not just the method in the block
|
86
|
-
corrector.remove(node.loc.expression)
|
87
|
+
corrector.remove(range_with_surrounding_space(range: node.loc.expression, side: :left))
|
87
88
|
return
|
88
89
|
end
|
89
90
|
|
90
91
|
require_rewind?(node) do
|
91
|
-
corrector.remove(node.loc.expression)
|
92
|
+
corrector.remove(range_with_surrounding_space(range: node.loc.expression, side: :left))
|
92
93
|
return
|
93
94
|
end
|
94
95
|
|
@@ -26,6 +26,7 @@ module RuboCop
|
|
26
26
|
# depends 'compat_resource'
|
27
27
|
#
|
28
28
|
class CookbookDependsOnCompatResource < Cop
|
29
|
+
include RangeHelp
|
29
30
|
extend TargetChefVersion
|
30
31
|
|
31
32
|
minimum_target_chef_version '12.19'
|
@@ -44,7 +45,7 @@ module RuboCop
|
|
44
45
|
|
45
46
|
def autocorrect(node)
|
46
47
|
lambda do |corrector|
|
47
|
-
corrector.remove(node.loc.expression)
|
48
|
+
corrector.remove(range_with_surrounding_space(range: node.loc.expression, side: :left))
|
48
49
|
end
|
49
50
|
end
|
50
51
|
end
|
@@ -34,6 +34,8 @@ module RuboCop
|
|
34
34
|
# require 'chef/mixin/language_include_recipe'
|
35
35
|
#
|
36
36
|
class UsesDeprecatedMixins < Cop
|
37
|
+
include RangeHelp
|
38
|
+
|
37
39
|
MSG = "Don't use deprecated Mixins no longer included in Chef Infra Client 14 and later.".freeze
|
38
40
|
|
39
41
|
def_node_matcher :deprecated_mixin?, <<-PATTERN
|
@@ -64,7 +66,7 @@ module RuboCop
|
|
64
66
|
|
65
67
|
def autocorrect(node)
|
66
68
|
lambda do |corrector|
|
67
|
-
corrector.remove(node.loc.expression)
|
69
|
+
corrector.remove(range_with_surrounding_space(range: node.loc.expression, side: :left))
|
68
70
|
end
|
69
71
|
end
|
70
72
|
end
|
@@ -29,6 +29,8 @@ module RuboCop
|
|
29
29
|
# use_inline_resources if respond_to?(:use_inline_resources)
|
30
30
|
#
|
31
31
|
class UseInlineResourcesDefined < Cop
|
32
|
+
include RangeHelp
|
33
|
+
|
32
34
|
MSG = 'use_inline_resources is now the default for resources in Chef Infra Client 13+ and does not need to be specified.'.freeze
|
33
35
|
|
34
36
|
def on_send(node)
|
@@ -47,7 +49,7 @@ module RuboCop
|
|
47
49
|
|
48
50
|
def autocorrect(node)
|
49
51
|
lambda do |corrector|
|
50
|
-
corrector.remove(node.loc.expression)
|
52
|
+
corrector.remove(range_with_surrounding_space(range: node.loc.expression, side: :left))
|
51
53
|
end
|
52
54
|
end
|
53
55
|
end
|
@@ -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");
|
@@ -30,6 +30,10 @@ module RuboCop
|
|
30
30
|
# })
|
31
31
|
# end
|
32
32
|
#
|
33
|
+
# user 'betty' do
|
34
|
+
# supports :manage_home => true
|
35
|
+
# end
|
36
|
+
#
|
33
37
|
# # good
|
34
38
|
# user "betty" do
|
35
39
|
# manage_home true
|
@@ -51,7 +55,7 @@ module RuboCop
|
|
51
55
|
lambda do |corrector|
|
52
56
|
new_text = []
|
53
57
|
node.arguments.first.each_pair do |k, v|
|
54
|
-
new_text << "#{k.
|
58
|
+
new_text << "#{k.value} #{v.source}"
|
55
59
|
end
|
56
60
|
|
57
61
|
corrector.replace(node.loc.expression, new_text.join("\n "))
|
@@ -27,6 +27,8 @@ module RuboCop
|
|
27
27
|
# include_recipe 'yum::dnf_yum_compat'
|
28
28
|
#
|
29
29
|
class IncludingYumDNFCompatRecipe < Cop
|
30
|
+
include RangeHelp
|
31
|
+
|
30
32
|
MSG = 'Do not include the deprecated yum::dnf_yum_compat default recipe to install yum on dnf systems. Chef Infra Client now includes built in support for DNF packages.'.freeze
|
31
33
|
|
32
34
|
def_node_matcher :yum_dnf_compat_recipe_usage?, <<-PATTERN
|
@@ -41,7 +43,7 @@ module RuboCop
|
|
41
43
|
|
42
44
|
def autocorrect(node)
|
43
45
|
lambda do |corrector|
|
44
|
-
corrector.remove(node.loc.expression)
|
46
|
+
corrector.remove(range_with_surrounding_space(range: node.loc.expression, side: :left))
|
45
47
|
end
|
46
48
|
end
|
47
49
|
end
|
@@ -47,7 +47,7 @@ module RuboCop
|
|
47
47
|
return if node.body.nil? # nil body is an empty initialize method
|
48
48
|
|
49
49
|
node.body.each_node do |x|
|
50
|
-
if x.assignment? && !x.node_parts.empty? && %i(@actions @allowed_actions).include?(x.node_parts.first)
|
50
|
+
if x.assignment? && !x.parent.op_asgn_type? && !x.node_parts.empty? && %i(@actions @allowed_actions).include?(x.node_parts.first)
|
51
51
|
add_offense(x, location: :expression, message: MSG, severity: :refactor)
|
52
52
|
end
|
53
53
|
end
|
@@ -33,6 +33,7 @@ module RuboCop
|
|
33
33
|
#
|
34
34
|
class UnnecessaryDependsChef14 < Cop
|
35
35
|
extend TargetChefVersion
|
36
|
+
include RangeHelp
|
36
37
|
|
37
38
|
minimum_target_chef_version '14.0'
|
38
39
|
|
@@ -50,7 +51,7 @@ module RuboCop
|
|
50
51
|
|
51
52
|
def autocorrect(node)
|
52
53
|
lambda do |corrector|
|
53
|
-
corrector.remove(node.loc.expression)
|
54
|
+
corrector.remove(range_with_surrounding_space(range: node.loc.expression, side: :left))
|
54
55
|
end
|
55
56
|
end
|
56
57
|
end
|
@@ -27,6 +27,7 @@ module RuboCop
|
|
27
27
|
# chef_gem 'nokogiri'
|
28
28
|
#
|
29
29
|
class ChefGemNokogiri < Cop
|
30
|
+
include RangeHelp
|
30
31
|
include RuboCop::Chef::CookbookHelpers
|
31
32
|
|
32
33
|
MSG = 'The nokogiri gem ships in Chef Infra Client 12+ and does not need to be installed before being used.'.freeze
|
@@ -50,7 +51,7 @@ module RuboCop
|
|
50
51
|
def autocorrect(node)
|
51
52
|
lambda do |corrector|
|
52
53
|
node = node.parent if node.parent&.block_type? # make sure we get the whole block not just the method in the block
|
53
|
-
corrector.remove(node.loc.expression)
|
54
|
+
corrector.remove(range_with_surrounding_space(range: node.loc.expression, side: :left))
|
54
55
|
end
|
55
56
|
end
|
56
57
|
end
|
@@ -42,20 +42,19 @@ 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
|
-
|
46
|
-
|
47
|
-
|
45
|
+
def_node_matcher :action_in_initializer?, <<-PATTERN
|
46
|
+
(def :initialize (args ...) <(begin ... $(ivasgn {:@action :@default_action} $(...)))> )
|
47
|
+
PATTERN
|
48
48
|
|
49
|
-
|
50
|
-
if x.assignment? && !x.node_parts.empty? && %i(@action @default_action).include?(x.node_parts.first)
|
51
|
-
add_offense(x, location: :expression, message: MSG, severity: :refactor)
|
52
|
-
end
|
53
|
-
end
|
54
|
-
end
|
49
|
+
def_node_search :intialize_method, '(def :initialize ... )'
|
55
50
|
|
56
51
|
def_node_search :default_action_method?, '(send nil? :default_action ... )'
|
57
52
|
|
58
|
-
|
53
|
+
def on_def(node)
|
54
|
+
action_in_initializer?(node) do |action, _val|
|
55
|
+
add_offense(action, location: :expression, message: MSG, severity: :refactor)
|
56
|
+
end
|
57
|
+
end
|
59
58
|
|
60
59
|
def autocorrect(node)
|
61
60
|
lambda do |corrector|
|
@@ -30,6 +30,8 @@ module RuboCop
|
|
30
30
|
# end
|
31
31
|
#
|
32
32
|
class DefinesChefSpecMatchers < Cop
|
33
|
+
include RangeHelp
|
34
|
+
|
33
35
|
MSG = 'ChefSpec matchers are now auto generated by ChefSpec 7.1+ and do not need to be defined in a cookbook'.freeze
|
34
36
|
|
35
37
|
def_node_matcher :chefspec_matcher?, <<-PATTERN
|
@@ -44,7 +46,7 @@ module RuboCop
|
|
44
46
|
|
45
47
|
def autocorrect(node)
|
46
48
|
lambda do |corrector|
|
47
|
-
corrector.remove(node.loc.expression)
|
49
|
+
corrector.remove(range_with_surrounding_space(range: node.loc.expression, side: :left))
|
48
50
|
end
|
49
51
|
end
|
50
52
|
end
|
@@ -27,6 +27,7 @@ module RuboCop
|
|
27
27
|
#
|
28
28
|
class DependsOnZypperCookbook < Cop
|
29
29
|
extend TargetChefVersion
|
30
|
+
include RangeHelp
|
30
31
|
|
31
32
|
minimum_target_chef_version '13.3'
|
32
33
|
|
@@ -44,7 +45,7 @@ module RuboCop
|
|
44
45
|
|
45
46
|
def autocorrect(node)
|
46
47
|
lambda do |corrector|
|
47
|
-
corrector.remove(node.loc.expression)
|
48
|
+
corrector.remove(range_with_surrounding_space(range: node.loc.expression, side: :left))
|
48
49
|
end
|
49
50
|
end
|
50
51
|
end
|
@@ -28,6 +28,8 @@ module RuboCop
|
|
28
28
|
# end
|
29
29
|
#
|
30
30
|
class EmptyResourceInitializeMethod < Cop
|
31
|
+
include RangeHelp
|
32
|
+
|
31
33
|
MSG = 'There is no need for an empty initialize method in a resource'.freeze
|
32
34
|
|
33
35
|
def_node_matcher :empty_initialize?, <<-PATTERN
|
@@ -42,7 +44,7 @@ module RuboCop
|
|
42
44
|
|
43
45
|
def autocorrect(node)
|
44
46
|
lambda do |corrector|
|
45
|
-
corrector.remove(node.loc.expression)
|
47
|
+
corrector.remove(range_with_surrounding_space(range: node.loc.expression, side: :left))
|
46
48
|
end
|
47
49
|
end
|
48
50
|
end
|
@@ -30,6 +30,8 @@ module RuboCop
|
|
30
30
|
# include Chef::Mixin::PowershellOut
|
31
31
|
#
|
32
32
|
class IncludingMixinShelloutInResources < Cop
|
33
|
+
include RangeHelp
|
34
|
+
|
33
35
|
MSG = 'There is no need to include Chef::Mixin::ShellOut or Chef::Mixin::PowershellOut in resources or providers as this is already done by Chef Infra Client 12.4+.'.freeze
|
34
36
|
|
35
37
|
def_node_matcher :include_shellout?, <<-PATTERN
|
@@ -52,7 +54,7 @@ module RuboCop
|
|
52
54
|
|
53
55
|
def autocorrect(node)
|
54
56
|
lambda do |corrector|
|
55
|
-
corrector.remove(node.loc.expression)
|
57
|
+
corrector.remove(range_with_surrounding_space(range: node.loc.expression, side: :left))
|
56
58
|
end
|
57
59
|
end
|
58
60
|
end
|
@@ -26,6 +26,8 @@ module RuboCop
|
|
26
26
|
# depends 'minitest-handler'
|
27
27
|
#
|
28
28
|
class MinitestHandlerUsage < Cop
|
29
|
+
include RangeHelp
|
30
|
+
|
29
31
|
MSG = 'Use Chef InSpec for testing instead of the Minitest Handler cookbook pattern.'.freeze
|
30
32
|
|
31
33
|
def_node_matcher :minitest_depends?, <<-PATTERN
|
@@ -40,7 +42,7 @@ module RuboCop
|
|
40
42
|
|
41
43
|
def autocorrect(node)
|
42
44
|
lambda do |corrector|
|
43
|
-
corrector.remove(node.loc.expression)
|
45
|
+
corrector.remove(range_with_surrounding_space(range: node.loc.expression, side: :left))
|
44
46
|
end
|
45
47
|
end
|
46
48
|
end
|
@@ -27,6 +27,8 @@ module RuboCop
|
|
27
27
|
# require 'mixlib/shellout'
|
28
28
|
#
|
29
29
|
class UnnecessaryMixlibShelloutRequire < Cop
|
30
|
+
include RangeHelp
|
31
|
+
|
30
32
|
MSG = 'Chef Infra Client 12.4+ includes mixlib/shellout automatically in resources and providers.'.freeze
|
31
33
|
|
32
34
|
def_node_matcher :require_mixlibshellout?, <<-PATTERN
|
@@ -41,7 +43,7 @@ module RuboCop
|
|
41
43
|
|
42
44
|
def autocorrect(node)
|
43
45
|
lambda do |corrector|
|
44
|
-
corrector.remove(node.loc.expression)
|
46
|
+
corrector.remove(range_with_surrounding_space(range: node.loc.expression, side: :left))
|
45
47
|
end
|
46
48
|
end
|
47
49
|
end
|
@@ -29,6 +29,7 @@ module RuboCop
|
|
29
29
|
#
|
30
30
|
class WhyRunSupportedTrue < Cop
|
31
31
|
extend TargetChefVersion
|
32
|
+
include RangeHelp
|
32
33
|
|
33
34
|
minimum_target_chef_version '13.0'
|
34
35
|
|
@@ -42,7 +43,7 @@ module RuboCop
|
|
42
43
|
|
43
44
|
def autocorrect(node)
|
44
45
|
lambda do |corrector|
|
45
|
-
corrector.remove(node.loc.expression)
|
46
|
+
corrector.remove(range_with_surrounding_space(range: node.loc.expression, side: :left))
|
46
47
|
end
|
47
48
|
end
|
48
49
|
end
|
@@ -27,6 +27,8 @@ module RuboCop
|
|
27
27
|
# include_recipe 'windows'
|
28
28
|
#
|
29
29
|
class IncludingWindowsDefaultRecipe < Cop
|
30
|
+
include RangeHelp
|
31
|
+
|
30
32
|
MSG = 'Do not include the Windows default recipe, which only installs win32 gems already included in Chef Infra Client'.freeze
|
31
33
|
|
32
34
|
def_node_matcher :windows_recipe_usage?, <<-PATTERN
|
@@ -41,7 +43,7 @@ module RuboCop
|
|
41
43
|
|
42
44
|
def autocorrect(node)
|
43
45
|
lambda do |corrector|
|
44
|
-
corrector.remove(node.loc.expression)
|
46
|
+
corrector.remove(range_with_surrounding_space(range: node.loc.expression, side: :left))
|
45
47
|
end
|
46
48
|
end
|
47
49
|
end
|
@@ -33,6 +33,8 @@ module RuboCop
|
|
33
33
|
# default: '"127.0.0.1:2181"'
|
34
34
|
#
|
35
35
|
class AttributeMetadata < Cop
|
36
|
+
include RangeHelp
|
37
|
+
|
36
38
|
MSG = 'The attribute metadata.rb method is not used and is unnecessary in cookbooks.'.freeze
|
37
39
|
|
38
40
|
def on_send(node)
|
@@ -41,7 +43,7 @@ module RuboCop
|
|
41
43
|
|
42
44
|
def autocorrect(node)
|
43
45
|
lambda do |corrector|
|
44
|
-
corrector.remove(node.loc.expression)
|
46
|
+
corrector.remove(range_with_surrounding_space(range: node.loc.expression, side: :right))
|
45
47
|
end
|
46
48
|
end
|
47
49
|
end
|
@@ -28,6 +28,8 @@ module RuboCop
|
|
28
28
|
# conflicts "another_cookbook"
|
29
29
|
#
|
30
30
|
class ConflictsMetadata < Cop
|
31
|
+
include RangeHelp
|
32
|
+
|
31
33
|
MSG = 'The conflicts metadata.rb method is not used and is unnecessary in cookbooks.'.freeze
|
32
34
|
|
33
35
|
def on_send(node)
|
@@ -36,7 +38,7 @@ module RuboCop
|
|
36
38
|
|
37
39
|
def autocorrect(node)
|
38
40
|
lambda do |corrector|
|
39
|
-
corrector.remove(node.loc.expression)
|
41
|
+
corrector.remove(range_with_surrounding_space(range: node.loc.expression, side: :right))
|
40
42
|
end
|
41
43
|
end
|
42
44
|
end
|
@@ -0,0 +1,48 @@
|
|
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
|
+
|
18
|
+
module RuboCop
|
19
|
+
module Cop
|
20
|
+
module Chef
|
21
|
+
module ChefRedundantCode
|
22
|
+
# The grouping metadata.rb method is not used and is unnecessary in cookbooks.
|
23
|
+
#
|
24
|
+
# @example
|
25
|
+
#
|
26
|
+
# # bad
|
27
|
+
# grouping 'windows_log_rotate', title: 'Demonstration cookbook with code to switch loggers'
|
28
|
+
#
|
29
|
+
#
|
30
|
+
class GroupingMetadata < Cop
|
31
|
+
include RangeHelp
|
32
|
+
|
33
|
+
MSG = 'The grouping metadata.rb method is not used and is unnecessary in cookbooks.'.freeze
|
34
|
+
|
35
|
+
def on_send(node)
|
36
|
+
add_offense(node, location: :expression, message: MSG, severity: :refactor) if node.method_name == :grouping
|
37
|
+
end
|
38
|
+
|
39
|
+
def autocorrect(node)
|
40
|
+
lambda do |corrector|
|
41
|
+
corrector.remove(range_with_surrounding_space(range: node.loc.expression, side: :left))
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
@@ -37,7 +37,12 @@ module RuboCop
|
|
37
37
|
|
38
38
|
def autocorrect(node)
|
39
39
|
lambda do |corrector|
|
40
|
-
|
40
|
+
if node.arguments.first.respond_to?(:heredoc?) && node.arguments.first.heredoc?
|
41
|
+
total_range = range_with_surrounding_space(range: node.loc.expression.join(node.arguments.first.loc.heredoc_end), side: :left)
|
42
|
+
corrector.remove(total_range)
|
43
|
+
else
|
44
|
+
corrector.remove(range_with_surrounding_space(range: node.loc.expression, side: :left))
|
45
|
+
end
|
41
46
|
end
|
42
47
|
end
|
43
48
|
end
|
@@ -28,6 +28,8 @@ module RuboCop
|
|
28
28
|
# provides "some_thing"
|
29
29
|
#
|
30
30
|
class ProvidesMetadata < Cop
|
31
|
+
include RangeHelp
|
32
|
+
|
31
33
|
MSG = 'The provides metadata.rb method is not used and is unnecessary in cookbooks.'.freeze
|
32
34
|
|
33
35
|
def on_send(node)
|
@@ -36,7 +38,7 @@ module RuboCop
|
|
36
38
|
|
37
39
|
def autocorrect(node)
|
38
40
|
lambda do |corrector|
|
39
|
-
corrector.remove(node.loc.expression)
|
41
|
+
corrector.remove(range_with_surrounding_space(range: node.loc.expression, side: :left))
|
40
42
|
end
|
41
43
|
end
|
42
44
|
end
|
@@ -28,6 +28,8 @@ module RuboCop
|
|
28
28
|
#
|
29
29
|
#
|
30
30
|
class RecipeMetadata < Cop
|
31
|
+
include RangeHelp
|
32
|
+
|
31
33
|
MSG = "The recipe metadata.rb method is not used and is unnecessary in cookbooks. Recipes should be documented in the cookbook's README.md file instead.".freeze
|
32
34
|
|
33
35
|
def on_send(node)
|
@@ -36,7 +38,7 @@ module RuboCop
|
|
36
38
|
|
37
39
|
def autocorrect(node)
|
38
40
|
lambda do |corrector|
|
39
|
-
corrector.remove(node.loc.expression)
|
41
|
+
corrector.remove(range_with_surrounding_space(range: node.loc.expression, side: :left))
|
40
42
|
end
|
41
43
|
end
|
42
44
|
end
|
@@ -28,6 +28,8 @@ module RuboCop
|
|
28
28
|
# replaces "another_cookbook"
|
29
29
|
#
|
30
30
|
class ReplacesMetadata < Cop
|
31
|
+
include RangeHelp
|
32
|
+
|
31
33
|
MSG = 'The replaces metadata.rb method is not used and is unnecessary in cookbooks.'.freeze
|
32
34
|
|
33
35
|
def on_send(node)
|
@@ -36,7 +38,7 @@ module RuboCop
|
|
36
38
|
|
37
39
|
def autocorrect(node)
|
38
40
|
lambda do |corrector|
|
39
|
-
corrector.remove(node.loc.expression)
|
41
|
+
corrector.remove(range_with_surrounding_space(range: node.loc.expression, side: :left))
|
40
42
|
end
|
41
43
|
end
|
42
44
|
end
|
@@ -28,6 +28,8 @@ module RuboCop
|
|
28
28
|
# end
|
29
29
|
#
|
30
30
|
class ResourceWithNothingAction < Cop
|
31
|
+
include RangeHelp
|
32
|
+
|
31
33
|
MSG = 'There is no need to define a :nothing action in your resource as Chef Infra Client provides the :nothing action by default for every resource.'.freeze
|
32
34
|
|
33
35
|
def_node_matcher :nothing_action?, <<-PATTERN
|
@@ -42,7 +44,7 @@ module RuboCop
|
|
42
44
|
|
43
45
|
def autocorrect(node)
|
44
46
|
lambda do |corrector|
|
45
|
-
corrector.remove(node.
|
47
|
+
corrector.remove(range_with_surrounding_space(range: node.loc.expression, side: :left))
|
46
48
|
end
|
47
49
|
end
|
48
50
|
end
|
@@ -28,6 +28,8 @@ module RuboCop
|
|
28
28
|
# suggests "another_cookbook"
|
29
29
|
#
|
30
30
|
class SuggestsMetadata < Cop
|
31
|
+
include RangeHelp
|
32
|
+
|
31
33
|
MSG = 'The suggests metadata.rb method is not used and is unnecessary in cookbooks.'.freeze
|
32
34
|
|
33
35
|
def on_send(node)
|
@@ -36,7 +38,7 @@ module RuboCop
|
|
36
38
|
|
37
39
|
def autocorrect(node)
|
38
40
|
lambda do |corrector|
|
39
|
-
corrector.remove(node.loc.expression)
|
41
|
+
corrector.remove(range_with_surrounding_space(range: node.loc.expression, side: :left))
|
40
42
|
end
|
41
43
|
end
|
42
44
|
end
|
@@ -450,6 +450,7 @@ module RuboCop
|
|
450
450
|
'gplv2': 'GPL-2.0',
|
451
451
|
'gplv3': 'GPL-3.0',
|
452
452
|
'mit license': 'MIT',
|
453
|
+
'UNLICENSED': 'all rights reserved',
|
453
454
|
}.freeze
|
454
455
|
|
455
456
|
MSG = 'Cookbook metadata.rb does not use a SPDX compliant license string or "all rights reserved". See https://spdx.org/licenses/ for a complete list of license identifiers.'.freeze
|
@@ -47,7 +47,10 @@ module RuboCop
|
|
47
47
|
# If it was an octal literal, make sure we write out the right number.
|
48
48
|
replacement_base = octal?(node) ? 8 : 10
|
49
49
|
replacement_mode = node.children.first.to_s(replacement_base)
|
50
|
-
|
50
|
+
|
51
|
+
# we build our own escaped string instead of using .inspect because that way
|
52
|
+
# we can use single quotes instead of the double quotes that .inspect adds
|
53
|
+
corrector.replace(node.loc.expression, "\'#{replacement_mode}\'")
|
51
54
|
end
|
52
55
|
end
|
53
56
|
|
@@ -0,0 +1,73 @@
|
|
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 ChefStyle
|
21
|
+
# Don't loop over an array to set cookbook dependencies or supported platforms if you have fewer than three values to set. Setting multiple `supports` or `depends` values is simpler and easier to understand for new users.
|
22
|
+
#
|
23
|
+
# @example
|
24
|
+
#
|
25
|
+
# # bad
|
26
|
+
#
|
27
|
+
# %w( debian ubuntu ).each do |os|
|
28
|
+
# supports os
|
29
|
+
# end
|
30
|
+
#
|
31
|
+
# %w( apt yum ).each do |cb|
|
32
|
+
# depends cb
|
33
|
+
# end
|
34
|
+
#
|
35
|
+
# # good
|
36
|
+
#
|
37
|
+
# supports 'debian'
|
38
|
+
# supports 'ubuntu'
|
39
|
+
#
|
40
|
+
# depends 'apt'
|
41
|
+
# depends 'yum'
|
42
|
+
#
|
43
|
+
class OverlyComplexSupportsDependsMetadata < Cop
|
44
|
+
MSG = "Don't loop over an array to set cookbook dependencies or supported platforms if you have fewer than three values to set.".freeze
|
45
|
+
|
46
|
+
def_node_matcher :supports_depends_array?, <<-PATTERN
|
47
|
+
(block
|
48
|
+
(send
|
49
|
+
$(array ...) :each)
|
50
|
+
(args
|
51
|
+
(arg _))
|
52
|
+
(send nil? ${:supports :depends} (lvar _)))
|
53
|
+
PATTERN
|
54
|
+
|
55
|
+
def on_block(node)
|
56
|
+
supports_depends_array?(node) do |array, _type|
|
57
|
+
add_offense(node, location: :expression, message: MSG, severity: :refactor) if array.values.count < 3
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
def autocorrect(node)
|
62
|
+
lambda do |corrector|
|
63
|
+
supports_depends_array?(node) do |array, type|
|
64
|
+
corrected_value = array.values.map { |x| "#{type} '#{x.source}'" }
|
65
|
+
corrector.replace(node.loc.expression, corrected_value.join("\n"))
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
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.19.9
|
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-01-
|
12
|
+
date: 2020-01-07 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rubocop
|
@@ -179,6 +179,7 @@ files:
|
|
179
179
|
- lib/rubocop/cop/chef/redundant/attribute_metadata.rb
|
180
180
|
- lib/rubocop/cop/chef/redundant/conflicts_metadata.rb
|
181
181
|
- lib/rubocop/cop/chef/redundant/custom_resource_with_allowed_actions.rb
|
182
|
+
- lib/rubocop/cop/chef/redundant/grouping_metadata.rb
|
182
183
|
- lib/rubocop/cop/chef/redundant/long_description_metadata.rb
|
183
184
|
- lib/rubocop/cop/chef/redundant/name_property_and_required.rb
|
184
185
|
- lib/rubocop/cop/chef/redundant/property_with_default_and_required.rb
|
@@ -201,6 +202,7 @@ files:
|
|
201
202
|
- lib/rubocop/cop/chef/style/comments_format.rb
|
202
203
|
- lib/rubocop/cop/chef/style/file_mode.rb
|
203
204
|
- lib/rubocop/cop/chef/style/immediate_notification_timing.rb
|
205
|
+
- lib/rubocop/cop/chef/style/overly_complex_supports_depends_metadata.rb
|
204
206
|
- lib/rubocop/cop/chef/style/simplify_platform_major_version_check.rb
|
205
207
|
- lib/rubocop/cop/chef/style/true_false_resource_properties.rb
|
206
208
|
- lib/rubocop/cop/chef/style/unnecessary_platform_case_statement.rb
|