cookstyle 5.16.11 → 5.17.4
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 -1
- data/lib/cookstyle.rb +6 -6
- data/lib/cookstyle/version.rb +1 -1
- data/lib/rubocop/cop/chef/correctness/invalid_platform_metadata.rb +27 -4
- data/lib/rubocop/cop/chef/modernize/dsl_include_in_resource.rb +54 -0
- data/lib/rubocop/cop/chef/modernize/includes_mixin_shellout.rb +7 -5
- data/lib/rubocop/cop/chef/redundant/apt_repository_distribution_default.rb +66 -0
- data/lib/rubocop/cop/chef/redundant/apt_repository_notifies_apt_update.rb +59 -0
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9542dd1a3bbc3a2f0f4db8c2108e67ef70cec17da89557746489ccc9dd89d4f5
|
4
|
+
data.tar.gz: b2a67152f01ef162bfe42b833e15b627fe361403a2ad450b0f591bc490a1b551
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1432f849f9464fabd9e9b17c559889f1c537671175b5690fb48d2f311030dd51c12746fc1dbad60dfd084fde4377e48ea5ee4c8a3bdd991f486f46ffafa8627e
|
7
|
+
data.tar.gz: a0f4c2a88b75f3049967747a8fc183d922800ff0b84d0d11bcb853444d1755bc83c7ee90e02c70a0bdb04b4d65b208ee438093010fbcab184c5bbeb817f7ec62
|
data/config/cookstyle.yml
CHANGED
@@ -801,7 +801,7 @@ ChefModernize/MinitestHandlerUsage:
|
|
801
801
|
- '**/metadata.rb'
|
802
802
|
|
803
803
|
ChefModernize/IncludingMixinShelloutInResources:
|
804
|
-
Description: There is no need to include Chef::Mixin::ShellOut in resources or providers as this is already done by Chef Infra Client.
|
804
|
+
Description: 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+.
|
805
805
|
Enabled: true
|
806
806
|
VersionAdded: '5.4.0'
|
807
807
|
Include:
|
@@ -1056,6 +1056,14 @@ ChefModernize/ExecuteSleep:
|
|
1056
1056
|
- '**/attributes/*.rb'
|
1057
1057
|
- '**/Berksfile'
|
1058
1058
|
|
1059
|
+
ChefModernize/DslIncludeInResource:
|
1060
|
+
Description: 'There is no need to include Chef::DSL::Recipe or Chef::DSL::IncludeRecipe classes in resources or providers as this is done automatically.'
|
1061
|
+
Enabled: true
|
1062
|
+
VersionAdded: '5.17.0'
|
1063
|
+
Include:
|
1064
|
+
- '**/resources/*.rb'
|
1065
|
+
- '**/providers/*.rb'
|
1066
|
+
|
1059
1067
|
###############################
|
1060
1068
|
# ChefRedundantCode: Cleanup unncessary code in your cookbooks regardless of chef-client release
|
1061
1069
|
###############################
|
@@ -1177,6 +1185,24 @@ ChefRedundantCode/UnnecessaryDesiredState:
|
|
1177
1185
|
- '**/resources/*.rb'
|
1178
1186
|
- '**/libraries/*.rb'
|
1179
1187
|
|
1188
|
+
ChefRedundantCode/AptRepositoryNotifiesAptUpdate:
|
1189
|
+
Description: There is no need to notify an apt-get update when an apt_repository is created as this is done automatically by the apt_repository resource.
|
1190
|
+
Enabled: true
|
1191
|
+
VersionAdded: '5.17.0'
|
1192
|
+
Exclude:
|
1193
|
+
- '**/metadata.rb'
|
1194
|
+
- '**/attributes/*.rb'
|
1195
|
+
- '**/Berksfile'
|
1196
|
+
|
1197
|
+
ChefRedundantCode/AptRepositoryDistributionDefault:
|
1198
|
+
Description: There is no need to pass `distribution node['lsb']['codename']` to an apt_repository resource as this is done automatically by the apt_repository resource.
|
1199
|
+
Enabled: true
|
1200
|
+
VersionAdded: '5.17.0'
|
1201
|
+
Exclude:
|
1202
|
+
- '**/metadata.rb'
|
1203
|
+
- '**/attributes/*.rb'
|
1204
|
+
- '**/Berksfile'
|
1205
|
+
|
1180
1206
|
###############################
|
1181
1207
|
# Migrating to new patterns
|
1182
1208
|
###############################
|
data/lib/cookstyle.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
|
1
|
+
require_relative 'cookstyle/version'
|
2
2
|
|
3
3
|
require 'pathname'
|
4
4
|
require 'yaml'
|
@@ -37,11 +37,11 @@ module Cookstyle
|
|
37
37
|
end
|
38
38
|
end
|
39
39
|
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
40
|
+
require_relative 'rubocop/chef'
|
41
|
+
require_relative 'rubocop/chef/cookbook_helpers'
|
42
|
+
require_relative 'rubocop/chef/platform_helpers'
|
43
|
+
require_relative 'rubocop/chef/cookbook_only'
|
44
|
+
require_relative 'rubocop/cop/target_chef_version'
|
45
45
|
|
46
46
|
# Chef specific cops
|
47
47
|
Dir.glob(File.dirname(__FILE__) + '/rubocop/cop/chef/**/*.rb') do |file|
|
data/lib/cookstyle/version.rb
CHANGED
@@ -38,6 +38,15 @@ module RuboCop
|
|
38
38
|
|
39
39
|
def_node_matcher :supports?, '(send nil? :supports $str ...)'
|
40
40
|
|
41
|
+
def_node_matcher :supports_array?, <<-PATTERN
|
42
|
+
(block
|
43
|
+
(send
|
44
|
+
$(array ...) :each)
|
45
|
+
(args
|
46
|
+
(arg _))
|
47
|
+
(send nil? :supports (lvar _)))
|
48
|
+
PATTERN
|
49
|
+
|
41
50
|
def on_send(node)
|
42
51
|
supports?(node) do |plat|
|
43
52
|
if INVALID_PLATFORMS[plat.str_content]
|
@@ -46,19 +55,33 @@ module RuboCop
|
|
46
55
|
end
|
47
56
|
end
|
48
57
|
|
58
|
+
def on_block(node)
|
59
|
+
supports_array?(node) do |plats|
|
60
|
+
plats.values.each do |plat|
|
61
|
+
if INVALID_PLATFORMS[plat.str_content]
|
62
|
+
add_offense(plat, location: :expression, message: MSG, severity: :refactor)
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
49
68
|
def autocorrect(node)
|
50
|
-
correct_string =
|
69
|
+
correct_string = corrected_platform_source(node)
|
51
70
|
if correct_string
|
52
71
|
lambda do |corrector|
|
53
|
-
corrector.replace(node.loc.expression,
|
72
|
+
corrector.replace(node.loc.expression, correct_string)
|
54
73
|
end
|
55
74
|
end
|
56
75
|
end
|
57
76
|
|
58
77
|
# private
|
59
78
|
|
60
|
-
def
|
61
|
-
INVALID_PLATFORMS[
|
79
|
+
def corrected_platform_source(node)
|
80
|
+
val = INVALID_PLATFORMS[node.str_content.delete(',').downcase]
|
81
|
+
return false unless val
|
82
|
+
|
83
|
+
# if the value was previously quoted make sure to quote it again
|
84
|
+
node.source.match?(/^('|")/) ? "'" + val + "'" : val
|
62
85
|
end
|
63
86
|
end
|
64
87
|
end
|
@@ -0,0 +1,54 @@
|
|
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
|
+
# Chef Infra Client 12.4+ includes the Chef::DSL::Recipe in the resource and provider classed by default so there is no need to include this DSL in your resources or providers.
|
22
|
+
#
|
23
|
+
# # bad
|
24
|
+
# include Chef::DSL::Recipe
|
25
|
+
# include Chef::DSL::IncludeRecipe
|
26
|
+
#
|
27
|
+
class DslIncludeInResource < Cop
|
28
|
+
include RangeHelp
|
29
|
+
|
30
|
+
MSG = 'Chef Infra Client 12.4+ includes the Chef::DSL::Recipe in the resource and provider classed by default so there is no need to include this DSL in your resources or providers.'.freeze
|
31
|
+
|
32
|
+
def_node_matcher :dsl_include?, <<-PATTERN
|
33
|
+
(send nil? :include
|
34
|
+
(const
|
35
|
+
(const
|
36
|
+
(const nil? :Chef) :DSL) {:Recipe :IncludeRecipe}))
|
37
|
+
PATTERN
|
38
|
+
|
39
|
+
def on_send(node)
|
40
|
+
dsl_include?(node) do
|
41
|
+
add_offense(node, location: :expression, message: MSG, severity: :refactor)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def autocorrect(node)
|
46
|
+
lambda do |corrector|
|
47
|
+
corrector.remove(range_with_surrounding_space(range: node.loc.expression, side: :left))
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
@@ -19,23 +19,25 @@ module RuboCop
|
|
19
19
|
module Cop
|
20
20
|
module Chef
|
21
21
|
module ChefModernize
|
22
|
-
# There is no need to include Chef::Mixin::ShellOut in resources or providers as this is already done by Chef Infra Client 12.4+.
|
22
|
+
# 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+.
|
23
23
|
#
|
24
24
|
# @example
|
25
25
|
#
|
26
26
|
# # bad
|
27
27
|
# require 'chef/mixin/shell_out'
|
28
28
|
# include Chef::Mixin::ShellOut
|
29
|
-
|
29
|
+
# require 'chef/mixin/powershell_out'
|
30
|
+
# include Chef::Mixin::PowershellOut
|
31
|
+
#
|
30
32
|
class IncludingMixinShelloutInResources < Cop
|
31
|
-
MSG = 'There is no need to include Chef::Mixin::ShellOut in resources or providers as this is already done by Chef Infra Client 12.4+.'.freeze
|
33
|
+
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
|
32
34
|
|
33
35
|
def_node_matcher :include_shellout?, <<-PATTERN
|
34
|
-
(send nil? :include (const (const (const nil? :Chef) :Mixin) :ShellOut))
|
36
|
+
(send nil? :include (const (const (const nil? :Chef) :Mixin) {:ShellOut :PowershellOut}))
|
35
37
|
PATTERN
|
36
38
|
|
37
39
|
def_node_matcher :require_shellout?, <<-PATTERN
|
38
|
-
(send nil? :require ( str "chef/mixin/shell_out"))
|
40
|
+
(send nil? :require ( str {"chef/mixin/shell_out" "chef/mixin/powershell_out"} ))
|
39
41
|
PATTERN
|
40
42
|
|
41
43
|
def on_send(node)
|
@@ -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 ChefRedundantCode
|
21
|
+
# There is no need to pass `distribution node['lsb']['codename']` to an apt_repository resource as this is done automatically by the apt_repository resource.
|
22
|
+
#
|
23
|
+
# # bad
|
24
|
+
# apt_repository 'my repo' do
|
25
|
+
# uri 'http://packages.example.com/debian'
|
26
|
+
# components %w(stable main)
|
27
|
+
# deb_src false
|
28
|
+
# distribution node['lsb']['codename']
|
29
|
+
# end
|
30
|
+
#
|
31
|
+
# # good
|
32
|
+
# apt_repository 'my repo' do
|
33
|
+
# uri 'http://packages.example.com/debian'
|
34
|
+
# components %w(stable main)
|
35
|
+
# deb_src false
|
36
|
+
# end
|
37
|
+
#
|
38
|
+
class AptRepositoryDistributionDefault < Cop
|
39
|
+
include RuboCop::Chef::CookbookHelpers
|
40
|
+
include RangeHelp
|
41
|
+
|
42
|
+
MSG = "There is no need to pass `distribution node['lsb']['codename']` to an apt_repository resource as this is done automatically by the apt_repository resource.".freeze
|
43
|
+
|
44
|
+
def_node_matcher :default_dist?, <<-PATTERN
|
45
|
+
(send nil? :distribution (send (send (send nil? :node) :[] ({sym str} {:lsb "lsb"})) :[] ({sym str} {:codename "codename"})))
|
46
|
+
PATTERN
|
47
|
+
|
48
|
+
def on_block(node)
|
49
|
+
match_property_in_resource?(:apt_repository, 'distribution', node) do |dist|
|
50
|
+
## require 'pry'; binding.pry
|
51
|
+
default_dist?(dist) do
|
52
|
+
add_offense(dist, location: :expression, message: MSG, severity: :refactor)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
def autocorrect(node)
|
58
|
+
lambda do |corrector|
|
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,59 @@
|
|
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 ChefRedundantCode
|
21
|
+
# There is no need to notify an apt-get update when an apt_repository is created as this is done automatically by the apt_repository resource.
|
22
|
+
#
|
23
|
+
# # bad
|
24
|
+
# apt_repository 'my repo' do
|
25
|
+
# uri 'http://packages.example.com/debian'
|
26
|
+
# components %w(stable main)
|
27
|
+
# deb_src false
|
28
|
+
# notifies :run, 'execute[apt-get update]', :immediately
|
29
|
+
# end
|
30
|
+
#
|
31
|
+
# # good
|
32
|
+
# apt_repository 'my repo' do
|
33
|
+
# uri 'http://packages.example.com/debian'
|
34
|
+
# components %w(stable main)
|
35
|
+
# deb_src false
|
36
|
+
# end
|
37
|
+
#
|
38
|
+
class AptRepositoryNotifiesAptUpdate < Cop
|
39
|
+
include RuboCop::Chef::CookbookHelpers
|
40
|
+
include RangeHelp
|
41
|
+
|
42
|
+
MSG = 'There is no need to notify an apt-get update when an apt_repository is created as this is done automatically by the apt_repository resource.'.freeze
|
43
|
+
|
44
|
+
def on_block(node)
|
45
|
+
match_property_in_resource?(:apt_repository, 'notifies', node) do |notifies|
|
46
|
+
add_offense(notifies, location: :expression, message: MSG, severity: :refactor) if notifies.arguments[1] == s(:str, 'execute[apt-get update]')
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
def autocorrect(node)
|
51
|
+
lambda do |corrector|
|
52
|
+
corrector.remove(range_with_surrounding_space(range: node.loc.expression, side: :left))
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
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.17.4
|
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-12-
|
12
|
+
date: 2019-12-20 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rubocop
|
@@ -134,6 +134,7 @@ files:
|
|
134
134
|
- lib/rubocop/cop/chef/modernize/defines_chefspec_matchers.rb
|
135
135
|
- lib/rubocop/cop/chef/modernize/definitions.rb
|
136
136
|
- lib/rubocop/cop/chef/modernize/depends_zypper_cookbook.rb
|
137
|
+
- lib/rubocop/cop/chef/modernize/dsl_include_in_resource.rb
|
137
138
|
- lib/rubocop/cop/chef/modernize/empty_resource_initialize.rb
|
138
139
|
- lib/rubocop/cop/chef/modernize/execute_apt_update.rb
|
139
140
|
- lib/rubocop/cop/chef/modernize/execute_sc_exe.rb
|
@@ -171,6 +172,8 @@ files:
|
|
171
172
|
- lib/rubocop/cop/chef/modernize/windows_zipfile.rb
|
172
173
|
- lib/rubocop/cop/chef/modernize/zipfile_resource.rb
|
173
174
|
- lib/rubocop/cop/chef/modernize/zypper_repo.rb
|
175
|
+
- lib/rubocop/cop/chef/redundant/apt_repository_distribution_default.rb
|
176
|
+
- lib/rubocop/cop/chef/redundant/apt_repository_notifies_apt_update.rb
|
174
177
|
- lib/rubocop/cop/chef/redundant/attribute_metadata.rb
|
175
178
|
- lib/rubocop/cop/chef/redundant/conflicts_metadata.rb
|
176
179
|
- lib/rubocop/cop/chef/redundant/custom_resource_with_allowed_actions.rb
|