File tree Expand file tree Collapse file tree 3 files changed +27
-2
lines changed Expand file tree Collapse file tree 3 files changed +27
-2
lines changed Original file line number Diff line number Diff line change @@ -625,6 +625,31 @@ documentation](https://docs.rubocop.org/rubocop/configuration.html#inheriting-co
625
625
* Prefer ` Time.iso8601(foo) ` instead of ` Time.parse(foo) ` when expecting ISO8601
626
626
formatted time strings like ` "2018-03-20T11:16:39-04:00" ` .
627
627
628
+ * Avoid returning from a ` begin ` block in assignment contexts. If you return
629
+ from a method inside a ` begin ` block, the return will prevent the assignment
630
+ from taking place, potentially causing confusing memoization bugs.
631
+
632
+ ~~~ ruby
633
+ # bad
634
+ def foo
635
+ @foo ||= begin
636
+ return 1 if flag?
637
+ 2
638
+ end
639
+ end
640
+
641
+ # good
642
+ def foo
643
+ @foo ||= begin
644
+ if flag?
645
+ 1
646
+ else
647
+ 2
648
+ end
649
+ end
650
+ end
651
+ ~~~
652
+
628
653
## Naming
629
654
630
655
* Use ` snake_case ` for symbols, methods, and variables.
Original file line number Diff line number Diff line change @@ -195,7 +195,7 @@ Lint/NestedPercentLiteral:
195
195
Enabled : false
196
196
197
197
Lint/NoReturnInBeginEndBlocks :
198
- Enabled : false
198
+ Enabled : true
199
199
200
200
Lint/NonAtomicFileOperation :
201
201
Enabled : false
Original file line number Diff line number Diff line change @@ -1464,7 +1464,7 @@ Lint/NextWithoutAccumulator:
1464
1464
VersionAdded : ' 0.36'
1465
1465
Lint/NoReturnInBeginEndBlocks :
1466
1466
Description : Do not `return` inside `begin..end` blocks in assignment contexts.
1467
- Enabled : false
1467
+ Enabled : true
1468
1468
VersionAdded : ' 1.2'
1469
1469
Lint/NonAtomicFileOperation :
1470
1470
Description : Checks for non-atomic file operations.
You can’t perform that action at this time.
0 commit comments