diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md index 08b3d5d6738c..f351aabbe960 100644 --- a/.github/ISSUE_TEMPLATE/bug_report.md +++ b/.github/ISSUE_TEMPLATE/bug_report.md @@ -38,7 +38,7 @@ output by `rubocop -V`, include them as well. Here's an example: ``` $ [bundle exec] rubocop -V -1.10.0 (using Parser 2.7.2.0, rubocop-ast 1.1.1, running on ruby 2.7.2 x86_64-linux) +1.11.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 ``` diff --git a/CHANGELOG.md b/CHANGELOG.md index bcb07be0bdcb..1988fe9c0c39 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,8 @@ ## master (unreleased) +## 1.11.0 (2021-03-01) + ### New features * [#5388](https://github.com/rubocop/rubocop/issues/5388): Add new `Style/UnlessLogicalOperators` cop. ([@caalberts][]) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 827fc6878ce7..c2a95d418ffb 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -17,7 +17,7 @@ do so. ``` $ rubocop -V -1.10.0 (using Parser 2.7.2.0, rubocop-ast 1.1.1, running on ruby 2.7.2 x86_64-linux) +1.11.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 ``` diff --git a/README.md b/README.md index c51492b484b4..4e10b5aabe5a 100644 --- a/README.md +++ b/README.md @@ -51,7 +51,7 @@ To prevent an unwanted RuboCop update you might want to use a conservative versi in your `Gemfile`: ```rb -gem 'rubocop', '~> 1.10', require: false +gem 'rubocop', '~> 1.11', require: false ``` See [versioning](https://docs.rubocop.org/rubocop/1.0/versioning.html) for further details. diff --git a/config/default.yml b/config/default.yml index 34dae8e6502d..80330a9ad299 100644 --- a/config/default.yml +++ b/config/default.yml @@ -3446,7 +3446,7 @@ Style/HashConversion: Description: 'Avoid Hash[] in favor of ary.to_h or literal hashes.' Enabled: pending VersionAdded: '1.10' - VersionChanged: <> + VersionChanged: '1.11' AllowSplatArgument: true Style/HashEachMethods: @@ -4745,7 +4745,7 @@ Style/UnlessLogicalOperators: Description: >- Checks for use of logical operators in an unless condition. Enabled: false - VersionAdded: '<>' + VersionAdded: '1.11' EnforcedStyle: forbid_mixed_logical_operators SupportedStyles: - forbid_mixed_logical_operators diff --git a/docs/antora.yml b/docs/antora.yml index 52f2c59156f5..c5b84a9a57d1 100644 --- a/docs/antora.yml +++ b/docs/antora.yml @@ -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: 'master' +version: '1.11' nav: - modules/ROOT/nav.adoc diff --git a/docs/modules/ROOT/pages/cops.adoc b/docs/modules/ROOT/pages/cops.adoc index 6eb4632c552a..e797776382d8 100644 --- a/docs/modules/ROOT/pages/cops.adoc +++ b/docs/modules/ROOT/pages/cops.adoc @@ -551,6 +551,7 @@ In the following section you find all available cops: * xref:cops_style.adoc#styletrailingunderscorevariable[Style/TrailingUnderscoreVariable] * xref:cops_style.adoc#styletrivialaccessors[Style/TrivialAccessors] * xref:cops_style.adoc#styleunlesselse[Style/UnlessElse] +* xref:cops_style.adoc#styleunlesslogicaloperators[Style/UnlessLogicalOperators] * xref:cops_style.adoc#styleunpackfirst[Style/UnpackFirst] * xref:cops_style.adoc#stylevariableinterpolation[Style/VariableInterpolation] * xref:cops_style.adoc#stylewhenthen[Style/WhenThen] diff --git a/docs/modules/ROOT/pages/cops_layout.adoc b/docs/modules/ROOT/pages/cops_layout.adoc index 6290d388c4b7..9299ca68dd64 100644 --- a/docs/modules/ROOT/pages/cops_layout.adoc +++ b/docs/modules/ROOT/pages/cops_layout.adoc @@ -728,7 +728,7 @@ end | Categories | `{"module_inclusion"=>["include", "prepend", "extend"]}` -| +| | ExpectedOrder | `module_inclusion`, `constants`, `public_class_methods`, `initializer`, `public_methods`, `protected_methods`, `private_methods` diff --git a/docs/modules/ROOT/pages/cops_style.adoc b/docs/modules/ROOT/pages/cops_style.adoc index 40b5192e9f63..bc7ba341dd74 100644 --- a/docs/modules/ROOT/pages/cops_style.adoc +++ b/docs/modules/ROOT/pages/cops_style.adoc @@ -4246,12 +4246,16 @@ EnforcedStyle. | Yes | Yes | 1.10 -| - +| 1.11 |=== This cop checks the usage of pre-2.1 `Hash[args]` method of converting enumerables and sequences of values to hashes. +Correction code from splat argument (`Hash[*ary]`) is not simply determined. For example, +`Hash[*ary]` can be replaced with `ary.each_slice(2).to_h` but it will be complicated. +So, `AllowSplatArgument` option is true by default to allow splat argument for simple code. + === Examples [source,ruby] @@ -4269,6 +4273,32 @@ Hash[key1, value1, key2, value2] {key1 => value1, key2 => value2} ---- +==== AllowSplatArgument: true (default) + +[source,ruby] +---- +# good +Hash[*ary] +---- + +==== AllowSplatArgument: false + +[source,ruby] +---- +# bad +Hash[*ary] +---- + +=== Configurable attributes + +|=== +| Name | Default value | Configurable values + +| AllowSplatArgument +| `true` +| Boolean +|=== + == Style/HashEachMethods |=== @@ -10781,6 +10811,9 @@ This cop checks symbol literal syntax. Use symbols as procs when possible. +If you prefer a style that allows block for method with arguments, +please set `true` to `AllowMethodsWithArguments`. + === Examples [source,ruby] @@ -10793,11 +10826,34 @@ something.map { _1.upcase } something.map(&:upcase) ---- +==== AllowMethodsWithArguments: false (default) + +[source,ruby] +---- +# bad +something.do_something(foo) { |o| o.bar } + +# good +something.do_something(foo, &:bar) +---- + +==== AllowMethodsWithArguments: true + +[source,ruby] +---- +# good +something.do_something(foo) { |o| o.bar } +---- + === Configurable attributes |=== | Name | Default value | Configurable values +| AllowMethodsWithArguments +| `false` +| Boolean + | IgnoredMethods | `respond_to`, `define_method` | Array @@ -11618,6 +11674,82 @@ end * https://rubystyle.guide#no-else-with-unless +== Style/UnlessLogicalOperators + +|=== +| Enabled by default | Safe | Supports autocorrection | VersionAdded | VersionChanged + +| Disabled +| Yes +| No +| 1.11 +| - +|=== + +This cop checks for the use of logical operators in an `unless` condition. +It discourages such code, as the condition becomes more difficult +to read and understand. + +This cop supports two styles: +- `forbid_mixed_logical_operators` (default) +- `forbid_logical_operators` + +`forbid_mixed_logical_operators` style forbids the use of more than one type +of logical operators. This makes the `unless` condition easier to read +because either all conditions need to be met or any condition need to be met +in order for the expression to be truthy or falsey. + +`forbid_logical_operators` style forbids any use of logical operator. +This makes it even more easy to read the `unless` condition as +there is only one condition in the expression. + +=== Examples + +==== EnforcedStyle: forbid_mixed_logical_operators (default) + +[source,ruby] +---- +# bad +return unless a || b && c +return unless a && b || c +return unless a && b and c +return unless a || b or c +return unless a && b or c +return unless a || b and c + +# good +return unless a && b && c +return unless a || b || c +return unless a and b and c +return unless a or b or c +return unless a? +---- + +==== EnforcedStyle: forbid_logical_operators + +[source,ruby] +---- +# bad +return unless a || b +return unless a && b +return unless a or b +return unless a and b + +# good +return unless a +return unless a? +---- + +=== Configurable attributes + +|=== +| Name | Default value | Configurable values + +| EnforcedStyle +| `forbid_mixed_logical_operators` +| `forbid_mixed_logical_operators`, `forbid_logical_operators` +|=== + == Style/UnpackFirst |=== diff --git a/docs/modules/ROOT/pages/installation.adoc b/docs/modules/ROOT/pages/installation.adoc index 47c55c9e9be0..30ac7f14dc57 100644 --- a/docs/modules/ROOT/pages/installation.adoc +++ b/docs/modules/ROOT/pages/installation.adoc @@ -22,7 +22,7 @@ in your `Gemfile`: [source,rb] ---- -gem 'rubocop', '~> 1.10', require: false +gem 'rubocop', '~> 1.11', require: false ---- NOTE: You can check out our progress on the road to version 1.0 https://github.com/rubocop/rubocop/milestone/4[here]. diff --git a/lib/rubocop/version.rb b/lib/rubocop/version.rb index b649928e1bb1..69689ed94fc5 100644 --- a/lib/rubocop/version.rb +++ b/lib/rubocop/version.rb @@ -3,7 +3,7 @@ module RuboCop # This module holds the RuboCop version information. module Version - STRING = '1.10.0' + STRING = '1.11.0' MSG = '%s (using Parser %s, '\ 'rubocop-ast %s, ' \ diff --git a/relnotes/v1.11.0.md b/relnotes/v1.11.0.md new file mode 100644 index 000000000000..03e98403dec4 --- /dev/null +++ b/relnotes/v1.11.0.md @@ -0,0 +1,25 @@ +### New features + +* [#5388](https://github.com/rubocop/rubocop/issues/5388): Add new `Style/UnlessLogicalOperators` cop. ([@caalberts][]) +* [#9525](https://github.com/rubocop/rubocop/issues/9525): Add `AllowMethodsWithArguments` option to `Style/SymbolProc`. ([@koic][]) + +### Bug fixes + +* [#9520](https://github.com/rubocop/rubocop/issues/9520): Fix an incorrect auto-correct for `Style/MultipleComparison` when comparing a variable with multiple items in `if` and `elsif` conditions. ([@koic][]) +* [#9548](https://github.com/rubocop/rubocop/pull/9548): Fix a false positive for `Style/TrailingBodyOnMethodDefinition` when endless method definition body is after newline in opening parenthesis. ([@koic][]) +* [#9541](https://github.com/rubocop/rubocop/issues/9541): Fix `Style/HashConversion` when the correction needs to be wrapped in parens. ([@dvandersluis][]) +* [#9533](https://github.com/rubocop/rubocop/issues/9533): Make metrics length cops aware of multi-line kwargs. ([@koic][]) +* [#9523](https://github.com/rubocop/rubocop/issues/9523): Fix an error for `Style/TrailingMethodEndStatement` when endless method definition signature and body are on different lines. ([@koic][]) +* [#9482](https://github.com/rubocop/rubocop/issues/9482): Return minimal known ruby version from gemspecs `required_ruby_version`. ([@HeroProtagonist][]) +* [#9539](https://github.com/rubocop/rubocop/issues/9539): Fix an error for `Style/RedundantBegin` when using body of `begin` is empty. ([@koic][]) +* [#9542](https://github.com/rubocop/rubocop/pull/9542): Fix `Layout/FirstArgumentIndentation` for operator methods not called as operators. ([@dvandersluis][], [@TSMMark][]) + +### Changes + +* [#9526](https://github.com/rubocop/rubocop/issues/9526): Add `AllowSplatArgument` option to `Style/HashConversion` and the option is true by default. ([@koic][]) + +[@caalberts]: https://github.com/caalberts +[@koic]: https://github.com/koic +[@dvandersluis]: https://github.com/dvandersluis +[@HeroProtagonist]: https://github.com/HeroProtagonist +[@TSMMark]: https://github.com/TSMMark