Skip to content

Commit

Permalink
Cut 1.42
Browse files Browse the repository at this point in the history
  • Loading branch information
bbatsov committed Jan 1, 2023
1 parent b58c2cd commit 0f7416a
Show file tree
Hide file tree
Showing 12 changed files with 231 additions and 18 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.41.1 (using Parser 2.7.2.0, rubocop-ast 1.1.1, running on ruby 2.7.2) [x86_64-linux]
1.42.0 (using Parser 2.7.2.0, rubocop-ast 1.1.1, running on ruby 2.7.2) [x86_64-linux]
- rubocop-performance 1.9.1
- rubocop-rspec 2.0.0
```
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## master (unreleased)

## 1.42.0 (2023-01-01)

### New features

* [#11339](https://github.com/rubocop/rubocop/issues/11339): Add new `Style/MapToSet` cop. ([@koic][])
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.41.1 (using Parser 2.7.2.0, rubocop-ast 1.1.1, running on ruby 2.7.2) [x86_64-linux]
1.42.0 (using Parser 2.7.2.0, rubocop-ast 1.1.1, running on ruby 2.7.2) [x86_64-linux]
- rubocop-performance 1.9.1
- rubocop-rspec 2.0.0
```
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ To prevent an unwanted RuboCop update you might want to use a conservative versi
in your `Gemfile`:

```rb
gem 'rubocop', '~> 1.41', require: false
gem 'rubocop', '~> 1.42', require: false
```

See [our versioning policy](https://docs.rubocop.org/rubocop/versioning.html) for further details.
Expand Down
6 changes: 3 additions & 3 deletions config/default.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4114,7 +4114,7 @@ Style/MapToSet:
Description: 'Prefer `to_set` with a block over `map.to_set`.'
Enabled: pending
Safe: false
VersionAdded: '<<next>>'
VersionAdded: '1.42'

Style/MethodCallWithArgsParentheses:
Description: 'Use parentheses for method calls with arguments.'
Expand Down Expand Up @@ -4178,7 +4178,7 @@ Style/MinMaxComparison:
Description: 'Enforces the use of `max` or `min` instead of comparison for greater or less.'
Enabled: pending
Safe: false
VersionAdded: '<<next>>'
VersionAdded: '1.42'

Style/MissingElse:
Description: >-
Expand Down Expand Up @@ -5442,7 +5442,7 @@ Style/YodaExpression:
Description: 'Forbid the use of yoda expressions.'
Enabled: pending
Safe: false
VersionAdded: '<<next>>'
VersionAdded: '1.42'
SupportedOperators:
- '*'
- '+'
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.42'
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 @@ -480,11 +480,13 @@ In the following section you find all available cops:
* xref:cops_style.adoc#stylemagiccommentformat[Style/MagicCommentFormat]
* xref:cops_style.adoc#stylemapcompactwithconditionalblock[Style/MapCompactWithConditionalBlock]
* xref:cops_style.adoc#stylemaptohash[Style/MapToHash]
* xref:cops_style.adoc#stylemaptoset[Style/MapToSet]
* xref:cops_style.adoc#stylemethodcallwithargsparentheses[Style/MethodCallWithArgsParentheses]
* xref:cops_style.adoc#stylemethodcallwithoutargsparentheses[Style/MethodCallWithoutArgsParentheses]
* xref:cops_style.adoc#stylemethodcalledondoendblock[Style/MethodCalledOnDoEndBlock]
* xref:cops_style.adoc#stylemethoddefparentheses[Style/MethodDefParentheses]
* xref:cops_style.adoc#styleminmax[Style/MinMax]
* xref:cops_style.adoc#styleminmaxcomparison[Style/MinMaxComparison]
* xref:cops_style.adoc#stylemissingelse[Style/MissingElse]
* xref:cops_style.adoc#stylemissingrespondtomissing[Style/MissingRespondToMissing]
* xref:cops_style.adoc#stylemixingrouping[Style/MixinGrouping]
Expand Down Expand Up @@ -616,6 +618,7 @@ In the following section you find all available cops:
* xref:cops_style.adoc#stylewhileuntilmodifier[Style/WhileUntilModifier]
* xref:cops_style.adoc#stylewordarray[Style/WordArray]
* xref:cops_style.adoc#styleyodacondition[Style/YodaCondition]
* xref:cops_style.adoc#styleyodaexpression[Style/YodaExpression]
* xref:cops_style.adoc#stylezerolengthpredicate[Style/ZeroLengthPredicate]

// END_COP_LIST
3 changes: 2 additions & 1 deletion docs/modules/ROOT/pages/cops_security.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ values using custom logic instead of delegating to `Array#hash`.
Manually combining hashes is error prone and hard to follow, especially
when there are many values. Poor implementations may also introduce
performance or security concerns if they are prone to collisions.
Delegating to `Array#hash` is clearer, faster, and safer.
Delegating to `Array#hash` is clearer and safer, although it might be slower
depending on the use case.

=== Safety

Expand Down
187 changes: 179 additions & 8 deletions docs/modules/ROOT/pages/cops_style.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -5326,7 +5326,7 @@ The supported styles are:
* always - forces use of the 3.1 syntax (e.g. {foo:})
* never - forces use of explicit hash literal value
* either - accepts both shorthand and explicit use of hash literal value
* consistent - like "either", but will avoid mixing styles in a single hash
* consistent - forces use of the 3.1 syntax only if all values can be omitted in the hash

=== Examples

Expand Down Expand Up @@ -5419,16 +5419,19 @@ The supported styles are:

[source,ruby]
----
# bad
{foo: , bar: bar}
# bad - `foo` and `bar` values can be omitted
{foo: foo, bar: bar}
# good
{foo:, bar:}
# bad - `bar` value can be omitted
{foo:, bar: bar}
# bad
{foo: , bar: baz}
# bad - mixed syntaxes
{foo:, bar: baz}
# good
{foo:, bar:}
# good - can't omit `baz`
{foo: foo, bar: baz}
----

Expand Down Expand Up @@ -6678,6 +6681,43 @@ something.to_h { |v| [v, v * 2] }
{foo: bar}.to_h { |k, v| [k.to_s, v.do_something] }
----

== Style/MapToSet

|===
| Enabled by default | Safe | Supports autocorrection | Version Added | Version Changed

| Pending
| No
| Yes (Unsafe)
| 1.42
| -
|===

Looks for uses of `map.to_set` or `collect.to_set` that could be
written with just `to_set`.

=== Safety

This cop is unsafe, as it can produce false positives if the receiver
is not an `Enumerable`.

=== Examples

[source,ruby]
----
# bad
something.map { |i| i * 2 }.to_set
# good
something.to_set { |i| i * 2 }
# bad
[1, 2, 3].collect { |i| i.to_s }.to_set
# good
[1, 2, 3].to_set { |i| i.to_s }
----

== Style/MethodCallWithArgsParentheses

|===
Expand Down Expand Up @@ -7096,7 +7136,9 @@ Regardless of style, parentheses are necessary for:

1. Endless methods
2. Argument lists containing a `forward-arg` (`...`)
3. Argument lists containing an anonymous block forwarding (`&`)
3. Argument lists containing an anonymous rest arguments forwarding (`*`)
4. Argument lists containing an anonymous keyword rest arguments forwarding (`**`)
5. Argument lists containing an anonymous block forwarding (`&`)

Removing the parens would be a syntax error here.

Expand Down Expand Up @@ -7234,6 +7276,53 @@ bar = foo.minmax
return foo.minmax
----

== Style/MinMaxComparison

|===
| Enabled by default | Safe | Supports autocorrection | Version Added | Version Changed

| Pending
| No
| Yes (Unsafe)
| 1.42
| -
|===

Enforces the use of `max` or `min` instead of comparison for greater or less.

NOTE: It can be used if you want to present limit or threshold in Ruby 2.7+.
That it is slow though. So autocorrection will apply generic `max` or `min`:

[source,ruby]
----
a.clamp(b..) # Same as `[a, b].max`
a.clamp(..b) # Same as `[a, b].min`
----

=== Safety

This cop is unsafe because even if a value has `<` or `>` method,
it is not necessarily `Comparable`.

=== Examples

[source,ruby]
----
# bad
a > b ? a : b
a >= b ? a : b
# good
[a, b].max
# bad
a < b ? a : b
a <= b ? a : b
# good
[a, b].min
----

== Style/MissingElse

|===
Expand Down Expand Up @@ -14978,6 +15067,25 @@ array of 2 or fewer elements.
# bad (contains spaces)
%w[foo\ bar baz\ quux]
# bad
[
['one', 'One'],
['two', 'Two']
]
# good
[
%w[one One],
%w[two Two]
]
# good (2d array containing spaces)
[
['one', 'One'],
['two', 'Two'],
['forty two', 'Forty Two']
]
----

==== EnforcedStyle: brackets
Expand All @@ -14992,6 +15100,18 @@ array of 2 or fewer elements.
# good (contains spaces)
['foo bar', 'baz quux']
# good
[
['one', 'One'],
['two', 'Two']
]
# bad
[
%w[one One],
%w[two Two]
]
----

=== Configurable attributes
Expand Down Expand Up @@ -15131,6 +15251,57 @@ bar > 10

* https://en.wikipedia.org/wiki/Yoda_conditions

== Style/YodaExpression

|===
| Enabled by default | Safe | Supports autocorrection | Version Added | Version Changed

| Pending
| No
| Yes (Unsafe)
| 1.42
| -
|===

Forbids Yoda expressions, i.e. binary operations (using `*`, `+`, `&`, `|`,
and `^` operators) where the order of expression is reversed, eg. `1 + x`.
This cop complements `Style/YodaCondition` cop, which has a similar purpose.

=== Safety

This cop is unsafe because binary operators can be defined
differently on different classes, and are not guaranteed to
have the same result if reversed.

=== Examples

==== SupportedOperators: ['*', '+', '&'']

[source,ruby]
----
# bad
1 + x
10 * y
1 & z
# good
60 * 24
x + 1
y * 10
z & 1
# good
1 | x
----

=== Configurable attributes

|===
| Name | Default value | Configurable values


|===

== Style/ZeroLengthPredicate

|===
Expand Down
2 changes: 1 addition & 1 deletion docs/modules/ROOT/pages/installation.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ in your `Gemfile`:

[source,rb]
----
gem 'rubocop', '~> 1.41', require: false
gem 'rubocop', '~> 1.42', require: false
----

.A Modular RuboCop
Expand Down
2 changes: 1 addition & 1 deletion lib/rubocop/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
module RuboCop
# This module holds the RuboCop version information.
module Version
STRING = '1.41.1'
STRING = '1.42.0'

MSG = '%<version>s (using Parser %<parser_version>s, ' \
'rubocop-ast %<rubocop_ast_version>s, ' \
Expand Down

0 comments on commit 0f7416a

Please sign in to comment.