cookstyle 6.17.7 → 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: '0385aed05c2f7b990958984ace106ea1f8b12d62feae5ba63fc0c382a880f678'
4
- data.tar.gz: e7888f5a8f5959069e00a5d3be8ce8a80325b34fe0d943baddb8a414f97947fd
3
+ metadata.gz: 5155a9b35b7783b4f93c60355db6c98114c8f337536cd468738d06481b5e8e7e
4
+ data.tar.gz: 0f7d7fae656539861f7bcdd6b4bda8463896eacd3a82c9ba4964b6ad4d35f193
5
5
  SHA512:
6
- metadata.gz: a89eab0482fd1c1c158b9f5ead6f61b4693a391fd88855bba6b5e46f60ae3ebb28074ef7782e4d249cd097ebd8093461c25baaff2c699ae214bc12d8584b95ef
7
- data.tar.gz: b125b09055b3388353ac3374ea1aa5061dc6dfe75f051a538004ed13d064820e40920d2d13fd2a0557cfe3b602237f346b7316adaa2e1174f9b0e4400ff7e71b
6
+ metadata.gz: de5247580b6f6432ac8d0fff694115b8c8765ec012c3f5686fd56453ea7ebb3b943c60025102d0a8531ecb0c605484786d3fa7c500819fd6d188bc8589e11a56
7
+ data.tar.gz: 54baddbe1f9419c2387ed4c94d678fdc7d599e903876ed84ccaa9aa99aa7add6443167b003f05a38f7f1b79d574e14507006650152a0bce0ed65d4ba368adf47
@@ -1,5 +1,4 @@
1
1
  #!/usr/bin/env ruby
2
- # -*- encoding: utf-8 -*-
3
2
  # frozen_string_literal: true
4
3
 
5
4
  $LOAD_PATH.unshift File.join(__dir__, %w(.. lib))
@@ -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
  ###############################
@@ -2343,21 +2361,6 @@ Lint/UselessSetterCall:
2343
2361
  Lint/Void:
2344
2362
  Enabled: true
2345
2363
 
2346
- ##### Additional rules we enable/disable over the rubocop 0.37 rules ago #####
2347
-
2348
- Layout/AlignParameters:
2349
- Enabled: false
2350
- Style/Encoding:
2351
- Enabled: false
2352
- Style/Alias:
2353
- Enabled: false
2354
- Layout/SpaceBeforeFirstArg:
2355
- Enabled: false
2356
- Style/ClassAndModuleChildren:
2357
- Enabled: false
2358
- Style/DoubleNegation:
2359
- Enabled: false
2360
-
2361
2364
  # file names don't matter in cookbooks
2362
2365
  Naming/FileName:
2363
2366
  Enabled: false
@@ -2658,3 +2661,51 @@ Style/RedundantAssignment:
2658
2661
  # alert on invalid ruby
2659
2662
  Lint/Syntax:
2660
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:
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: >-
@@ -1861,6 +1889,7 @@ Lint/Syntax:
1861
1889
  Enabled: true
1862
1890
  VersionAdded: '0.9'
1863
1891
 
1892
+
1864
1893
  Lint/ToJSON:
1865
1894
  Description: 'Ensure #to_json includes an optional argument.'
1866
1895
  Enabled: true
@@ -1965,6 +1994,12 @@ Lint/UselessSetterCall:
1965
1994
  VersionChanged: '0.80'
1966
1995
  Safe: false
1967
1996
 
1997
+ Lint/UselessTimes:
1998
+ Description: 'Checks for useless `Integer#times` calls.'
1999
+ Enabled: pending
2000
+ VersionAdded: '0.91'
2001
+ Safe: false
2002
+
1968
2003
  Lint/Void:
1969
2004
  Description: 'Possible use of operator/literal/variable in void context.'
1970
2005
  Enabled: true
@@ -3073,6 +3108,7 @@ Style/GlobalStdStream:
3073
3108
  StyleGuide: '#global-stdout'
3074
3109
  Enabled: pending
3075
3110
  VersionAdded: '0.89'
3111
+ SafeAutoCorrect: false
3076
3112
 
3077
3113
  Style/GlobalVars:
3078
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,13 +7,16 @@ 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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
  module Cookstyle
3
- VERSION = "6.17.7" # 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
@@ -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
@@ -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.17.7
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-14 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
@@ -268,6 +270,7 @@ files:
268
270
  - lib/rubocop/monkey_patches/comment_config.rb
269
271
  - lib/rubocop/monkey_patches/config.rb
270
272
  - lib/rubocop/monkey_patches/registry_cop.rb
273
+ - lib/rubocop/monkey_patches/rescue_ensure_alignment.rb
271
274
  - lib/rubocop/monkey_patches/team.rb
272
275
  homepage: https://docs.chef.io/workstation/cookstyle/
273
276
  licenses: