cookstyle 6.9.0 → 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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b65eaf5352ddaf7aa98b395f94211e6c8ff7f408d17d869a4fa4e0dd7f33931a
4
- data.tar.gz: 7f09b6880e5301bc2e41c97b9d6dc4eb2d6e8cc33d6ed1621c7cd4b7c04ba530
3
+ metadata.gz: fe8edd0728c5a74a2496aa1fea1093bbcafbe584b37c2e3a65edc1103fa8580d
4
+ data.tar.gz: 11abc23f923ef8b0e50bb91223cedc33c6b230ba1d30c2f4d37feb49df1452e4
5
5
  SHA512:
6
- metadata.gz: 942e6f7efeb10b18996de509b6c9af74f2e33b691e3778df3e0a8c1b6530d7b848362bfb45a0521531cb2a143e68b27f8b1d9867606e6b6132f9f0a92e286d3b
7
- data.tar.gz: b6356cf4266f6bd9162f13de266e3f8390614004b4a7cb13f2a50f3c9e2be70338b7d6dc8bdeb3fb5d8605f5acbf9b87e4f42fd293c4ad280999650ad3023c0f
6
+ metadata.gz: 779695f4dd5a791a76ba01c59debefcc697826bbd3bbe2663369163a0d451d703dfc30f28c44017e34f9574c7c6365690ed1a4839fe116e51e1a42037bfb7144
7
+ data.tar.gz: 87aed3d5935014296eae0b5280ef942011e31a546e92391d604eb581fcd0ea8f0882f03b08a50633c18ed876acbe895fc8dbd653adcd3345ac70a683b30afceb
@@ -503,6 +503,14 @@ ChefSharing/IncludeResourceDescriptions:
503
503
  Include:
504
504
  - '**/resources/*.rb'
505
505
 
506
+ ChefSharing/IncludeResourceExamples:
507
+ Description: Resources should include examples field to allow automated documention. Requires Chef Infra Client 13.9 or later.
508
+ StyleGuide: '#chefsharingincluderesourceexamples'
509
+ Enabled: false
510
+ VersionAdded: '6.10.0'
511
+ Include:
512
+ - '**/resources/*.rb'
513
+
506
514
  ###############################
507
515
  # ChefDeprecations: Resolving Deprecations that block upgrading Chef Infra Client
508
516
  ###############################
@@ -1727,6 +1735,24 @@ ChefRedundantCode/UseCreateIfMissing:
1727
1735
  - '**/attributes/*.rb'
1728
1736
  - '**/Berksfile'
1729
1737
 
1738
+ ChefRedundantCode/OhaiAttributeToString:
1739
+ Description: Many Ohai node attributes are already strings and don't need to be cast to strings again
1740
+ StyleGuide: '#ohaiattributetostring'
1741
+ Enabled: true
1742
+ VersionAdded: '6.10.0'
1743
+ Exclude:
1744
+ - '**/metadata.rb'
1745
+ - '**/Berksfile'
1746
+
1747
+ ChefRedundantCode/MultiplePlatformChecks:
1748
+ Description: You can pass multiple values to the platform? and platform_family? helpers instead of calling the helpers multiple times.
1749
+ StyleGuide: '#multipleplatformchecks'
1750
+ Enabled: true
1751
+ VersionAdded: '6.10.0'
1752
+ Exclude:
1753
+ - '**/metadata.rb'
1754
+ - '**/Berksfile'
1755
+
1730
1756
  ###############################
1731
1757
  # ChefEffortless: Migrating to new patterns
1732
1758
  ###############################
@@ -12,6 +12,7 @@ require 'rubocop/monkey_patches/comment_config.rb'
12
12
  require 'rubocop/monkey_patches/config.rb'
13
13
  require 'rubocop/monkey_patches/cop.rb'
14
14
  require 'rubocop/monkey_patches/team.rb'
15
+ require 'rubocop/monkey_patches/registry_cop.rb'
15
16
 
16
17
  module RuboCop
17
18
  class ConfigLoader
@@ -1,4 +1,4 @@
1
1
  module Cookstyle
2
- VERSION = "6.9.0".freeze # rubocop: disable Style/StringLiterals
2
+ VERSION = "6.10.2".freeze # rubocop: disable Style/StringLiterals
3
3
  RUBOCOP_VERSION = '0.86.0'.freeze
4
4
  end
@@ -0,0 +1,60 @@
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
+ # You can pass multiple values to the platform? and platform_family? helpers instead of calling the helpers multiple times.
23
+ #
24
+ # @example
25
+ #
26
+ # # bad
27
+ # platform?('redhat') || platform?('ubuntu')
28
+ # platform_family?('debian') || platform_family?('rhel')
29
+ #
30
+ # # good
31
+ # platform?('redhat', 'ubuntu')
32
+ # platform_family?('debian', 'rhel')
33
+ #
34
+ class MultiplePlatformChecks < Cop
35
+ MSG = 'You can pass multiple values to the platform? and platform_family? helpers instead of calling the helpers multiple times.'.freeze
36
+
37
+ def_node_matcher :or_platform_helpers?, <<-PATTERN
38
+ (or (send nil? ${:platform? :platform_family?} $_ )* )
39
+ PATTERN
40
+
41
+ def on_or(node)
42
+ or_platform_helpers?(node) do |helpers, _plats|
43
+ # if the helper types were the same it's an offense, but platform_family?('rhel') || platform?('ubuntu') is legit
44
+ add_offense(node, location: :expression, message: MSG, severity: :refactor) if helpers.uniq.size == 1
45
+ end
46
+ end
47
+
48
+ def autocorrect(node)
49
+ or_platform_helpers?(node) do |type, plats|
50
+ lambda do |corrector|
51
+ new_string = "#{type.first}(#{plats.map(&:source).join(', ')})"
52
+ corrector.replace(node.loc.expression, new_string)
53
+ end
54
+ end
55
+ end
56
+ end
57
+ end
58
+ end
59
+ end
60
+ end
@@ -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
@@ -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
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.9.0
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-06-25 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
@@ -209,7 +209,9 @@ files:
209
209
  - lib/rubocop/cop/chef/redundant/custom_resource_with_allowed_actions.rb
210
210
  - lib/rubocop/cop/chef/redundant/grouping_metadata.rb
211
211
  - lib/rubocop/cop/chef/redundant/long_description_metadata.rb
212
+ - lib/rubocop/cop/chef/redundant/multiple_platform_checks.rb
212
213
  - lib/rubocop/cop/chef/redundant/name_property_and_required.rb
214
+ - lib/rubocop/cop/chef/redundant/ohai_attribute_to_string.rb
213
215
  - lib/rubocop/cop/chef/redundant/property_splat_regex.rb
214
216
  - lib/rubocop/cop/chef/redundant/property_with_default_and_required.rb
215
217
  - lib/rubocop/cop/chef/redundant/provides_metadata.rb
@@ -226,6 +228,7 @@ files:
226
228
  - lib/rubocop/cop/chef/sharing/empty_metadata_field.rb
227
229
  - lib/rubocop/cop/chef/sharing/include_property_descriptions.rb
228
230
  - lib/rubocop/cop/chef/sharing/include_resource_descriptions.rb
231
+ - lib/rubocop/cop/chef/sharing/include_resource_examples.rb
229
232
  - lib/rubocop/cop/chef/sharing/insecure_cookbook_url.rb
230
233
  - lib/rubocop/cop/chef/sharing/invalid_license_string.rb
231
234
  - lib/rubocop/cop/chef/style/attribute_keys.rb
@@ -247,6 +250,7 @@ files:
247
250
  - lib/rubocop/monkey_patches/comment_config.rb
248
251
  - lib/rubocop/monkey_patches/config.rb
249
252
  - lib/rubocop/monkey_patches/cop.rb
253
+ - lib/rubocop/monkey_patches/registry_cop.rb
250
254
  - lib/rubocop/monkey_patches/team.rb
251
255
  homepage:
252
256
  licenses: