chefstyle 1.2.1 → 1.3.2

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: e8a5a9a139fa8c13a7ed8661a647267905503b17e62362412af969e40d0df91b
4
- data.tar.gz: 51ed4bc5b0918b590a16dc9892623385610c5033db3bc1aca87cbe1da30c5c1d
3
+ metadata.gz: 53fa6bb2f80dbe12ea389014623ddc52076c9432383e533f21e5c571e069c14d
4
+ data.tar.gz: 064cdbbf2ba18a12b09e5db1d4a508bab1c27e36a91007e0c5e03aeaed14b36f
5
5
  SHA512:
6
- metadata.gz: c9cbd2f2fe158de67c16ec5932f449fc9e42877ddffe9e4e7f29881c05a645188f197241a930ddd4b51ffd2a75c38a726032a4e98fb22d922f8a755633a294d3
7
- data.tar.gz: c439d8ae28a519fdd8190a13546db53f820ea46c8bcbd56eb8f676cf6b5f04b485d09a4da9ff52de1f46144aa00a6d0fda2cf60d377300f003a1a079a434d548
6
+ metadata.gz: 7cc1e3008f9624c9868f5d13d4a0010b932c4ce4a41d3b4368405c62b808acf34b712914b580e0334dbdfdb19510da7840866a0a126656ef84eb2a5b829c1f0f
7
+ data.tar.gz: 27707feacf6dcd7e0890d95a07fcab77d44d7bb474f56a5e6f4f1c363161683c48881946b920c660b5fe277bf18a8980cdc67379b458d242406803dd4d0c3be1
@@ -18,8 +18,5 @@ Gem::Specification.new do |spec|
18
18
  spec.executables = %w{chefstyle}
19
19
  spec.require_paths = ["lib"]
20
20
 
21
- spec.add_development_dependency "bundler"
22
- spec.add_development_dependency "rake", ">= 12.0"
23
- spec.add_development_dependency "rspec"
24
21
  spec.add_dependency("rubocop", Chefstyle::RUBOCOP_VERSION)
25
22
  end
@@ -554,7 +554,7 @@ Style/RescueModifier:
554
554
  Style/AsciiComments:
555
555
  Enabled: false
556
556
 
557
- # Parens around ternaries often make them more readable and reduces cognitive load over operator precidence
557
+ # Parens around ternaries often make them more readable and reduces cognitive load over operator precedence
558
558
  Style/TernaryParentheses:
559
559
  Enabled: false
560
560
 
@@ -631,4 +631,28 @@ Style/CommentedKeyword:
631
631
 
632
632
  # make sure we catch this Ruby 3.0 breaking change now
633
633
  Lint/DeprecatedOpenSSLConstant:
634
- Enabled: true
634
+ Enabled: true
635
+
636
+ ChefRuby/Ruby27KeywordArgumentWarnings:
637
+ Description: Pass options to shell_out helpers without the brackets to avoid Ruby 2.7 deprecation warnings.
638
+ Enabled: true
639
+ VersionAdded: '1.3.0'
640
+
641
+ ChefRuby/UnlessDefinedRequire:
642
+ Description: Workaround RubyGems' slow requires by only running require if the constant isn't already defined
643
+ Enabled: true
644
+ VersionAdded: '1.3.0'
645
+ Include:
646
+ - 'lib/**/*'
647
+
648
+ ChefRuby/GemspecRequireRubygems:
649
+ Description: Rubygems does not need to be required in a Gemspec
650
+ Enabled: true
651
+ VersionAdded: '1.3.0'
652
+ Include:
653
+ - '**/*.gemspec'
654
+
655
+ ChefRuby/RequireNetHttps:
656
+ Description: net/https is deprecated and just includes net/http and openssl. We should include those directly instead
657
+ Enabled: true
658
+ VersionAdded: '1.3.0'
@@ -53,6 +53,8 @@ Layout/EmptyLineAfterGuardClause:
53
53
  Enabled: false
54
54
  Layout/EmptyLineAfterMagicComment:
55
55
  Enabled: false
56
+ Layout/EmptyLineAfterMultilineCondition:
57
+ Enabled: false
56
58
  Layout/EmptyLineBetweenDefs:
57
59
  Enabled: false
58
60
  Layout/EmptyLinesAroundAccessModifier:
@@ -231,6 +233,8 @@ Lint/DuplicateHashKey:
231
233
  Enabled: false
232
234
  Lint/DuplicateMethods:
233
235
  Enabled: false
236
+ Lint/DuplicateRequire:
237
+ Enabled: false
234
238
  Lint/DuplicateRescueException:
235
239
  Enabled: false
236
240
  Lint/EachWithObjectArgument:
@@ -243,6 +247,8 @@ Lint/EmptyEnsure:
243
247
  Enabled: false
244
248
  Lint/EmptyExpression:
245
249
  Enabled: false
250
+ Lint/EmptyFile:
251
+ Enabled: false
246
252
  Lint/EmptyInterpolation:
247
253
  Enabled: false
248
254
  Lint/EmptyWhen:
@@ -361,6 +367,8 @@ Lint/ToJSON:
361
367
  Enabled: false
362
368
  Lint/TopLevelReturnWithArgument:
363
369
  Enabled: false
370
+ Lint/TrailingCommaInAttributeDeclaration:
371
+ Enabled: false
364
372
  Lint/UnderscorePrefixedVariableName:
365
373
  Enabled: false
366
374
  Lint/UnifiedInteger:
@@ -383,6 +391,8 @@ Lint/UselessAssignment:
383
391
  Enabled: false
384
392
  Lint/UselessElseWithoutRescue:
385
393
  Enabled: false
394
+ Lint/UselessMethodDefinition:
395
+ Enabled: false
386
396
  Lint/UselessSetterCall:
387
397
  Enabled: false
388
398
  Lint/Void:
@@ -477,6 +487,8 @@ Style/ClassCheck:
477
487
  Enabled: false
478
488
  Style/ClassMethods:
479
489
  Enabled: false
490
+ Style/ClassMethodsDefinitions:
491
+ Enabled: false
480
492
  Style/ClassVars:
481
493
  Enabled: false
482
494
  Style/CollectionMethods:
@@ -485,6 +497,8 @@ Style/ColonMethodCall:
485
497
  Enabled: false
486
498
  Style/ColonMethodDefinition:
487
499
  Enabled: false
500
+ Style/CombinableLoops:
501
+ Enabled: false
488
502
  Style/CommandLiteral:
489
503
  Enabled: false
490
504
  Style/CommentAnnotation:
@@ -591,6 +605,8 @@ Style/InlineComment:
591
605
  Enabled: false
592
606
  Style/IpAddresses:
593
607
  Enabled: false
608
+ Style/KeywordParametersOrder:
609
+ Enabled: false
594
610
  Style/Lambda:
595
611
  Enabled: false
596
612
  Style/LambdaCall:
@@ -607,6 +623,10 @@ Style/RedundantFetchBlock:
607
623
  Enabled: false
608
624
  Style/RedundantFileExtensionInRequire:
609
625
  Enabled: false
626
+ Style/RedundantSelfAssignment:
627
+ Enabled: false
628
+ Style/SoleNestedConditional:
629
+ Enabled: false
610
630
  Style/MethodCalledOnDoEndBlock:
611
631
  Enabled: false
612
632
  Style/MethodDefParentheses:
@@ -828,4 +848,4 @@ Security/MarshalLoad:
828
848
  Security/Open:
829
849
  Enabled: false
830
850
  Security/YAMLLoad:
831
- Enabled: false
851
+ Enabled: false
@@ -399,7 +399,6 @@ Layout/DefEndAlignment:
399
399
  SupportedStylesAlignWith:
400
400
  - start_of_line
401
401
  - def
402
- AutoCorrect: false
403
402
  Severity: warning
404
403
 
405
404
  Layout/DotPosition:
@@ -436,6 +435,14 @@ Layout/EmptyLineAfterMagicComment:
436
435
  Enabled: true
437
436
  VersionAdded: '0.49'
438
437
 
438
+ Layout/EmptyLineAfterMultilineCondition:
439
+ Description: 'Enforces empty line after multiline condition.'
440
+ # This is disabled, because this style is not very common in practice.
441
+ Enabled: false
442
+ VersionAdded: '0.90'
443
+ Reference:
444
+ - https://github.com/airbnb/ruby#multiline-if-newline
445
+
439
446
  Layout/EmptyLineBetweenDefs:
440
447
  Description: 'Use empty lines between defs.'
441
448
  StyleGuide: '#empty-lines-between-methods'
@@ -555,7 +562,6 @@ Layout/EndAlignment:
555
562
  - keyword
556
563
  - variable
557
564
  - start_of_line
558
- AutoCorrect: false
559
565
  Severity: warning
560
566
 
561
567
  Layout/EndOfLine:
@@ -1427,6 +1433,11 @@ Lint/DuplicateMethods:
1427
1433
  Enabled: true
1428
1434
  VersionAdded: '0.29'
1429
1435
 
1436
+ Lint/DuplicateRequire:
1437
+ Description: 'Check for duplicate `require`s and `require_relative`s.'
1438
+ Enabled: pending
1439
+ VersionAdded: '0.90'
1440
+
1430
1441
  Lint/DuplicateRescueException:
1431
1442
  Description: 'Checks that there are no repeated exceptions used in `rescue` expressions.'
1432
1443
  Enabled: pending
@@ -1453,13 +1464,18 @@ Lint/EmptyEnsure:
1453
1464
  Enabled: true
1454
1465
  VersionAdded: '0.10'
1455
1466
  VersionChanged: '0.48'
1456
- AutoCorrect: false
1457
1467
 
1458
1468
  Lint/EmptyExpression:
1459
1469
  Description: 'Checks for empty expressions.'
1460
1470
  Enabled: true
1461
1471
  VersionAdded: '0.45'
1462
1472
 
1473
+ Lint/EmptyFile:
1474
+ Description: 'Enforces that Ruby source files are not empty.'
1475
+ Enabled: pending
1476
+ AllowComments: true
1477
+ VersionAdded: '0.90'
1478
+
1463
1479
  Lint/EmptyInterpolation:
1464
1480
  Description: 'Checks for empty string interpolation.'
1465
1481
  Enabled: true
@@ -1856,6 +1872,11 @@ Lint/TopLevelReturnWithArgument:
1856
1872
  Enabled: 'pending'
1857
1873
  VersionAdded: '0.89'
1858
1874
 
1875
+ Lint/TrailingCommaInAttributeDeclaration:
1876
+ Description: 'This cop checks for trailing commas in attribute declarations.'
1877
+ Enabled: pending
1878
+ VersionAdded: '0.90'
1879
+
1859
1880
  Lint/UnderscorePrefixedVariableName:
1860
1881
  Description: 'Do not use prefix `_` for a variable that is used.'
1861
1882
  Enabled: true
@@ -1931,6 +1952,13 @@ Lint/UselessElseWithoutRescue:
1931
1952
  Enabled: true
1932
1953
  VersionAdded: '0.17'
1933
1954
 
1955
+ Lint/UselessMethodDefinition:
1956
+ Description: 'Checks for useless method definitions.'
1957
+ Enabled: pending
1958
+ VersionAdded: '0.90'
1959
+ Safe: false
1960
+ AllowComments: true
1961
+
1934
1962
  Lint/UselessSetterCall:
1935
1963
  Description: 'Checks for useless setter call to a local variable.'
1936
1964
  Enabled: true
@@ -2591,6 +2619,7 @@ Style/CaseLikeIf:
2591
2619
  Description: 'This cop identifies places where `if-elsif` constructions can be replaced with `case-when`.'
2592
2620
  StyleGuide: '#case-vs-if-else'
2593
2621
  Enabled: 'pending'
2622
+ Safe: false
2594
2623
  VersionAdded: '0.88'
2595
2624
 
2596
2625
  Style/CharacterLiteral:
@@ -2608,7 +2637,6 @@ Style/ClassAndModuleChildren:
2608
2637
  # have the knowledge to perform either operation safely and thus requires
2609
2638
  # manual oversight.
2610
2639
  SafeAutoCorrect: false
2611
- AutoCorrect: false
2612
2640
  Enabled: true
2613
2641
  VersionAdded: '0.19'
2614
2642
  #
@@ -2647,6 +2675,16 @@ Style/ClassMethods:
2647
2675
  VersionAdded: '0.9'
2648
2676
  VersionChanged: '0.20'
2649
2677
 
2678
+ Style/ClassMethodsDefinitions:
2679
+ Description: 'Enforces using `def self.method_name` or `class << self` to define class methods.'
2680
+ StyleGuide: '#def-self-class-methods'
2681
+ Enabled: false
2682
+ VersionAdded: '0.89'
2683
+ EnforcedStyle: def_self
2684
+ SupportedStyles:
2685
+ - def_self
2686
+ - self_class
2687
+
2650
2688
  Style/ClassVars:
2651
2689
  Description: 'Avoid the use of class variables.'
2652
2690
  StyleGuide: '#no-class-vars'
@@ -2687,6 +2725,14 @@ Style/ColonMethodDefinition:
2687
2725
  Enabled: true
2688
2726
  VersionAdded: '0.52'
2689
2727
 
2728
+ Style/CombinableLoops:
2729
+ Description: >-
2730
+ Checks for places where multiple consecutive loops over the same data
2731
+ can be combined into a single loop.
2732
+ Enabled: pending
2733
+ Safe: false
2734
+ VersionAdded: '0.90'
2735
+
2690
2736
  Style/CommandLiteral:
2691
2737
  Description: 'Use `` or %x around command literals.'
2692
2738
  StyleGuide: '#percent-x'
@@ -3021,7 +3067,7 @@ Style/FrozenStringLiteralComment:
3021
3067
  # `never` will enforce that the frozen string literal comment does not
3022
3068
  # exist in a file.
3023
3069
  - never
3024
- Safe: false
3070
+ SafeAutoCorrect: false
3025
3071
 
3026
3072
  Style/GlobalStdStream:
3027
3073
  Description: 'Enforces the use of `$stdout/$stderr/$stdin` instead of `STDOUT/STDERR/STDIN`.'
@@ -3101,15 +3147,17 @@ Style/HashSyntax:
3101
3147
  PreferHashRocketsForNonAlnumEndingSymbols: false
3102
3148
 
3103
3149
  Style/HashTransformKeys:
3104
- Description: 'Prefer `transform_keys` over `each_with_object` and `map`.'
3150
+ Description: 'Prefer `transform_keys` over `each_with_object`, `map`, or `to_h`.'
3105
3151
  Enabled: 'pending'
3106
3152
  VersionAdded: '0.80'
3153
+ VersionChanged: '0.90'
3107
3154
  Safe: false
3108
3155
 
3109
3156
  Style/HashTransformValues:
3110
- Description: 'Prefer `transform_values` over `each_with_object` and `map`.'
3157
+ Description: 'Prefer `transform_values` over `each_with_object`, `map`, or `to_h`.'
3111
3158
  Enabled: 'pending'
3112
3159
  VersionAdded: '0.80'
3160
+ VersionChanged: '0.90'
3113
3161
  Safe: false
3114
3162
 
3115
3163
  Style/IdenticalConditionalBranches:
@@ -3206,6 +3254,12 @@ Style/IpAddresses:
3206
3254
  - "::"
3207
3255
  # :: is a valid IPv6 address, but could potentially be legitimately in code
3208
3256
 
3257
+ Style/KeywordParametersOrder:
3258
+ Description: 'Enforces that optional keyword parameters are placed at the end of the parameters list.'
3259
+ StyleGuide: '#keyword-parameters-order'
3260
+ Enabled: pending
3261
+ VersionAdded: '0.90'
3262
+
3209
3263
  Style/Lambda:
3210
3264
  Description: 'Use the new lambda literal syntax for single-line blocks.'
3211
3265
  StyleGuide: '#lambda-multi-line'
@@ -3579,7 +3633,6 @@ Style/NumericPredicate:
3579
3633
  # object. Switching these methods has to be done with knowledge of the types
3580
3634
  # of the variables which rubocop doesn't have.
3581
3635
  SafeAutoCorrect: false
3582
- AutoCorrect: false
3583
3636
  Enabled: true
3584
3637
  VersionAdded: '0.42'
3585
3638
  VersionChanged: '0.59'
@@ -3595,12 +3648,13 @@ Style/NumericPredicate:
3595
3648
 
3596
3649
  Style/OneLineConditional:
3597
3650
  Description: >-
3598
- Favor the ternary operator(?:) over
3599
- if/then/else/end constructs.
3651
+ Favor the ternary operator (?:) or multi-line constructs over
3652
+ single-line if/then/else/end constructs.
3600
3653
  StyleGuide: '#ternary-operator'
3601
3654
  Enabled: true
3655
+ AlwaysCorrectToMultiline: false
3602
3656
  VersionAdded: '0.9'
3603
- VersionChanged: '0.38'
3657
+ VersionChanged: '0.90'
3604
3658
 
3605
3659
  Style/OptionHash:
3606
3660
  Description: "Don't use option hashes when you can use keyword arguments."
@@ -3831,6 +3885,12 @@ Style/RedundantSelf:
3831
3885
  VersionAdded: '0.10'
3832
3886
  VersionChanged: '0.13'
3833
3887
 
3888
+ Style/RedundantSelfAssignment:
3889
+ Description: 'Checks for places where redundant assignments are made for in place modification methods.'
3890
+ Enabled: pending
3891
+ Safe: false
3892
+ VersionAdded: '0.90'
3893
+
3834
3894
  Style/RedundantSort:
3835
3895
  Description: >-
3836
3896
  Use `min` instead of `sort.first`,
@@ -3983,6 +4043,14 @@ Style/SlicingWithRange:
3983
4043
  VersionAdded: '0.83'
3984
4044
  Safe: false
3985
4045
 
4046
+ Style/SoleNestedConditional:
4047
+ Description: >-
4048
+ Finds sole nested conditional nodes
4049
+ which can be merged into outer conditional node.
4050
+ Enabled: pending
4051
+ VersionAdded: '0.89'
4052
+ AllowModifier: false
4053
+
3986
4054
  Style/SpecialGlobalVars:
3987
4055
  Description: 'Avoid Perl-style global variables.'
3988
4056
  StyleGuide: '#no-cryptic-perlisms'
@@ -22,9 +22,17 @@ end
22
22
  # Chefstyle patches the RuboCop tool to set a new default configuration that
23
23
  # is vendored in the Chefstyle codebase.
24
24
  module Chefstyle
25
- # @return [String] the absolute path to the main RuboCop configuration YAML
26
- # file
25
+ # @return [String] the absolute path to the main RuboCop configuration YAML file
27
26
  def self.config
28
27
  RuboCop::ConfigLoader::DEFAULT_FILE
29
28
  end
30
29
  end
30
+
31
+ require_relative "rubocop/chef"
32
+
33
+ # Chef custom cops
34
+ Dir.glob(File.dirname(__FILE__) + "/rubocop/cop/chef/**/*.rb") do |file|
35
+ next if File.directory?(file)
36
+
37
+ require_relative file # not actually relative but require_relative is faster
38
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
  module Chefstyle
3
- VERSION = "1.2.1"
4
- RUBOCOP_VERSION = "0.89.1"
3
+ VERSION = "1.3.2"
4
+ RUBOCOP_VERSION = "0.90"
5
5
  end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+ module RuboCop
3
+ # RuboCop Chef project namespace
4
+ module Chef
5
+ PROJECT_ROOT = Pathname.new(__dir__).parent.parent.expand_path.freeze
6
+ CONFIG_DEFAULT = PROJECT_ROOT.join("config", "chefstyle.yml").freeze
7
+ CONFIG = YAML.load(CONFIG_DEFAULT.read).freeze
8
+
9
+ private_constant(*constants(false))
10
+ end
11
+ end
@@ -0,0 +1,46 @@
1
+ # frozen_string_literal: true
2
+ #
3
+ # Copyright:: 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 ChefRuby
23
+ # Rubygems does not need to be required in a Gemspec. It's already loaded out of the box in Ruby now.
24
+ class GemspecRequireRubygems < Base
25
+ extend RuboCop::Cop::AutoCorrector
26
+ include RangeHelp
27
+
28
+ MSG = "Rubygems does not need to be required in a Gemspec. It's already loaded out of the box in Ruby now."
29
+
30
+ def_node_matcher :require_rubygems?, <<-PATTERN
31
+ (send nil? :require (str "rubygems") )
32
+ PATTERN
33
+
34
+ def on_send(node)
35
+ require_rubygems?(node) do |r|
36
+ node = node.parent if node.parent && node.parent.conditional? # make sure we identify conditionals on the require
37
+ add_offense(node.loc.expression, message: MSG, severity: :refactor) do |corrector|
38
+ corrector.remove(range_with_surrounding_space(range: node.loc.expression, side: :left))
39
+ end
40
+ end
41
+ end
42
+ end
43
+ end
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,54 @@
1
+ # frozen_string_literal: true
2
+ #
3
+ # Copyright:: 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 ChefRuby
23
+ # net/https is deprecated and just includes net/http and openssl. We should include those directly instead.
24
+ #
25
+ # @example
26
+ #
27
+ # # bad
28
+ # require 'net/https'
29
+ #
30
+ # # good
31
+ # require 'net/http'
32
+ # require 'openssl'
33
+ #
34
+ class RequireNetHttps < Base
35
+ extend RuboCop::Cop::AutoCorrector
36
+
37
+ MSG = "net/https is deprecated and just includes net/http and openssl. We should include those directly instead."
38
+
39
+ def_node_matcher :require_net_https?, <<-PATTERN
40
+ (send nil? :require (str "net/https"))
41
+ PATTERN
42
+
43
+ def on_send(node)
44
+ require_net_https?(node) do
45
+ add_offense(node.loc.expression, message: MSG, severity: :refactor) do |corrector|
46
+ corrector.replace(node, %Q{require "net/http"\nrequire "openssl"})
47
+ end
48
+ end
49
+ end
50
+ end
51
+ end
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,57 @@
1
+ # frozen_string_literal: true
2
+ #
3
+ # Copyright:: 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 ChefRuby
23
+ # Pass options to shell_out helpers without the brackets to avoid Ruby 2.7 deprecation warnings.
24
+ #
25
+ # @example
26
+ #
27
+ # # bad
28
+ # shell_out!('hostnamectl status', { returns: [0, 1] })
29
+ # shell_out('hostnamectl status', { returns: [0, 1] })
30
+ #
31
+ # # good
32
+ # shell_out!('hostnamectl status', returns: [0, 1])
33
+ # shell_out('hostnamectl status', returns: [0, 1])
34
+ #
35
+ class Ruby27KeywordArgumentWarnings < Base
36
+ extend RuboCop::Cop::AutoCorrector
37
+
38
+ MSG = "Pass options to shell_out helpers without the brackets to avoid Ruby 2.7 deprecation warnings."
39
+
40
+ def_node_matcher :positional_shellout?, <<-PATTERN
41
+ (send nil? {:shell_out :shell_out!} ... $(hash ... ))
42
+ PATTERN
43
+
44
+ def on_send(node)
45
+ positional_shellout?(node) do |h|
46
+ next unless h.braces?
47
+
48
+ add_offense(h.loc.expression, message: MSG, severity: :refactor) do |corrector|
49
+ corrector.replace(h.loc.expression, h.loc.expression.source[1..-2])
50
+ end
51
+ end
52
+ end
53
+ end
54
+ end
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,121 @@
1
+ # frozen_string_literal: true
2
+ #
3
+ # Copyright:: 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 ChefRuby
23
+ # Rubygems is VERY slow to require gems even if they've already been loaded. To work around this
24
+ # wrap your require statement with an `if defined?()` check.
25
+ #
26
+ class UnlessDefinedRequire < Base
27
+ extend RuboCop::Cop::AutoCorrector
28
+
29
+ MSG = "Workaround rubygems slow requires by only running require if the class isn't already defined"
30
+
31
+ REQUIRE_TO_CLASS = {
32
+ "addressable/uri" => "Addressable::URI",
33
+ "appscript" => "Appscript",
34
+ "base64" => "Base64",
35
+ "benchmark" => "Benchmark",
36
+ "cgi" => "CGI",
37
+ "chef-utils" => "ChefUtils",
38
+ "csv" => "CSV",
39
+ "digest" => "Digest",
40
+ "digest/md5" => "Digest::MD5",
41
+ "digest/sha1" => "Digest::SHA1",
42
+ "digest/sha2" => "Digest::SHA2",
43
+ "droplet_kit" => "DropletKit",
44
+ "erb" => "Erb",
45
+ "erubis" => "Erubis",
46
+ "etc" => "Etc",
47
+ "excon" => "Excon",
48
+ "faraday" => "Faraday",
49
+ "ffi_yajl" => "FFI_Yajl",
50
+ "ffi" => "FFI",
51
+ "fileutils" => "FileUtils",
52
+ "find" => "Find.find",
53
+ "forwardable" => "Forwardable",
54
+ "ipaddr" => "IPAddr",
55
+ "json" => "JSON",
56
+ "mime/types" => "MIME::Types",
57
+ "mixlib/archive" => "Mixlib::Archive",
58
+ "mixlib/cli" => "Mixlib::CLI",
59
+ "mixlib/config" => "Mixlib::Config",
60
+ "mixlib/shellout" => "Mixlib::ShellOut",
61
+ "multi_json" => "MultiJson",
62
+ "net/http" => "Net::HTTP",
63
+ "net/ssh" => "Net::SSH",
64
+ "netaddr" => "NetAddr",
65
+ "nokogiri" => "Nokogiri",
66
+ "ohai" => "Ohai::System",
67
+ "open-uri" => "OpenURI",
68
+ "openssl" => "OpenSSL",
69
+ "optparse" => "OptionParser",
70
+ "ostruct" => "OpenStruct",
71
+ "pathname" => "Pathname",
72
+ "pp" => "PP",
73
+ "rack" => "Rack",
74
+ "rbconfig" => "RbConfig",
75
+ "retryable" => "Retryable",
76
+ "rexml/document" => "REXML::Document",
77
+ "rubygems" => "Gem",
78
+ "rubygems/package" => "Gem::Package",
79
+ "securerandom" => "SecureRandom",
80
+ "set" => "Set",
81
+ "shellwords" => "Shellwords",
82
+ "singleton" => "Singleton",
83
+ "socket" => "Socket",
84
+ "sslshake" => "SSLShake",
85
+ "stringio" => "StringIO",
86
+ "tempfile" => "Tempfile",
87
+ "thor" => "Thor",
88
+ "time" => "Time.zone_offset",
89
+ "timeout" => "Timeout",
90
+ "tmpdir" => "Dir.mktmpdir",
91
+ "tomlrb" => "Tomlrb",
92
+ "uri" => "URI",
93
+ "webrick" => "WEBrick",
94
+ "win32/registry" => "Win32::Registry",
95
+ "win32ole" => "WIN32OLE",
96
+ "winrm" => "WinRM::Connection",
97
+ "yaml" => "YAML",
98
+ "yard" => "YARD",
99
+ "zip" => "Zip",
100
+ "zlib" => "Zlib",
101
+ }.freeze
102
+
103
+ def_node_matcher :require?, <<-PATTERN
104
+ (send nil? :require (str $_) )
105
+ PATTERN
106
+
107
+ def on_send(node)
108
+ require?(node) do |r|
109
+ next if node.parent && node.parent.conditional? # catch both if and unless
110
+ next unless REQUIRE_TO_CLASS[r]
111
+
112
+ add_offense(node.loc.expression, message: MSG, severity: :refactor) do |corrector|
113
+ corrector.replace(node.loc.expression, "#{node.source} unless defined?(#{REQUIRE_TO_CLASS[r]})")
114
+ end
115
+ end
116
+ end
117
+ end
118
+ end
119
+ end
120
+ end
121
+ end
metadata CHANGED
@@ -1,71 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: chefstyle
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.1
4
+ version: 1.3.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chef Software, Inc.
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-08-10 00:00:00.000000000 Z
11
+ date: 2020-09-01 00:00:00.000000000 Z
12
12
  dependencies:
13
- - !ruby/object:Gem::Dependency
14
- name: bundler
15
- requirement: !ruby/object:Gem::Requirement
16
- requirements:
17
- - - ">="
18
- - !ruby/object:Gem::Version
19
- version: '0'
20
- type: :development
21
- prerelease: false
22
- version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
24
- - - ">="
25
- - !ruby/object:Gem::Version
26
- version: '0'
27
- - !ruby/object:Gem::Dependency
28
- name: rake
29
- requirement: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - ">="
32
- - !ruby/object:Gem::Version
33
- version: '12.0'
34
- type: :development
35
- prerelease: false
36
- version_requirements: !ruby/object:Gem::Requirement
37
- requirements:
38
- - - ">="
39
- - !ruby/object:Gem::Version
40
- version: '12.0'
41
- - !ruby/object:Gem::Dependency
42
- name: rspec
43
- requirement: !ruby/object:Gem::Requirement
44
- requirements:
45
- - - ">="
46
- - !ruby/object:Gem::Version
47
- version: '0'
48
- type: :development
49
- prerelease: false
50
- version_requirements: !ruby/object:Gem::Requirement
51
- requirements:
52
- - - ">="
53
- - !ruby/object:Gem::Version
54
- version: '0'
55
13
  - !ruby/object:Gem::Dependency
56
14
  name: rubocop
57
15
  requirement: !ruby/object:Gem::Requirement
58
16
  requirements:
59
17
  - - '='
60
18
  - !ruby/object:Gem::Version
61
- version: 0.89.1
19
+ version: '0.90'
62
20
  type: :runtime
63
21
  prerelease: false
64
22
  version_requirements: !ruby/object:Gem::Requirement
65
23
  requirements:
66
24
  - - '='
67
25
  - !ruby/object:Gem::Version
68
- version: 0.89.1
26
+ version: '0.90'
69
27
  description:
70
28
  email:
71
29
  - oss@chef.io
@@ -83,6 +41,11 @@ files:
83
41
  - config/upstream.yml
84
42
  - lib/chefstyle.rb
85
43
  - lib/chefstyle/version.rb
44
+ - lib/rubocop/chef.rb
45
+ - lib/rubocop/cop/chef/ruby/gemspec_require_rubygems.rb
46
+ - lib/rubocop/cop/chef/ruby/require_net_https.rb
47
+ - lib/rubocop/cop/chef/ruby/ruby_27_keyword_argument_warnings.rb
48
+ - lib/rubocop/cop/chef/ruby/unless_defined_require.rb
86
49
  homepage: https://github.com/chef/chefstyle
87
50
  licenses:
88
51
  - Apache-2.0