chefstyle 1.2.1 → 1.4.4

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: d720ee7f411ec4e21714e8caca7822a67440deae3ad360a3c9591749b4cc17e8
4
+ data.tar.gz: 8cee92cb7017f748d6b55c4c7c87b7a4d3c0a88db3051e47c20fe208421e386b
5
5
  SHA512:
6
- metadata.gz: c9cbd2f2fe158de67c16ec5932f449fc9e42877ddffe9e4e7f29881c05a645188f197241a930ddd4b51ffd2a75c38a726032a4e98fb22d922f8a755633a294d3
7
- data.tar.gz: c439d8ae28a519fdd8190a13546db53f820ea46c8bcbd56eb8f676cf6b5f04b485d09a4da9ff52de1f46144aa00a6d0fda2cf60d377300f003a1a079a434d548
6
+ metadata.gz: 84accab6836d7c5ca64b75f257262ecf66f0aad405aec5683aa11c379a5dbb0dfce677635b13f33d2ca95262708d7729f32eae9c06a493d6e4295c8a082b14ef
7
+ data.tar.gz: 0d905d5e1da9b5dc5332e56ddec2a60c480faa085efb1982b5bfed067d33e6a9863a014aafb81bfb35b7609f9b25b31e6dd00aa497e17eb8fd611e42d2ec0b8e
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env ruby
2
2
  # frozen_string_literal: true
3
- $LOAD_PATH.unshift File.join(File.dirname(__FILE__), %w{.. lib})
3
+ $LOAD_PATH.unshift File.join(__dir__, %w{.. lib})
4
4
 
5
5
  require "chefstyle"
6
6
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
- lib = File.expand_path("../lib", __FILE__)
2
+ lib = File.expand_path("lib", __dir__)
3
3
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
  require "chefstyle/version"
5
5
 
@@ -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,64 @@ 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
+ # alert on invalid ruby synatx
637
+ Lint/Syntax:
638
+ Enabled: true
639
+
640
+ # remove extra requires like 'thread'
641
+ Lint/RedundantRequireStatement:
642
+ Enabled: true
643
+
644
+ # simplify stripping strings
645
+ Style/Strip:
646
+ Enabled: true
647
+
648
+ # simplify getting min/max
649
+ Style/RedundantSort:
650
+ Enabled: true
651
+
652
+ # no need for .rb in requires
653
+ Style/RedundantFileExtensionInRequire:
654
+ Enabled: true
655
+
656
+ # more code you don't need
657
+ Style/RedundantCondition:
658
+ Enabled: true
659
+
660
+ # Use __dir__ to simplify things
661
+ Style/Dir:
662
+ Enabled: true
663
+
664
+ # Use __FILE__ or __dir__ to simplify expand_paths
665
+ Style/ExpandPathArguments:
666
+ Enabled: true
667
+
668
+ # more code you don't need
669
+ Lint/RedundantSafeNavigation:
670
+ Enabled: true
671
+
672
+ ChefRuby/Ruby27KeywordArgumentWarnings:
673
+ Description: Pass options to shell_out helpers without the brackets to avoid Ruby 2.7 deprecation warnings.
674
+ Enabled: true
675
+ VersionAdded: '1.3.0'
676
+
677
+ ChefRuby/UnlessDefinedRequire:
678
+ Description: Workaround RubyGems' slow requires by only running require if the constant isn't already defined
679
+ Enabled: true
680
+ VersionAdded: '1.3.0'
681
+ Include:
682
+ - 'lib/**/*'
683
+
684
+ ChefRuby/GemspecRequireRubygems:
685
+ Description: Rubygems does not need to be required in a Gemspec
686
+ Enabled: true
687
+ VersionAdded: '1.3.0'
688
+ Include:
689
+ - '**/*.gemspec'
690
+
691
+ ChefRuby/RequireNetHttps:
692
+ Description: net/https is deprecated and just includes net/http and openssl. We should include those directly instead
693
+ Enabled: true
694
+ VersionAdded: '1.3.0'
@@ -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:
@@ -53,6 +55,8 @@ Layout/EmptyLineAfterGuardClause:
53
55
  Enabled: false
54
56
  Layout/EmptyLineAfterMagicComment:
55
57
  Enabled: false
58
+ Layout/EmptyLineAfterMultilineCondition:
59
+ Enabled: false
56
60
  Layout/EmptyLineBetweenDefs:
57
61
  Enabled: false
58
62
  Layout/EmptyLinesAroundAccessModifier:
@@ -213,6 +217,8 @@ Lint/BooleanSymbol:
213
217
  Enabled: false
214
218
  Lint/CircularArgumentReference:
215
219
  Enabled: false
220
+ Lint/ConstantDefinitionInBlock:
221
+ Enabled: false
216
222
  Lint/ConstantResolution:
217
223
  Enabled: false
218
224
  Lint/Debugger:
@@ -231,6 +237,8 @@ Lint/DuplicateHashKey:
231
237
  Enabled: false
232
238
  Lint/DuplicateMethods:
233
239
  Enabled: false
240
+ Lint/DuplicateRequire:
241
+ Enabled: false
234
242
  Lint/DuplicateRescueException:
235
243
  Enabled: false
236
244
  Lint/EachWithObjectArgument:
@@ -243,6 +251,8 @@ Lint/EmptyEnsure:
243
251
  Enabled: false
244
252
  Lint/EmptyExpression:
245
253
  Enabled: false
254
+ Lint/EmptyFile:
255
+ Enabled: false
246
256
  Lint/EmptyInterpolation:
247
257
  Enabled: false
248
258
  Lint/EmptyWhen:
@@ -259,8 +269,12 @@ Lint/FloatOutOfRange:
259
269
  Enabled: false
260
270
  Lint/FormatParameterMismatch:
261
271
  Enabled: false
272
+ Lint/HashCompareByIdentity:
273
+ Enabled: false
262
274
  Lint/HeredocMethodCallPosition:
263
275
  Enabled: false
276
+ Lint/IdentityComparison:
277
+ Enabled: false
264
278
  Lint/ImplicitStringConcatenation:
265
279
  Enabled: false
266
280
  Lint/InheritException:
@@ -315,6 +329,8 @@ Lint/RedundantCopEnableDirective:
315
329
  Enabled: false
316
330
  Lint/RedundantRequireStatement:
317
331
  Enabled: false
332
+ Lint/RedundantSafeNavigation:
333
+ Enabled: false
318
334
  Lint/RedundantSplatExpansion:
319
335
  Enabled: false
320
336
  Lint/RedundantStringCoercion:
@@ -361,6 +377,8 @@ Lint/ToJSON:
361
377
  Enabled: false
362
378
  Lint/TopLevelReturnWithArgument:
363
379
  Enabled: false
380
+ Lint/TrailingCommaInAttributeDeclaration:
381
+ Enabled: false
364
382
  Lint/UnderscorePrefixedVariableName:
365
383
  Enabled: false
366
384
  Lint/UnifiedInteger:
@@ -383,8 +401,12 @@ Lint/UselessAssignment:
383
401
  Enabled: false
384
402
  Lint/UselessElseWithoutRescue:
385
403
  Enabled: false
404
+ Lint/UselessMethodDefinition:
405
+ Enabled: false
386
406
  Lint/UselessSetterCall:
387
407
  Enabled: false
408
+ Lint/UselessTimes:
409
+ Enabled: false
388
410
  Lint/Void:
389
411
  Enabled: false
390
412
  Metrics/CyclomaticComplexity:
@@ -475,8 +497,12 @@ Style/ClassAndModuleChildren:
475
497
  Enabled: false
476
498
  Style/ClassCheck:
477
499
  Enabled: false
500
+ Style/ClassEqualityComparison:
501
+ Enabled: false
478
502
  Style/ClassMethods:
479
503
  Enabled: false
504
+ Style/ClassMethodsDefinitions:
505
+ Enabled: false
480
506
  Style/ClassVars:
481
507
  Enabled: false
482
508
  Style/CollectionMethods:
@@ -485,6 +511,8 @@ Style/ColonMethodCall:
485
511
  Enabled: false
486
512
  Style/ColonMethodDefinition:
487
513
  Enabled: false
514
+ Style/CombinableLoops:
515
+ Enabled: false
488
516
  Style/CommandLiteral:
489
517
  Enabled: false
490
518
  Style/CommentAnnotation:
@@ -591,6 +619,8 @@ Style/InlineComment:
591
619
  Enabled: false
592
620
  Style/IpAddresses:
593
621
  Enabled: false
622
+ Style/KeywordParametersOrder:
623
+ Enabled: false
594
624
  Style/Lambda:
595
625
  Enabled: false
596
626
  Style/LambdaCall:
@@ -607,6 +637,10 @@ Style/RedundantFetchBlock:
607
637
  Enabled: false
608
638
  Style/RedundantFileExtensionInRequire:
609
639
  Enabled: false
640
+ Style/RedundantSelfAssignment:
641
+ Enabled: false
642
+ Style/SoleNestedConditional:
643
+ Enabled: false
610
644
  Style/MethodCalledOnDoEndBlock:
611
645
  Enabled: false
612
646
  Style/MethodDefParentheses:
@@ -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
@@ -399,7 +414,6 @@ Layout/DefEndAlignment:
399
414
  SupportedStylesAlignWith:
400
415
  - start_of_line
401
416
  - def
402
- AutoCorrect: false
403
417
  Severity: warning
404
418
 
405
419
  Layout/DotPosition:
@@ -436,6 +450,14 @@ Layout/EmptyLineAfterMagicComment:
436
450
  Enabled: true
437
451
  VersionAdded: '0.49'
438
452
 
453
+ Layout/EmptyLineAfterMultilineCondition:
454
+ Description: 'Enforces empty line after multiline condition.'
455
+ # This is disabled, because this style is not very common in practice.
456
+ Enabled: false
457
+ VersionAdded: '0.90'
458
+ Reference:
459
+ - https://github.com/airbnb/ruby#multiline-if-newline
460
+
439
461
  Layout/EmptyLineBetweenDefs:
440
462
  Description: 'Use empty lines between defs.'
441
463
  StyleGuide: '#empty-lines-between-methods'
@@ -555,7 +577,6 @@ Layout/EndAlignment:
555
577
  - keyword
556
578
  - variable
557
579
  - start_of_line
558
- AutoCorrect: false
559
580
  Severity: warning
560
581
 
561
582
  Layout/EndOfLine:
@@ -1374,6 +1395,12 @@ Lint/CircularArgumentReference:
1374
1395
  Enabled: true
1375
1396
  VersionAdded: '0.33'
1376
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
+
1377
1404
  Lint/ConstantResolution:
1378
1405
  Description: 'Check that constants are fully qualified with `::`.'
1379
1406
  Enabled: false
@@ -1427,6 +1454,11 @@ Lint/DuplicateMethods:
1427
1454
  Enabled: true
1428
1455
  VersionAdded: '0.29'
1429
1456
 
1457
+ Lint/DuplicateRequire:
1458
+ Description: 'Check for duplicate `require`s and `require_relative`s.'
1459
+ Enabled: pending
1460
+ VersionAdded: '0.90'
1461
+
1430
1462
  Lint/DuplicateRescueException:
1431
1463
  Description: 'Checks that there are no repeated exceptions used in `rescue` expressions.'
1432
1464
  Enabled: pending
@@ -1453,13 +1485,18 @@ Lint/EmptyEnsure:
1453
1485
  Enabled: true
1454
1486
  VersionAdded: '0.10'
1455
1487
  VersionChanged: '0.48'
1456
- AutoCorrect: false
1457
1488
 
1458
1489
  Lint/EmptyExpression:
1459
1490
  Description: 'Checks for empty expressions.'
1460
1491
  Enabled: true
1461
1492
  VersionAdded: '0.45'
1462
1493
 
1494
+ Lint/EmptyFile:
1495
+ Description: 'Enforces that Ruby source files are not empty.'
1496
+ Enabled: pending
1497
+ AllowComments: true
1498
+ VersionAdded: '0.90'
1499
+
1463
1500
  Lint/EmptyInterpolation:
1464
1501
  Description: 'Checks for empty string interpolation.'
1465
1502
  Enabled: true
@@ -1509,6 +1546,13 @@ Lint/FormatParameterMismatch:
1509
1546
  Enabled: true
1510
1547
  VersionAdded: '0.33'
1511
1548
 
1549
+ Lint/HashCompareByIdentity:
1550
+ Description: 'Prefer using `Hash#compare_by_identity` than using `object_id` for keys.'
1551
+ StyleGuide: '#identity-comparison'
1552
+ Enabled: pending
1553
+ Safe: false
1554
+ VersionAdded: '0.93'
1555
+
1512
1556
  Lint/HeredocMethodCallPosition:
1513
1557
  Description: >-
1514
1558
  Checks for the ordering of a method call where
@@ -1517,6 +1561,12 @@ Lint/HeredocMethodCallPosition:
1517
1561
  StyleGuide: '#heredoc-method-calls'
1518
1562
  VersionAdded: '0.68'
1519
1563
 
1564
+ Lint/IdentityComparison:
1565
+ Description: 'Prefer `equal?` over `==` when comparing `object_id`.'
1566
+ Enabled: pending
1567
+ StyleGuide: '#identity-comparison'
1568
+ VersionAdded: '0.91'
1569
+
1520
1570
  Lint/ImplicitStringConcatenation:
1521
1571
  Description: >-
1522
1572
  Checks for adjacent string literals on the same line, which
@@ -1703,6 +1753,21 @@ Lint/RedundantRequireStatement:
1703
1753
  Enabled: true
1704
1754
  VersionAdded: '0.76'
1705
1755
 
1756
+ Lint/RedundantSafeNavigation:
1757
+ Description: 'Checks for redundant safe navigation calls.'
1758
+ Enabled: pending
1759
+ VersionAdded: '0.93'
1760
+ Safe: false
1761
+ IgnoredMethods:
1762
+ - to_c
1763
+ - to_f
1764
+ - to_i
1765
+ - to_r
1766
+ - rationalize
1767
+ - public_send
1768
+ - send
1769
+ - __send__
1770
+
1706
1771
  Lint/RedundantSplatExpansion:
1707
1772
  Description: 'Checks for splat unnecessarily being called on literals.'
1708
1773
  Enabled: true
@@ -1768,6 +1833,7 @@ Lint/SafeNavigationChain:
1768
1833
  - presence
1769
1834
  - try
1770
1835
  - try!
1836
+ - in?
1771
1837
 
1772
1838
  Lint/SafeNavigationConsistency:
1773
1839
  Description: >-
@@ -1856,6 +1922,11 @@ Lint/TopLevelReturnWithArgument:
1856
1922
  Enabled: 'pending'
1857
1923
  VersionAdded: '0.89'
1858
1924
 
1925
+ Lint/TrailingCommaInAttributeDeclaration:
1926
+ Description: 'This cop checks for trailing commas in attribute declarations.'
1927
+ Enabled: pending
1928
+ VersionAdded: '0.90'
1929
+
1859
1930
  Lint/UnderscorePrefixedVariableName:
1860
1931
  Description: 'Do not use prefix `_` for a variable that is used.'
1861
1932
  Enabled: true
@@ -1931,6 +2002,13 @@ Lint/UselessElseWithoutRescue:
1931
2002
  Enabled: true
1932
2003
  VersionAdded: '0.17'
1933
2004
 
2005
+ Lint/UselessMethodDefinition:
2006
+ Description: 'Checks for useless method definitions.'
2007
+ Enabled: pending
2008
+ VersionAdded: '0.90'
2009
+ Safe: false
2010
+ AllowComments: true
2011
+
1934
2012
  Lint/UselessSetterCall:
1935
2013
  Description: 'Checks for useless setter call to a local variable.'
1936
2014
  Enabled: true
@@ -1938,6 +2016,12 @@ Lint/UselessSetterCall:
1938
2016
  VersionChanged: '0.80'
1939
2017
  Safe: false
1940
2018
 
2019
+ Lint/UselessTimes:
2020
+ Description: 'Checks for useless `Integer#times` calls.'
2021
+ Enabled: pending
2022
+ VersionAdded: '0.91'
2023
+ Safe: false
2024
+
1941
2025
  Lint/Void:
1942
2026
  Description: 'Possible use of operator/literal/variable in void context.'
1943
2027
  Enabled: true
@@ -2401,7 +2485,7 @@ Style/ArrayCoercion:
2401
2485
  with a variable you want to treat as an Array, but you're not certain it's an array.
2402
2486
  StyleGuide: '#array-coercion'
2403
2487
  Safe: false
2404
- Enabled: 'pending'
2488
+ Enabled: false
2405
2489
  VersionAdded: '0.88'
2406
2490
 
2407
2491
  Style/ArrayJoin:
@@ -2591,6 +2675,7 @@ Style/CaseLikeIf:
2591
2675
  Description: 'This cop identifies places where `if-elsif` constructions can be replaced with `case-when`.'
2592
2676
  StyleGuide: '#case-vs-if-else'
2593
2677
  Enabled: 'pending'
2678
+ Safe: false
2594
2679
  VersionAdded: '0.88'
2595
2680
 
2596
2681
  Style/CharacterLiteral:
@@ -2608,7 +2693,6 @@ Style/ClassAndModuleChildren:
2608
2693
  # have the knowledge to perform either operation safely and thus requires
2609
2694
  # manual oversight.
2610
2695
  SafeAutoCorrect: false
2611
- AutoCorrect: false
2612
2696
  Enabled: true
2613
2697
  VersionAdded: '0.19'
2614
2698
  #
@@ -2640,6 +2724,16 @@ Style/ClassCheck:
2640
2724
  - is_a?
2641
2725
  - kind_of?
2642
2726
 
2727
+ Style/ClassEqualityComparison:
2728
+ Description: 'Enforces the use of `Object#instance_of?` instead of class comparison for equality.'
2729
+ StyleGuide: '#instance-of-vs-class-comparison'
2730
+ Enabled: pending
2731
+ VersionAdded: '0.93'
2732
+ IgnoredMethods:
2733
+ - ==
2734
+ - equal?
2735
+ - eql?
2736
+
2643
2737
  Style/ClassMethods:
2644
2738
  Description: 'Use self when defining module/class methods.'
2645
2739
  StyleGuide: '#def-self-class-methods'
@@ -2647,6 +2741,16 @@ Style/ClassMethods:
2647
2741
  VersionAdded: '0.9'
2648
2742
  VersionChanged: '0.20'
2649
2743
 
2744
+ Style/ClassMethodsDefinitions:
2745
+ Description: 'Enforces using `def self.method_name` or `class << self` to define class methods.'
2746
+ StyleGuide: '#def-self-class-methods'
2747
+ Enabled: false
2748
+ VersionAdded: '0.89'
2749
+ EnforcedStyle: def_self
2750
+ SupportedStyles:
2751
+ - def_self
2752
+ - self_class
2753
+
2650
2754
  Style/ClassVars:
2651
2755
  Description: 'Avoid the use of class variables.'
2652
2756
  StyleGuide: '#no-class-vars'
@@ -2687,6 +2791,14 @@ Style/ColonMethodDefinition:
2687
2791
  Enabled: true
2688
2792
  VersionAdded: '0.52'
2689
2793
 
2794
+ Style/CombinableLoops:
2795
+ Description: >-
2796
+ Checks for places where multiple consecutive loops over the same data
2797
+ can be combined into a single loop.
2798
+ Enabled: pending
2799
+ Safe: false
2800
+ VersionAdded: '0.90'
2801
+
2690
2802
  Style/CommandLiteral:
2691
2803
  Description: 'Use `` or %x around command literals.'
2692
2804
  StyleGuide: '#percent-x'
@@ -2783,7 +2895,8 @@ Style/DateTime:
2783
2895
  StyleGuide: '#date--time'
2784
2896
  Enabled: false
2785
2897
  VersionAdded: '0.51'
2786
- VersionChanged: '0.59'
2898
+ VersionChanged: '0.92'
2899
+ SafeAutoCorrect: false
2787
2900
  AllowCoercion: false
2788
2901
 
2789
2902
  Style/DefWithParentheses:
@@ -3021,13 +3134,14 @@ Style/FrozenStringLiteralComment:
3021
3134
  # `never` will enforce that the frozen string literal comment does not
3022
3135
  # exist in a file.
3023
3136
  - never
3024
- Safe: false
3137
+ SafeAutoCorrect: false
3025
3138
 
3026
3139
  Style/GlobalStdStream:
3027
3140
  Description: 'Enforces the use of `$stdout/$stderr/$stdin` instead of `STDOUT/STDERR/STDIN`.'
3028
3141
  StyleGuide: '#global-stdout'
3029
3142
  Enabled: pending
3030
3143
  VersionAdded: '0.89'
3144
+ SafeAutoCorrect: false
3031
3145
 
3032
3146
  Style/GlobalVars:
3033
3147
  Description: 'Do not introduce global variables.'
@@ -3101,15 +3215,17 @@ Style/HashSyntax:
3101
3215
  PreferHashRocketsForNonAlnumEndingSymbols: false
3102
3216
 
3103
3217
  Style/HashTransformKeys:
3104
- Description: 'Prefer `transform_keys` over `each_with_object` and `map`.'
3218
+ Description: 'Prefer `transform_keys` over `each_with_object`, `map`, or `to_h`.'
3105
3219
  Enabled: 'pending'
3106
3220
  VersionAdded: '0.80'
3221
+ VersionChanged: '0.90'
3107
3222
  Safe: false
3108
3223
 
3109
3224
  Style/HashTransformValues:
3110
- Description: 'Prefer `transform_values` over `each_with_object` and `map`.'
3225
+ Description: 'Prefer `transform_values` over `each_with_object`, `map`, or `to_h`.'
3111
3226
  Enabled: 'pending'
3112
3227
  VersionAdded: '0.80'
3228
+ VersionChanged: '0.90'
3113
3229
  Safe: false
3114
3230
 
3115
3231
  Style/IdenticalConditionalBranches:
@@ -3200,11 +3316,22 @@ Style/IpAddresses:
3200
3316
  Description: "Don't include literal IP addresses in code."
3201
3317
  Enabled: false
3202
3318
  VersionAdded: '0.58'
3203
- VersionChanged: '0.77'
3319
+ VersionChanged: '0.91'
3204
3320
  # Allow addresses to be permitted
3205
3321
  AllowedAddresses:
3206
3322
  - "::"
3207
3323
  # :: is a valid IPv6 address, but could potentially be legitimately in code
3324
+ Exclude:
3325
+ - '**/*.gemfile'
3326
+ - '**/Gemfile'
3327
+ - '**/gems.rb'
3328
+ - '**/*.gemspec'
3329
+
3330
+ Style/KeywordParametersOrder:
3331
+ Description: 'Enforces that optional keyword parameters are placed at the end of the parameters list.'
3332
+ StyleGuide: '#keyword-parameters-order'
3333
+ Enabled: pending
3334
+ VersionAdded: '0.90'
3208
3335
 
3209
3336
  Style/Lambda:
3210
3337
  Description: 'Use the new lambda literal syntax for single-line blocks.'
@@ -3579,7 +3706,6 @@ Style/NumericPredicate:
3579
3706
  # object. Switching these methods has to be done with knowledge of the types
3580
3707
  # of the variables which rubocop doesn't have.
3581
3708
  SafeAutoCorrect: false
3582
- AutoCorrect: false
3583
3709
  Enabled: true
3584
3710
  VersionAdded: '0.42'
3585
3711
  VersionChanged: '0.59'
@@ -3595,12 +3721,13 @@ Style/NumericPredicate:
3595
3721
 
3596
3722
  Style/OneLineConditional:
3597
3723
  Description: >-
3598
- Favor the ternary operator(?:) over
3599
- if/then/else/end constructs.
3724
+ Favor the ternary operator (?:) or multi-line constructs over
3725
+ single-line if/then/else/end constructs.
3600
3726
  StyleGuide: '#ternary-operator'
3601
3727
  Enabled: true
3728
+ AlwaysCorrectToMultiline: false
3602
3729
  VersionAdded: '0.9'
3603
- VersionChanged: '0.38'
3730
+ VersionChanged: '0.90'
3604
3731
 
3605
3732
  Style/OptionHash:
3606
3733
  Description: "Don't use option hashes when you can use keyword arguments."
@@ -3631,6 +3758,8 @@ Style/OptionalBooleanParameter:
3631
3758
  Enabled: pending
3632
3759
  Safe: false
3633
3760
  VersionAdded: '0.89'
3761
+ AllowedMethods:
3762
+ - respond_to_missing?
3634
3763
 
3635
3764
  Style/OrAssignment:
3636
3765
  Description: 'Recommend usage of double pipe equals (||=) where applicable.'
@@ -3831,6 +3960,12 @@ Style/RedundantSelf:
3831
3960
  VersionAdded: '0.10'
3832
3961
  VersionChanged: '0.13'
3833
3962
 
3963
+ Style/RedundantSelfAssignment:
3964
+ Description: 'Checks for places where redundant assignments are made for in place modification methods.'
3965
+ Enabled: pending
3966
+ Safe: false
3967
+ VersionAdded: '0.90'
3968
+
3834
3969
  Style/RedundantSort:
3835
3970
  Description: >-
3836
3971
  Use `min` instead of `sort.first`,
@@ -3893,6 +4028,8 @@ Style/SafeNavigation:
3893
4028
  This cop transforms usages of a method call safeguarded by
3894
4029
  a check for the existence of the object to
3895
4030
  safe navigation (`&.`).
4031
+ Auto-correction is unsafe as it assumes the object will
4032
+ be `nil` or truthy, but never `false`.
3896
4033
  Enabled: true
3897
4034
  VersionAdded: '0.43'
3898
4035
  VersionChanged: '0.77'
@@ -3905,6 +4042,7 @@ Style/SafeNavigation:
3905
4042
  - presence
3906
4043
  - try
3907
4044
  - try!
4045
+ SafeAutoCorrect: false
3908
4046
 
3909
4047
  Style/Sample:
3910
4048
  Description: >-
@@ -3983,6 +4121,14 @@ Style/SlicingWithRange:
3983
4121
  VersionAdded: '0.83'
3984
4122
  Safe: false
3985
4123
 
4124
+ Style/SoleNestedConditional:
4125
+ Description: >-
4126
+ Finds sole nested conditional nodes
4127
+ which can be merged into outer conditional node.
4128
+ Enabled: pending
4129
+ VersionAdded: '0.89'
4130
+ AllowModifier: false
4131
+
3986
4132
  Style/SpecialGlobalVars:
3987
4133
  Description: 'Avoid Perl-style global variables.'
3988
4134
  StyleGuide: '#no-cryptic-perlisms'
@@ -9,7 +9,7 @@ module RuboCop
9
9
  class ConfigLoader
10
10
  RUBOCOP_HOME.gsub!(
11
11
  /^.*$/,
12
- File.realpath(File.join(File.dirname(__FILE__), ".."))
12
+ File.realpath(File.join(__dir__, ".."))
13
13
  )
14
14
 
15
15
  DEFAULT_FILE.gsub!(
@@ -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(__dir__ + "/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"
5
- end
3
+ VERSION = "1.4.4"
4
+ RUBOCOP_VERSION = "0.93.0"
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,122 @@
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::CANARY",
38
+ "chef-utils/dist" => "ChefUtils::Dist",
39
+ "csv" => "CSV",
40
+ "digest" => "Digest",
41
+ "digest/md5" => "Digest::MD5",
42
+ "digest/sha1" => "Digest::SHA1",
43
+ "digest/sha2" => "Digest::SHA2",
44
+ "droplet_kit" => "DropletKit",
45
+ "erb" => "Erb",
46
+ "erubis" => "Erubis",
47
+ "etc" => "Etc",
48
+ "excon" => "Excon",
49
+ "faraday" => "Faraday",
50
+ "ffi_yajl" => "FFI_Yajl",
51
+ "ffi" => "FFI",
52
+ "fileutils" => "FileUtils",
53
+ "find" => "Find.find",
54
+ "forwardable" => "Forwardable",
55
+ "ipaddr" => "IPAddr",
56
+ "json" => "JSON",
57
+ "mime/types" => "MIME::Types",
58
+ "mixlib/archive" => "Mixlib::Archive",
59
+ "mixlib/cli" => "Mixlib::CLI",
60
+ "mixlib/config" => "Mixlib::Config",
61
+ "mixlib/shellout" => "Mixlib::ShellOut",
62
+ "multi_json" => "MultiJson",
63
+ "net/http" => "Net::HTTP",
64
+ "net/ssh" => "Net::SSH",
65
+ "netaddr" => "NetAddr",
66
+ "nokogiri" => "Nokogiri",
67
+ "ohai" => "Ohai::System",
68
+ "open-uri" => "OpenURI",
69
+ "openssl" => "OpenSSL",
70
+ "optparse" => "OptionParser",
71
+ "ostruct" => "OpenStruct",
72
+ "pathname" => "Pathname",
73
+ "pp" => "PP",
74
+ "rack" => "Rack",
75
+ "rbconfig" => "RbConfig",
76
+ "retryable" => "Retryable",
77
+ "rexml/document" => "REXML::Document",
78
+ "rubygems" => "Gem",
79
+ "rubygems/package" => "Gem::Package",
80
+ "securerandom" => "SecureRandom",
81
+ "set" => "Set",
82
+ "shellwords" => "Shellwords",
83
+ "singleton" => "Singleton",
84
+ "socket" => "Socket",
85
+ "sslshake" => "SSLShake",
86
+ "stringio" => "StringIO",
87
+ "tempfile" => "Tempfile",
88
+ "thor" => "Thor",
89
+ "time" => "Time.zone_offset",
90
+ "timeout" => "Timeout",
91
+ "tmpdir" => "Dir.mktmpdir",
92
+ "tomlrb" => "Tomlrb",
93
+ "uri" => "URI",
94
+ "webrick" => "WEBrick",
95
+ "win32/registry" => "Win32::Registry",
96
+ "win32ole" => "WIN32OLE",
97
+ "winrm" => "WinRM::Connection",
98
+ "yard" => "YARD",
99
+ "zip" => "Zip",
100
+ "zlib" => "Zlib",
101
+ "pastel" => "Pastel",
102
+ }.freeze
103
+
104
+ def_node_matcher :require?, <<-PATTERN
105
+ (send nil? :require (str $_) )
106
+ PATTERN
107
+
108
+ def on_send(node)
109
+ require?(node) do |r|
110
+ next if node.parent && node.parent.conditional? # catch both if and unless
111
+ next unless REQUIRE_TO_CLASS[r]
112
+
113
+ add_offense(node.loc.expression, message: MSG, severity: :refactor) do |corrector|
114
+ corrector.replace(node.loc.expression, "#{node.source} unless defined?(#{REQUIRE_TO_CLASS[r]})")
115
+ end
116
+ end
117
+ end
118
+ end
119
+ end
120
+ end
121
+ end
122
+ 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.4.4
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-10-08 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.93.0
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.93.0
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