Skip to content

Commit

Permalink
Cut 1.70
Browse files Browse the repository at this point in the history
  • Loading branch information
bbatsov committed Jan 10, 2025
1 parent 3994f94 commit e2f2d5c
Show file tree
Hide file tree
Showing 14 changed files with 380 additions and 28 deletions.
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ output by `rubocop -V`, include them as well. Here's an example:

```
$ [bundle exec] rubocop -V
1.69.2 (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]
1.70.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]
- rubocop-performance 1.22.1
- rubocop-rspec 3.1.0
```
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@

## master (unreleased)

## 1.70.0 (2025-01-10)

### New features

* [#13474](https://github.com/rubocop/rubocop/pull/13474): Add new `Style/ItAssignment` cop to detect local assignments to `it` inside blocks. ([@dvandersluis][])
Expand Down
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ do so.

```console
$ rubocop -V
1.69.2 (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]
1.70.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]
- rubocop-performance 1.22.1
- rubocop-rspec 3.1.0
```
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ To prevent an unwanted RuboCop update you might want to use a conservative versi
in your `Gemfile`:

```rb
gem 'rubocop', '~> 1.69', require: false
gem 'rubocop', '~> 1.70', require: false
```

See [our versioning policy](https://docs.rubocop.org/rubocop/versioning.html) for further details.
Expand Down
8 changes: 4 additions & 4 deletions config/default.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1668,7 +1668,7 @@ Lint/ConstantOverwrittenInRescue:
Lint/ConstantReassignment:
Description: 'Checks for constant reassignments.'
Enabled: pending
VersionAdded: '<<next>>'
VersionAdded: '1.70'

Lint/ConstantResolution:
Description: 'Check that constants are fully qualified with `::`.'
Expand Down Expand Up @@ -2411,7 +2411,7 @@ Lint/SharedMutableDefault:
Description: 'Checks for mutable literals used as default arguments during Hash initialization.'
StyleGuide: '#no-mutable-defaults'
Enabled: pending
VersionAdded: '<<next>>'
VersionAdded: '1.70'

Lint/StructNewOverride:
Description: 'Disallow overriding the `Struct` built-in methods via `Struct.new`.'
Expand Down Expand Up @@ -3147,7 +3147,7 @@ Style/AccessModifierDeclarations:
Description: 'Checks style of how access modifiers are used.'
Enabled: true
VersionAdded: '0.57'
VersionChanged: '<<next>>'
VersionChanged: '1.70'
EnforcedStyle: group
SupportedStyles:
- inline
Expand Down Expand Up @@ -4331,7 +4331,7 @@ Style/IpAddresses:
Style/ItAssignment:
Description: 'Checks for assignment to `it` inside a block.'
Enabled: pending
VersionAdded: '<<next>>'
VersionAdded: '1.70'

Style/KeywordArgumentsMerging:
Description: >-
Expand Down
2 changes: 1 addition & 1 deletion docs/antora.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ name: rubocop
title: RuboCop
# We always provide version without patch here (e.g. 1.1),
# as patch versions should not appear in the docs.
version: ~
version: '1.70'
nav:
- modules/ROOT/nav.adoc
3 changes: 3 additions & 0 deletions docs/modules/ROOT/pages/cops.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,7 @@ In the following section you find all available cops:
* xref:cops_lint.adoc#lintcircularargumentreference[Lint/CircularArgumentReference]
* xref:cops_lint.adoc#lintconstantdefinitioninblock[Lint/ConstantDefinitionInBlock]
* xref:cops_lint.adoc#lintconstantoverwritteninrescue[Lint/ConstantOverwrittenInRescue]
* xref:cops_lint.adoc#lintconstantreassignment[Lint/ConstantReassignment]
* xref:cops_lint.adoc#lintconstantresolution[Lint/ConstantResolution]
* xref:cops_lint.adoc#lintdebugger[Lint/Debugger]
* xref:cops_lint.adoc#lintdeprecatedclassmethods[Lint/DeprecatedClassMethods]
Expand Down Expand Up @@ -312,6 +313,7 @@ In the following section you find all available cops:
* xref:cops_lint.adoc#lintshadowedargument[Lint/ShadowedArgument]
* xref:cops_lint.adoc#lintshadowedexception[Lint/ShadowedException]
* xref:cops_lint.adoc#lintshadowingouterlocalvariable[Lint/ShadowingOuterLocalVariable]
* xref:cops_lint.adoc#lintsharedmutabledefault[Lint/SharedMutableDefault]
* xref:cops_lint.adoc#lintstructnewoverride[Lint/StructNewOverride]
* xref:cops_lint.adoc#lintsuppressedexception[Lint/SuppressedException]
* xref:cops_lint.adoc#lintsymbolconversion[Lint/SymbolConversion]
Expand Down Expand Up @@ -502,6 +504,7 @@ In the following section you find all available cops:
* xref:cops_style.adoc#styleinversemethods[Style/InverseMethods]
* xref:cops_style.adoc#styleinvertibleunlesscondition[Style/InvertibleUnlessCondition]
* xref:cops_style.adoc#styleipaddresses[Style/IpAddresses]
* xref:cops_style.adoc#styleitassignment[Style/ItAssignment]
* xref:cops_style.adoc#stylekeywordargumentsmerging[Style/KeywordArgumentsMerging]
* xref:cops_style.adoc#stylekeywordparametersorder[Style/KeywordParametersOrder]
* xref:cops_style.adoc#stylelambda[Style/Lambda]
Expand Down
24 changes: 24 additions & 0 deletions docs/modules/ROOT/pages/cops_layout.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -5535,6 +5535,18 @@ foo(a, b, c)
[source,ruby]
----
# bad
foo(a, b,
c
)
# bad
foo(
a, b, {
foo: "bar",
}
)
# good
foo(
a,
Expand All @@ -5550,6 +5562,18 @@ foo(
[source,ruby]
----
# bad
foo(a, b,
c
)
# good
foo(
a, b, {
foo: "bar",
}
)
# good
foo(
a,
Expand Down
169 changes: 160 additions & 9 deletions docs/modules/ROOT/pages/cops_lint.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -741,6 +741,83 @@ rescue StandardError
end
----
[#lintconstantreassignment]
== Lint/ConstantReassignment
|===
| Enabled by default | Safe | Supports autocorrection | Version Added | Version Changed
| Pending
| Yes
| No
| 1.70
| -
|===
Checks for constant reassignments.
Emulates Ruby's runtime warning "already initialized constant X"
when a constant is reassigned in the same file and namespace using the
`NAME = value` syntax.
The cop cannot catch all offenses, like, for example, when a constant
is reassigned in another file, or when using metaprogramming (`Module#const_set`).
The cop only takes into account constants assigned in a "simple" way: directly
inside class/module definition, or within another constant. Other type of assignments
(e.g., inside a conditional) are disregarded.
The cop also tracks constant removal using `Module#remove_const` with symbol
or string argument.
[#examples-lintconstantreassignment]
=== Examples
[source,ruby]
----
# bad
X = :foo
X = :bar
# bad
class A
X = :foo
X = :bar
end
# bad
module A
X = :foo
X = :bar
end
# good - keep only one assignment
X = :bar
class A
X = :bar
end
module A
X = :bar
end
# good - use OR assignment
X = :foo
X ||= :bar
# good - use conditional assignment
X = :foo
X = :bar unless defined?(X)
# good - remove the assigned constant first
class A
X = :foo
remove_const :X
X = :bar
end
----
[#lintconstantresolution]
== Lint/ConstantResolution
Expand Down Expand Up @@ -1730,7 +1807,7 @@ end
| -
|===
Checks for duplicate literal, constant, or variable elements in Set.
Checks for duplicate literal, constant, or variable elements in Set and SortedSet.
[#examples-lintduplicatesetelement]
=== Examples
Expand All @@ -1754,6 +1831,18 @@ Set.new([:foo, :bar])
# good
[:foo, :bar].to_set
# bad
SortedSet[:foo, :bar, :foo]
# good
SortedSet[:foo, :bar]
# bad
SortedSet.new([:foo, :bar, :foo])
# good
SortedSet.new([:foo, :bar])
----
[#linteachwithobjectargument]
Expand Down Expand Up @@ -4386,33 +4475,30 @@ non_numbered_parameter_name = :value
|===
Certain numeric operations have a constant result, usually 0 or 1.
Subtracting a number from itself or multiplying it by 0 will always return 0.
Additionally, a variable modulo 0 or itself will always return 0.
Multiplying a number by 0 will always return 0.
Dividing a number by itself or raising it to the power of 0 will always return 1.
As such, they can be replaced with that result.
These are probably leftover from debugging, or are mistakes.
Other numeric operations that are similarly leftover from debugging or mistakes
are handled by Lint/UselessNumericOperation.
NOTE: This cop doesn't detect offenses for the `-` and `%` operator because it
can't determine the type of `x`. If `x` is an Array or String, it doesn't perform
a numeric operation.
[#examples-lintnumericoperationwithconstantresult]
=== Examples
[source,ruby]
----
# bad
x - x
x * 0
x % 1
x % x
# good
0
# bad
x -= x
x *= 0
x %= 1
x %= x
# good
x = 0
Expand Down Expand Up @@ -6172,6 +6258,71 @@ def some_method
end
----
[#lintsharedmutabledefault]
== Lint/SharedMutableDefault
|===
| Enabled by default | Safe | Supports autocorrection | Version Added | Version Changed
| Pending
| Yes
| No
| 1.70
| -
|===
Checks for Hash creation with a mutable default value.
Creating a Hash in such a way will share the default value
across all keys, causing unexpected behavior when modifying it.
For example, when the Hash was created with an Array as the argument,
calling `hash[:foo] << 'bar'` will also change the value of all
other keys that have not been explicitly assigned to.
[#examples-lintsharedmutabledefault]
=== Examples
[source,ruby]
----
# bad
Hash.new([])
Hash.new({})
Hash.new(Array.new)
Hash.new(Hash.new)
# okay -- In rare cases that intentionally have this behavior,
# without disabling the cop, you can set the default explicitly.
h = Hash.new
h.default = []
h[:a] << 1
h[:b] << 2
h # => {:a => [1, 2], :b => [1, 2]}
# okay -- beware this will discard mutations and only remember assignments
Hash.new { Array.new }
Hash.new { Hash.new }
Hash.new { {} }
Hash.new { [] }
# good - frozen solution will raise an error when mutation attempted
Hash.new([].freeze)
Hash.new({}.freeze)
# good - using a proc will create a new object for each key
h = Hash.new
h.default_proc = ->(h, k) { [] }
h.default_proc = ->(h, k) { {} }
# good - using a block will create a new object for each key
Hash.new { |h, k| h[k] = [] }
Hash.new { |h, k| h[k] = {} }
----
[#references-lintsharedmutabledefault]
=== References
* https://rubystyle.guide#no-mutable-defaults
[#lintstructnewoverride]
== Lint/StructNewOverride
Expand Down
Loading

0 comments on commit e2f2d5c

Please sign in to comment.