chefstyle 1.2.0 → 1.4.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 16247205f8d2e388a3ac7c5a4336c245cc549c15b9398b5386ca99cf05baccfd
4
- data.tar.gz: fd8755fc0d427637a9b1945a335eb3b3469d51d40b998aaf8e97ef872b7207bb
3
+ metadata.gz: 4c8fc8e2962659e925a493a6f047c5bc497e4a02cc6a2b01f7e0291325030d42
4
+ data.tar.gz: c0c5b937798636ddf7d098d02d26b3cff23d11f26017e393cfbc33c89031c0e9
5
5
  SHA512:
6
- metadata.gz: c8e4b623134b357308f474ffcfe4f4ec4aa5b93b05f3a86218f8b824f6c6be31d78470cb89a87735e02744d147ac6d727b21e71183a43a8a24739940e26fa6f1
7
- data.tar.gz: 9118fa2012461bee7207ddd039fb6da69d6a0d85e673ce052a3c76543c38f167e3e8fa0dda142bf8193004be525a87614d17d26dd55d48327eb3555745acd8db
6
+ metadata.gz: 0a5b1c1f423ed919f78bd2438328d42f99afd80eff4929207efd46a0ce588a73524e9ef8d14e1f790b7d0db375abeaf1aca8646395ce4d18345ebb846a8281b1
7
+ data.tar.gz: 6ae21c6628190f2a371f831a39dfef3277111e2dc3c3c88686151d856b1c96f1bd2c7fbada5b04200948eed557255b94c88851c17b151697e828c5551ddfad99
@@ -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,60 @@ 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
+ ChefRuby/Ruby27KeywordArgumentWarnings:
669
+ Description: Pass options to shell_out helpers without the brackets to avoid Ruby 2.7 deprecation warnings.
670
+ Enabled: true
671
+ VersionAdded: '1.3.0'
672
+
673
+ ChefRuby/UnlessDefinedRequire:
674
+ Description: Workaround RubyGems' slow requires by only running require if the constant isn't already defined
675
+ Enabled: true
676
+ VersionAdded: '1.3.0'
677
+ Include:
678
+ - 'lib/**/*'
679
+
680
+ ChefRuby/GemspecRequireRubygems:
681
+ Description: Rubygems does not need to be required in a Gemspec
682
+ Enabled: true
683
+ VersionAdded: '1.3.0'
684
+ Include:
685
+ - '**/*.gemspec'
686
+
687
+ ChefRuby/RequireNetHttps:
688
+ Description: net/https is deprecated and just includes net/http and openssl. We should include those directly instead
689
+ Enabled: true
690
+ 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:
@@ -207,10 +211,14 @@ Lint/AssignmentInCondition:
207
211
  Enabled: false
208
212
  Lint/BigDecimalNew:
209
213
  Enabled: false
214
+ Lint/BinaryOperatorWithIdenticalOperands:
215
+ Enabled: false
210
216
  Lint/BooleanSymbol:
211
217
  Enabled: false
212
218
  Lint/CircularArgumentReference:
213
219
  Enabled: false
220
+ Lint/ConstantDefinitionInBlock:
221
+ Enabled: false
214
222
  Lint/ConstantResolution:
215
223
  Enabled: false
216
224
  Lint/Debugger:
@@ -229,14 +237,22 @@ Lint/DuplicateHashKey:
229
237
  Enabled: false
230
238
  Lint/DuplicateMethods:
231
239
  Enabled: false
240
+ Lint/DuplicateRequire:
241
+ Enabled: false
242
+ Lint/DuplicateRescueException:
243
+ Enabled: false
232
244
  Lint/EachWithObjectArgument:
233
245
  Enabled: false
234
246
  Lint/ElseLayout:
235
247
  Enabled: false
248
+ Lint/EmptyConditionalBody:
249
+ Enabled: false
236
250
  Lint/EmptyEnsure:
237
251
  Enabled: false
238
252
  Lint/EmptyExpression:
239
253
  Enabled: false
254
+ Lint/EmptyFile:
255
+ Enabled: false
240
256
  Lint/EmptyInterpolation:
241
257
  Enabled: false
242
258
  Lint/EmptyWhen:
@@ -247,12 +263,16 @@ Lint/ErbNewArguments:
247
263
  Enabled: false
248
264
  Lint/FlipFlop:
249
265
  Enabled: false
266
+ Lint/FloatComparison:
267
+ Enabled: false
250
268
  Lint/FloatOutOfRange:
251
269
  Enabled: false
252
270
  Lint/FormatParameterMismatch:
253
271
  Enabled: false
254
272
  Lint/HeredocMethodCallPosition:
255
273
  Enabled: false
274
+ Lint/IdentityComparison:
275
+ Enabled: false
256
276
  Lint/ImplicitStringConcatenation:
257
277
  Enabled: false
258
278
  Lint/InheritException:
@@ -269,6 +289,8 @@ Lint/Loop:
269
289
  Enabled: false
270
290
  Lint/MissingCopEnableDirective:
271
291
  Enabled: false
292
+ Lint/MissingSuper:
293
+ Enabled: false
272
294
  Lint/MixedRegexpCaptureTypes:
273
295
  Enabled: false
274
296
  Lint/MultipleComparison:
@@ -287,6 +309,8 @@ Lint/NumberConversion:
287
309
  Enabled: false
288
310
  Lint/OrderedMagicComments:
289
311
  Enabled: false
312
+ Lint/OutOfRangeRegexpRef:
313
+ Enabled: false
290
314
  Lint/ParenthesesAsGroupedExpression:
291
315
  Enabled: false
292
316
  Lint/PercentStringArray:
@@ -329,6 +353,8 @@ Lint/SafeNavigationWithEmpty:
329
353
  Enabled: false
330
354
  Lint/ScriptPermission:
331
355
  Enabled: false
356
+ Lint/SelfAssignment:
357
+ Enabled: false
332
358
  Lint/SendWithMixinArgument:
333
359
  Enabled: false
334
360
  Lint/ShadowedArgument:
@@ -345,12 +371,18 @@ Lint/Syntax:
345
371
  Enabled: false
346
372
  Lint/ToJSON:
347
373
  Enabled: false
374
+ Lint/TopLevelReturnWithArgument:
375
+ Enabled: false
376
+ Lint/TrailingCommaInAttributeDeclaration:
377
+ Enabled: false
348
378
  Lint/UnderscorePrefixedVariableName:
349
379
  Enabled: false
350
380
  Lint/UnifiedInteger:
351
381
  Enabled: false
352
382
  Lint/UnreachableCode:
353
383
  Enabled: false
384
+ Lint/UnreachableLoop:
385
+ Enabled: false
354
386
  Lint/UnusedBlockArgument:
355
387
  Enabled: false
356
388
  Lint/UnusedMethodArgument:
@@ -363,12 +395,14 @@ Lint/UselessAccessModifier:
363
395
  Enabled: false
364
396
  Lint/UselessAssignment:
365
397
  Enabled: false
366
- Lint/UselessComparison:
367
- Enabled: false
368
398
  Lint/UselessElseWithoutRescue:
369
399
  Enabled: false
400
+ Lint/UselessMethodDefinition:
401
+ Enabled: false
370
402
  Lint/UselessSetterCall:
371
403
  Enabled: false
404
+ Lint/UselessTimes:
405
+ Enabled: false
372
406
  Lint/Void:
373
407
  Enabled: false
374
408
  Metrics/CyclomaticComplexity:
@@ -461,6 +495,8 @@ Style/ClassCheck:
461
495
  Enabled: false
462
496
  Style/ClassMethods:
463
497
  Enabled: false
498
+ Style/ClassMethodsDefinitions:
499
+ Enabled: false
464
500
  Style/ClassVars:
465
501
  Enabled: false
466
502
  Style/CollectionMethods:
@@ -469,6 +505,8 @@ Style/ColonMethodCall:
469
505
  Enabled: false
470
506
  Style/ColonMethodDefinition:
471
507
  Enabled: false
508
+ Style/CombinableLoops:
509
+ Enabled: false
472
510
  Style/CommandLiteral:
473
511
  Enabled: false
474
512
  Style/CommentAnnotation:
@@ -523,6 +561,8 @@ Style/EvenOdd:
523
561
  Enabled: false
524
562
  Style/ExpandPathArguments:
525
563
  Enabled: false
564
+ Style/ExplicitBlockArgument:
565
+ Enabled: false
526
566
  Style/ExponentialNotation:
527
567
  Enabled: false
528
568
  Style/FloatDivision:
@@ -535,6 +575,8 @@ Style/FormatStringToken:
535
575
  Enabled: false
536
576
  Style/FrozenStringLiteralComment:
537
577
  Enabled: false
578
+ Style/GlobalStdStream:
579
+ Enabled: false
538
580
  Style/GlobalVars:
539
581
  Enabled: false
540
582
  Style/GuardClause:
@@ -571,6 +613,8 @@ Style/InlineComment:
571
613
  Enabled: false
572
614
  Style/IpAddresses:
573
615
  Enabled: false
616
+ Style/KeywordParametersOrder:
617
+ Enabled: false
574
618
  Style/Lambda:
575
619
  Enabled: false
576
620
  Style/LambdaCall:
@@ -587,12 +631,14 @@ Style/RedundantFetchBlock:
587
631
  Enabled: false
588
632
  Style/RedundantFileExtensionInRequire:
589
633
  Enabled: false
634
+ Style/RedundantSelfAssignment:
635
+ Enabled: false
636
+ Style/SoleNestedConditional:
637
+ Enabled: false
590
638
  Style/MethodCalledOnDoEndBlock:
591
639
  Enabled: false
592
640
  Style/MethodDefParentheses:
593
641
  Enabled: false
594
- Style/MethodMissingSuper:
595
- Enabled: false
596
642
  Style/MinMax:
597
643
  Enabled: false
598
644
  Style/MissingElse:
@@ -657,6 +703,8 @@ Style/OptionHash:
657
703
  Enabled: false
658
704
  Style/OptionalArguments:
659
705
  Enabled: false
706
+ Style/OptionalBooleanParameter:
707
+ Enabled: false
660
708
  Style/ParallelAssignment:
661
709
  Enabled: false
662
710
  Style/ParenthesesAroundCondition:
@@ -725,6 +773,8 @@ Style/Send:
725
773
  Enabled: false
726
774
  Style/SignalException:
727
775
  Enabled: false
776
+ Style/SingleArgumentDig:
777
+ Enabled: false
728
778
  Style/SingleLineBlockParams:
729
779
  Enabled: false
730
780
  Style/SingleLineMethods:
@@ -737,6 +787,8 @@ Style/StabbyLambdaParentheses:
737
787
  Enabled: false
738
788
  Style/StderrPuts:
739
789
  Enabled: false
790
+ Style/StringConcatenation:
791
+ Enabled: false
740
792
  Style/StringHashKeys:
741
793
  Enabled: false
742
794
  Style/StringLiterals:
@@ -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
@@ -210,9 +212,10 @@ Gemspec/OrderedDependencies:
210
212
  - '**/*.gemspec'
211
213
 
212
214
  Gemspec/RequiredRubyVersion:
213
- Description: 'Checks that `required_ruby_version` of gemspec and `TargetRubyVersion` of .rubocop.yml are equal.'
215
+ Description: 'Checks that `required_ruby_version` of gemspec is specified and equal to `TargetRubyVersion` of .rubocop.yml.'
214
216
  Enabled: true
215
217
  VersionAdded: '0.52'
218
+ VersionChanged: '0.89'
216
219
  Include:
217
220
  - '**/*.gemspec'
218
221
 
@@ -308,6 +311,19 @@ Layout/AssignmentIndentation:
308
311
  # But it can be overridden by setting this parameter
309
312
  IndentationWidth: ~
310
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
+
311
327
  Layout/BlockAlignment:
312
328
  Description: 'Align block ends correctly.'
313
329
  Enabled: true
@@ -398,7 +414,6 @@ Layout/DefEndAlignment:
398
414
  SupportedStylesAlignWith:
399
415
  - start_of_line
400
416
  - def
401
- AutoCorrect: false
402
417
  Severity: warning
403
418
 
404
419
  Layout/DotPosition:
@@ -435,6 +450,14 @@ Layout/EmptyLineAfterMagicComment:
435
450
  Enabled: true
436
451
  VersionAdded: '0.49'
437
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
+
438
461
  Layout/EmptyLineBetweenDefs:
439
462
  Description: 'Use empty lines between defs.'
440
463
  StyleGuide: '#empty-lines-between-methods'
@@ -554,7 +577,6 @@ Layout/EndAlignment:
554
577
  - keyword
555
578
  - variable
556
579
  - start_of_line
557
- AutoCorrect: false
558
580
  Severity: warning
559
581
 
560
582
  Layout/EndOfLine:
@@ -1234,7 +1256,7 @@ Layout/SpaceInsideBlockBraces:
1234
1256
 
1235
1257
  Layout/SpaceInsideHashLiteralBraces:
1236
1258
  Description: "Use spaces inside hash literal braces - or don't."
1237
- StyleGuide: '#spaces-operators'
1259
+ StyleGuide: '#spaces-braces'
1238
1260
  Enabled: true
1239
1261
  VersionAdded: '0.49'
1240
1262
  EnforcedStyle: space
@@ -1355,6 +1377,12 @@ Lint/BigDecimalNew:
1355
1377
  Enabled: true
1356
1378
  VersionAdded: '0.53'
1357
1379
 
1380
+ Lint/BinaryOperatorWithIdenticalOperands:
1381
+ Description: 'This cop checks for places where binary operator has identical operands.'
1382
+ Enabled: pending
1383
+ Safe: false
1384
+ VersionAdded: '0.89'
1385
+
1358
1386
  Lint/BooleanSymbol:
1359
1387
  Description: 'Check for `:true` and `:false` symbols.'
1360
1388
  Enabled: true
@@ -1367,6 +1395,12 @@ Lint/CircularArgumentReference:
1367
1395
  Enabled: true
1368
1396
  VersionAdded: '0.33'
1369
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
+
1370
1404
  Lint/ConstantResolution:
1371
1405
  Description: 'Check that constants are fully qualified with `::`.'
1372
1406
  Enabled: false
@@ -1420,6 +1454,16 @@ Lint/DuplicateMethods:
1420
1454
  Enabled: true
1421
1455
  VersionAdded: '0.29'
1422
1456
 
1457
+ Lint/DuplicateRequire:
1458
+ Description: 'Check for duplicate `require`s and `require_relative`s.'
1459
+ Enabled: pending
1460
+ VersionAdded: '0.90'
1461
+
1462
+ Lint/DuplicateRescueException:
1463
+ Description: 'Checks that there are no repeated exceptions used in `rescue` expressions.'
1464
+ Enabled: pending
1465
+ VersionAdded: '0.89'
1466
+
1423
1467
  Lint/EachWithObjectArgument:
1424
1468
  Description: 'Check for immutable argument given to each_with_object.'
1425
1469
  Enabled: true
@@ -1430,18 +1474,29 @@ Lint/ElseLayout:
1430
1474
  Enabled: true
1431
1475
  VersionAdded: '0.17'
1432
1476
 
1477
+ Lint/EmptyConditionalBody:
1478
+ Description: 'This cop checks for the presence of `if`, `elsif` and `unless` branches without a body.'
1479
+ Enabled: 'pending'
1480
+ AllowComments: true
1481
+ VersionAdded: '0.89'
1482
+
1433
1483
  Lint/EmptyEnsure:
1434
1484
  Description: 'Checks for empty ensure block.'
1435
1485
  Enabled: true
1436
1486
  VersionAdded: '0.10'
1437
1487
  VersionChanged: '0.48'
1438
- AutoCorrect: false
1439
1488
 
1440
1489
  Lint/EmptyExpression:
1441
1490
  Description: 'Checks for empty expressions.'
1442
1491
  Enabled: true
1443
1492
  VersionAdded: '0.45'
1444
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
+
1445
1500
  Lint/EmptyInterpolation:
1446
1501
  Description: 'Checks for empty string interpolation.'
1447
1502
  Enabled: true
@@ -1473,6 +1528,12 @@ Lint/FlipFlop:
1473
1528
  Enabled: true
1474
1529
  VersionAdded: '0.16'
1475
1530
 
1531
+ Lint/FloatComparison:
1532
+ Description: 'Checks for the presence of precise comparison of floating point numbers.'
1533
+ StyleGuide: '#float-comparison'
1534
+ Enabled: pending
1535
+ VersionAdded: '0.89'
1536
+
1476
1537
  Lint/FloatOutOfRange:
1477
1538
  Description: >-
1478
1539
  Catches floating-point literals too large or small for Ruby to
@@ -1493,6 +1554,12 @@ Lint/HeredocMethodCallPosition:
1493
1554
  StyleGuide: '#heredoc-method-calls'
1494
1555
  VersionAdded: '0.68'
1495
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
+
1496
1563
  Lint/ImplicitStringConcatenation:
1497
1564
  Description: >-
1498
1565
  Checks for adjacent string literals on the same line, which
@@ -1520,7 +1587,7 @@ Lint/InheritException:
1520
1587
  Lint/InterpolationCheck:
1521
1588
  Description: 'Raise warning for interpolation in single q strs.'
1522
1589
  Enabled: true
1523
- SafeAutoCorrect: false
1590
+ Safe: false
1524
1591
  VersionAdded: '0.50'
1525
1592
  VersionChanged: '0.87'
1526
1593
 
@@ -1542,6 +1609,7 @@ Lint/Loop:
1542
1609
  StyleGuide: '#loop-with-break'
1543
1610
  Enabled: true
1544
1611
  VersionAdded: '0.9'
1612
+ VersionChanged: '0.89'
1545
1613
 
1546
1614
  Lint/MissingCopEnableDirective:
1547
1615
  Description: 'Checks for a `# rubocop:enable` after `# rubocop:disable`.'
@@ -1556,6 +1624,13 @@ Lint/MissingCopEnableDirective:
1556
1624
  # .inf for any size
1557
1625
  MaximumRangeSize: .inf
1558
1626
 
1627
+ Lint/MissingSuper:
1628
+ Description: >-
1629
+ This cop checks for the presence of constructors and lifecycle callbacks
1630
+ without calls to `super`'.
1631
+ Enabled: pending
1632
+ VersionAdded: '0.89'
1633
+
1559
1634
  Lint/MixedRegexpCaptureTypes:
1560
1635
  Description: 'Do not mix named captures and numbered captures in a Regexp literal.'
1561
1636
  Enabled: pending
@@ -1608,6 +1683,12 @@ Lint/OrderedMagicComments:
1608
1683
  Enabled: true
1609
1684
  VersionAdded: '0.53'
1610
1685
 
1686
+ Lint/OutOfRangeRegexpRef:
1687
+ Description: 'Checks for out of range reference for Regexp because it always returns nil.'
1688
+ Enabled: pending
1689
+ Safe: false
1690
+ VersionAdded: '0.89'
1691
+
1611
1692
  Lint/ParenthesesAsGroupedExpression:
1612
1693
  Description: >-
1613
1694
  Checks for method calls with a space before the opening
@@ -1730,6 +1811,7 @@ Lint/SafeNavigationChain:
1730
1811
  - presence
1731
1812
  - try
1732
1813
  - try!
1814
+ - in?
1733
1815
 
1734
1816
  Lint/SafeNavigationConsistency:
1735
1817
  Description: >-
@@ -1758,6 +1840,11 @@ Lint/ScriptPermission:
1758
1840
  VersionAdded: '0.49'
1759
1841
  VersionChanged: '0.50'
1760
1842
 
1843
+ Lint/SelfAssignment:
1844
+ Description: 'Checks for self-assignments.'
1845
+ Enabled: pending
1846
+ VersionAdded: '0.89'
1847
+
1761
1848
  Lint/SendWithMixinArgument:
1762
1849
  Description: 'Checks for `send` method when using mixin.'
1763
1850
  Enabled: true
@@ -1808,6 +1895,16 @@ Lint/ToJSON:
1808
1895
  Enabled: true
1809
1896
  VersionAdded: '0.66'
1810
1897
 
1898
+ Lint/TopLevelReturnWithArgument:
1899
+ Description: 'This cop detects top level return statements with argument.'
1900
+ Enabled: 'pending'
1901
+ VersionAdded: '0.89'
1902
+
1903
+ Lint/TrailingCommaInAttributeDeclaration:
1904
+ Description: 'This cop checks for trailing commas in attribute declarations.'
1905
+ Enabled: pending
1906
+ VersionAdded: '0.90'
1907
+
1811
1908
  Lint/UnderscorePrefixedVariableName:
1812
1909
  Description: 'Do not use prefix `_` for a variable that is used.'
1813
1910
  Enabled: true
@@ -1824,6 +1921,11 @@ Lint/UnreachableCode:
1824
1921
  Enabled: true
1825
1922
  VersionAdded: '0.9'
1826
1923
 
1924
+ Lint/UnreachableLoop:
1925
+ Description: 'This cop checks for loops that will have at most one iteration.'
1926
+ Enabled: pending
1927
+ VersionAdded: '0.89'
1928
+
1827
1929
  Lint/UnusedBlockArgument:
1828
1930
  Description: 'Checks for unused block arguments.'
1829
1931
  StyleGuide: '#underscore-unused-vars'
@@ -1873,16 +1975,18 @@ Lint/UselessAssignment:
1873
1975
  Enabled: true
1874
1976
  VersionAdded: '0.11'
1875
1977
 
1876
- Lint/UselessComparison:
1877
- Description: 'Checks for comparison of something with itself.'
1878
- Enabled: true
1879
- VersionAdded: '0.11'
1880
-
1881
1978
  Lint/UselessElseWithoutRescue:
1882
1979
  Description: 'Checks for useless `else` in `begin..end` without `rescue`.'
1883
1980
  Enabled: true
1884
1981
  VersionAdded: '0.17'
1885
1982
 
1983
+ Lint/UselessMethodDefinition:
1984
+ Description: 'Checks for useless method definitions.'
1985
+ Enabled: pending
1986
+ VersionAdded: '0.90'
1987
+ Safe: false
1988
+ AllowComments: true
1989
+
1886
1990
  Lint/UselessSetterCall:
1887
1991
  Description: 'Checks for useless setter call to a local variable.'
1888
1992
  Enabled: true
@@ -1890,6 +1994,12 @@ Lint/UselessSetterCall:
1890
1994
  VersionChanged: '0.80'
1891
1995
  Safe: false
1892
1996
 
1997
+ Lint/UselessTimes:
1998
+ Description: 'Checks for useless `Integer#times` calls.'
1999
+ Enabled: pending
2000
+ VersionAdded: '0.91'
2001
+ Safe: false
2002
+
1893
2003
  Lint/Void:
1894
2004
  Description: 'Possible use of operator/literal/variable in void context.'
1895
2005
  Enabled: true
@@ -1911,7 +2021,7 @@ Metrics/AbcSize:
1911
2021
  # The ABC size is a calculated magnitude, so this number can be an Integer or
1912
2022
  # a Float.
1913
2023
  IgnoredMethods: []
1914
- Max: 15
2024
+ Max: 17
1915
2025
 
1916
2026
  Metrics/BlockLength:
1917
2027
  Description: 'Avoid long blocks with many lines.'
@@ -1993,7 +2103,7 @@ Metrics/PerceivedComplexity:
1993
2103
  VersionAdded: '0.25'
1994
2104
  VersionChanged: '0.81'
1995
2105
  IgnoredMethods: []
1996
- Max: 7
2106
+ Max: 8
1997
2107
 
1998
2108
  ################## Migration #############################
1999
2109
 
@@ -2352,7 +2462,8 @@ Style/ArrayCoercion:
2352
2462
  Use Array() instead of explicit Array check or [*var], when dealing
2353
2463
  with a variable you want to treat as an Array, but you're not certain it's an array.
2354
2464
  StyleGuide: '#array-coercion'
2355
- Enabled: 'pending'
2465
+ Safe: false
2466
+ Enabled: false
2356
2467
  VersionAdded: '0.88'
2357
2468
 
2358
2469
  Style/ArrayJoin:
@@ -2527,6 +2638,7 @@ Style/CaseEquality:
2527
2638
  StyleGuide: '#no-case-equality'
2528
2639
  Enabled: true
2529
2640
  VersionAdded: '0.9'
2641
+ VersionChanged: '0.89'
2530
2642
  # If AllowOnConstant is enabled, the cop will ignore violations when the receiver of
2531
2643
  # the case equality operator is a constant.
2532
2644
  #
@@ -2541,6 +2653,7 @@ Style/CaseLikeIf:
2541
2653
  Description: 'This cop identifies places where `if-elsif` constructions can be replaced with `case-when`.'
2542
2654
  StyleGuide: '#case-vs-if-else'
2543
2655
  Enabled: 'pending'
2656
+ Safe: false
2544
2657
  VersionAdded: '0.88'
2545
2658
 
2546
2659
  Style/CharacterLiteral:
@@ -2558,7 +2671,6 @@ Style/ClassAndModuleChildren:
2558
2671
  # have the knowledge to perform either operation safely and thus requires
2559
2672
  # manual oversight.
2560
2673
  SafeAutoCorrect: false
2561
- AutoCorrect: false
2562
2674
  Enabled: true
2563
2675
  VersionAdded: '0.19'
2564
2676
  #
@@ -2597,6 +2709,16 @@ Style/ClassMethods:
2597
2709
  VersionAdded: '0.9'
2598
2710
  VersionChanged: '0.20'
2599
2711
 
2712
+ Style/ClassMethodsDefinitions:
2713
+ Description: 'Enforces using `def self.method_name` or `class << self` to define class methods.'
2714
+ StyleGuide: '#def-self-class-methods'
2715
+ Enabled: false
2716
+ VersionAdded: '0.89'
2717
+ EnforcedStyle: def_self
2718
+ SupportedStyles:
2719
+ - def_self
2720
+ - self_class
2721
+
2600
2722
  Style/ClassVars:
2601
2723
  Description: 'Avoid the use of class variables.'
2602
2724
  StyleGuide: '#no-class-vars'
@@ -2637,6 +2759,14 @@ Style/ColonMethodDefinition:
2637
2759
  Enabled: true
2638
2760
  VersionAdded: '0.52'
2639
2761
 
2762
+ Style/CombinableLoops:
2763
+ Description: >-
2764
+ Checks for places where multiple consecutive loops over the same data
2765
+ can be combined into a single loop.
2766
+ Enabled: pending
2767
+ Safe: false
2768
+ VersionAdded: '0.90'
2769
+
2640
2770
  Style/CommandLiteral:
2641
2771
  Description: 'Use `` or %x around command literals.'
2642
2772
  StyleGuide: '#percent-x'
@@ -2733,7 +2863,8 @@ Style/DateTime:
2733
2863
  StyleGuide: '#date--time'
2734
2864
  Enabled: false
2735
2865
  VersionAdded: '0.51'
2736
- VersionChanged: '0.59'
2866
+ VersionChanged: '0.92'
2867
+ SafeAutoCorrect: false
2737
2868
  AllowCoercion: false
2738
2869
 
2739
2870
  Style/DefWithParentheses:
@@ -2880,6 +3011,16 @@ Style/ExpandPathArguments:
2880
3011
  Enabled: true
2881
3012
  VersionAdded: '0.53'
2882
3013
 
3014
+ Style/ExplicitBlockArgument:
3015
+ Description: >-
3016
+ Consider using explicit block argument to avoid writing block literal
3017
+ that just passes its arguments to another block.
3018
+ StyleGuide: '#block-argument'
3019
+ Enabled: pending
3020
+ # May change the yielding arity.
3021
+ Safe: false
3022
+ VersionAdded: '0.89'
3023
+
2883
3024
  Style/ExponentialNotation:
2884
3025
  Description: 'When using exponential notation, favor a mantissa between 1 (inclusive) and 10 (exclusive).'
2885
3026
  StyleGuide: '#exponential-notation'
@@ -2961,7 +3102,14 @@ Style/FrozenStringLiteralComment:
2961
3102
  # `never` will enforce that the frozen string literal comment does not
2962
3103
  # exist in a file.
2963
3104
  - never
2964
- Safe: false
3105
+ SafeAutoCorrect: false
3106
+
3107
+ Style/GlobalStdStream:
3108
+ Description: 'Enforces the use of `$stdout/$stderr/$stdin` instead of `STDOUT/STDERR/STDIN`.'
3109
+ StyleGuide: '#global-stdout'
3110
+ Enabled: pending
3111
+ VersionAdded: '0.89'
3112
+ SafeAutoCorrect: false
2965
3113
 
2966
3114
  Style/GlobalVars:
2967
3115
  Description: 'Do not introduce global variables.'
@@ -3035,15 +3183,17 @@ Style/HashSyntax:
3035
3183
  PreferHashRocketsForNonAlnumEndingSymbols: false
3036
3184
 
3037
3185
  Style/HashTransformKeys:
3038
- Description: 'Prefer `transform_keys` over `each_with_object` and `map`.'
3186
+ Description: 'Prefer `transform_keys` over `each_with_object`, `map`, or `to_h`.'
3039
3187
  Enabled: 'pending'
3040
3188
  VersionAdded: '0.80'
3189
+ VersionChanged: '0.90'
3041
3190
  Safe: false
3042
3191
 
3043
3192
  Style/HashTransformValues:
3044
- Description: 'Prefer `transform_values` over `each_with_object` and `map`.'
3193
+ Description: 'Prefer `transform_values` over `each_with_object`, `map`, or `to_h`.'
3045
3194
  Enabled: 'pending'
3046
3195
  VersionAdded: '0.80'
3196
+ VersionChanged: '0.90'
3047
3197
  Safe: false
3048
3198
 
3049
3199
  Style/IdenticalConditionalBranches:
@@ -3134,11 +3284,22 @@ Style/IpAddresses:
3134
3284
  Description: "Don't include literal IP addresses in code."
3135
3285
  Enabled: false
3136
3286
  VersionAdded: '0.58'
3137
- VersionChanged: '0.77'
3287
+ VersionChanged: '0.91'
3138
3288
  # Allow addresses to be permitted
3139
3289
  AllowedAddresses:
3140
3290
  - "::"
3141
3291
  # :: is a valid IPv6 address, but could potentially be legitimately in code
3292
+ Exclude:
3293
+ - '**/*.gemfile'
3294
+ - '**/Gemfile'
3295
+ - '**/gems.rb'
3296
+ - '**/*.gemspec'
3297
+
3298
+ Style/KeywordParametersOrder:
3299
+ Description: 'Enforces that optional keyword parameters are placed at the end of the parameters list.'
3300
+ StyleGuide: '#keyword-parameters-order'
3301
+ Enabled: pending
3302
+ VersionAdded: '0.90'
3142
3303
 
3143
3304
  Style/Lambda:
3144
3305
  Description: 'Use the new lambda literal syntax for single-line blocks.'
@@ -3218,12 +3379,6 @@ Style/MethodDefParentheses:
3218
3379
  - require_no_parentheses
3219
3380
  - require_no_parentheses_except_multiline
3220
3381
 
3221
- Style/MethodMissingSuper:
3222
- Description: Checks for `method_missing` to call `super`.
3223
- StyleGuide: '#no-method-missing'
3224
- Enabled: true
3225
- VersionAdded: '0.56'
3226
-
3227
3382
  Style/MinMax:
3228
3383
  Description: >-
3229
3384
  Use `Enumerable#minmax` instead of `Enumerable#min`
@@ -3519,7 +3674,6 @@ Style/NumericPredicate:
3519
3674
  # object. Switching these methods has to be done with knowledge of the types
3520
3675
  # of the variables which rubocop doesn't have.
3521
3676
  SafeAutoCorrect: false
3522
- AutoCorrect: false
3523
3677
  Enabled: true
3524
3678
  VersionAdded: '0.42'
3525
3679
  VersionChanged: '0.59'
@@ -3535,12 +3689,13 @@ Style/NumericPredicate:
3535
3689
 
3536
3690
  Style/OneLineConditional:
3537
3691
  Description: >-
3538
- Favor the ternary operator(?:) over
3539
- if/then/else/end constructs.
3692
+ Favor the ternary operator (?:) or multi-line constructs over
3693
+ single-line if/then/else/end constructs.
3540
3694
  StyleGuide: '#ternary-operator'
3541
3695
  Enabled: true
3696
+ AlwaysCorrectToMultiline: false
3542
3697
  VersionAdded: '0.9'
3543
- VersionChanged: '0.38'
3698
+ VersionChanged: '0.90'
3544
3699
 
3545
3700
  Style/OptionHash:
3546
3701
  Description: "Don't use option hashes when you can use keyword arguments."
@@ -3565,6 +3720,15 @@ Style/OptionalArguments:
3565
3720
  VersionAdded: '0.33'
3566
3721
  VersionChanged: '0.83'
3567
3722
 
3723
+ Style/OptionalBooleanParameter:
3724
+ Description: 'Use keyword arguments when defining method with boolean argument.'
3725
+ StyleGuide: '#boolean-keyword-arguments'
3726
+ Enabled: pending
3727
+ Safe: false
3728
+ VersionAdded: '0.89'
3729
+ AllowedMethods:
3730
+ - respond_to_missing?
3731
+
3568
3732
  Style/OrAssignment:
3569
3733
  Description: 'Recommend usage of double pipe equals (||=) where applicable.'
3570
3734
  StyleGuide: '#double-pipe-for-uninit'
@@ -3764,6 +3928,12 @@ Style/RedundantSelf:
3764
3928
  VersionAdded: '0.10'
3765
3929
  VersionChanged: '0.13'
3766
3930
 
3931
+ Style/RedundantSelfAssignment:
3932
+ Description: 'Checks for places where redundant assignments are made for in place modification methods.'
3933
+ Enabled: pending
3934
+ Safe: false
3935
+ VersionAdded: '0.90'
3936
+
3767
3937
  Style/RedundantSort:
3768
3938
  Description: >-
3769
3939
  Use `min` instead of `sort.first`,
@@ -3826,6 +3996,8 @@ Style/SafeNavigation:
3826
3996
  This cop transforms usages of a method call safeguarded by
3827
3997
  a check for the existence of the object to
3828
3998
  safe navigation (`&.`).
3999
+ Auto-correction is unsafe as it assumes the object will
4000
+ be `nil` or truthy, but never `false`.
3829
4001
  Enabled: true
3830
4002
  VersionAdded: '0.43'
3831
4003
  VersionChanged: '0.77'
@@ -3838,6 +4010,7 @@ Style/SafeNavigation:
3838
4010
  - presence
3839
4011
  - try
3840
4012
  - try!
4013
+ SafeAutoCorrect: false
3841
4014
 
3842
4015
  Style/Sample:
3843
4016
  Description: >-
@@ -3883,6 +4056,12 @@ Style/SignalException:
3883
4056
  - only_fail
3884
4057
  - semantic
3885
4058
 
4059
+ Style/SingleArgumentDig:
4060
+ Description: 'Avoid using single argument dig method.'
4061
+ Enabled: pending
4062
+ VersionAdded: '0.89'
4063
+ Safe: false
4064
+
3886
4065
  Style/SingleLineBlockParams:
3887
4066
  Description: 'Enforces the names of some block params.'
3888
4067
  Enabled: false
@@ -3910,6 +4089,14 @@ Style/SlicingWithRange:
3910
4089
  VersionAdded: '0.83'
3911
4090
  Safe: false
3912
4091
 
4092
+ Style/SoleNestedConditional:
4093
+ Description: >-
4094
+ Finds sole nested conditional nodes
4095
+ which can be merged into outer conditional node.
4096
+ Enabled: pending
4097
+ VersionAdded: '0.89'
4098
+ AllowModifier: false
4099
+
3913
4100
  Style/SpecialGlobalVars:
3914
4101
  Description: 'Avoid Perl-style global variables.'
3915
4102
  StyleGuide: '#no-cryptic-perlisms'
@@ -3938,6 +4125,13 @@ Style/StderrPuts:
3938
4125
  Enabled: true
3939
4126
  VersionAdded: '0.51'
3940
4127
 
4128
+ Style/StringConcatenation:
4129
+ Description: 'Checks for places where string concatenation can be replaced with string interpolation.'
4130
+ StyleGuide: '#string-interpolation'
4131
+ Enabled: pending
4132
+ Safe: false
4133
+ VersionAdded: '0.89'
4134
+
3941
4135
  Style/StringHashKeys:
3942
4136
  Description: 'Prefer symbols instead of strings as hash keys.'
3943
4137
  StyleGuide: '#symbols-as-keys'
@@ -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.0"
4
- RUBOCOP_VERSION = "0.88.0"
5
- end
3
+ VERSION = "1.4.3"
4
+ RUBOCOP_VERSION = "0.92.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.0
4
+ version: 1.4.3
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-07-14 00:00:00.000000000 Z
11
+ date: 2020-09-29 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.88.0
19
+ version: 0.92.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.88.0
26
+ version: 0.92.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