cookstyle 7.20.0 → 7.24.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: 1beeee72a35f1c32830c7c968ba50d7a277bed019de89697fb54e232d53cfa3d
4
- data.tar.gz: 98a912f077a8d14033a03ace34622f1b651dec2b1aea69e3c7c8121f9c487423
3
+ metadata.gz: f15883e8b06ca175e673c9bc97a1d33f2e79da76a8f9a3a60ee0262868890ac3
4
+ data.tar.gz: 518d0db21d8525486fc3406898afecd84bb6d27b52ea49c155a4b8000af39cdb
5
5
  SHA512:
6
- metadata.gz: b7a79148cf57524f1df2f880fcaea77f82cff8d87f1b2e347c1f0ed39a6629bfd91436caa4c7a6b55d99da6d2429e8bea99d9feeb78bc29585458bddf739f4a1
7
- data.tar.gz: 6793431fc22cb1de03923569fcf0d2fb57fe3e0b646df99579752fa999d1898956b799dd2734b1e0459bc156fb48081ba685ad0fbedd45204b3b45a9438a5101
6
+ metadata.gz: 53bde638d1b3829cfece0f84c9d9d25cc69c6d775181155ef154fcc40b310daefb1a01ed424db39e16fcff7fb61fe01469ee3b6cf8d1e320b2dd58f212b70145
7
+ data.tar.gz: d24b861cf7b56441c16e2be78fc97650ab093b70fc7734c8b3ee8fa889f2e60406026e23af3b19da3984c4050bf2c1e763d50d5f09a59c55af61bee4cc88e577
data/Gemfile CHANGED
@@ -7,7 +7,7 @@ gemspec
7
7
  group :debug do
8
8
  gem 'pry'
9
9
  gem 'pry-byebug'
10
- gem 'pry-stack_explorer', '< 0.4.13' # 0.4.13+ drops support for Ruby < 2.6
10
+ gem 'pry-stack_explorer', '<= 0.4.13' # 0.4.13+ drops support for Ruby < 2.6
11
11
  end
12
12
 
13
13
  group :docs do
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'
@@ -979,7 +979,7 @@ Chef/Deprecations/DeprecatedPlatformMethods:
979
979
  - '**/providers/*.rb'
980
980
 
981
981
  Chef/Deprecations/DeprecatedChefSpecPlatform:
982
- Description: Use currently supported platforms in ChefSpec listed at https://github.com/chefspec/fauxhai/blob/master/PLATFORMS.md. Fauxhai / ChefSpec will perform fuzzy matching on platform version so it's always best to be less specific ie. 10 instead of 10.3
982
+ Description: Use currently supported platforms in ChefSpec listed at https://github.com/chefspec/fauxhai/blob/main/PLATFORMS.md. Fauxhai / ChefSpec will perform fuzzy matching on platform version so it's always best to be less specific ie. 10 instead of 10.3
983
983
  StyleGuide: 'chef_deprecations_deprecatedchefspecplatform'
984
984
  Enabled: true
985
985
  VersionAdded: '5.20.0'
@@ -1198,7 +1198,7 @@ Chef/Deprecations/DeprecatedYumRepositoryActions:
1198
1198
  - '**/Rakefile'
1199
1199
 
1200
1200
  Chef/Deprecations/ChefSugarHelpers:
1201
- Description: Do not use legacy chef-sugar helper methods, which will not be moved into Chef Infra Client itself. For a complete set of chef-sugar helpers now shipping in Chef Infra Client itself see https://github.com/chef/chef/tree/master/chef-utils#getting-started
1201
+ Description: Do not use legacy chef-sugar helper methods, which will not be moved into Chef Infra Client itself. For a complete set of chef-sugar helpers now shipping in Chef Infra Client itself see https://github.com/chef/chef/tree/main/chef-utils#getting-started
1202
1202
  StyleGuide: 'chef_deprecations_chefsugarhelpers'
1203
1203
  Enabled: true
1204
1204
  VersionAdded: '7.3.0'
@@ -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,50 @@ 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 attributes 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
+
1909
+ Chef/Modernize/UseChefLanguageCloudHelpers:
1910
+ Description: Chef Infra Client 15.5 and later include cloud helpers to make detecting instances that run on public and private clouds easier.
1911
+ StyleGuide: 'chef_modernize_usecheflanguagecloudhelpers'
1912
+ Enabled: true
1913
+ VersionAdded: '7.22.0'
1914
+ Include:
1915
+ - '**/resources/*.rb'
1916
+ - '**/providers/*.rb'
1917
+ - '**/recipes/*.rb'
1918
+
1919
+ Chef/Modernize/ClassEvalActionClass:
1920
+ Description: In Chef Infra Client 12.9 and later it is no longer necessary to call the class_eval method on the action class block.
1921
+ StyleGuide: 'chef_modernize_classevalactionclass'
1922
+ Enabled: true
1923
+ VersionAdded: '7.23.0'
1924
+ Include:
1925
+ - '**/resources/*.rb'
1926
+
1927
+ Chef/Modernize/UseChefLanguageSystemdHelper:
1928
+ Description: Chef Infra Client 15.5 and later include a `systemd?` helper for checking if a Linux system uses systemd.
1929
+ StyleGuide: 'chef_modernize_usecheflanguagesystemdhelper'
1930
+ Enabled: true
1931
+ VersionAdded: '7.24.0'
1932
+ Exclude:
1933
+ - '**/metadata.rb'
1934
+ - '**/Berksfile'
1935
+
1899
1936
  ###############################
1900
1937
  # Chef/RedundantCode: Cleanup unnecessary code in your cookbooks regardless of Chef Infra Client release
1901
1938
  ###############################
@@ -5,6 +5,8 @@ Bundler/DuplicatedGem:
5
5
  Enabled: false
6
6
  Bundler/GemComment:
7
7
  Enabled: false
8
+ Bundler/GemFilename:
9
+ Enabled: false
8
10
  Bundler/GemVersion:
9
11
  Enabled: false
10
12
  Bundler/InsecureProtocolSource:
data/config/upstream.yml CHANGED
@@ -174,6 +174,20 @@ Bundler/GemComment:
174
174
  IgnoredGems: []
175
175
  OnlyFor: []
176
176
 
177
+ Bundler/GemFilename:
178
+ Description: 'Enforces the filename for managing gems.'
179
+ Enabled: true
180
+ VersionAdded: '1.20'
181
+ EnforcedStyle: 'Gemfile'
182
+ SupportedStyles:
183
+ - 'Gemfile'
184
+ - 'gems.rb'
185
+ Include:
186
+ - '**/Gemfile'
187
+ - '**/gems.rb'
188
+ - '**/Gemfile.lock'
189
+ - '**/gems.locked'
190
+
177
191
  Bundler/GemVersion:
178
192
  Description: 'Requires or forbids specifying gem versions.'
179
193
  Enabled: false
@@ -1519,6 +1533,11 @@ Lint/Debugger:
1519
1533
  Capybara:
1520
1534
  - save_and_open_page
1521
1535
  - save_and_open_screenshot
1536
+ debug.rb:
1537
+ - binding.b
1538
+ - binding.break
1539
+ - Kernel.binding.b
1540
+ - Kernel.binding.break
1522
1541
  Pry:
1523
1542
  - binding.pry
1524
1543
  - binding.remote_pry
@@ -1527,6 +1546,8 @@ Lint/Debugger:
1527
1546
  Rails:
1528
1547
  - debugger
1529
1548
  - Kernel.debugger
1549
+ RubyJard:
1550
+ - jard
1530
1551
  WebConsole:
1531
1552
  - binding.console
1532
1553
 
@@ -3149,7 +3170,7 @@ Style/CommentAnnotation:
3149
3170
  StyleGuide: '#annotate-keywords'
3150
3171
  Enabled: true
3151
3172
  VersionAdded: '0.10'
3152
- VersionChanged: '1.3'
3173
+ VersionChanged: '1.20'
3153
3174
  Keywords:
3154
3175
  - TODO
3155
3176
  - FIXME
@@ -4692,8 +4713,9 @@ Style/StructInheritance:
4692
4713
  Description: 'Checks for inheritance from Struct.new.'
4693
4714
  StyleGuide: '#no-extend-struct-new'
4694
4715
  Enabled: true
4716
+ SafeAutoCorrect: false
4695
4717
  VersionAdded: '0.29'
4696
- VersionChanged: '0.86'
4718
+ VersionChanged: '1.20'
4697
4719
 
4698
4720
  Style/SwapValues:
4699
4721
  Description: 'This cop enforces the use of shorthand-style swapping of 2 variables.'
data/cookstyle.gemspec CHANGED
@@ -22,7 +22,7 @@ Gem::Specification.new do |spec|
22
22
 
23
23
  spec.metadata = {
24
24
  'homepage_uri' => 'https://github.com/chef/cookstyle',
25
- 'changelog_uri' => 'https://github.com/chef/cookstyle/blob/master/CHANGELOG.md',
25
+ 'changelog_uri' => 'https://github.com/chef/cookstyle/blob/main/CHANGELOG.md',
26
26
  'source_code_uri' => 'https://github.com/chef/cookstyle',
27
27
  'documentation_uri' => 'https://docs.chef.io/workstation/cookstyle/',
28
28
  'bug_tracker_uri' => 'https://github.com/chef/cookstyle/issues',
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
  module Cookstyle
3
- VERSION = "7.20.0" # rubocop: disable Style/StringLiterals
4
- RUBOCOP_VERSION = '1.19.0'
3
+ VERSION = "7.24.1" # rubocop: disable Style/StringLiterals
4
+ RUBOCOP_VERSION = '1.20.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
- # Do not use legacy chef-sugar helper methods, which will not be moved into Chef Infra Client itself. For a complete set of chef-sugar helpers now shipping in Chef Infra Client itself see https://github.com/chef/chef/tree/master/chef-utils#getting-started
22
+ # Do not use legacy chef-sugar helper methods, which will not be moved into Chef Infra Client itself. For a complete set of chef-sugar helpers now shipping in Chef Infra Client itself see https://github.com/chef/chef/tree/main/chef-utils#getting-started
23
23
  #
24
24
  # @example
25
25
  #
@@ -42,7 +42,7 @@ module RuboCop
42
42
  # opensolaris?
43
43
  #
44
44
  class ChefSugarHelpers < Base
45
- MSG = 'Do not use legacy chef-sugar helper methods, which will not be moved into Chef Infra Client itself. For a complete set of chef-sugar helpers now shipping in Chef Infra Client itself see https://github.com/chef/chef/tree/master/chef-utils#getting-started'
45
+ MSG = 'Do not use legacy chef-sugar helper methods, which will not be moved into Chef Infra Client itself. For a complete set of chef-sugar helpers now shipping in Chef Infra Client itself see https://github.com/chef/chef/tree/main/chef-utils#getting-started'
46
46
  RESTRICT_ON_SEND = [:vagrant_key?, :vagrant_domain?, :vagrant_user?, :require_chef_gem, :best_ip_for, :nexus?, :ios_xr?, :ruby_20?, :ruby_19?, :includes_recipe?, :wrlinux?, :dev_null, :nexentacore_platform?, :opensolaris_platform?, :nexentacore?, :opensolaris?].freeze
47
47
 
48
48
  def on_send(node)
@@ -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 Deprecations
22
- # Use currently supported platforms in ChefSpec listed at https://github.com/chefspec/fauxhai/blob/master/PLATFORMS.md. Fauxhai / ChefSpec will perform fuzzy matching on platform version values so it's always best to be less specific ie. 10 instead of 10.3
22
+ # Use currently supported platforms in ChefSpec listed at https://github.com/chefspec/fauxhai/blob/main/PLATFORMS.md. Fauxhai / ChefSpec will perform fuzzy matching on platform version values so it's always best to be less specific ie. 10 instead of 10.3
23
23
  #
24
24
  # @example
25
25
  #
@@ -29,7 +29,7 @@ module RuboCop
29
29
  include RuboCop::Chef::CookbookHelpers
30
30
  extend AutoCorrector
31
31
 
32
- MSG = "Use currently supported platforms in ChefSpec listed at https://github.com/chefspec/fauxhai/blob/master/PLATFORMS.md. Fauxhai / ChefSpec will perform fuzzy matching on platform version so it's always best to be less specific ie. 10 instead of 10.3"
32
+ MSG = "Use currently supported platforms in ChefSpec listed at https://github.com/chefspec/fauxhai/blob/main/PLATFORMS.md. Fauxhai / ChefSpec will perform fuzzy matching on platform version so it's always best to be less specific ie. 10 instead of 10.3"
33
33
 
34
34
  DEPRECATED_MAPPING = {
35
35
  'amazon' => {
@@ -19,7 +19,7 @@ module RuboCop
19
19
  module Cop
20
20
  module Chef
21
21
  module Deprecations
22
- # Chef Infra Client 15.3 and later include a new Unified Mode that simplies the execution of resoures by replace the traditional compile and converge phases with a single phase. Unified mode simplies writing advanced resources and avoids confusing errors that often occur when mixing ruby and Chef Infra resources. Chef Infra Client 17.0 and later will beging warning that `unified_mode true` should be set in all resources to validate that they will continue to function in Chef Infra Client 18.0 (April 2022) when Unified Mode becomes the default.
22
+ # Chef Infra Client 15.3 and later include a new Unified Mode that simplifies the execution of resources by replace the traditional compile and converge phases with a single phase. Unified mode simplifies writing advanced resources and avoids confusing errors that often occur when mixing ruby and Chef Infra resources. Chef Infra Client 17.0 and later will begin warning that `unified_mode true` should be set in all resources to validate that they will continue to function in Chef Infra Client 18.0 (April 2022) when Unified Mode becomes the default.
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
- # Chef Infra Client 15.3 and later include a new Unified Mode that simplies the execution of resoures by replace the traditional compile and converge phases with a single phase. Unified mode simplies writing advanced resources and avoids confusing errors that often occur when mixing ruby and Chef Infra resources. Chef Infra Client 17.0 and later will beging warning that `unified_mode true` should be set in all resources to validate that they will continue to function in Chef Infra Client 18.0 (April 2022) when Unified Mode becomes the default.
22
+ # Chef Infra Client 15.3 and later include a new Unified Mode that simplifies the execution of resources by replace the traditional compile and converge phases with a single phase. Unified mode simplifies writing advanced resources and avoids confusing errors that often occur when mixing ruby and Chef Infra resources. Chef Infra Client 17.0 and later will begin warning that `unified_mode true` should be set in all resources to validate that they will continue to function in Chef Infra Client 18.0 (April 2022) when Unified Mode becomes the default.
23
23
  #
24
24
  # @example
25
25
  #
@@ -0,0 +1,64 @@
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
+ # In Chef Infra Client 12.9 and later it is no longer necessary to call the class_eval method on the action class block.
23
+ #
24
+ # @example
25
+ #
26
+ # #### incorrect
27
+ # action_class.class_eval do
28
+ # foo
29
+ # end
30
+ #
31
+ # #### correct
32
+ # action_class do
33
+ # foo
34
+ # end
35
+ #
36
+ class ClassEvalActionClass < Base
37
+ extend TargetChefVersion
38
+ extend AutoCorrector
39
+
40
+ minimum_target_chef_version '12.9'
41
+
42
+ MSG = 'In Chef Infra Client 12.9 and later it is no longer necessary to call the class_eval method on the action class block.'
43
+ RESTRICT_ON_SEND = [:include_recipe].freeze
44
+
45
+ def_node_matcher :class_eval_action_class?, <<-PATTERN
46
+ (block
47
+ (send
48
+ (send nil? :action_class) :class_eval)
49
+ (args)
50
+ ... )
51
+ PATTERN
52
+
53
+ def on_block(node)
54
+ class_eval_action_class?(node) do
55
+ add_offense(node, message: MSG, severity: :refactor) do |corrector|
56
+ corrector.replace(node, node.source.gsub('.class_eval', ''))
57
+ end
58
+ end
59
+ end
60
+ end
61
+ end
62
+ end
63
+ end
64
+ end
@@ -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,93 @@
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 instances that run on public and private clouds easier.
23
+ #
24
+ # @example
25
+ #
26
+ # #### incorrect
27
+ # node['cloud']['provider'] == 'alibaba'
28
+ # node['cloud']['provider'] == 'ec2'
29
+ # node['cloud']['provider'] == 'gce'
30
+ # node['cloud']['provider'] == 'rackspace'
31
+ # node['cloud']['provider'] == 'eucalyptus'
32
+ # node['cloud']['provider'] == 'linode'
33
+ # node['cloud']['provider'] == 'openstack'
34
+ # node['cloud']['provider'] == 'azure'
35
+ # node['cloud']['provider'] == 'digital_ocean'
36
+ # node['cloud']['provider'] == 'softlayer'
37
+ #
38
+ # #### correct
39
+ # alibaba?
40
+ # ec2?
41
+ # gce?
42
+ # rackspace?
43
+ # eucalyptus?
44
+ # linode?
45
+ # openstack?
46
+ # azure?
47
+ # digital_ocean?
48
+ # softlayer?
49
+ #
50
+ class UseChefLanguageCloudHelpers < Base
51
+ extend AutoCorrector
52
+ extend TargetChefVersion
53
+
54
+ minimum_target_chef_version '15.5'
55
+
56
+ MSG = 'Chef Infra Client 15.5 and later include cloud helpers to make detecting instances that run on public and private clouds easier.'
57
+ RESTRICT_ON_SEND = [:==, :[]].freeze
58
+ VALID_CLOUDS = %w(alibaba ec2 gce rackspace eucalyptus linode openstack azure digital_ocean softlayer).freeze
59
+
60
+ def_node_matcher :provider_comparison?, <<-PATTERN
61
+ (send
62
+ (send
63
+ (send
64
+ (send nil? :node) :[]
65
+ (str "cloud")) :[]
66
+ (str "provider")) :==
67
+ (str $_))
68
+ PATTERN
69
+
70
+ def_node_matcher :node_cloud?, <<-PATTERN
71
+ (send
72
+ (send nil? :node) :[]
73
+ (str "cloud"))
74
+ PATTERN
75
+
76
+ def on_send(node)
77
+ provider_comparison?(node) do |cloud_name|
78
+ # skip it if someone was checking for a bogus cloud provider
79
+ next unless VALID_CLOUDS.include?(cloud_name)
80
+
81
+ # if they were checking for node['cloud'] and the provider replace it all
82
+ node = node.parent if node.parent.and_type? && node_cloud?(node.left_sibling)
83
+
84
+ add_offense(node, message: MSG, severity: :refactor) do |corrector|
85
+ corrector.replace(node, "#{cloud_name}?")
86
+ end
87
+ end
88
+ end
89
+ end
90
+ end
91
+ end
92
+ end
93
+ end
@@ -0,0 +1,69 @@
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 attributes 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
+ extend TargetChefVersion
37
+
38
+ minimum_target_chef_version '15.5'
39
+
40
+ RESTRICT_ON_SEND = [:[]].freeze
41
+
42
+ def_node_matcher :env?, <<-PATTERN
43
+ (send
44
+ (const nil? :ENV) :[]
45
+ (str ${"TEST_KITCHEN" "CI"}))
46
+ PATTERN
47
+
48
+ def on_send(node)
49
+ env?(node) do |env_value|
50
+ # we don't handle .nil? checks yet so just skip them
51
+ next if node.parent.send_type? && node.parent.method_name == :nil?
52
+
53
+ case env_value
54
+ when 'CI'
55
+ 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|
56
+ corrector.replace(node, 'ci?')
57
+ end
58
+ when 'TEST_KITCHEN'
59
+ 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|
60
+ corrector.replace(node, 'kitchen?')
61
+ end
62
+ end
63
+ end
64
+ end
65
+ end
66
+ end
67
+ end
68
+ end
69
+ end
@@ -0,0 +1,60 @@
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 `systemd?` helper for checking if a Linux system uses systemd.
23
+ #
24
+ # @example
25
+ #
26
+ # #### incorrect
27
+ # node['init_package'] == 'systemd'
28
+ #
29
+ # #### correct
30
+ # systemd?
31
+ #
32
+ class UseChefLanguageSystemdHelper < Base
33
+ extend AutoCorrector
34
+ extend TargetChefVersion
35
+
36
+ minimum_target_chef_version '15.5'
37
+
38
+ MSG = 'Chef Infra Client 15.5 and later include a `systemd?` helper for checking if a Linux system uses systemd.'
39
+ RESTRICT_ON_SEND = [:==].freeze
40
+
41
+ def_node_matcher :node_init_package?, <<-PATTERN
42
+ (send
43
+ (send
44
+ (send nil? :node) :[]
45
+ (str "init_package")) :==
46
+ (str "systemd"))
47
+ PATTERN
48
+
49
+ def on_send(node)
50
+ node_init_package?(node) do |_cloud_name|
51
+ add_offense(node, message: MSG, severity: :refactor) do |corrector|
52
+ corrector.replace(node, 'systemd?')
53
+ end
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 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,7 +1,7 @@
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.24.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: 2021-08-19 00:00:00.000000000 Z
12
+ date: 2021-09-02 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: 1.19.0
20
+ version: 1.20.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: 1.19.0
27
+ version: 1.20.0
28
28
  description:
29
29
  email:
30
30
  - thom@chef.io
@@ -181,6 +181,7 @@ files:
181
181
  - lib/rubocop/cop/chef/modernize/chef_14_resources.rb
182
182
  - lib/rubocop/cop/chef/modernize/chef_15_resources.rb
183
183
  - lib/rubocop/cop/chef/modernize/chef_gem_nokogiri.rb
184
+ - lib/rubocop/cop/chef/modernize/class_eval_action_class.rb
184
185
  - lib/rubocop/cop/chef/modernize/compile_time_resources.rb
185
186
  - lib/rubocop/cop/chef/modernize/conditional_using_test.rb
186
187
  - lib/rubocop/cop/chef/modernize/cron_d_file_or_template.rb
@@ -236,6 +237,9 @@ files:
236
237
  - lib/rubocop/cop/chef/modernize/simplify_apt_ppa_setup.rb
237
238
  - lib/rubocop/cop/chef/modernize/sysctl_param_resource.rb
238
239
  - lib/rubocop/cop/chef/modernize/unnecessary_mixlib_shellout_require.rb
240
+ - lib/rubocop/cop/chef/modernize/use_chef_language_cloud_helpers.rb
241
+ - lib/rubocop/cop/chef/modernize/use_chef_language_env_helpers.rb
242
+ - lib/rubocop/cop/chef/modernize/use_chef_language_systemd_helper.rb
239
243
  - lib/rubocop/cop/chef/modernize/use_multipackage_installs.rb
240
244
  - lib/rubocop/cop/chef/modernize/use_require_relative.rb
241
245
  - lib/rubocop/cop/chef/modernize/whyrun_supported_true.rb
@@ -303,7 +307,7 @@ licenses:
303
307
  - Apache-2.0
304
308
  metadata:
305
309
  homepage_uri: https://github.com/chef/cookstyle
306
- changelog_uri: https://github.com/chef/cookstyle/blob/master/CHANGELOG.md
310
+ changelog_uri: https://github.com/chef/cookstyle/blob/main/CHANGELOG.md
307
311
  source_code_uri: https://github.com/chef/cookstyle
308
312
  documentation_uri: https://docs.chef.io/workstation/cookstyle/
309
313
  bug_tracker_uri: https://github.com/chef/cookstyle/issues