cookstyle 5.11.0 → 5.12.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 23367383d5c8736b9ab2f8bfbf580f79fb41584840e5f7c8bc00fe473cbb0ef7
4
- data.tar.gz: fc2c67a465da5575f311f2eebcb658a2aa161d55fb2a41c2ddfe234fb9303ce7
3
+ metadata.gz: adfb34aede19f924d41272b3cc06e40fab062c0f64fd17afc721d3cbd51c0c4d
4
+ data.tar.gz: dfaa41b6b14e96c68750d030571bac640feca178a6f88f57486d2b47774bafb9
5
5
  SHA512:
6
- metadata.gz: 38e8cbb19de77adcb8eb239749fd729e2aced72b20ba31b8e6cc81b186c3125fcbf774ce2c88a00b03da779f477f8247e3d219cf024d9ac9e2e05799ea3003a2
7
- data.tar.gz: 6a29d736057c956ec4b420af00f3f84db703ccc3c959ec05f30ab6d195c7d7dac738cfe768f3705539d158211232626a74ea5b7e876f2f4674596dfc29963b1b
6
+ metadata.gz: c05b9647db46fe529e1d34c149a40fd0012a4245ec8000a835a3c4592048e57846a83de88d2912a1c2d8d944267a96fb4e13cdd317ad3b09d107e1c41b728d9d
7
+ data.tar.gz: 9d6c334342bb2c9f8fdc2d39818b57e2452dc9a31f364fd27540f56195772664f357bbd88b05a677457ebf8bbfbd3f16ddc47dcc0a39ecb39443d80aea9ad9c3
@@ -78,6 +78,11 @@ ChefStyle/SimplifyPlatformMajorVersionCheck:
78
78
  Exclude:
79
79
  - '**/metadata.rb'
80
80
 
81
+ ChefStyle/DefaultCopyrightComments:
82
+ Description: Cookbook copyright comment headers should be updated for a real person or organization.
83
+ Enabled: true
84
+ VersionAdded: '5.12.0'
85
+
81
86
  ###############################
82
87
  # ChefCorrectness: Avoiding potential problems
83
88
  ###############################
@@ -216,7 +221,7 @@ ChefCorrectness/IncludingOhaiDefaultRecipe:
216
221
  - '**/metadata.rb'
217
222
 
218
223
  ChefCorrectness/UnnecessaryNameProperty:
219
- Description: There is no need to define a property named :name in a resource as Chef Infra defines that property for all resources out of the box.
224
+ Description: There is no need to define a property named :name in a resource as Chef Infra defines that property for all resources by default.
220
225
  Enabled: true
221
226
  VersionAdded: '5.8.0'
222
227
  Include:
@@ -251,10 +256,26 @@ ChefCorrectness/IncorrectLibraryInjection:
251
256
  Include:
252
257
  - '**/libraries/*.rb'
253
258
 
259
+ ChefCorrectness/ResourceWithNothingAction:
260
+ Description: 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.
261
+ Enabled: true
262
+ VersionAdded: '5.12.0'
263
+ Include:
264
+ - '**/libraries/*.rb'
265
+ - '**/resources/*.rb'
266
+ - '**/providers/*.rb'
267
+
254
268
  ###############################
255
269
  # ChefDeprecations: Resolving Deprecations that block upgrading Chef Infra Client
256
270
  ###############################
257
271
 
272
+ ChefDeprecations/NodeDeepFetch:
273
+ Description: Do not use the deprecated chef-sugar node.deep_fetch methods
274
+ Enabled: true
275
+ VersionAdded: '5.12.0'
276
+ Exclude:
277
+ - '**/metadata.rb'
278
+
258
279
  ChefDeprecations/NodeSet:
259
280
  Description: Do not use the deprecated node.set method
260
281
  Enabled: true
@@ -582,6 +603,13 @@ ChefDeprecations/PartialSearchClassUsage:
582
603
  Exclude:
583
604
  - '**/metadata.rb'
584
605
 
606
+ ChefDeprecations/Cheffile:
607
+ Description: The Libarian-Chef depsolving project is no longer maintained and should not be used for cookbook depsolving. Consider using Policyfiles instead.
608
+ Enabled: true
609
+ VersionAdded: '5.12.0'
610
+ Include:
611
+ - '**/Cheffile'
612
+
585
613
  ###############################
586
614
  # ChefModernize: Cleaning up legacy code and using new built-in resources
587
615
  ###############################
@@ -856,6 +884,27 @@ ChefModernize/Definitions:
856
884
  Include:
857
885
  - '**/definitions/*.rb'
858
886
 
887
+ ChefModernize/IfProvidesDefaultAction:
888
+ Description: if defined?(default_action) is no longer necessary in Chef Resources as default_action shipped in Chef 10.8.
889
+ Enabled: true
890
+ VersionAdded: '5.12.0'
891
+ Include:
892
+ - '**/resources/*.rb'
893
+ - '**/libraries/*.rb'
894
+
895
+ ChefModernize/ZipfileResource:
896
+ Description: Use the archive_file resource built into Chef Infra Client 15+ instead of the zipfile resource from the zipfile cookbook.
897
+ Enabled: true
898
+ VersionAdded: '5.12.0'
899
+
900
+ ChefModernize/UnnecessaryMixlibShelloutRequire:
901
+ Description: Chef Infra Client includes mixlib/shellout automatically in resources and providers.
902
+ Enabled: true
903
+ VersionAdded: '5.12.0'
904
+ Include:
905
+ - '**/resources/*.rb'
906
+ - '**/providers/*.rb'
907
+
859
908
  ###############################
860
909
  # Migrating to new patterns
861
910
  ###############################
@@ -902,6 +951,13 @@ ChefEffortless/SearchForEnvironmentsOrRoles:
902
951
  Exclude:
903
952
  - '**/metadata.rb'
904
953
 
954
+ ChefEffortless/Berksfile:
955
+ Description: Policyfiles should be used for cookbook dependency solving instead of a Berkshelf Berksfile.
956
+ Enabled: true
957
+ VersionAdded: '5.12.0'
958
+ Include:
959
+ - '**/Berksfile'
960
+
905
961
  #### The base rubocop 0.37 enabled.yml file we started with ####
906
962
 
907
963
  Layout/AccessModifierIndentation:
@@ -6,6 +6,7 @@ require 'yaml'
6
6
  # ensure the desired target version of RuboCop is gem activated
7
7
  gem 'rubocop', "= #{Cookstyle::RUBOCOP_VERSION}"
8
8
  require 'rubocop'
9
+ require 'rubocop/monkey_patches/comment_config.rb'
9
10
 
10
11
  module RuboCop
11
12
  class ConfigLoader
@@ -1,4 +1,4 @@
1
1
  module Cookstyle
2
- VERSION = "5.11.0".freeze # rubocop: disable Style/StringLiterals
2
+ VERSION = "5.12.12".freeze # rubocop: disable Style/StringLiterals
3
3
  RUBOCOP_VERSION = '0.75.1'.freeze
4
4
  end
@@ -53,6 +53,7 @@ module RuboCop
53
53
  #
54
54
  # # bad
55
55
  # property :config_file, String, required: true, name_property: true
56
+ # attribute :config_file, String, required: true, name_attribute: true
56
57
  #
57
58
  # # good
58
59
  # property :config_file, String, required: true
@@ -69,10 +70,10 @@ module RuboCop
69
70
  private
70
71
 
71
72
  def property_is_name_property?(node)
72
- if node.method_name == :property
73
+ if %i(property attribute).include?(node.method_name)
73
74
  node.arguments.each do |arg|
74
75
  if arg.type == :hash
75
- return true if arg.source.match?(/name_property:\s*true/)
76
+ return true if arg.source.match?(/name_(property|attribute):\s*true/)
76
77
  end
77
78
  end
78
79
  false # no required: true found
@@ -80,7 +81,7 @@ module RuboCop
80
81
  end
81
82
 
82
83
  def required_property?(node)
83
- if node.method_name == :property
84
+ if %i(property attribute).include?(node.method_name)
84
85
  node.arguments.each do |arg|
85
86
  if arg.type == :hash
86
87
  return true if arg.source.match?(/required:\s*true/)
@@ -0,0 +1,52 @@
1
+ #
2
+ # Copyright:: 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 ChefCorrectness
21
+ # Chef Infra Client provides the :nothing action by default for every resource. There is no need to define a :nothing action in your resource code.
22
+ #
23
+ # @example
24
+ #
25
+ # # bad
26
+ # action :nothing
27
+ # # let's do nothing
28
+ # end
29
+ #
30
+ class ResourceWithNothingAction < Cop
31
+ 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
+
33
+ def_node_matcher :nothing_action?, <<-PATTERN
34
+ (block (send nil? :action (sym :nothing)) (args) ... )
35
+ PATTERN
36
+
37
+ def on_block(node)
38
+ nothing_action?(node) do
39
+ add_offense(node, location: :expression, message: MSG, severity: :refactor)
40
+ end
41
+ end
42
+
43
+ def autocorrect(node)
44
+ lambda do |corrector|
45
+ corrector.remove(node.source_range)
46
+ end
47
+ end
48
+ end
49
+ end
50
+ end
51
+ end
52
+ end
@@ -18,7 +18,7 @@ module RuboCop
18
18
  module Cop
19
19
  module Chef
20
20
  module ChefCorrectness
21
- # There is no need to define a property named :name in a resource as Chef Infra defines that property for all resources out of the box.
21
+ # There is no need to define a property named :name in a resource as Chef Infra defines that property for all resources by default.
22
22
  #
23
23
  # @example
24
24
  #
@@ -27,7 +27,7 @@ module RuboCop
27
27
  # property :name, String, name_property: true
28
28
  #
29
29
  class UnnecessaryNameProperty < Cop
30
- MSG = 'There is no need to define a property named :name in a resource as Chef Infra defines that property for all resources out of the box.'.freeze
30
+ MSG = 'There is no need to define a property named :name in a resource as Chef Infra defines that property for all resources by default.'.freeze
31
31
 
32
32
  def_node_matcher :name_property?, <<-PATTERN
33
33
  (send nil? :property (sym :name) (const nil? :String) $...)
@@ -0,0 +1,41 @@
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
+ # The Libarian-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 Bershelf offers a more similar, and still supported, experience to Librarian-Chef.
22
+ #
23
+ module ChefDeprecations
24
+ class Cheffile < Cop
25
+ include RangeHelp
26
+
27
+ MSG = 'The Libarian-Chef depsolving project is no longer maintained and a Cheffile should not be used for cookbook depsolving. Consider using Policyfiles instead.'.freeze
28
+
29
+ def investigate(processed_source)
30
+ return if processed_source.blank?
31
+
32
+ # Using range similar to RuboCop::Cop::Naming::Filename (file_name.rb)
33
+ range = source_range(processed_source.buffer, 1, 0)
34
+
35
+ add_offense(nil, location: range, message: MSG, severity: :refactor)
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,76 @@
1
+ #
2
+ # Copyright:: Copyright 2019, Chef Software Inc.
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ #
16
+ module RuboCop
17
+ module Cop
18
+ module Chef
19
+ module ChefDeprecations
20
+ # The node.deep_fetch method has been removed from Chef-Sugar, and must be replaced by
21
+ # the node.read API.
22
+ #
23
+ # @example
24
+ #
25
+ # # bad
26
+ # node.deep_fetch("foo")
27
+ #
28
+ # # good
29
+ # node.read("foo")
30
+ #
31
+ # # bad
32
+ # node.deep_fetch!("foo")
33
+ #
34
+ # # good
35
+ # node.read!("foo")
36
+ #
37
+ class NodeDeepFetch < Cop
38
+ MSG = 'Do not use node.deep_fetch. Replace with node.read to keep identical behavior.'.freeze
39
+ MSG2 = 'Do not use node.deep_fetch!. Replace with node.read! to keep identical behavior.'.freeze
40
+
41
+ def_node_matcher :node_deep_fetch?, <<-PATTERN
42
+ (send (send _ :node) $:deep_fetch _)
43
+ PATTERN
44
+
45
+ def_node_matcher :node_deep_fetch_bang?, <<-PATTERN
46
+ (send (send _ :node) $:deep_fetch! _)
47
+ PATTERN
48
+
49
+ def on_send(node)
50
+ node_deep_fetch?(node) do
51
+ add_offense(node, location: :selector, message: MSG, severity: :refactor)
52
+ end
53
+
54
+ node_deep_fetch_bang?(node) do
55
+ add_offense(node, location: :selector, message: MSG2, severity: :refactor)
56
+ end
57
+ end
58
+
59
+ def autocorrect(node)
60
+ lambda do |corrector|
61
+ corrector.replace(node.loc.selector, fix_name(node.method_name))
62
+ end
63
+ end
64
+
65
+ private
66
+
67
+ def fix_name(name)
68
+ return 'read!' if name == :deep_fetch!
69
+ return 'read' if name == :deep_fetch
70
+ name.to_s
71
+ end
72
+ end
73
+ end
74
+ end
75
+ end
76
+ end
@@ -18,21 +18,22 @@ module RuboCop
18
18
  module Cop
19
19
  module Chef
20
20
  module ChefDeprecations
21
- # Use 'shell_out!' instead of the legacy 'run_command' helper for shelling out. The run_command helper was removed in Chef Infra Client 13.
21
+ # 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.
22
22
  #
23
23
  # @example
24
24
  #
25
25
  # # bad
26
26
  # run_command('/bin/foo')
27
+ # run_command_with_systems_locale('/bin/foo')
27
28
  #
28
29
  # # good
29
30
  # shell_out!('/bin/foo')
30
31
  #
31
32
  class UsesRunCommandHelper < Cop
32
- MSG = "Use 'shell_out!' instead of the legacy 'run_command' helper for shelling out. The run_command helper was removed in Chef Infra Client 13.".freeze
33
+ 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
33
34
 
34
- def_node_matcher :calls_run_command?, '(send nil? :run_command ...)'
35
- def_node_search :defines_run_command?, '(def :run_command ...)'
35
+ def_node_matcher :calls_run_command?, '(send nil? {:run_command :run_command_with_systems_locale} ...)'
36
+ def_node_search :defines_run_command?, '(def {:run_command :run_command_with_systems_locale} ...)'
36
37
 
37
38
  def on_send(node)
38
39
  calls_run_command?(node) do
@@ -0,0 +1,41 @@
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
+ # Policyfiles should be used for cookbook dependency solving instead of a Berkshelf Berksfile.
22
+ #
23
+ module ChefEffortless
24
+ class Berksfile < Cop
25
+ include RangeHelp
26
+
27
+ MSG = 'Policyfiles should be used for cookbook dependency solving instead of a Berkshelf Berksfile.'.freeze
28
+
29
+ def investigate(processed_source)
30
+ return if processed_source.blank?
31
+
32
+ # Using range similar to RuboCop::Cop::Naming::Filename (file_name.rb)
33
+ range = source_range(processed_source.buffer, 1, 0)
34
+
35
+ add_offense(nil, location: range, message: MSG, severity: :refactor)
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,49 @@
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
+ # if defined?(default_action) is no longer necessary in Chef Resources as default_action shipped in Chef 10.8.
22
+ #
23
+ # @example
24
+ #
25
+ # # bad
26
+ # default_action :foo if defined?(default_action)
27
+ #
28
+ # # good
29
+ # default_action :foo
30
+ #
31
+ class IfProvidesDefaultAction < Cop
32
+ MSG = 'if defined?(default_action) is no longer necessary in Chef Resources as default_action shipped in Chef 10.8.'.freeze
33
+
34
+ def on_defined?(node)
35
+ return unless node.arguments.first == s(:send, nil, :default_action)
36
+ node = node.parent if node.parent.respond_to?(:if?) && node.parent.if? # we want the whole if statement
37
+ add_offense(node, location: :expression, message: MSG, severity: :refactor)
38
+ end
39
+
40
+ def autocorrect(node)
41
+ lambda do |corrector|
42
+ corrector.replace(node.loc.expression, node.children[1].source)
43
+ end
44
+ end
45
+ end
46
+ end
47
+ end
48
+ end
49
+ end
@@ -26,6 +26,9 @@ module RuboCop
26
26
  # # bad
27
27
  # chef_version '>= 13' if respond_to?(:chef_version)
28
28
  # chef_version '>= 13' if defined?(chef_version)
29
+ # if defined(chef_version)
30
+ # chef_version '>= 13'
31
+ # end
29
32
  #
30
33
  # # good
31
34
  # chef_version '>= 13'
@@ -50,7 +53,13 @@ module RuboCop
50
53
 
51
54
  def autocorrect(node)
52
55
  lambda do |corrector|
53
- corrector.replace(node.loc.expression, node.children[1].source)
56
+ # When the if statement is if modifier like `foo if respond_to?(:foo)` then
57
+ # node.if_branch is the actual method call we want to extract.
58
+ # If a series of metadata methods are wrapped in an if statement then the content we want
59
+ # is a block under the if statement and node.parent.if_branch can get us that block
60
+ node = node.parent unless node.if_type?
61
+
62
+ corrector.replace(node.loc.expression, node.if_branch.source)
54
63
  end
55
64
  end
56
65
  end
@@ -0,0 +1,51 @@
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
+ # Chef Infra Client includes mixlib/shellout automatically in resources and providers.
23
+ #
24
+ # @example
25
+ #
26
+ # # bad
27
+ # require 'mixlib/shellout'
28
+ #
29
+ class UnnecessaryMixlibShelloutRequire < Cop
30
+ MSG = 'Chef Infra Client includes mixlib/shellout automatically in resources and providers.'.freeze
31
+
32
+ def_node_matcher :require_mixlibshellout?, <<-PATTERN
33
+ (send nil? :require ( str "mixlib/shellout"))
34
+ PATTERN
35
+
36
+ def on_send(node)
37
+ require_mixlibshellout?(node) do
38
+ add_offense(node, location: :expression, message: MSG, severity: :refactor)
39
+ end
40
+ end
41
+
42
+ def autocorrect(node)
43
+ lambda do |corrector|
44
+ corrector.remove(node.loc.expression)
45
+ end
46
+ end
47
+ end
48
+ end
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,55 @@
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
+ # Use the archive_file resource built into Chef Infra Client 15+ instead of the zipfile resource from the zipfile cookbook.
23
+ #
24
+ # @example
25
+ #
26
+ # # bad
27
+ # zipfile "C:\file.zip" do
28
+ # path 'C:\expand_here'
29
+ # end
30
+ #
31
+ class ZipfileResource < Cop
32
+ include RuboCop::Chef::CookbookHelpers
33
+
34
+ MSG = 'Use the archive_file resource built into Chef Infra Client 15+ instead of the zipfile resource from the zipfile cookbook.'.freeze
35
+
36
+ def_node_matcher :depends_zipfile?, <<-PATTERN
37
+ (send nil? :depends (str "zipfile"))
38
+ PATTERN
39
+
40
+ def on_send(node)
41
+ depends_zipfile?(node) do
42
+ add_offense(node, location: :expression, message: MSG, severity: :refactor)
43
+ end
44
+ end
45
+
46
+ def on_block(node)
47
+ match_resource_type?(:zipfile, node) do
48
+ add_offense(node, location: :expression, message: MSG, severity: :refactor)
49
+ end
50
+ end
51
+ end
52
+ end
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,52 @@
1
+ #
2
+ # Copyright:: 2016-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 ChefStyle
22
+ # Checks for default copyright comments from the chef generator cookbook command
23
+ #
24
+ # @example
25
+ #
26
+ # # bad
27
+ # Copyright:: 2019 YOUR_NAME
28
+ # Copyright:: 2019 YOUR_COMPANY_NAME
29
+ #
30
+ # # good
31
+ # Copyright:: 2019 Tim Smith
32
+ # Copyright:: 2019 Chef Software, Inc.
33
+ #
34
+ class DefaultCopyrightComments < Cop
35
+ MSG = 'Cookbook copyright comment headers should be updated for a real person or organization.'.freeze
36
+
37
+ def investigate(processed_source)
38
+ return unless processed_source.ast
39
+
40
+ processed_source.comments.each do |comment|
41
+ next unless comment.inline? # headers aren't in blocks
42
+
43
+ if /# (?:Copyright\W*).*YOUR_(NAME|COMPANY_NAME)/.match?(comment.text)
44
+ add_offense(comment, location: comment.loc.expression, message: MSG, severity: :refactor)
45
+ end
46
+ end
47
+ end
48
+ end
49
+ end
50
+ end
51
+ end
52
+ end
@@ -18,23 +18,27 @@ module RuboCop
18
18
  module Cop
19
19
  module Chef
20
20
  module ChefStyle
21
- # Use the platform?() and platform_family?() helpers instead of node['platform] == 'foo'
22
- # and node['platform_family'] == 'bar'. These helpers are easier to read and can accept multiple
23
- # platform arguments, which greatly simplifies complex platform logic.
21
+ # Use the platform?() and platform_family?() helpers instead of node['platform] == 'foo' and node['platform_family'] == 'bar'. These helpers are easier to read and can accept multiple platform arguments, which greatly simplifies complex platform logic.
24
22
  #
25
23
  # @example
26
24
  #
27
25
  # # bad
28
26
  # node['platform'] == 'ubuntu'
27
+ # node['platform_family'] == 'debian'
28
+ # node['platform'] != 'ubuntu'
29
+ # node['platform_family'] != 'debian'
29
30
  #
30
31
  # # good
31
32
  # platform?('ubuntu')
33
+ # !platform?('ubuntu')
34
+ # platform_family?('debian')
35
+ # !platform_family?('debian')
32
36
  #
33
37
  class UsePlatformHelpers < Cop
34
- MSG = 'Use platform? and platform_family? helpers for checking node platform'.freeze
38
+ MSG = "Use platform? and platform_family? helpers for checking a node's platform".freeze
35
39
 
36
40
  def_node_matcher :platform_check?, <<-PATTERN
37
- ( send (send (send nil? :node) :[] $(str {"platform" "platform_family"}) ) :== $str )
41
+ ( send (send (send nil? :node) :[] $(str {"platform" "platform_family"}) ) ${:== :!=} $str )
38
42
  PATTERN
39
43
 
40
44
  def on_send(node)
@@ -45,8 +49,10 @@ module RuboCop
45
49
 
46
50
  def autocorrect(node)
47
51
  lambda do |corrector|
48
- platform_check?(node) do |type, plat|
49
- corrector.replace(node.loc.expression, "#{type.value}?('#{plat.value}')")
52
+ platform_check?(node) do |type, operator, plat|
53
+ corrected_string = operator == :!= ? '!' : ''
54
+ corrected_string << "#{type.value}?('#{plat.value}')"
55
+ corrector.replace(node.loc.expression, corrected_string)
50
56
  end
51
57
  end
52
58
  end
@@ -0,0 +1,10 @@
1
+ module RuboCop
2
+ # we're monkey patching the config regex to allow for # cookstyle: disable whatever
3
+ # in addition to the # rubocop: disable whatever that comes with Rubocop
4
+ class CommentConfig
5
+ remove_const('COMMENT_DIRECTIVE_REGEXP')
6
+ COMMENT_DIRECTIVE_REGEXP = Regexp.new(
7
+ ('# (?:rubocop|cookstyle) : ((?:dis|en)able)\b ' + COPS_PATTERN).gsub(' ', '\s*')
8
+ )
9
+ end
10
+ 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.11.0
4
+ version: 5.12.12
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-08 00:00:00.000000000 Z
12
+ date: 2019-11-14 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rubocop
@@ -68,12 +68,14 @@ files:
68
68
  - lib/rubocop/cop/chef/correctness/resource_sets_internal_properties.rb
69
69
  - lib/rubocop/cop/chef/correctness/resource_sets_name_property.rb
70
70
  - lib/rubocop/cop/chef/correctness/resource_with_none_action.rb
71
+ - lib/rubocop/cop/chef/correctness/resource_with_nothing_action.rb
71
72
  - lib/rubocop/cop/chef/correctness/service_resource.rb
72
73
  - lib/rubocop/cop/chef/correctness/tmp_path.rb
73
74
  - lib/rubocop/cop/chef/correctness/unnecessary_name_property.rb
74
75
  - lib/rubocop/cop/chef/deprecation/attribute_metadata.rb
75
76
  - lib/rubocop/cop/chef/deprecation/chef_handler_supports.rb
76
77
  - lib/rubocop/cop/chef/deprecation/chef_rest.rb
78
+ - lib/rubocop/cop/chef/deprecation/cheffile.rb
77
79
  - lib/rubocop/cop/chef/deprecation/chefspec_coverage_report.rb
78
80
  - lib/rubocop/cop/chef/deprecation/chefspec_legacy_runner.rb
79
81
  - lib/rubocop/cop/chef/deprecation/chocolatey_package_uninstall_action.rb
@@ -93,6 +95,7 @@ files:
93
95
  - lib/rubocop/cop/chef/deprecation/locale_lc_all_property.rb
94
96
  - lib/rubocop/cop/chef/deprecation/long_description_metadata.rb
95
97
  - lib/rubocop/cop/chef/deprecation/name_property_and_default.rb
98
+ - lib/rubocop/cop/chef/deprecation/node_deep_fetch.rb
96
99
  - lib/rubocop/cop/chef/deprecation/node_methods_not_attributes.rb
97
100
  - lib/rubocop/cop/chef/deprecation/node_set.rb
98
101
  - lib/rubocop/cop/chef/deprecation/node_set_unless.rb
@@ -116,6 +119,7 @@ files:
116
119
  - lib/rubocop/cop/chef/deprecation/windows_task_change_action.rb
117
120
  - lib/rubocop/cop/chef/deprecation/xml_ruby_recipe.rb
118
121
  - lib/rubocop/cop/chef/deprecation/yum_dnf_compat_recipe.rb
122
+ - lib/rubocop/cop/chef/effortless/berksfile.rb
119
123
  - lib/rubocop/cop/chef/effortless/data_bags.rb
120
124
  - lib/rubocop/cop/chef/effortless/node_environment.rb
121
125
  - lib/rubocop/cop/chef/effortless/node_policygroup.rb
@@ -133,6 +137,7 @@ files:
133
137
  - lib/rubocop/cop/chef/modernize/depends_zypper_cookbook.rb
134
138
  - lib/rubocop/cop/chef/modernize/execute_apt_update.rb
135
139
  - lib/rubocop/cop/chef/modernize/execute_tzutil.rb
140
+ - lib/rubocop/cop/chef/modernize/if_provides_default_action.rb
136
141
  - lib/rubocop/cop/chef/modernize/includes_mixin_shellout.rb
137
142
  - lib/rubocop/cop/chef/modernize/libarchive_file.rb
138
143
  - lib/rubocop/cop/chef/modernize/macos_user_defaults.rb
@@ -154,18 +159,22 @@ files:
154
159
  - lib/rubocop/cop/chef/modernize/seven_zip_archive.rb
155
160
  - lib/rubocop/cop/chef/modernize/shellouts_to_chocolatey.rb
156
161
  - lib/rubocop/cop/chef/modernize/systctl_param_resource.rb
162
+ - lib/rubocop/cop/chef/modernize/unnecessary_mixlib_shellout_require.rb
157
163
  - lib/rubocop/cop/chef/modernize/whyrun_supported_true.rb
158
164
  - lib/rubocop/cop/chef/modernize/windows_default_recipe.rb
159
165
  - lib/rubocop/cop/chef/modernize/windows_version_helper.rb
160
166
  - lib/rubocop/cop/chef/modernize/windows_zipfile.rb
167
+ - lib/rubocop/cop/chef/modernize/zipfile_resource.rb
161
168
  - lib/rubocop/cop/chef/modernize/zypper_repo.rb
162
169
  - lib/rubocop/cop/chef/style/attribute_keys.rb
163
170
  - lib/rubocop/cop/chef/style/comment_sentence_spacing.rb
164
171
  - lib/rubocop/cop/chef/style/comments_copyright_format.rb
172
+ - lib/rubocop/cop/chef/style/comments_default_copyright.rb
165
173
  - lib/rubocop/cop/chef/style/comments_format.rb
166
174
  - lib/rubocop/cop/chef/style/file_mode.rb
167
175
  - lib/rubocop/cop/chef/style/simplify_platform_major_version_check.rb
168
176
  - lib/rubocop/cop/chef/style/use_platform_helpers.rb
177
+ - lib/rubocop/monkey_patches/comment_config.rb
169
178
  homepage: https://github.com/chef/cookstyle
170
179
  licenses:
171
180
  - Apache-2.0