cookstyle 6.5.3 → 6.10.2

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.
Files changed (27) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +1 -1
  3. data/config/cookstyle.yml +296 -12
  4. data/config/disable_all.yml +12 -0
  5. data/config/upstream.yml +82 -19
  6. data/lib/cookstyle.rb +2 -1
  7. data/lib/cookstyle/version.rb +2 -2
  8. data/lib/rubocop/chef/platform_helpers.rb +2 -1
  9. data/lib/rubocop/cop/chef/correctness/invalid_platform_family_values_in_case.rb +77 -0
  10. data/lib/rubocop/cop/chef/correctness/invalid_platform_values_in_case.rb +77 -0
  11. data/lib/rubocop/cop/chef/correctness/invalid_version_metadata.rb +1 -1
  12. data/lib/rubocop/cop/chef/correctness/lazy_eval_node_attribute_defaults.rb +56 -0
  13. data/lib/rubocop/cop/chef/correctness/openssl_password_helpers.rb +45 -0
  14. data/lib/rubocop/cop/chef/deprecation/hwrp_without_provides.rb +141 -0
  15. data/lib/rubocop/cop/chef/deprecation/resource_uses_only_resource_name.rb +86 -0
  16. data/lib/rubocop/cop/chef/deprecation/xml_ruby_recipe.rb +3 -3
  17. data/lib/rubocop/cop/chef/modernize/includes_mixin_shellout.rb +24 -3
  18. data/lib/rubocop/cop/chef/modernize/use_multipackage_installs.rb +8 -4
  19. data/lib/rubocop/cop/chef/redundant/multiple_platform_checks.rb +60 -0
  20. data/lib/rubocop/cop/chef/redundant/ohai_attribute_to_string.rb +68 -0
  21. data/lib/rubocop/cop/chef/sharing/include_resource_examples.rb +59 -0
  22. data/lib/rubocop/cop/chef/sharing/invalid_license_string.rb +1 -1
  23. data/lib/rubocop/monkey_patches/registry_cop.rb +14 -0
  24. data/lib/rubocop/monkey_patches/team.rb +24 -0
  25. metadata +15 -6
  26. data/lib/rubocop/cop/chef/deprecation/resource_without_name_or_provides.rb +0 -81
  27. data/lib/rubocop/monkey_patches/commissioner.rb +0 -26
@@ -0,0 +1,68 @@
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
+
18
+ module RuboCop
19
+ module Cop
20
+ module Chef
21
+ module ChefRedundantCode
22
+ # Many Ohai node attributes are already strings and don't need to be cast to strings again
23
+ #
24
+ # @example
25
+ #
26
+ # # bad
27
+ # node['platform'].to_s
28
+ # node['platform_family'].to_s
29
+ # node['platform_version'].to_s
30
+ # node['fqdn'].to_s
31
+ # node['hostname'].to_s
32
+ # node['os'].to_s
33
+ # node['name'].to_s
34
+ #
35
+ # # good
36
+ # node['platform']
37
+ # node['platform_family']
38
+ # node['platform_version']
39
+ # node['fqdn']
40
+ # node['hostname']
41
+ # node['os']
42
+ # node['name']
43
+ #
44
+ class OhaiAttributeToString < Cop
45
+ MSG = "This Ohai node attribute is already a string and doesn't need to be converted".freeze
46
+
47
+ def_node_matcher :platform_to_s?, <<-PATTERN
48
+ (send (send (send nil? :node) :[] $(str {"platform" "platform_family" "platform_version" "fqdn" "hostname" "os" "name"}) ) :to_s )
49
+ PATTERN
50
+
51
+ def on_send(node)
52
+ platform_to_s?(node) do
53
+ add_offense(node, location: :expression, message: MSG, severity: :refactor)
54
+ end
55
+ end
56
+
57
+ def autocorrect(node)
58
+ platform_to_s?(node) do |method|
59
+ lambda do |corrector|
60
+ corrector.replace(node.loc.expression, "node['#{method.value}']")
61
+ end
62
+ end
63
+ end
64
+ end
65
+ end
66
+ end
67
+ end
68
+ end
@@ -0,0 +1,59 @@
1
+ #
2
+ # Copyright:: 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 ChefSharing
21
+ # Resources should include examples field to allow automated documention. Requires Chef Infra Client 13.9 or later.
22
+ #
23
+ # @example
24
+ #
25
+ # # good
26
+ # examples <<~DOC
27
+ # **Specify a global domain value**
28
+ #
29
+ # ```ruby
30
+ # macos_userdefaults 'full keyboard access to all controls' do
31
+ # key 'AppleKeyboardUIMode'
32
+ # value '2'
33
+ # end
34
+ # ```
35
+ # DOC
36
+ #
37
+ class IncludeResourceExamples < Cop
38
+ include RangeHelp
39
+ extend TargetChefVersion
40
+
41
+ minimum_target_chef_version '13.9'
42
+
43
+ MSG = 'Resources should include examples field to allow automated documention. Requires Chef Infra Client 13.9 or later.'.freeze
44
+
45
+ def investigate(processed_source)
46
+ return if processed_source.blank?
47
+
48
+ # Using range similar to RuboCop::Cop::Naming::Filename (file_name.rb)
49
+ range = source_range(processed_source.buffer, 1, 0)
50
+
51
+ add_offense(nil, location: range, message: MSG, severity: :refactor) unless resource_examples(processed_source.ast).any?
52
+ end
53
+
54
+ def_node_search :resource_examples, '(send nil? :examples dstr ...)'
55
+ end
56
+ end
57
+ end
58
+ end
59
+ end
@@ -483,7 +483,7 @@ module RuboCop
483
483
 
484
484
  def valid_license?(license)
485
485
  VALID_LICENSE_STRING.include?(license) ||
486
- license.downcase == 'all rights reserved'
486
+ license.casecmp('all rights reserved') == 0
487
487
  end
488
488
  end
489
489
  end
@@ -0,0 +1,14 @@
1
+ module RuboCop
2
+ module Cop
3
+ class Registry
4
+ # we monkeypatch this warning to replace rubocop with cookstyle
5
+ def print_warning(name, path)
6
+ message = "#{path}: Warning: no department given for #{name}."
7
+ if path.end_with?('.rb')
8
+ message += ' Run `cookstyle -a --only Migration/DepartmentName` to fix.'
9
+ end
10
+ warn message
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RuboCop
4
+ module Cop
5
+ class Team
6
+ def support_target_chef_version?(cop)
7
+ return true unless cop.class.respond_to?(:support_target_chef_version?)
8
+
9
+ cop.class.support_target_chef_version?(cop.target_chef_version)
10
+ end
11
+
12
+ ### START COOKSTYLE MODIFICATION
13
+ def roundup_relevant_cops(filename)
14
+ cops.reject do |cop|
15
+ cop.excluded_file?(filename) ||
16
+ !support_target_ruby_version?(cop) ||
17
+ !support_target_chef_version?(cop) ||
18
+ !support_target_rails_version?(cop)
19
+ end
20
+ end
21
+ ### END COOKSTYLE MODIFICATION
22
+ end
23
+ end
24
+ 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: 6.5.3
4
+ version: 6.10.2
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-05-19 00:00:00.000000000 Z
12
+ date: 2020-07-07 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rubocop
@@ -17,14 +17,14 @@ dependencies:
17
17
  requirements:
18
18
  - - '='
19
19
  - !ruby/object:Gem::Version
20
- version: 0.83.0
20
+ version: 0.86.0
21
21
  type: :runtime
22
22
  prerelease: false
23
23
  version_requirements: !ruby/object:Gem::Requirement
24
24
  requirements:
25
25
  - - '='
26
26
  - !ruby/object:Gem::Version
27
- version: 0.83.0
27
+ version: 0.86.0
28
28
  description:
29
29
  email:
30
30
  - thom@chef.io
@@ -57,17 +57,21 @@ files:
57
57
  - lib/rubocop/cop/chef/correctness/incorrect_library_injection.rb
58
58
  - lib/rubocop/cop/chef/correctness/invalid_notification_timing.rb
59
59
  - lib/rubocop/cop/chef/correctness/invalid_platform_family_helper.rb
60
+ - lib/rubocop/cop/chef/correctness/invalid_platform_family_values_in_case.rb
60
61
  - lib/rubocop/cop/chef/correctness/invalid_platform_helper.rb
61
62
  - lib/rubocop/cop/chef/correctness/invalid_platform_metadata.rb
63
+ - lib/rubocop/cop/chef/correctness/invalid_platform_values_in_case.rb
62
64
  - lib/rubocop/cop/chef/correctness/invalid_value_for_platform_family_helper.rb
63
65
  - lib/rubocop/cop/chef/correctness/invalid_value_for_platform_helper.rb
64
66
  - lib/rubocop/cop/chef/correctness/invalid_version_metadata.rb
67
+ - lib/rubocop/cop/chef/correctness/lazy_eval_node_attribute_defaults.rb
65
68
  - lib/rubocop/cop/chef/correctness/malformed_value_for_platform.rb
66
69
  - lib/rubocop/cop/chef/correctness/metadata_missing_name.rb
67
70
  - lib/rubocop/cop/chef/correctness/node_normal.rb
68
71
  - lib/rubocop/cop/chef/correctness/node_normal_unless.rb
69
72
  - lib/rubocop/cop/chef/correctness/node_save.rb
70
73
  - lib/rubocop/cop/chef/correctness/notifies_action_not_symbol.rb
74
+ - lib/rubocop/cop/chef/correctness/openssl_password_helpers.rb
71
75
  - lib/rubocop/cop/chef/correctness/powershell_delete_file.rb
72
76
  - lib/rubocop/cop/chef/correctness/resource_sets_internal_properties.rb
73
77
  - lib/rubocop/cop/chef/correctness/resource_sets_name_property.rb
@@ -96,6 +100,7 @@ files:
96
100
  - lib/rubocop/cop/chef/deprecation/eol_audit_mode.rb
97
101
  - lib/rubocop/cop/chef/deprecation/epic_fail.rb
98
102
  - lib/rubocop/cop/chef/deprecation/erl_call.rb
103
+ - lib/rubocop/cop/chef/deprecation/hwrp_without_provides.rb
99
104
  - lib/rubocop/cop/chef/deprecation/inherits_compat_resource.rb
100
105
  - lib/rubocop/cop/chef/deprecation/launchd_deprecated_hash_property.rb
101
106
  - lib/rubocop/cop/chef/deprecation/legacy_notify_syntax.rb
@@ -115,9 +120,9 @@ files:
115
120
  - lib/rubocop/cop/chef/deprecation/require_recipe.rb
116
121
  - lib/rubocop/cop/chef/deprecation/resource_overrides_provides_method.rb
117
122
  - lib/rubocop/cop/chef/deprecation/resource_uses_dsl_name_method.rb
123
+ - lib/rubocop/cop/chef/deprecation/resource_uses_only_resource_name.rb
118
124
  - lib/rubocop/cop/chef/deprecation/resource_uses_provider_base_method.rb
119
125
  - lib/rubocop/cop/chef/deprecation/resource_uses_updated_method.rb
120
- - lib/rubocop/cop/chef/deprecation/resource_without_name_or_provides.rb
121
126
  - lib/rubocop/cop/chef/deprecation/ruby_27_keyword_argument_warnings.rb
122
127
  - lib/rubocop/cop/chef/deprecation/ruby_block_create_action.rb
123
128
  - lib/rubocop/cop/chef/deprecation/run_command_helper.rb
@@ -204,7 +209,9 @@ files:
204
209
  - lib/rubocop/cop/chef/redundant/custom_resource_with_allowed_actions.rb
205
210
  - lib/rubocop/cop/chef/redundant/grouping_metadata.rb
206
211
  - lib/rubocop/cop/chef/redundant/long_description_metadata.rb
212
+ - lib/rubocop/cop/chef/redundant/multiple_platform_checks.rb
207
213
  - lib/rubocop/cop/chef/redundant/name_property_and_required.rb
214
+ - lib/rubocop/cop/chef/redundant/ohai_attribute_to_string.rb
208
215
  - lib/rubocop/cop/chef/redundant/property_splat_regex.rb
209
216
  - lib/rubocop/cop/chef/redundant/property_with_default_and_required.rb
210
217
  - lib/rubocop/cop/chef/redundant/provides_metadata.rb
@@ -221,6 +228,7 @@ files:
221
228
  - lib/rubocop/cop/chef/sharing/empty_metadata_field.rb
222
229
  - lib/rubocop/cop/chef/sharing/include_property_descriptions.rb
223
230
  - lib/rubocop/cop/chef/sharing/include_resource_descriptions.rb
231
+ - lib/rubocop/cop/chef/sharing/include_resource_examples.rb
224
232
  - lib/rubocop/cop/chef/sharing/insecure_cookbook_url.rb
225
233
  - lib/rubocop/cop/chef/sharing/invalid_license_string.rb
226
234
  - lib/rubocop/cop/chef/style/attribute_keys.rb
@@ -240,9 +248,10 @@ files:
240
248
  - lib/rubocop/cop/chef/style/use_platform_helpers.rb
241
249
  - lib/rubocop/cop/target_chef_version.rb
242
250
  - lib/rubocop/monkey_patches/comment_config.rb
243
- - lib/rubocop/monkey_patches/commissioner.rb
244
251
  - lib/rubocop/monkey_patches/config.rb
245
252
  - lib/rubocop/monkey_patches/cop.rb
253
+ - lib/rubocop/monkey_patches/registry_cop.rb
254
+ - lib/rubocop/monkey_patches/team.rb
246
255
  homepage:
247
256
  licenses:
248
257
  - Apache-2.0
@@ -1,81 +0,0 @@
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
-
18
- module RuboCop
19
- module Cop
20
- module Chef
21
- module ChefDeprecations
22
- # In Chef Infra Client 16 and later a legacy HWRP resource must use either `resource_name` or `provides` to define the resource name.
23
- #
24
- # @example
25
- #
26
- # # bad
27
- # class Chef
28
- # class Resource
29
- # class UlimitRule < Chef::Resource
30
- # property :type, [Symbol, String], required: true
31
- # property :item, [Symbol, String], required: true
32
- #
33
- # # additional resource code
34
- # end
35
- # end
36
- # end
37
- #
38
- # # good
39
- # class Chef
40
- # class Resource
41
- # class UlimitRule < Chef::Resource
42
- # resource_name :ulimit_rule
43
- #
44
- # property :type, [Symbol, String], required: true
45
- # property :item, [Symbol, String], required: true
46
- #
47
- # # additional resource code
48
- # end
49
- # end
50
- # end
51
- #
52
- # # better
53
- # Convert your legacy HWRPs to custom resources
54
- #
55
- class ResourceWithoutNameOrProvides < Cop
56
- MSG = 'In Chef Infra Client 16 and later legacy HWRP resources must use either `resource_name` or `provides` to define the resource name.'.freeze
57
-
58
- def_node_matcher :HWRP?, <<-PATTERN
59
- (class
60
- (const nil? :Chef) nil?
61
- (class
62
- (const nil? :Resource) nil?
63
- $(class
64
- (const nil? ... )
65
- (const
66
- (const nil? :Chef) :Resource)
67
- (begin ... ))))
68
- PATTERN
69
-
70
- def_node_search :provides_or_resource_name?, '(send nil? {:provides :resource_name} ...)'
71
-
72
- def on_class(node)
73
- HWRP?(node) do |inherit|
74
- add_offense(inherit, location: :expression, message: MSG, severity: :warning) if provides_or_resource_name?(processed_source.ast).nil?
75
- end
76
- end
77
- end
78
- end
79
- end
80
- end
81
- end
@@ -1,26 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module RuboCop
4
- module Cop
5
- class Commissioner
6
- def remove_irrelevant_cops(filename)
7
- @cops.reject! { |cop| cop.excluded_file?(filename) }
8
- @cops.reject! do |cop|
9
- cop.class.respond_to?(:support_target_ruby_version?) &&
10
- !cop.class.support_target_ruby_version?(cop.target_ruby_version)
11
- end
12
- @cops.reject! do |cop|
13
- cop.class.respond_to?(:support_target_rails_version?) &&
14
- !cop.class.support_target_rails_version?(cop.target_rails_version)
15
- end
16
-
17
- ### START COOKSTYLE MODIFICATION
18
- @cops.reject! do |cop|
19
- cop.class.respond_to?(:support_target_chef_version?) &&
20
- !cop.class.support_target_chef_version?(cop.target_chef_version)
21
- end
22
- ### END COOKSTYLE MODIFICATION
23
- end
24
- end
25
- end
26
- end