cookstyle 5.13.7 → 5.14.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 536183d50b038f3bd9db265813f38f29502167e80aca88124b8419d5124b786d
4
- data.tar.gz: a13c369bc38ce2c8dda503438d86988bff7d6899972df4b3b8f2773d3b96d631
3
+ metadata.gz: f0fe10480691d3522f05f3d4a0db77cac9543e29cd50ed9f6764d45294973c2f
4
+ data.tar.gz: 7308ec701ae4d522633a62a59cf28d6eab5b1460179ef1af5be3a7926a8d688c
5
5
  SHA512:
6
- metadata.gz: d6d0cd3db208a387271bbb6afd4c8ba4afc5e5f625e6e715c03cffe2360f0ef16de1d9d1c6e7e1d3b7d610a891b0cf40281e2691ca47b56931a9144e18ffd260
7
- data.tar.gz: 76d0d91643ed7837f8c2316a811e79adf68dc6092ef2b764c4f41c9c4c96bead89db404fdc83bc75f485d83c11b3f8980691208fb8b393f9b08ee82af3afb3ab
6
+ metadata.gz: d3659fda58293a623b91d907a30fd5f5f1229da9dcbd7a8d5ebc83083baa101db9e274e15a1feae9f14071c274dbac4ee7a86069dc05c0b69fdf3650fd622da9
7
+ data.tar.gz: b08f3957087487156952dc5856bf2ece8c0f4f432e11d8551d9c4492c10ff148cce4ebad8cdef712a6e1179190106893c6490f07443c54dbef92062c1d8308a1
@@ -625,6 +625,14 @@ ChefDeprecations/NodeSetWithoutLevel:
625
625
  - '**/metadata.rb'
626
626
  - '**/attributes/*.rb'
627
627
 
628
+ ChefDeprecations/ChefRewind:
629
+ Description: Use delete_resource / edit_resource instead of functionality in the deprecated chef-rewind gem
630
+ Enabled: true
631
+ VersionAdded: '5.14.0'
632
+ Exclude:
633
+ - '**/metadata.rb'
634
+ - '**/attributes/*.rb'
635
+
628
636
  ###############################
629
637
  # ChefModernize: Cleaning up legacy code and using new built-in resources
630
638
  ###############################
@@ -913,7 +921,7 @@ ChefModernize/ZipfileResource:
913
921
  VersionAdded: '5.12.0'
914
922
 
915
923
  ChefModernize/UnnecessaryMixlibShelloutRequire:
916
- Description: Chef Infra Client includes mixlib/shellout automatically in resources and providers.
924
+ Description: Chef Infra Client 12.4 and later include mixlib/shellout automatically in resources and providers.
917
925
  Enabled: true
918
926
  VersionAdded: '5.12.0'
919
927
  Include:
@@ -928,6 +936,14 @@ ChefModernize/EmptyResourceInitializeMethod:
928
936
  - '**/resources/*.rb'
929
937
  - '**/providers/*.rb'
930
938
 
939
+ ChefModernize/ChefGemNokogiri:
940
+ Description: The nokogiri gem ships in Chef Infra Client 12+ and does not need to be installed before being used.
941
+ Enabled: true
942
+ VersionAdded: '5.14.0'
943
+ Exclude:
944
+ - '**/metadata.rb'
945
+ - '**/attributes/*.rb'
946
+
931
947
  ###############################
932
948
  # Migrating to new patterns
933
949
  ###############################
@@ -1,4 +1,4 @@
1
1
  module Cookstyle
2
- VERSION = "5.13.7".freeze # rubocop: disable Style/StringLiterals
2
+ VERSION = "5.14.1".freeze # rubocop: disable Style/StringLiterals
3
3
  RUBOCOP_VERSION = '0.75.1'.freeze
4
4
  end
@@ -0,0 +1,106 @@
1
+ #
2
+ # Copyright:: 2019, Chef Software Inc.
3
+ # Author:: Tim Smith (<tsmith@chef.io>)
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+ #
17
+
18
+ module RuboCop
19
+ module Cop
20
+ module Chef
21
+ module ChefDeprecations
22
+ # Use delete_resource / edit_resource instead of functionality in the deprecated chef-rewind gem
23
+ #
24
+ # @example
25
+ #
26
+ # chef_gem 'chef-rewind'
27
+ #
28
+ # require 'chef/rewind'
29
+ #
30
+ # rewind "user[postgres]" do
31
+ # home '/var/lib/pgsql/9.2'
32
+ # cookbook 'my-postgresql' # or `cookbook cookbook_name()`
33
+ # end
34
+ #
35
+ # unwind "user[postgres]"
36
+ #
37
+ class ChefRewind < Cop
38
+ include RuboCop::Chef::CookbookHelpers
39
+
40
+ MAPPING = {
41
+ rewind: 'edit_resource',
42
+ unwind: 'delete_resource',
43
+ }.freeze
44
+
45
+ MSG = 'Use delete_resource / edit_resource instead of functionality in the deprecated chef-rewind gem'.freeze
46
+
47
+ def_node_matcher :rewind_gem_install?, <<-PATTERN
48
+ (send nil? :chef_gem (str "chef-rewind"))
49
+ PATTERN
50
+
51
+ def_node_matcher :require_rewind?, <<-PATTERN
52
+ (send nil? :require (str "chef/rewind"))
53
+ PATTERN
54
+
55
+ def_node_matcher :rewind_resources?, <<-PATTERN
56
+ (send nil? ${:rewind :unwind} ... )
57
+ PATTERN
58
+
59
+ def on_send(node)
60
+ rewind_gem_install?(node) do
61
+ add_offense(node, location: :expression, message: MSG, severity: :refactor)
62
+ end
63
+
64
+ require_rewind?(node) do
65
+ add_offense(node, location: :expression, message: MSG, severity: :refactor)
66
+ end
67
+
68
+ rewind_resources?(node) do
69
+ add_offense(node, location: :expression, message: MSG, severity: :refactor)
70
+ end
71
+ end
72
+
73
+ def on_block(node)
74
+ match_property_in_resource?(:chef_gem, 'package_name', node) do |pkg_name|
75
+ add_offense(node, location: :expression, message: MSG, severity: :refactor) if pkg_name.arguments&.first&.str_content == 'chef-rewind'
76
+ end
77
+ end
78
+
79
+ def autocorrect(node)
80
+ lambda do |corrector|
81
+ rewind_gem_install?(node) do
82
+ node = node.parent if node.parent&.block_type? # make sure we get the whole block not just the method in the block
83
+ corrector.remove(node.loc.expression)
84
+ return
85
+ end
86
+
87
+ require_rewind?(node) do
88
+ corrector.remove(node.loc.expression)
89
+ return
90
+ end
91
+
92
+ match_property_in_resource?(:chef_gem, 'package_name', node) do |pkg_name|
93
+ corrector.remove(node.loc.expression) if pkg_name.arguments&.first&.str_content == 'chef-rewind'
94
+ return
95
+ end
96
+
97
+ rewind_resources?(node) do |string|
98
+ corrector.replace(node.loc.expression, node.source.gsub(string.to_s, MAPPING[string]))
99
+ end
100
+ end
101
+ end
102
+ end
103
+ end
104
+ end
105
+ end
106
+ end
@@ -23,6 +23,9 @@ module RuboCop
23
23
  # @example
24
24
  #
25
25
  # # bad
26
+ # require 'chef/mixin/command'
27
+ # include Chef::Mixin::Command
28
+ #
26
29
  # run_command('/bin/foo')
27
30
  # run_command_with_systems_locale('/bin/foo')
28
31
  #
@@ -33,12 +36,23 @@ module RuboCop
33
36
  MSG = "Use 'shell_out!' instead of the legacy 'run_command' or 'run_command_with_systems_locale' helpers for shelling out. The run_command helper was removed in Chef Infra Client 13.".freeze
34
37
 
35
38
  def_node_matcher :calls_run_command?, '(send nil? {:run_command :run_command_with_systems_locale} ...)'
39
+ def_node_matcher :require_mixin_command?, '(send nil? :require (str "chef/mixin/command"))'
40
+ def_node_matcher :include_mixin_command?, '(send nil? :include (const (const (const nil? :Chef) :Mixin) :Command))'
41
+
36
42
  def_node_search :defines_run_command?, '(def {:run_command :run_command_with_systems_locale} ...)'
37
43
 
38
44
  def on_send(node)
39
45
  calls_run_command?(node) do
40
46
  add_offense(node, location: :expression, message: MSG, severity: :refactor) unless defines_run_command?(processed_source.ast)
41
47
  end
48
+
49
+ require_mixin_command?(node) do
50
+ add_offense(node, location: :expression, message: MSG, severity: :refactor)
51
+ end
52
+
53
+ include_mixin_command?(node) do
54
+ add_offense(node, location: :expression, message: MSG, severity: :refactor)
55
+ end
42
56
  end
43
57
  end
44
58
  end
@@ -0,0 +1,60 @@
1
+ #
2
+ # Copyright:: 2019, Chef Software Inc.
3
+ # Author:: Tim Smith (<tsmith@chef.io>)
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+ #
17
+
18
+ module RuboCop
19
+ module Cop
20
+ module Chef
21
+ module ChefModernize
22
+ # The nokogiri gem ships in Chef Infra Client 12+ and does not need to be installed before being used
23
+ #
24
+ # @example
25
+ #
26
+ # # bad
27
+ # chef_gem 'nokogiri'
28
+ #
29
+ class ChefGemNokogiri < Cop
30
+ include RuboCop::Chef::CookbookHelpers
31
+
32
+ MSG = 'The nokogiri gem ships in Chef Infra Client 12+ and does not need to be installed before being used.'.freeze
33
+
34
+ def_node_matcher :nokogiri_install?, <<-PATTERN
35
+ (send nil? :chef_gem (str "nokogiri"))
36
+ PATTERN
37
+
38
+ def on_block(node)
39
+ match_property_in_resource?(:chef_gem, 'package_name', node) do |pkg_name|
40
+ add_offense(node, location: :expression, message: MSG, severity: :refactor) if pkg_name.arguments&.first&.str_content == 'nokogiri'
41
+ end
42
+ end
43
+
44
+ def on_send(node)
45
+ nokogiri_install?(node) do
46
+ add_offense(node, location: :expression, message: MSG, severity: :refactor)
47
+ end
48
+ end
49
+
50
+ def autocorrect(node)
51
+ lambda do |corrector|
52
+ 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
+ end
55
+ end
56
+ end
57
+ end
58
+ end
59
+ end
60
+ end
@@ -19,7 +19,7 @@ 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.
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+.
23
23
  #
24
24
  # @example
25
25
  #
@@ -28,7 +28,7 @@ module RuboCop
28
28
  # include Chef::Mixin::ShellOut
29
29
 
30
30
  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.'.freeze
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
32
32
 
33
33
  def_node_matcher :include_shellout?, <<-PATTERN
34
34
  (send nil? :include (const (const (const nil? :Chef) :Mixin) :ShellOut))
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.13.7
4
+ version: 5.14.1
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-11-21 00:00:00.000000000 Z
12
+ date: 2019-12-06 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rubocop
@@ -75,6 +75,7 @@ files:
75
75
  - lib/rubocop/cop/chef/deprecation/attribute_metadata.rb
76
76
  - lib/rubocop/cop/chef/deprecation/chef_handler_supports.rb
77
77
  - lib/rubocop/cop/chef/deprecation/chef_rest.rb
78
+ - lib/rubocop/cop/chef/deprecation/chef_rewind.rb
78
79
  - lib/rubocop/cop/chef/deprecation/cheffile.rb
79
80
  - lib/rubocop/cop/chef/deprecation/chefspec_coverage_report.rb
80
81
  - lib/rubocop/cop/chef/deprecation/chefspec_legacy_runner.rb
@@ -132,6 +133,7 @@ files:
132
133
  - lib/rubocop/cop/chef/modernize/berksfile_source.rb
133
134
  - lib/rubocop/cop/chef/modernize/build_essential.rb
134
135
  - lib/rubocop/cop/chef/modernize/chef_14_resources.rb
136
+ - lib/rubocop/cop/chef/modernize/chef_gem_nokogiri.rb
135
137
  - lib/rubocop/cop/chef/modernize/cron_manage_resource.rb
136
138
  - lib/rubocop/cop/chef/modernize/default_action_initializer.rb
137
139
  - lib/rubocop/cop/chef/modernize/defines_chefspec_matchers.rb