Skip to content

Commit

Permalink
Cut 1.44
Browse files Browse the repository at this point in the history
  • Loading branch information
bbatsov committed Jan 23, 2023
1 parent fb9b25e commit 6139e40
Show file tree
Hide file tree
Showing 13 changed files with 285 additions and 9 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.43.0 (using Parser 2.7.2.0, rubocop-ast 1.1.1, running on ruby 2.7.2) [x86_64-linux]
1.44.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.44.0 (2023-01-23)

### New features

* [#11410](https://github.com/rubocop/rubocop/issues/11410): Add new `Style/InvertibleUnlessCondition` cop. ([@fatkodima][])
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.43.0 (using Parser 2.7.2.0, rubocop-ast 1.1.1, running on ruby 2.7.2) [x86_64-linux]
1.44.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.43', require: false
gem 'rubocop', '~> 1.44', 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 @@ -265,7 +265,7 @@ Gemspec/DeprecatedAttributeAssignment:
Gemspec/DevelopmentDependencies:
Description: Checks that development dependencies are specified in Gemfile rather than gemspec.
Enabled: pending
VersionAdded: '<<next>>'
VersionAdded: '1.44'
EnforcedStyle: Gemfile
SupportedStyles:
- Gemfile
Expand Down Expand Up @@ -3450,7 +3450,7 @@ Style/CommentedKeyword:
Style/ComparableClamp:
Description: 'Enforces the use of `Comparable#clamp` instead of comparison by minimum and maximum.'
Enabled: pending
VersionAdded: '<<next>>'
VersionAdded: '1.44'

Style/ConcatArrayLiterals:
Description: 'Enforces the use of `Array#push(item)` instead of `Array#concat([item])` to avoid redundant array literals.'
Expand Down Expand Up @@ -4055,7 +4055,7 @@ Style/InverseMethods:
Style/InvertibleUnlessCondition:
Description: 'Favor `if` with inverted condition over `unless`.'
Enabled: false
VersionAdded: '<<next>>'
VersionAdded: '1.44'
# `InverseMethods` are methods that can be inverted in a `unless` condition.
# The relationship of inverse methods needs to be defined in both directions.
# Keys and values both need to be defined as symbols.
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.44'
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 @@ -87,6 +87,7 @@ In the following section you find all available cops:

* xref:cops_gemspec.adoc#gemspecdependencyversion[Gemspec/DependencyVersion]
* xref:cops_gemspec.adoc#gemspecdeprecatedattributeassignment[Gemspec/DeprecatedAttributeAssignment]
* xref:cops_gemspec.adoc#gemspecdevelopmentdependencies[Gemspec/DevelopmentDependencies]
* xref:cops_gemspec.adoc#gemspecduplicatedassignment[Gemspec/DuplicatedAssignment]
* xref:cops_gemspec.adoc#gemspecordereddependencies[Gemspec/OrderedDependencies]
* xref:cops_gemspec.adoc#gemspecrequiremfa[Gemspec/RequireMFA]
Expand Down Expand Up @@ -412,6 +413,7 @@ In the following section you find all available cops:
* xref:cops_style.adoc#stylecommandliteral[Style/CommandLiteral]
* xref:cops_style.adoc#stylecommentannotation[Style/CommentAnnotation]
* xref:cops_style.adoc#stylecommentedkeyword[Style/CommentedKeyword]
* xref:cops_style.adoc#stylecomparableclamp[Style/ComparableClamp]
* xref:cops_style.adoc#styleconcatarrayliterals[Style/ConcatArrayLiterals]
* xref:cops_style.adoc#styleconditionalassignment[Style/ConditionalAssignment]
* xref:cops_style.adoc#styleconstantvisibility[Style/ConstantVisibility]
Expand Down Expand Up @@ -473,6 +475,7 @@ In the following section you find all available cops:
* xref:cops_style.adoc#styleinfiniteloop[Style/InfiniteLoop]
* xref:cops_style.adoc#styleinlinecomment[Style/InlineComment]
* 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#stylekeywordparametersorder[Style/KeywordParametersOrder]
* xref:cops_style.adoc#stylelambda[Style/Lambda]
Expand Down
108 changes: 108 additions & 0 deletions docs/modules/ROOT/pages/cops_gemspec.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,114 @@ end
| Array
|===

== Gemspec/DevelopmentDependencies

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

| Pending
| Yes
| No
| 1.44
| -
|===

Enforce that development dependencies for a gem are specified in
`Gemfile`, rather than in the `gemspec` using
`add_development_dependency`. Alternatively, using `EnforcedStyle:
gemspec`, enforce that all dependencies are specified in `gemspec`,
rather than in `Gemfile`.

=== Examples

==== EnforcedStyle: Gemfile (default)

[source,ruby]
----
# Specify runtime dependencies in your gemspec,
# but all other dependencies in your Gemfile.
# bad
# example.gemspec
s.add_development_dependency "foo"
# good
# Gemfile
gem "foo"
# good
# gems.rb
gem "foo"
# good (with AllowedGems: ["bar"])
# example.gemspec
s.add_development_dependency "bar"
----

==== EnforcedStyle: gems.rb

[source,ruby]
----
# Specify runtime dependencies in your gemspec,
# but all other dependencies in your Gemfile.
#
# Identical to `EnforcedStyle: Gemfile`, but with a different error message.
# Rely on Bundler/GemFilename to enforce the use of `Gemfile` vs `gems.rb`.
# bad
# example.gemspec
s.add_development_dependency "foo"
# good
# Gemfile
gem "foo"
# good
# gems.rb
gem "foo"
# good (with AllowedGems: ["bar"])
# example.gemspec
s.add_development_dependency "bar"
----

==== EnforcedStyle: gemspec

[source,ruby]
----
# Specify all dependencies in your gemspec.
# bad
# Gemfile
gem "foo"
# good
# example.gemspec
s.add_development_dependency "foo"
# good (with AllowedGems: ["bar"])
# Gemfile
gem "bar"
----

=== Configurable attributes

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

| EnforcedStyle
| `Gemfile`
| `Gemfile`, `gems.rb`, `gemspec`

| AllowedGems
| `bundler`
| Array

| Include
| `+**/*.gemspec+`, `+**/Gemfile+`, `+**/gems.rb+`
| Array
|===

== Gemspec/DuplicatedAssignment

|===
Expand Down
4 changes: 4 additions & 0 deletions docs/modules/ROOT/pages/cops_lint.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -936,6 +936,8 @@ Checks for uses of the deprecated class method usages.
File.exists?(some_path)
Dir.exists?(some_path)
iterator?
attr :name, true
attr :name, false
ENV.freeze # Calling `Env.freeze` raises `TypeError` since Ruby 2.7.
ENV.clone
ENV.dup # Calling `Env.dup` raises `TypeError` since Ruby 3.1.
Expand All @@ -946,6 +948,8 @@ Socket.gethostbyaddr(host)
File.exist?(some_path)
Dir.exist?(some_path)
block_given?
attr_accessor :name
attr_reader :name
ENV # `ENV.freeze` cannot prohibit changes to environment variables.
ENV.to_h
ENV.to_h # `ENV.dup` cannot dup `ENV`, use `ENV.to_h` to get a copy of `ENV` as a hash.
Expand Down
114 changes: 114 additions & 0 deletions docs/modules/ROOT/pages/cops_style.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -2157,6 +2157,52 @@ class X # :nodoc:
end
----

== Style/ComparableClamp

NOTE: Required Ruby version: 2.4

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

| Pending
| Yes
| Yes
| 1.44
| -
|===

Enforces the use of `Comparable#clamp` instead of comparison by minimum and maximum.

This cop supports autocorrection for `if/elsif/else` bad style only.
Because `ArgumentError` occurs if the minimum and maximum of `clamp` arguments are reversed.
When these are variables, it is not possible to determine which is the minimum and maximum:

[source,ruby]
----
[1, [2, 3].max].min # => 1
1.clamp(3, 1) # => min argument must be smaller than max argument (ArgumentError)
----

=== Examples

[source,ruby]
----
# bad
[[x, low].max, high].min
# bad
if x < low
low
elsif high < x
high
else
x
end
# good
x.clamp(low, high)
----

== Style/ConcatArrayLiterals

|===
Expand Down Expand Up @@ -6162,6 +6208,74 @@ end
|
|===

== Style/InvertibleUnlessCondition

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

| Disabled
| Yes
| Yes
| 1.44
| -
|===

Checks for usages of `unless` which can be replaced by `if` with inverted condition.
Code without `unless` is easier to read, but that is subjective, so this cop
is disabled by default.

Methods that can be inverted should be defined in `InverseMethods`. Note that
the relationship of inverse methods needs to be defined in both directions.
For example,
InverseMethods:
:!=: :==
:even?: :odd?
:odd?: :even?

will suggest both `even?` and `odd?` to be inverted, but only `!=` (and not `==`).

=== Safety

This cop is unsafe because it cannot be guaranteed that the method
and its inverse method are both defined on receiver, and also are
actually inverse of each other.

=== Examples

[source,ruby]
----
# bad (simple condition)
foo unless !bar
foo unless x != y
foo unless x >= 10
foo unless x.even?
# good
foo if bar
foo if x == y
foo if x < 10
foo if x.odd?
# bad (complex condition)
foo unless x != y || x.even?
# good
foo if x == y && x.odd?
# good (if)
foo if !condition
----

=== Configurable attributes

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

| InverseMethods
| `{:!==>:==, :>=>:<=, :<==>:>, :<=>:>=, :>==>:<, :!~=>:=~, :zero?=>:nonzero?, :nonzero?=>:zero?, :any?=>:none?, :none?=>:any?, :even?=>:odd?, :odd?=>:even?}`
|
|===

== Style/IpAddresses

|===
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.43', require: false
gem 'rubocop', '~> 1.44', 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.43.0'
STRING = '1.44.0'

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

0 comments on commit 6139e40

Please sign in to comment.