cookstyle 7.20.0 → 7.21.0

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: 1beeee72a35f1c32830c7c968ba50d7a277bed019de89697fb54e232d53cfa3d
4
- data.tar.gz: 98a912f077a8d14033a03ace34622f1b651dec2b1aea69e3c7c8121f9c487423
3
+ metadata.gz: 48e9eba9990f29d5ece83efea73a5ceba5c49ed781909b437c40c43da790210a
4
+ data.tar.gz: 9f177a0a2cadc3cb703ec87337bd4485e872ae748d9af95f53473dec22eebd7d
5
5
  SHA512:
6
- metadata.gz: b7a79148cf57524f1df2f880fcaea77f82cff8d87f1b2e347c1f0ed39a6629bfd91436caa4c7a6b55d99da6d2429e8bea99d9feeb78bc29585458bddf739f4a1
7
- data.tar.gz: 6793431fc22cb1de03923569fcf0d2fb57fe3e0b646df99579752fa999d1898956b799dd2734b1e0459bc156fb48081ba685ad0fbedd45204b3b45a9438a5101
6
+ metadata.gz: fbeebdde748ba5abca797bf203ab8465c74e1b1714847d27e35576b3801daae3e962b9bfb3516c84f684e69a3088535d8811ea7df74005f6262005bb844295a7
7
+ data.tar.gz: 4e3c683249684fdae3717f88b9ea92c9eb26147d55eb90e43e024f7c0ce03870d03c66b4f2c7ad6eb9c057cf1eb687ce28ed44efea7b2a61e5a9002b3b143628
data/config/cookstyle.yml CHANGED
@@ -482,7 +482,7 @@ Chef/Correctness/OctalModeAsString:
482
482
  - '**/Berksfile'
483
483
 
484
484
  Chef/Correctness/MetadataMalformedDepends:
485
- Description: Don't represent file modes as strings containing octal values. Use standard base 10 file modes instead.
485
+ Description: metadata.rb cookbook dependencies and version constraints should be comma separated.
486
486
  StyleGuide: 'chef_correctness_metadatamalformeddepends'
487
487
  Enabled: true
488
488
  VersionAdded: '7.16'
@@ -1263,7 +1263,7 @@ Chef/Deprecations/DependsOnChefReportingCookbook:
1263
1263
  - '**/metadata.rb'
1264
1264
 
1265
1265
  Chef/Deprecations/DependsOnOmnibusUpdaterCookbook:
1266
- Description: Don't depend on the EOL `omnibus_updater` cookbook. This cookbook no longer works with newer Chef Infra Client releases and has been replaced by with the more reliable `chef_client_updater` cookbook.
1266
+ Description: Don't depend on the EOL `omnibus_updater` cookbook. This cookbook no longer works with newer Chef Infra Client releases and has been replaced with the more reliable `chef_client_updater` cookbook.
1267
1267
  StyleGuide: 'chef_deprecations_dependsonomnibusupdatercookbook'
1268
1268
  Enabled: true
1269
1269
  VersionAdded: '7.20.0'
@@ -1889,13 +1889,23 @@ Chef/Modernize/DependsOnChocolateyCookbooks:
1889
1889
  - '**/metadata.rb'
1890
1890
 
1891
1891
  Chef/Modernize/DependsOnOpensslCookbook:
1892
- Description: Don't depend on the openssl cookbook which was made obsolete by Chef Infra Client 14.4. All openssl resource are now included directly in Chef Infra Client.
1892
+ Description: Don't depend on the `openssl` cookbook which was made obsolete by Chef Infra Client 14.4. All `openssl_*` resources are now included directly in Chef Infra Client.
1893
1893
  StyleGuide: 'chef_modernize_dependsonopensslcookbook'
1894
1894
  Enabled: true
1895
1895
  VersionAdded: '7.20.0'
1896
1896
  Include:
1897
1897
  - '**/metadata.rb'
1898
1898
 
1899
+ Chef/Modernize/UseChefLanguageEnvHelpers:
1900
+ Description: Chef Infra Client 15.5 and later include a large number of new helpers in the Chef Infra Language to simplify checking the system configuration in recipes and resources. These should be used when possible over more complex attribute or ENV var comparisons.
1901
+ StyleGuide: 'chef_modernize_usecheflanguageenvhelpers'
1902
+ Enabled: true
1903
+ VersionAdded: '7.21.0'
1904
+ Include:
1905
+ - '**/resources/*.rb'
1906
+ - '**/providers/*.rb'
1907
+ - '**/recipes/*.rb'
1908
+
1899
1909
  ###############################
1900
1910
  # Chef/RedundantCode: Cleanup unnecessary code in your cookbooks regardless of Chef Infra Client release
1901
1911
  ###############################
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
  module Cookstyle
3
- VERSION = "7.20.0" # rubocop: disable Style/StringLiterals
3
+ VERSION = "7.21.0" # rubocop: disable Style/StringLiterals
4
4
  RUBOCOP_VERSION = '1.19.0'
5
5
  end
@@ -19,7 +19,7 @@ module RuboCop
19
19
  module Cop
20
20
  module Chef
21
21
  module Correctness
22
- # metadata.rb cookbook dependencies and version constraints should be comma separated
22
+ # metadata.rb cookbook dependencies and version constraints should be comma separated.
23
23
  #
24
24
  # @example
25
25
  #
@@ -19,7 +19,7 @@ module RuboCop
19
19
  module Cop
20
20
  module Chef
21
21
  module Deprecations
22
- # Don't depend on the EOL `omnibus_updater` cookbook. This cookbook no longer works with newer Chef Infra Client releases and has been replaced by with the more reliable `chef_client_updater` cookbook.
22
+ # Don't depend on the EOL `omnibus_updater` cookbook. This cookbook no longer works with newer Chef Infra Client releases and has been replaced with the more reliable `chef_client_updater` cookbook.
23
23
  #
24
24
  # @example
25
25
  #
@@ -33,7 +33,7 @@ module RuboCop
33
33
  extend AutoCorrector
34
34
  include RangeHelp
35
35
 
36
- MSG = "Don't depend on the EOL `omnibus_updater` cookbook. This cookbook no longer works with newer Chef Infra Client releases and has been replaced by with the more reliable `chef_client_updater` cookbook."
36
+ MSG = "Don't depend on the EOL `omnibus_updater` cookbook. This cookbook no longer works with newer Chef Infra Client releases and has been replaced with the more reliable `chef_client_updater` cookbook."
37
37
  RESTRICT_ON_SEND = [:depends].freeze
38
38
 
39
39
  def_node_matcher :legacy_depends?, <<-PATTERN
@@ -19,7 +19,7 @@ module RuboCop
19
19
  module Cop
20
20
  module Chef
21
21
  module Modernize
22
- # Don't depend on the openssl cookbook which was made obsolete by Chef Infra Client 14.4. All openssl resource are now included directly in Chef Infra Client.
22
+ # Don't depend on the `openssl` cookbook which was made obsolete by Chef Infra Client 14.4. All `openssl_*` resources are now included directly in Chef Infra Client.
23
23
  #
24
24
  # @example
25
25
  #
@@ -33,7 +33,7 @@ module RuboCop
33
33
 
34
34
  minimum_target_chef_version '14.4'
35
35
 
36
- MSG = "Don't depend on the openssl cookbook which was made obsolete by Chef Infra Client 14.4. All openssl resource are now included directly in Chef Infra Client."
36
+ MSG = "Don't depend on the `openssl` cookbook which was made obsolete by Chef Infra Client 14.4. All `openssl_*` resources are now included directly in Chef Infra Client."
37
37
  RESTRICT_ON_SEND = [:depends].freeze
38
38
 
39
39
  def_node_matcher :legacy_depends?, <<-PATTERN
@@ -0,0 +1,86 @@
1
+ # frozen_string_literal: true
2
+ #
3
+ # Copyright:: 2021, Chef Software, Inc.
4
+ # Author:: Tim Smith (<tsmith@chef.io>)
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+ #
18
+ module RuboCop
19
+ module Cop
20
+ module Chef
21
+ module Modernize
22
+ # Chef Infra Client 15.5 and later include cloud helpers to make detecting instance that run on public and private clouds easier.
23
+ #
24
+ # @example
25
+ #
26
+ # #### incorrect
27
+ # ENV['CI']
28
+ # ENV['TEST_KITCHEN']
29
+ #
30
+ # #### correct
31
+ # ci?
32
+ # kitchen?
33
+ #
34
+ class UseChefLanguageCloudHelpers < Base
35
+ extend AutoCorrector
36
+
37
+ MSG = 'Chef Infra Client 15.5 and later include cloud helpers to make detecting instance that run on public and private clouds easier.'.freeze
38
+ RESTRICT_ON_SEND = [:==, :[]].freeze
39
+ VALID_CLOUDS = %w(alibaba ec2 gce rackspace eucalyptus linode openstack azure digital_ocean softlayer).freeze
40
+
41
+ def_node_matcher :provider_comparison?, <<-PATTERN
42
+ (send
43
+ (send
44
+ (send
45
+ (send nil? :node) :[]
46
+ (str "cloud")) :[]
47
+ (str "provider")) :==
48
+ (str $_))
49
+ PATTERN
50
+
51
+ def_node_matcher :node_check?, <<-PATTERN
52
+ (send
53
+ (send nil? :node) :[]
54
+ (str ${"ec2"}))
55
+ PATTERN
56
+
57
+ def_node_matcher :node_cloud?, <<-PATTERN
58
+ (send
59
+ (send nil? :node) :[]
60
+ (str "cloud"))
61
+ PATTERN
62
+
63
+ def on_send(node)
64
+ node_check?(node) do |cloud_name|
65
+ add_offense(node, message: MSG, severity: :refactor) do |corrector|
66
+ corrector.replace(node, "#{cloud_name}?")
67
+ end
68
+ end
69
+
70
+ provider_comparison?(node) do |cloud_name|
71
+ # skip it if someone was checking for a bogus cloud provider
72
+ next unless VALID_CLOUDS.include?(cloud_name)
73
+
74
+ # if they were checking for node['cloud'] and the provider replace it all
75
+ node = node.parent if node.parent.and_type? && node_cloud?(node.left_sibling)
76
+
77
+ add_offense(node, message: MSG, severity: :refactor) do |corrector|
78
+ corrector.replace(node, "#{cloud_name}?")
79
+ end
80
+ end
81
+ end
82
+ end
83
+ end
84
+ end
85
+ end
86
+ end
@@ -0,0 +1,66 @@
1
+ # frozen_string_literal: true
2
+ #
3
+ # Copyright:: 2021, Chef Software, Inc.
4
+ # Author:: Tim Smith (<tsmith@chef.io>)
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+ #
18
+ module RuboCop
19
+ module Cop
20
+ module Chef
21
+ module Modernize
22
+ # Chef Infra Client 15.5 and later include a large number of new helpers in the Chef Infra Language to simplify checking the system configuration in recipes and resources. These should be used when possible over more complex attribute or ENV var comparisons.
23
+ #
24
+ # @example
25
+ #
26
+ # #### incorrect
27
+ # ENV['CI']
28
+ # ENV['TEST_KITCHEN']
29
+ #
30
+ # #### correct
31
+ # ci?
32
+ # kitchen?
33
+ #
34
+ class UseChefLanguageEnvHelpers < Base
35
+ extend AutoCorrector
36
+
37
+ RESTRICT_ON_SEND = [:[]].freeze
38
+
39
+ def_node_matcher :env?, <<-PATTERN
40
+ (send
41
+ (const nil? :ENV) :[]
42
+ (str ${"TEST_KITCHEN" "CI"}))
43
+ PATTERN
44
+
45
+ def on_send(node)
46
+ env?(node) do |env_value|
47
+ # we don't handle .nil? checks yet so just skip them
48
+ next if node.parent.send_type? && node.parent.method_name == :nil?
49
+
50
+ case env_value
51
+ when 'CI'
52
+ add_offense(node, message: 'Chef Infra Client 15.5 and later include a helper `ci?` that should be used to see if the `CI` env var is set.', severity: :refactor) do |corrector|
53
+ corrector.replace(node, 'ci?')
54
+ end
55
+ when 'TEST_KITCHEN'
56
+ add_offense(node, message: 'Chef Infra Client 15.5 and later include a helper `kitchen?` that should be used to see if the `TEST_KITCHEN` env var is set.', severity: :refactor) do |corrector|
57
+ corrector.replace(node, 'kitchen?')
58
+ end
59
+ end
60
+ end
61
+ end
62
+ end
63
+ end
64
+ end
65
+ end
66
+ end
@@ -19,7 +19,7 @@ module RuboCop
19
19
  module Cop
20
20
  module Chef
21
21
  module Style
22
- # Use :immediately instead of :immediate for resource notification timing
22
+ # Use :immediately instead of :immediate for resource notification timing.
23
23
  #
24
24
  # @example
25
25
  #
@@ -39,10 +39,10 @@ module RuboCop
39
39
  extend AutoCorrector
40
40
 
41
41
  MSG = 'Use :immediately instead of :immediate for resource notification timing'
42
- RESTRICT_ON_SEND = [:notifies].freeze
42
+ RESTRICT_ON_SEND = [:notifies, :subscribes].freeze
43
43
 
44
44
  def_node_matcher :immediate_notify?, <<-PATTERN
45
- (send nil? :notifies (sym _) (...) $(sym :immediate))
45
+ (send nil? {:notifies :subscribes} (sym _) (...) $(sym :immediate))
46
46
  PATTERN
47
47
 
48
48
  def on_send(node)
metadata CHANGED
@@ -1,15 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cookstyle
3
3
  version: !ruby/object:Gem::Version
4
- version: 7.20.0
4
+ version: 7.21.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Thom May
8
8
  - Tim Smith
9
- autorequire:
9
+ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2021-08-19 00:00:00.000000000 Z
12
+ date: 2021-08-26 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rubocop
@@ -25,7 +25,7 @@ dependencies:
25
25
  - - '='
26
26
  - !ruby/object:Gem::Version
27
27
  version: 1.19.0
28
- description:
28
+ description:
29
29
  email:
30
30
  - thom@chef.io
31
31
  - tsmith@chef.io
@@ -236,6 +236,8 @@ files:
236
236
  - lib/rubocop/cop/chef/modernize/simplify_apt_ppa_setup.rb
237
237
  - lib/rubocop/cop/chef/modernize/sysctl_param_resource.rb
238
238
  - lib/rubocop/cop/chef/modernize/unnecessary_mixlib_shellout_require.rb
239
+ - lib/rubocop/cop/chef/modernize/use_chef_language_cloud_helpers.rb
240
+ - lib/rubocop/cop/chef/modernize/use_chef_language_env_helpers.rb
239
241
  - lib/rubocop/cop/chef/modernize/use_multipackage_installs.rb
240
242
  - lib/rubocop/cop/chef/modernize/use_require_relative.rb
241
243
  - lib/rubocop/cop/chef/modernize/whyrun_supported_true.rb
@@ -307,7 +309,7 @@ metadata:
307
309
  source_code_uri: https://github.com/chef/cookstyle
308
310
  documentation_uri: https://docs.chef.io/workstation/cookstyle/
309
311
  bug_tracker_uri: https://github.com/chef/cookstyle/issues
310
- post_install_message:
312
+ post_install_message:
311
313
  rdoc_options: []
312
314
  require_paths:
313
315
  - lib
@@ -322,8 +324,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
322
324
  - !ruby/object:Gem::Version
323
325
  version: '0'
324
326
  requirements: []
325
- rubygems_version: 3.1.4
326
- signing_key:
327
+ rubygems_version: 3.2.22
328
+ signing_key:
327
329
  specification_version: 4
328
330
  summary: Cookstyle is a code linting tool that helps you to write better Chef Infra
329
331
  cookbooks by detecting and automatically correcting style, syntax, and logic mistakes