+268
-35
lines changedFilter options
+268
-35
lines changed Original file line number Diff line number Diff line change
@@ -39,7 +39,7 @@ output by `rubocop -V`, include them as well. Here's an example:
39
39
40
40
```
41
41
$ [bundle exec] rubocop -V
42
-
1.78.0 (using Parser 3.3.5.0, rubocop-ast 1.32.3, analyzing as Ruby 3.3, running on ruby 3.3.5) [x86_64-linux]
42
+
1.79.0 (using Parser 3.3.5.0, rubocop-ast 1.32.3, analyzing as Ruby 3.3, running on ruby 3.3.5) [x86_64-linux]
43
43
- rubocop-performance 1.22.1
44
44
- rubocop-rspec 3.1.0
45
45
```
Original file line number Diff line number Diff line change
@@ -11,6 +11,8 @@
11
11
12
12
## master (unreleased)
13
13
14
+
## 1.79.0 (2025-07-24)
15
+
14
16
### New features
15
17
16
18
* [#14348](https://github.com/rubocop/rubocop/pull/14348): Add new cop `Layout/EmptyLinesAfterModuleInclusion`. ([@lovro-bikic][])
Original file line number Diff line number Diff line change
@@ -17,7 +17,7 @@ do so.
17
17
18
18
```console
19
19
$ rubocop -V
20
-
1.78.0 (using Parser 3.3.5.0, rubocop-ast 1.32.3, analyzing as Ruby 3.3, running on ruby 3.3.5) [x86_64-linux]
20
+
1.79.0 (using Parser 3.3.5.0, rubocop-ast 1.32.3, analyzing as Ruby 3.3, running on ruby 3.3.5) [x86_64-linux]
21
21
- rubocop-performance 1.22.1
22
22
- rubocop-rspec 3.1.0
23
23
```
Original file line number Diff line number Diff line change
@@ -53,7 +53,7 @@ To prevent an unwanted RuboCop update you might want to use a conservative versi
53
53
in your `Gemfile`:
54
54
55
55
```rb
56
-
gem 'rubocop', '~> 1.78', require: false
56
+
gem 'rubocop', '~> 1.79', require: false
57
57
```
58
58
59
59
See [our versioning policy](https://docs.rubocop.org/rubocop/versioning.html) for further details.
Original file line number Diff line number Diff line change
@@ -642,7 +642,7 @@ Layout/EmptyLinesAfterModuleInclusion:
642
642
Description: 'Keeps track of empty lines after module inclusion methods.'
643
643
StyleGuide: '#empty-lines-after-module-inclusion'
644
644
Enabled: pending
645
-
VersionAdded: '<<next>>'
645
+
VersionAdded: '1.79'
646
646
647
647
Layout/EmptyLinesAroundAccessModifier:
648
648
Description: "Keep blank lines around access modifiers."
@@ -2284,7 +2284,7 @@ Lint/RedundantSafeNavigation:
2284
2284
Description: 'Checks for redundant safe navigation calls.'
2285
2285
Enabled: true
2286
2286
VersionAdded: '0.93'
2287
-
VersionChanged: '<<next>>'
2287
+
VersionChanged: '1.79'
2288
2288
AllowedMethods:
2289
2289
- instance_of?
2290
2290
- kind_of?
Original file line number Diff line number Diff line change
@@ -2,6 +2,6 @@ name: rubocop
2
2
title: RuboCop
3
3
# We always provide version without patch here (e.g. 1.1),
4
4
# as patch versions should not appear in the docs.
5
-
version: ~
5
+
version: '1.79'
6
6
nav:
7
7
- modules/ROOT/nav.adoc
Original file line number Diff line number Diff line change
@@ -121,6 +121,7 @@ In the following section you find all available cops:
121
121
* xref:cops_layout.adoc#layoutemptylineaftermultilinecondition[Layout/EmptyLineAfterMultilineCondition]
122
122
* xref:cops_layout.adoc#layoutemptylinebetweendefs[Layout/EmptyLineBetweenDefs]
123
123
* xref:cops_layout.adoc#layoutemptylines[Layout/EmptyLines]
124
+
* xref:cops_layout.adoc#layoutemptylinesaftermoduleinclusion[Layout/EmptyLinesAfterModuleInclusion]
124
125
* xref:cops_layout.adoc#layoutemptylinesaroundaccessmodifier[Layout/EmptyLinesAroundAccessModifier]
125
126
* xref:cops_layout.adoc#layoutemptylinesaroundarguments[Layout/EmptyLinesAroundArguments]
126
127
* xref:cops_layout.adoc#layoutemptylinesaroundattributeaccessor[Layout/EmptyLinesAroundAttributeAccessor]
Original file line number Diff line number Diff line change
@@ -1816,6 +1816,53 @@ some_method
1816
1816
1817
1817
* https://rubystyle.guide#two-or-more-empty-lines
1818
1818
1819
+
[#layoutemptylinesaftermoduleinclusion]
1820
+
== Layout/EmptyLinesAfterModuleInclusion
1821
+
1822
+
|===
1823
+
| Enabled by default | Safe | Supports autocorrection | Version Added | Version Changed
1824
+
1825
+
| Pending
1826
+
| Yes
1827
+
| Always
1828
+
| 1.79
1829
+
| -
1830
+
|===
1831
+
1832
+
Checks for an empty line after a module inclusion method (`extend`,
1833
+
`include` and `prepend`), or a group of them.
1834
+
1835
+
[#examples-layoutemptylinesaftermoduleinclusion]
1836
+
=== Examples
1837
+
1838
+
[source,ruby]
1839
+
----
1840
+
# bad
1841
+
class Foo
1842
+
include Bar
1843
+
attr_reader :baz
1844
+
end
1845
+
1846
+
# good
1847
+
class Foo
1848
+
include Bar
1849
+
1850
+
attr_reader :baz
1851
+
end
1852
+
1853
+
# also good - multiple module inclusions grouped together
1854
+
class Foo
1855
+
extend Bar
1856
+
include Baz
1857
+
prepend Qux
1858
+
end
1859
+
----
1860
+
1861
+
[#references-layoutemptylinesaftermoduleinclusion]
1862
+
=== References
1863
+
1864
+
* https://rubystyle.guide#empty-lines-after-module-inclusion
1865
+
1819
1866
[#layoutemptylinesaroundaccessmodifier]
1820
1867
== Layout/EmptyLinesAroundAccessModifier
1821
1868
@@ -6744,6 +6791,8 @@ end
6744
6791
6745
6792
something = 123if test
6746
6793
6794
+
return(foo + bar)
6795
+
6747
6796
# good
6748
6797
something 'test' do |x|
6749
6798
end
@@ -6752,6 +6801,8 @@ while (something)
6752
6801
end
6753
6802
6754
6803
something = 123 if test
6804
+
6805
+
return (foo + bar)
6755
6806
----
6756
6807
6757
6808
[#layoutspacearoundmethodcalloperator]
Original file line number Diff line number Diff line change
@@ -5301,7 +5301,7 @@ require 'unloaded_feature'
5301
5301
| No
5302
5302
| Always (Unsafe)
5303
5303
| 0.93
5304
-
| -
5304
+
| 1.79
5305
5305
|===
5306
5306
5307
5307
Checks for redundant safe navigation calls.
@@ -5321,6 +5321,15 @@ for which to suppress (allow) this cop's check.
5321
5321
In the example below, the safe navigation operator (`&.`) is unnecessary
5322
5322
because `NilClass` has methods like `respond_to?` and `is_a?`.
5323
5323
5324
+
The `InferNonNilReceiver` option specifies whether to look into previous code
5325
+
paths to infer if the receiver can't be nil. This check is unsafe because the receiver
5326
+
can be redefined between the safe navigation call and previous regular method call.
5327
+
It does the inference only in the current scope, e.g. within the same method definition etc.
5328
+
5329
+
The `AdditionalNilMethods` option specifies additional custom methods which are
5330
+
defined on `NilClass`. When `InferNonNilReceiver` is set, they are used to determine
5331
+
whether the receiver can be nil.
5332
+
5324
5333
[#safety-lintredundantsafenavigation]
5325
5334
=== Safety
5326
5335
@@ -5339,6 +5348,20 @@ CamelCaseConst&.do_something
5339
5348
# good
5340
5349
CamelCaseConst.do_something
5341
5350
5351
+
# bad
5352
+
foo.to_s&.strip
5353
+
foo.to_i&.zero?
5354
+
foo.to_f&.zero?
5355
+
foo.to_a&.size
5356
+
foo.to_h&.size
5357
+
5358
+
# good
5359
+
foo.to_s.strip
5360
+
foo.to_i.zero?
5361
+
foo.to_f.zero?
5362
+
foo.to_a.size
5363
+
foo.to_h.size
5364
+
5342
5365
# bad
5343
5366
do_something if attrs&.respond_to?(:[])
5344
5367
@@ -5394,6 +5417,59 @@ do_something if attrs.nil_safe_method(:[])
5394
5417
do_something if attrs&.not_nil_safe_method(:[])
5395
5418
----
5396
5419
5420
+
[#infernonnilreceiver_-false-_default_-lintredundantsafenavigation]
5421
+
==== InferNonNilReceiver: false (default)
5422
+
5423
+
[source,ruby]
5424
+
----
5425
+
# good
5426
+
foo.bar
5427
+
foo&.baz
5428
+
----
5429
+
5430
+
[#infernonnilreceiver_-true-lintredundantsafenavigation]
5431
+
==== InferNonNilReceiver: true
5432
+
5433
+
[source,ruby]
5434
+
----
5435
+
# bad
5436
+
foo.bar
5437
+
foo&.baz # would raise on previous line if `foo` is nil
5438
+
5439
+
# good
5440
+
foo.bar
5441
+
foo.baz
5442
+
5443
+
# bad
5444
+
if foo.condition?
5445
+
foo&.bar
5446
+
end
5447
+
5448
+
# good
5449
+
if foo.condition?
5450
+
foo.bar
5451
+
end
5452
+
5453
+
# good (different scopes)
5454
+
def method1
5455
+
foo.bar
5456
+
end
5457
+
5458
+
def method2
5459
+
foo&.bar
5460
+
end
5461
+
----
5462
+
5463
+
[#additionalnilmethods_-_present__-lintredundantsafenavigation]
5464
+
==== AdditionalNilMethods: [present?]
5465
+
5466
+
[source,ruby]
5467
+
----
5468
+
# good
5469
+
foo.present?
5470
+
foo&.bar
5471
+
----
5472
+
5397
5473
[#configurable-attributes-lintredundantsafenavigation]
5398
5474
=== Configurable attributes
5399
5475
@@ -5403,6 +5479,14 @@ do_something if attrs&.not_nil_safe_method(:[])
5403
5479
| AllowedMethods
5404
5480
| `instance_of?`, `kind_of?`, `is_a?`, `eql?`, `respond_to?`, `equal?`
5405
5481
| Array
5482
+
5483
+
| InferNonNilReceiver
5484
+
| `false`
5485
+
| Boolean
5486
+
5487
+
| AdditionalNilMethods
5488
+
| `present?`, `blank?`, `try`, `try!`
5489
+
| Array
5406
5490
|===
5407
5491
5408
5492
[#lintredundantsplatexpansion]
@@ -5974,7 +6058,7 @@ end
5974
6058
| -
5975
6059
|===
5976
6060
5977
-
Check for arguments to `rescue` that will result in a `TypeError`
6061
+
Checks for arguments to `rescue` that will result in a `TypeError`
5978
6062
if an exception is raised.
5979
6063
5980
6064
[#examples-lintrescuetype]
You can’t perform that action at this time.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4