cookstyle 6.16.9 → 6.18.8

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: a8e68daec28420e78dc490431b8d537e9f0ed6d1584169ac3a38ec5d5b299d74
4
- data.tar.gz: 748af99f0eca7196d254d8f780185e7bca2dbe7e6be2fa7442b2974f083c2db3
3
+ metadata.gz: 5155a9b35b7783b4f93c60355db6c98114c8f337536cd468738d06481b5e8e7e
4
+ data.tar.gz: 0f7d7fae656539861f7bcdd6b4bda8463896eacd3a82c9ba4964b6ad4d35f193
5
5
  SHA512:
6
- metadata.gz: fa5506a626d47605585b6d1d94a2eb4c1e8d2f5cd34ee85823beb240f4b3983f249bfe9abbd692a7905ecb939eea59e5ebfed61410c6bb93c9416b1c2d9df6da
7
- data.tar.gz: 2b49fd42843f06262d32690695f3e02ed86fe80d67fcc03f1c2abaf1fd8d3cba7751eabb9f1b35fd07efbd44f026f5ae1d18c5c00597b2516e59dcb6916920e3
6
+ metadata.gz: de5247580b6f6432ac8d0fff694115b8c8765ec012c3f5686fd56453ea7ebb3b943c60025102d0a8531ecb0c605484786d3fa7c500819fd6d188bc8589e11a56
7
+ data.tar.gz: 54baddbe1f9419c2387ed4c94d678fdc7d599e903876ed84ccaa9aa99aa7add6443167b003f05a38f7f1b79d574e14507006650152a0bce0ed65d4ba368adf47
@@ -1,8 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
- # -*- encoding: utf-8 -*-
3
2
  # frozen_string_literal: true
4
3
 
5
- $LOAD_PATH.unshift File.join(File.dirname(__FILE__), %w(.. lib))
4
+ $LOAD_PATH.unshift File.join(__dir__, %w(.. lib))
6
5
 
7
6
  require 'cookstyle'
8
7
 
@@ -451,6 +451,24 @@ ChefCorrectness/MacosUserdefaultsInvalidType:
451
451
  - '**/metadata.rb'
452
452
  - '**/Berksfile'
453
453
 
454
+ ChefCorrectness/LazyInResourceGuard:
455
+ Description: Using `lazy {}` within a resource guard (not_if/only_if) will cause failures and is unnecessary as resource guards are always lazily evaluated.
456
+ StyleGuide: '#chefcorrectnesslazyinresourceguard'
457
+ Enabled: true
458
+ VersionAdded: '6.18.0'
459
+ Exclude:
460
+ - '**/metadata.rb'
461
+ - '**/Berksfile'
462
+
463
+ ChefCorrectness/PropertyWithoutType:
464
+ Description: Custom resource properties or attributes should always define a type to help users understand the correct allowed values.
465
+ StyleGuide: '#chefcorrectnesspropertywithouttype'
466
+ Enabled: true
467
+ VersionAdded: '6.18.0'
468
+ Include:
469
+ - '**/libraries/*.rb'
470
+ - '**/resources/*.rb'
471
+
454
472
  ###############################
455
473
  # ChefSharing: Issues that prevent sharing code with other teams or with the Chef community in general
456
474
  ###############################
@@ -908,10 +926,11 @@ ChefDeprecations/RubyBlockCreateAction:
908
926
  - '**/Berksfile'
909
927
 
910
928
  ChefDeprecations/DeprecatedPlatformMethods:
911
- Description: Use provider_for_action instead of the deprecated Chef::Platform methods in resources.
929
+ Description: Use provider_for_action or provides instead of the deprecated Chef::Platform methods in resources.
912
930
  StyleGuide: '#chefdeprecationsdeprecatedplatformmethods'
913
931
  Enabled: true
914
932
  VersionAdded: '5.16.0'
933
+ VersionChanged: '6.17.0'
915
934
  Include:
916
935
  - '**/libraries/*.rb'
917
936
  - '**/resources/*.rb'
@@ -1062,6 +1081,46 @@ ChefDeprecations/CookbooksDependsOnSelf:
1062
1081
  Include:
1063
1082
  - '**/metadata.rb'
1064
1083
 
1084
+ ChefDeprecations/ChefShellout:
1085
+ Description: Don't use deprecated Chef::ShellOut which was removed in Chef Infra Client 13. Use Mixlib::ShellOut instead, which behaves identically.
1086
+ StyleGuide: '#chefdeprecationschefshellout'
1087
+ Enabled: true
1088
+ VersionAdded: '6.17.0'
1089
+ Exclude:
1090
+ - '**/metadata.rb'
1091
+ - '**/attributes/*.rb'
1092
+ - '**/Berksfile'
1093
+
1094
+ ChefDeprecations/ExecutePathProperty:
1095
+ Description: In Chef Infra Client 13 and later you must set path env vars in `execute` resources using the `environment` property not the legacy `path` property.
1096
+ StyleGuide: '#chefdeprecationsexecutepathproperty'
1097
+ Enabled: true
1098
+ VersionAdded: '6.17.0'
1099
+ Exclude:
1100
+ - '**/metadata.rb'
1101
+ - '**/attributes/*.rb'
1102
+ - '**/Berksfile'
1103
+
1104
+ ChefDeprecations/ExecuteRelativeCreatesWithoutCwd:
1105
+ Description: In Chef Infra Client 13 and later you must either specify an absolute path when using the `execute` resource's `creates` property or also use the `cwd` property.
1106
+ StyleGuide: '#chefdeprecationsexecuterelativecreateswithoutcwd'
1107
+ Enabled: true
1108
+ VersionAdded: '6.17.0'
1109
+ Exclude:
1110
+ - '**/metadata.rb'
1111
+ - '**/attributes/*.rb'
1112
+ - '**/Berksfile'
1113
+
1114
+ ChefDeprecations/WindowsPackageInstallerTypeString:
1115
+ Description: In Chef Infra Client 13 and later the `windows_package` resource's `installer_type` property must be a symbol.
1116
+ StyleGuide: '#chefdeprecationswindowspackageinstallertypestring'
1117
+ Enabled: true
1118
+ VersionAdded: '6.17.0'
1119
+ Exclude:
1120
+ - '**/metadata.rb'
1121
+ - '**/attributes/*.rb'
1122
+ - '**/Berksfile'
1123
+
1065
1124
  ###############################
1066
1125
  # ChefModernize: Cleaning up legacy code and using new built-in resources
1067
1126
  ###############################
@@ -2302,21 +2361,6 @@ Lint/UselessSetterCall:
2302
2361
  Lint/Void:
2303
2362
  Enabled: true
2304
2363
 
2305
- ##### Additional rules we enable/disable over the rubocop 0.37 rules ago #####
2306
-
2307
- Layout/AlignParameters:
2308
- Enabled: false
2309
- Style/Encoding:
2310
- Enabled: false
2311
- Style/Alias:
2312
- Enabled: false
2313
- Layout/SpaceBeforeFirstArg:
2314
- Enabled: false
2315
- Style/ClassAndModuleChildren:
2316
- Enabled: false
2317
- Style/DoubleNegation:
2318
- Enabled: false
2319
-
2320
2364
  # file names don't matter in cookbooks
2321
2365
  Naming/FileName:
2322
2366
  Enabled: false
@@ -2612,4 +2656,56 @@ Style/BisectedAttrAccessor:
2612
2656
 
2613
2657
  # avoid assignments that aren't needed
2614
2658
  Style/RedundantAssignment:
2659
+ Enabled: true
2660
+
2661
+ # alert on invalid ruby
2662
+ Lint/Syntax:
2663
+ Enabled: true
2664
+
2665
+ # remove extra requires like 'thread'
2666
+ Lint/RedundantRequireStatement:
2667
+ Enabled: true
2668
+
2669
+ # simplify stripping strings
2670
+ Style/Strip:
2671
+ Enabled: true
2672
+
2673
+ # simplify how you warn
2674
+ Style/StderrPuts:
2675
+ Enabled: true
2676
+
2677
+ # more code simplification
2678
+ Style/Sample:
2679
+ Enabled: true
2680
+
2681
+ # simpler returns
2682
+ Style/ReturnNil:
2683
+ Enabled: true
2684
+
2685
+ # use .sort when .sort_by isn't needed
2686
+ Style/RedundantSortBy:
2687
+ Enabled: true
2688
+
2689
+ # simplify getting min/max
2690
+ Style/RedundantSort:
2691
+ Enabled: true
2692
+
2693
+ # no need for .rb in requires
2694
+ Style/RedundantFileExtensionInRequire:
2695
+ Enabled: true
2696
+
2697
+ # more code you don't need
2698
+ Style/RedundantCondition:
2699
+ Enabled: true
2700
+
2701
+ # Ruby 2 makes these pointless
2702
+ Style/Encoding:
2703
+ Enabled: true
2704
+
2705
+ # Use __dir__ to simplify things
2706
+ Style/Dir:
2707
+ Enabled: true
2708
+
2709
+ # Use __FILE__ or __dir__ to simplify expand_paths
2710
+ Style/ExpandPathArguments:
2615
2711
  Enabled: true
@@ -25,6 +25,8 @@ Layout/ArrayAlignment:
25
25
  Enabled: false
26
26
  Layout/AssignmentIndentation:
27
27
  Enabled: false
28
+ Layout/BeginEndAlignment:
29
+ Enabled: false
28
30
  Layout/BlockAlignment:
29
31
  Enabled: false
30
32
  Layout/BlockEndNewline:
@@ -215,6 +217,8 @@ Lint/BooleanSymbol:
215
217
  Enabled: false
216
218
  Lint/CircularArgumentReference:
217
219
  Enabled: false
220
+ Lint/ConstantDefinitionInBlock:
221
+ Enabled: false
218
222
  Lint/ConstantResolution:
219
223
  Enabled: false
220
224
  Lint/Debugger:
@@ -267,6 +271,8 @@ Lint/FormatParameterMismatch:
267
271
  Enabled: false
268
272
  Lint/HeredocMethodCallPosition:
269
273
  Enabled: false
274
+ Lint/IdentityComparison:
275
+ Enabled: false
270
276
  Lint/ImplicitStringConcatenation:
271
277
  Enabled: false
272
278
  Lint/InheritException:
@@ -395,6 +401,8 @@ Lint/UselessMethodDefinition:
395
401
  Enabled: false
396
402
  Lint/UselessSetterCall:
397
403
  Enabled: false
404
+ Lint/UselessTimes:
405
+ Enabled: false
398
406
  Lint/Void:
399
407
  Enabled: false
400
408
  Metrics/CyclomaticComplexity:
@@ -117,6 +117,8 @@ AllCops:
117
117
  # CacheRootDirectory is ~ (nil), which it is by default, the root will be
118
118
  # taken from the environment variable `$XDG_CACHE_HOME` if it is set, or if
119
119
  # `$XDG_CACHE_HOME` is not set, it will be `$HOME/.cache/`.
120
+ # The CacheRootDirectory can be overwritten by passing the `--cache-root` command
121
+ # line option or by setting `$RUBOCOP_CACHE_ROOT` environment variable.
120
122
  CacheRootDirectory: ~
121
123
  # It is possible for a malicious user to know the location of RuboCop's cache
122
124
  # directory by looking at CacheRootDirectory, and create a symlink in its
@@ -309,6 +311,19 @@ Layout/AssignmentIndentation:
309
311
  # But it can be overridden by setting this parameter
310
312
  IndentationWidth: ~
311
313
 
314
+ Layout/BeginEndAlignment:
315
+ Description: 'Align ends corresponding to begins correctly.'
316
+ Enabled: pending
317
+ VersionAdded: '0.91'
318
+ # The value `start_of_line` means that `end` should be aligned the start of the line
319
+ # where the `begin` keyword is.
320
+ # The value `begin` means that `end` should be aligned with the `begin` keyword.
321
+ EnforcedStyleAlignWith: start_of_line
322
+ SupportedStylesAlignWith:
323
+ - start_of_line
324
+ - begin
325
+ Severity: warning
326
+
312
327
  Layout/BlockAlignment:
313
328
  Description: 'Align block ends correctly.'
314
329
  Enabled: true
@@ -1380,6 +1395,12 @@ Lint/CircularArgumentReference:
1380
1395
  Enabled: true
1381
1396
  VersionAdded: '0.33'
1382
1397
 
1398
+ Lint/ConstantDefinitionInBlock:
1399
+ Description: 'Do not define constants within a block.'
1400
+ StyleGuide: '#no-constant-definition-in-block'
1401
+ Enabled: pending
1402
+ VersionAdded: '0.91'
1403
+
1383
1404
  Lint/ConstantResolution:
1384
1405
  Description: 'Check that constants are fully qualified with `::`.'
1385
1406
  Enabled: false
@@ -1533,6 +1554,12 @@ Lint/HeredocMethodCallPosition:
1533
1554
  StyleGuide: '#heredoc-method-calls'
1534
1555
  VersionAdded: '0.68'
1535
1556
 
1557
+ Lint/IdentityComparison:
1558
+ Description: 'Prefer `equal?` over `==` when comparing `object_id`.'
1559
+ Enabled: pending
1560
+ StyleGuide: '#identity-comparison'
1561
+ VersionAdded: '0.91'
1562
+
1536
1563
  Lint/ImplicitStringConcatenation:
1537
1564
  Description: >-
1538
1565
  Checks for adjacent string literals on the same line, which
@@ -1784,6 +1811,7 @@ Lint/SafeNavigationChain:
1784
1811
  - presence
1785
1812
  - try
1786
1813
  - try!
1814
+ - in?
1787
1815
 
1788
1816
  Lint/SafeNavigationConsistency:
1789
1817
  Description: >-
@@ -1966,6 +1994,12 @@ Lint/UselessSetterCall:
1966
1994
  VersionChanged: '0.80'
1967
1995
  Safe: false
1968
1996
 
1997
+ Lint/UselessTimes:
1998
+ Description: 'Checks for useless `Integer#times` calls.'
1999
+ Enabled: pending
2000
+ VersionAdded: '0.91'
2001
+ Safe: false
2002
+
1969
2003
  Lint/Void:
1970
2004
  Description: 'Possible use of operator/literal/variable in void context.'
1971
2005
  Enabled: true
@@ -3074,6 +3108,7 @@ Style/GlobalStdStream:
3074
3108
  StyleGuide: '#global-stdout'
3075
3109
  Enabled: pending
3076
3110
  VersionAdded: '0.89'
3111
+ SafeAutoCorrect: false
3077
3112
 
3078
3113
  Style/GlobalVars:
3079
3114
  Description: 'Do not introduce global variables.'
@@ -1,6 +1,5 @@
1
- # coding: utf-8
2
1
  # frozen_string_literal: true
3
- lib = File.expand_path('../lib', __FILE__)
2
+ lib = File.expand_path('lib', __dir__)
4
3
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
4
  require 'cookstyle/version'
6
5
 
@@ -7,19 +7,22 @@ require 'yaml' unless defined?(YAML)
7
7
  # ensure the desired target version of RuboCop is gem activated
8
8
  gem 'rubocop', "= #{Cookstyle::RUBOCOP_VERSION}"
9
9
  require 'rubocop'
10
- require_relative 'rubocop/monkey_patches/comment_config.rb'
10
+ require_relative 'rubocop/monkey_patches/comment_config'
11
11
 
12
12
  # monkey patches needed for the TargetChefVersion config option
13
- require_relative 'rubocop/monkey_patches/config.rb'
14
- require_relative 'rubocop/monkey_patches/base.rb'
15
- require_relative 'rubocop/monkey_patches/team.rb'
16
- require_relative 'rubocop/monkey_patches/registry_cop.rb'
13
+ require_relative 'rubocop/monkey_patches/config'
14
+ require_relative 'rubocop/monkey_patches/base'
15
+ require_relative 'rubocop/monkey_patches/team'
16
+ require_relative 'rubocop/monkey_patches/registry_cop'
17
+
18
+ # @TODO remove this monkeypatch after we upgrade from 0.91.0
19
+ require_relative 'rubocop/monkey_patches/rescue_ensure_alignment'
17
20
 
18
21
  module RuboCop
19
22
  class ConfigLoader
20
23
  RUBOCOP_HOME.gsub!(
21
24
  /^.*$/,
22
- File.realpath(File.join(File.dirname(__FILE__), '..'))
25
+ File.realpath(File.join(__dir__, '..'))
23
26
  )
24
27
 
25
28
  DEFAULT_FILE.gsub!(
@@ -46,7 +49,7 @@ require_relative 'rubocop/chef/cookbook_only'
46
49
  require_relative 'rubocop/cop/target_chef_version'
47
50
 
48
51
  # Chef Infra specific cops
49
- Dir.glob(File.dirname(__FILE__) + '/rubocop/cop/chef/**/*.rb') do |file|
52
+ Dir.glob(__dir__ + '/rubocop/cop/chef/**/*.rb') do |file|
50
53
  next if File.directory?(file)
51
54
 
52
55
  require_relative file # not actually relative but require_relative is faster
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
  module Cookstyle
3
- VERSION = "6.16.9" # rubocop: disable Style/StringLiterals
4
- RUBOCOP_VERSION = '0.90.0'
3
+ VERSION = "6.18.8" # rubocop: disable Style/StringLiterals
4
+ RUBOCOP_VERSION = '0.91.0'
5
5
  end
@@ -33,30 +33,58 @@ module RuboCop
33
33
  # ::Chef::DSL::Recipe.send(:include, Filebeat::Helpers) # covers previous Recipe & Provider classes
34
34
  #
35
35
  class IncorrectLibraryInjection < Base
36
+ include RangeHelp
36
37
  extend AutoCorrector
37
38
 
38
39
  MSG = 'Libraries should be injected into the Chef::DSL::Recipe class and not Chef::Recipe or Chef::Provider classes directly.'
39
40
 
41
+ def_node_search :correct_send?, <<-PATTERN
42
+ (send
43
+ (const
44
+ (const
45
+ (const {cbase nil?} :Chef) :DSL) :Recipe) :send
46
+ (sym :include)
47
+ ... )
48
+ PATTERN
49
+
50
+ def_node_search :correct_include?, <<-PATTERN
51
+ (send
52
+ (const
53
+ (const
54
+ (const {cbase nil?} :Chef) :DSL) :Recipe) :include
55
+ ... )
56
+ PATTERN
57
+
40
58
  def_node_matcher :legacy_class_sends?, <<-PATTERN
41
- (send (const (const (cbase) :Chef) {:Recipe :Provider}) :send (sym :include) ... )
59
+ (send (const (const {cbase nil?} :Chef) {:Recipe :Provider}) :send (sym :include) ... )
42
60
  PATTERN
43
61
 
44
- def_node_matcher :legacy_class_includes?, <<-PATTERN
45
- (send (const (const (cbase) :Chef) {:Recipe :Provider}) :include ... )
62
+ def_node_matcher :legacy_class_include?, <<-PATTERN
63
+ (send (const (const {cbase nil?} :Chef) {:Recipe :Provider}) :include ... )
46
64
  PATTERN
47
65
 
66
+ # @todo: This is highly repetitive and could be simplified into a single node_matcher
67
+ # call with some matcher magic that should be figured out
48
68
  def on_send(node)
49
69
  legacy_class_sends?(node) do
50
70
  add_offense(node, message: MSG, severity: :refactor) do |corrector|
51
- corrector.replace(node.loc.expression,
52
- node.source.gsub(/Chef::(Provider|Recipe)/, 'Chef::DSL::Recipe'))
71
+ if node.parent && correct_send?(node.parent)
72
+ corrector.remove(range_with_surrounding_space(range: node.loc.expression, side: :left))
73
+ else
74
+ corrector.replace(node.loc.expression,
75
+ node.source.gsub(/Chef::(Provider|Recipe)/, 'Chef::DSL::Recipe'))
76
+ end
53
77
  end
54
78
  end
55
79
 
56
- legacy_class_includes?(node) do
80
+ legacy_class_include?(node) do
57
81
  add_offense(node, message: MSG, severity: :refactor) do |corrector|
58
- corrector.replace(node.loc.expression,
59
- node.source.gsub(/Chef::(Provider|Recipe)/, 'Chef::DSL::Recipe'))
82
+ if node.parent && correct_include?(node.parent)
83
+ corrector.remove(range_with_surrounding_space(range: node.loc.expression, side: :left))
84
+ else
85
+ corrector.replace(node.loc.expression,
86
+ node.source.gsub(/Chef::(Provider|Recipe)/, 'Chef::DSL::Recipe'))
87
+ end
60
88
  end
61
89
  end
62
90
  end
@@ -0,0 +1,67 @@
1
+ # frozen_string_literal: true
2
+ #
3
+ # Copyright:: Copyright 2020, 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 ChefCorrectness
22
+ # Using `lazy {}` within a resource guard (not_if/only_if) will cause failures and is unnecessary as resource guards are always lazily evaluated.
23
+ #
24
+ # @example
25
+ #
26
+ # # bad
27
+ # template '/etc/foo' do
28
+ # mode '0644'
29
+ # source 'foo.erb'
30
+ # only_if { lazy { ::File.exist?('/etc/foo')} }
31
+ # end
32
+ #
33
+ # # good
34
+ # template '/etc/foo' do
35
+ # mode '0644'
36
+ # source 'foo.erb'
37
+ # only_if { ::File.exist?('/etc/foo') }
38
+ # end
39
+ #
40
+ class LazyInResourceGuard < Base
41
+ extend AutoCorrector
42
+
43
+ MSG = 'Using `lazy {}` within a resource guard (not_if/only_if) will cause failures and is unnecessary as resource guards are always lazily evaluated.'
44
+
45
+ def_node_matcher :lazy_in_guard?, <<-PATTERN
46
+ (block
47
+ (send nil? ${:not_if :only_if})
48
+ (args)
49
+ (block
50
+ (send nil? :lazy)
51
+ (args)
52
+ $(...)
53
+ ))
54
+ PATTERN
55
+
56
+ def on_block(node)
57
+ lazy_in_guard?(node) do |type, code|
58
+ add_offense(node, message: MSG, severity: :refactor) do |corrector|
59
+ corrector.replace(node.loc.expression, "#{type} { #{code.source} }")
60
+ end
61
+ end
62
+ end
63
+ end
64
+ end
65
+ end
66
+ end
67
+ end
@@ -0,0 +1,59 @@
1
+ # frozen_string_literal: true
2
+ #
3
+ # Copyright:: Copyright 2020, 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 ChefCorrectness
22
+ # Resource properties or attributes should always define a type to help users understand the correct allowed values.
23
+ #
24
+ # @example
25
+ #
26
+ # # bad
27
+ # property :size, regex: /^\d+[KMGTP]$/
28
+ # attribute :size, regex: /^\d+[KMGTP]$/
29
+ #
30
+ # # good
31
+ # property :size, String, regex: /^\d+[KMGTP]$/
32
+ # attribute :size, kind_of: String, regex: /^\d+[KMGTP]$/
33
+ #
34
+ class PropertyWithoutType < Base
35
+ MSG = 'Resource properties or attributes should always define a type to help users understand the correct allowed values.'
36
+ RESTRICT_ON_SEND = [:property, :attribute].freeze
37
+
38
+ def_node_matcher :property_without_type?, <<-PATTERN
39
+ (send nil? {:property :attribute}
40
+ (sym _)
41
+ $(hash
42
+
43
+ ...
44
+ )?
45
+ )
46
+ PATTERN
47
+
48
+ def on_send(node)
49
+ property_without_type?(node) do |hash_vals|
50
+ return if hash_vals&.first&.keys&.include?(s(:sym, :kind_of))
51
+
52
+ add_offense(node, message: MSG, severity: :refactor)
53
+ end
54
+ end
55
+ end
56
+ end
57
+ end
58
+ end
59
+ end
@@ -0,0 +1,86 @@
1
+ # frozen_string_literal: true
2
+ #
3
+ # Copyright:: 2020, 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
+
19
+ module RuboCop
20
+ module Cop
21
+ module Chef
22
+ module ChefDeprecations
23
+ # Don't use deprecated Chef::ShellOut which was removed in Chef Infra Client 13.
24
+ # Use Mixlib::ShellOut instead, which behaves identically or convert to the shell_out
25
+ # helper provided in chef-utils.
26
+ #
27
+ # @example
28
+ #
29
+ # # bad
30
+ # include Chef::ShellOut
31
+ # require 'chef/shellout'
32
+ # Chef::ShellOut.new('some_command')
33
+ #
34
+ # # good
35
+ # include Mixlib::ShellOut
36
+ # require 'mixlib/shellout'
37
+ # Mixlib::ShellOut.new('some_command')
38
+ #
39
+ class ChefShellout < Base
40
+ include RangeHelp
41
+ extend AutoCorrector
42
+
43
+ MSG = "Don't use deprecated Chef::ShellOut which was removed in Chef Infra Client 13. Use Mixlib::ShellOut instead, which behaves identically."
44
+ # RESTRICT_ON_SEND = [:new, :require, :include].freeze
45
+
46
+ def_node_matcher :include_shellout?, <<-PATTERN
47
+ (send nil? :include
48
+ (const
49
+ (const nil? :Chef) :ShellOut))
50
+ PATTERN
51
+
52
+ def_node_matcher :require_shellout?, <<-PATTERN
53
+ (send nil? :require (str "chef/shellout"))
54
+ PATTERN
55
+
56
+ def_node_matcher :shellout_new?, <<-PATTERN
57
+ (send
58
+ (const
59
+ (const nil? :Chef) :ShellOut) :new
60
+ ... )
61
+ PATTERN
62
+
63
+ def on_send(node)
64
+ include_shellout?(node) do
65
+ add_offense(node, message: MSG, severity: :warning) do |corrector|
66
+ corrector.remove(range_with_surrounding_space(range: node.loc.expression, side: :left))
67
+ end
68
+ end
69
+
70
+ require_shellout?(node) do
71
+ add_offense(node, message: MSG, severity: :warning) do |corrector|
72
+ corrector.remove(range_with_surrounding_space(range: node.loc.expression, side: :left))
73
+ end
74
+ end
75
+
76
+ shellout_new?(node) do
77
+ add_offense(node, message: MSG, severity: :warning) do |corrector|
78
+ corrector.replace(node.loc.expression, node.source.gsub('Chef::ShellOut', 'Mixlib::ShellOut'))
79
+ end
80
+ end
81
+ end
82
+ end
83
+ end
84
+ end
85
+ end
86
+ end
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
  #
3
- # Copyright:: 2019, Chef Software Inc.
3
+ # Copyright:: 2019-2020, Chef Software Inc.
4
4
  # Author:: Tim Smith (<tsmith@chef.io>)
5
5
  #
6
6
  # Licensed under the Apache License, Version 2.0 (the "License");
@@ -20,7 +20,7 @@ module RuboCop
20
20
  module Cop
21
21
  module Chef
22
22
  module ChefDeprecations
23
- # Use provider_for_action instead of the deprecated Chef::Platform methods in resources, which were removed in Chef Infra Client 13.
23
+ # Use provider_for_action or provides instead of the deprecated Chef::Platform methods in resources, which were removed in Chef Infra Client 13.
24
24
  #
25
25
  # @example
26
26
  #
@@ -34,15 +34,19 @@ module RuboCop
34
34
  # resource = Chef::Resource::File.new("/tmp/foo.xyz", run_context)
35
35
  # provider = Chef::Platform.find_provider_for_node(node, resource)
36
36
  #
37
+ # Chef::Platform.set :platform => :mac_os_x, :resource => :package, :provider => Chef::Provider::Package::Homebrew
38
+ #
37
39
  # # good
38
40
  # resource = Chef::Resource::File.new("/tmp/foo.xyz", run_context)
39
41
  # provider = resource.provider_for_action(:create)
40
42
  #
43
+ # # provides :package, platform_family: 'mac_os_x'
44
+
41
45
  class DeprecatedPlatformMethods < Base
42
- MSG = 'Use provider_for_action instead of the deprecated Chef::Platform methods in resources, which were removed in Chef Infra Client 13.'
46
+ MSG = 'Use provider_for_action or provides instead of the deprecated Chef::Platform methods in resources, which were removed in Chef Infra Client 13.'
43
47
 
44
48
  def_node_matcher :platform_method?, <<-PATTERN
45
- (send (const (const nil? :Chef) :Platform) {:provider_for_resource :find_provider :find_provider_for_node} ... )
49
+ (send (const (const nil? :Chef) :Platform) {:provider_for_resource :find_provider :find_provider_for_node :set} ... )
46
50
  PATTERN
47
51
 
48
52
  def on_send(node)
@@ -0,0 +1,51 @@
1
+ # frozen_string_literal: true
2
+ #
3
+ # Copyright:: 2020, 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
+
19
+ module RuboCop
20
+ module Cop
21
+ module Chef
22
+ module ChefDeprecations
23
+ # In Chef Infra Client 13 and later you must set path env vars in execute resources using the `environment` property not the legacy `path` property.
24
+ #
25
+ # @example
26
+ #
27
+ # # bad
28
+ # execute 'some_cmd' do
29
+ # path '/foo/bar'
30
+ # end
31
+ #
32
+ # # good
33
+ # execute 'some_cmd' do
34
+ # environment {path: '/foo/bar'}
35
+ # end
36
+ #
37
+ class ExecutePathProperty < Base
38
+ include RuboCop::Chef::CookbookHelpers
39
+
40
+ MSG = 'In Chef Infra Client 13 and later you must set path env vars in execute resources using the `environment` property not the legacy `path` property.'
41
+
42
+ def on_block(node)
43
+ match_property_in_resource?(:execute, 'path', node) do |offense|
44
+ add_offense(offense.loc.expression, message: MSG, severity: :warning) # @todo: we could probably autocorrect this with some work
45
+ end
46
+ end
47
+ end
48
+ end
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,67 @@
1
+ # frozen_string_literal: true
2
+ #
3
+ # Copyright:: 2020, 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
+
19
+ module RuboCop
20
+ module Cop
21
+ module Chef
22
+ module ChefDeprecations
23
+ # In Chef Infra Client 13 and later you must either specific an absolute path when using the `execute` resource's `creates` property or also use the `cwd` property.
24
+ #
25
+ # @example
26
+ #
27
+ # # bad
28
+ # execute 'some_cmd' do
29
+ # creates 'something'
30
+ # end
31
+ #
32
+ # # good
33
+ # execute 'some_cmd' do
34
+ # creates '/tmp/something'
35
+ # end
36
+ #
37
+ # execute 'some_cmd' do
38
+ # creates 'something'
39
+ # cwd '/tmp/'
40
+ # end
41
+ #
42
+ class ExecuteRelativeCreatesWithoutCwd < Base
43
+ include RuboCop::Chef::CookbookHelpers
44
+
45
+ MSG = "In Chef Infra Client 13 and later you must either specific an absolute path when using the `execute` resource's `creates` property or also use the `cwd` property."
46
+
47
+ def on_block(node)
48
+ match_property_in_resource?(:execute, 'creates', node) do |offense|
49
+ return unless offense.arguments.count == 1 # we can only analyze simple string args
50
+ return unless offense.arguments.first.str_type? # we can only analyze simple string args
51
+
52
+ # skip any creates that are abs paths https://rubular.com/r/3TbDsgcAa1EaIF
53
+ return if offense.arguments.first.value.match?(%r{^(/|[a-zA-Z]:)})
54
+
55
+ # return if we have a cwd property
56
+ match_property_in_resource?(:execute, 'cwd', node) do
57
+ return
58
+ end
59
+
60
+ add_offense(offense.loc.expression, message: MSG, severity: :warning)
61
+ end
62
+ end
63
+ end
64
+ end
65
+ end
66
+ end
67
+ end
@@ -57,6 +57,8 @@ module RuboCop
57
57
 
58
58
  private
59
59
 
60
+ VALID_TYPES = %i(send hash block_pass).freeze
61
+
60
62
  #
61
63
  # Are the arguments in the passed node object positional
62
64
  #
@@ -68,7 +70,7 @@ module RuboCop
68
70
  return false if node.arguments.count < 3
69
71
  node.arguments[2..-1].each do |arg|
70
72
  # hashes, blocks, or variable/methods are valid. Anything else is not
71
- return true unless %i(send hash block_pass).include?(arg.type)
73
+ return true unless VALID_TYPES.include?(arg.type)
72
74
  end
73
75
  false
74
76
  end
@@ -81,7 +83,7 @@ module RuboCop
81
83
  # @return [String]
82
84
  #
83
85
  def corrected_string(node)
84
- args = node.arguments
86
+ args = node.arguments.dup
85
87
 
86
88
  # If the 2nd argument is a String and not an Integer as a String
87
89
  # then it's the old sort field and we need to delete it. Same thing
@@ -48,7 +48,7 @@ module RuboCop
48
48
 
49
49
  def on_block(node)
50
50
  match_property_in_resource?(:windows_feature, :install_method, node) do |prop_node|
51
- add_offense(prop_node, message: MSG, severity: :warning) if prop_node.source.match?(/:servermanagercmd/)
51
+ add_offense(prop_node, message: MSG, severity: :warning) if prop_node.source.include?(':servermanagercmd')
52
52
  end
53
53
  end
54
54
  end
@@ -0,0 +1,61 @@
1
+ # frozen_string_literal: true
2
+ #
3
+ # Copyright:: 2020, 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
+
19
+ module RuboCop
20
+ module Cop
21
+ module Chef
22
+ module ChefDeprecations
23
+ # In Chef Infra Client 13 and later the `windows_package` resource's `installer_type` property must be a symbol.
24
+ #
25
+ # @example
26
+ #
27
+ # # bad
28
+ # windows_package 'AppveyorDeploymentAgent' do
29
+ # source 'https://www.example.com/appveyor.msi'
30
+ # installer_type 'msi'
31
+ # options "/quiet /qn /norestart /log install.log"
32
+ # end
33
+ #
34
+ # # good
35
+ # windows_package 'AppveyorDeploymentAgent' do
36
+ # source 'https://www.example.com/appveyor.msi'
37
+ # installer_type :msi
38
+ # options "/quiet /qn /norestart /log install.log"
39
+ # end
40
+ #
41
+ class WindowsPackageInstallerTypeString < Base
42
+ include RuboCop::Chef::CookbookHelpers
43
+ extend AutoCorrector
44
+
45
+ MSG = "In Chef Infra Client 13 and later the `windows_package` resource's `installer_type` property must be a symbol."
46
+
47
+ def on_block(node)
48
+ match_property_in_resource?(:windows_package, 'installer_type', node) do |offense|
49
+ return unless offense.arguments.count == 1 # we can only analyze simple string args
50
+ return unless offense.arguments.first.str_type? # anything else is fine
51
+
52
+ add_offense(offense.loc.expression, message: MSG, severity: :warning) do |corrector|
53
+ corrector.replace(offense.arguments.first.source_range, ":#{offense.arguments.first.value}")
54
+ end
55
+ end
56
+ end
57
+ end
58
+ end
59
+ end
60
+ end
61
+ end
@@ -44,6 +44,7 @@ module RuboCop
44
44
  # end
45
45
  #
46
46
  class RespondToCompileTime < Base
47
+ include RuboCop::Chef::CookbookHelpers
47
48
  extend TargetChefVersion
48
49
  extend AutoCorrector
49
50
 
@@ -75,10 +76,12 @@ module RuboCop
75
76
  $(_)) nil?)
76
77
  PATTERN
77
78
 
78
- def on_if(node)
79
- compile_time_method_defined?(node) do |val|
80
- add_offense(node, message: MSG, severity: :refactor) do |corrector|
81
- corrector.replace(node.loc.expression, "compile_time #{val.source}")
79
+ def on_block(node)
80
+ match_property_in_resource?(:chef_gem, 'compile_time', node) do |compile_time_property|
81
+ compile_time_method_defined?(compile_time_property.parent) do |val|
82
+ add_offense(compile_time_property.parent, message: MSG, severity: :refactor) do |corrector|
83
+ corrector.replace(compile_time_property.parent.loc.expression, "compile_time #{val.source}")
84
+ end
82
85
  end
83
86
  end
84
87
  end
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+ module RuboCop
3
+ module Cop
4
+ module Layout
5
+ class RescueEnsureAlignment < Base
6
+ # @TODO remove this monkeypatch after we upgrade from RuboCop 0.91.0
7
+ def begin_end_alignment_style
8
+ # FIXME: Workaround for pending status for `Layout/BeginEndAlignment` cop
9
+ # When RuboCop 1.0 is released, please replace it with the following condition.
10
+ #
11
+ # config.for_cop('Layout/BeginEndAlignment')['Enabled'] &&
12
+ # config.for_cop('Layout/BeginEndAlignment')['EnforcedStyleAlignWith']
13
+ if config.for_all_cops['NewCops'] == 'enable' ||
14
+ config.for_cop('Layout/BeginEndAlignment')['Enabled'] &&
15
+ config.for_cop('Layout/BeginEndAlignment')['Enabled'] != 'pending'
16
+ config.for_cop('Layout/BeginEndAlignment')['EnforcedStyleAlignWith']
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
22
+ 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.16.9
4
+ version: 6.18.8
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-09-02 00:00:00.000000000 Z
12
+ date: 2020-09-17 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.90.0
20
+ version: 0.91.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.90.0
27
+ version: 0.91.0
28
28
  description:
29
29
  email:
30
30
  - thom@chef.io
@@ -66,6 +66,7 @@ files:
66
66
  - lib/rubocop/cop/chef/correctness/invalid_value_for_platform_helper.rb
67
67
  - lib/rubocop/cop/chef/correctness/invalid_version_metadata.rb
68
68
  - lib/rubocop/cop/chef/correctness/lazy_eval_node_attribute_defaults.rb
69
+ - lib/rubocop/cop/chef/correctness/lazy_in_resource_guard.rb
69
70
  - lib/rubocop/cop/chef/correctness/macos_userdefaults_invalid_type.rb
70
71
  - lib/rubocop/cop/chef/correctness/malformed_value_for_platform.rb
71
72
  - lib/rubocop/cop/chef/correctness/metadata_missing_name.rb
@@ -75,6 +76,7 @@ files:
75
76
  - lib/rubocop/cop/chef/correctness/notifies_action_not_symbol.rb
76
77
  - lib/rubocop/cop/chef/correctness/openssl_password_helpers.rb
77
78
  - lib/rubocop/cop/chef/correctness/powershell_delete_file.rb
79
+ - lib/rubocop/cop/chef/correctness/property_without_type.rb
78
80
  - lib/rubocop/cop/chef/correctness/resource_sets_internal_properties.rb
79
81
  - lib/rubocop/cop/chef/correctness/resource_sets_name_property.rb
80
82
  - lib/rubocop/cop/chef/correctness/resource_with_none_action.rb
@@ -88,6 +90,7 @@ files:
88
90
  - lib/rubocop/cop/chef/deprecation/chef_handler_supports.rb
89
91
  - lib/rubocop/cop/chef/deprecation/chef_rest.rb
90
92
  - lib/rubocop/cop/chef/deprecation/chef_rewind.rb
93
+ - lib/rubocop/cop/chef/deprecation/chef_shellout.rb
91
94
  - lib/rubocop/cop/chef/deprecation/chef_windows_platform_helper.rb
92
95
  - lib/rubocop/cop/chef/deprecation/chefdk_generators.rb
93
96
  - lib/rubocop/cop/chef/deprecation/cheffile.rb
@@ -107,6 +110,8 @@ files:
107
110
  - lib/rubocop/cop/chef/deprecation/eol_audit_mode.rb
108
111
  - lib/rubocop/cop/chef/deprecation/epic_fail.rb
109
112
  - lib/rubocop/cop/chef/deprecation/erl_call.rb
113
+ - lib/rubocop/cop/chef/deprecation/execute_path_property.rb
114
+ - lib/rubocop/cop/chef/deprecation/execute_relative_creates_without_cwd.rb
110
115
  - lib/rubocop/cop/chef/deprecation/hwrp_without_provides.rb
111
116
  - lib/rubocop/cop/chef/deprecation/inherits_compat_resource.rb
112
117
  - lib/rubocop/cop/chef/deprecation/launchd_deprecated_hash_property.rb
@@ -139,6 +144,7 @@ files:
139
144
  - lib/rubocop/cop/chef/deprecation/user_supports_property.rb
140
145
  - lib/rubocop/cop/chef/deprecation/verify_property_file_expansion.rb
141
146
  - lib/rubocop/cop/chef/deprecation/windows_feature_servermanagercmd.rb
147
+ - lib/rubocop/cop/chef/deprecation/windows_package_installer_type_string.rb
142
148
  - lib/rubocop/cop/chef/deprecation/windows_task_change_action.rb
143
149
  - lib/rubocop/cop/chef/deprecation/windows_version_helpers.rb
144
150
  - lib/rubocop/cop/chef/deprecation/xml_ruby_recipe.rb
@@ -264,6 +270,7 @@ files:
264
270
  - lib/rubocop/monkey_patches/comment_config.rb
265
271
  - lib/rubocop/monkey_patches/config.rb
266
272
  - lib/rubocop/monkey_patches/registry_cop.rb
273
+ - lib/rubocop/monkey_patches/rescue_ensure_alignment.rb
267
274
  - lib/rubocop/monkey_patches/team.rb
268
275
  homepage: https://docs.chef.io/workstation/cookstyle/
269
276
  licenses: