From 9e8a5ee053d93d4b0e2249a1d9abb22878b3dbdf Mon Sep 17 00:00:00 2001 From: Bozhidar Batsov Date: Mon, 15 Feb 2021 15:09:14 +0200 Subject: [PATCH] Cut 1.10 --- .github/ISSUE_TEMPLATE/bug_report.md | 2 +- CHANGELOG.md | 2 + CONTRIBUTING.md | 2 +- README.md | 2 +- config/default.yml | 8 +- docs/antora.yml | 2 +- docs/modules/ROOT/pages/cops.adoc | 2 + docs/modules/ROOT/pages/cops_gemspec.adoc | 41 +++++++++ docs/modules/ROOT/pages/cops_layout.adoc | 33 +++++++ docs/modules/ROOT/pages/cops_lint.adoc | 40 +++++--- docs/modules/ROOT/pages/cops_style.adoc | 107 +++++++++++++++++++--- docs/modules/ROOT/pages/installation.adoc | 2 +- lib/rubocop/version.rb | 2 +- relnotes/v1.10.0.md | 29 ++++++ 14 files changed, 242 insertions(+), 32 deletions(-) create mode 100644 relnotes/v1.10.0.md diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md index bd2106fe4af..08b3d5d6738 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.9.1 (using Parser 2.7.2.0, rubocop-ast 1.1.1, running on ruby 2.7.2 x86_64-linux) +1.10.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 8610874f1b2..94ecf376fe1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,8 @@ ## master (unreleased) +## 1.10.0 (2021-02-15) + ### New features * [#9478](https://github.com/rubocop-hq/rubocop/pull/9478): Add new `Style/HashConversion` cop. ([@zverok][]) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index cb48041aa99..464b085f1f3 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -17,7 +17,7 @@ do so. ``` $ rubocop -V -1.9.1 (using Parser 2.7.2.0, rubocop-ast 1.1.1, running on ruby 2.7.2 x86_64-linux) +1.10.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 89054fdeebf..e68c7df4996 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.9', require: false +gem 'rubocop', '~> 1.10', 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 3479e554a5b..01d3bccb37c 100644 --- a/config/default.yml +++ b/config/default.yml @@ -206,7 +206,7 @@ Bundler/OrderedGems: Gemspec/DateAssignment: Description: 'Checks that `date =` is not used in gemspec file, it is set automatically when the gem is packaged.' Enabled: pending - VersionAdded: '<>' + VersionAdded: '1.10' Include: - '**/*.gemspec' @@ -1453,7 +1453,7 @@ Lint/Debugger: Description: 'Check for debugger calls.' Enabled: true VersionAdded: '0.14' - VersionChanged: <> + VersionChanged: '1.10' DebuggerReceivers: [] # deprecated DebuggerMethods: # Groups are available so that a specific group can be disabled in @@ -3102,7 +3102,7 @@ Style/ConstantVisibility: visibility declarations. Enabled: false VersionAdded: '0.66' - VersionChanged: <> + VersionChanged: '1.10' IgnoreModules: false # Checks that you have put a copyright in a comment before any code. @@ -3445,7 +3445,7 @@ Style/HashAsLastArrayItem: Style/HashConversion: Description: 'Avoid Hash[] in favor of ary.to_h or literal hashes.' Enabled: pending - VersionAdded: <> + VersionAdded: '1.10' Style/HashEachMethods: Description: 'Use Hash#each_key and Hash#each_value.' diff --git a/docs/antora.yml b/docs/antora.yml index 52f2c59156f..08f0d1d31aa 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.10' nav: - modules/ROOT/nav.adoc diff --git a/docs/modules/ROOT/pages/cops.adoc b/docs/modules/ROOT/pages/cops.adoc index 574db1fed8b..6eb4632c552 100644 --- a/docs/modules/ROOT/pages/cops.adoc +++ b/docs/modules/ROOT/pages/cops.adoc @@ -80,6 +80,7 @@ In the following section you find all available cops: === Department xref:cops_gemspec.adoc[Gemspec] +* xref:cops_gemspec.adoc#gemspecdateassignment[Gemspec/DateAssignment] * xref:cops_gemspec.adoc#gemspecduplicatedassignment[Gemspec/DuplicatedAssignment] * xref:cops_gemspec.adoc#gemspecordereddependencies[Gemspec/OrderedDependencies] * xref:cops_gemspec.adoc#gemspecrequiredrubyversion[Gemspec/RequiredRubyVersion] @@ -418,6 +419,7 @@ In the following section you find all available cops: * xref:cops_style.adoc#styleglobalvars[Style/GlobalVars] * xref:cops_style.adoc#styleguardclause[Style/GuardClause] * xref:cops_style.adoc#stylehashaslastarrayitem[Style/HashAsLastArrayItem] +* xref:cops_style.adoc#stylehashconversion[Style/HashConversion] * xref:cops_style.adoc#stylehasheachmethods[Style/HashEachMethods] * xref:cops_style.adoc#stylehashexcept[Style/HashExcept] * xref:cops_style.adoc#stylehashlikecase[Style/HashLikeCase] diff --git a/docs/modules/ROOT/pages/cops_gemspec.adoc b/docs/modules/ROOT/pages/cops_gemspec.adoc index 8e864ea7b98..a6ace64da7d 100644 --- a/docs/modules/ROOT/pages/cops_gemspec.adoc +++ b/docs/modules/ROOT/pages/cops_gemspec.adoc @@ -1,5 +1,46 @@ = Gemspec +== Gemspec/DateAssignment + +|=== +| Enabled by default | Safe | Supports autocorrection | VersionAdded | VersionChanged + +| Pending +| Yes +| Yes +| 1.10 +| - +|=== + +This cop checks that `date =` is not used in gemspec file. +It is set automatically when the gem is packaged. + +=== Examples + +[source,ruby] +---- +# bad +Gem::Specification.new do |spec| + s.name = 'your_cool_gem_name' + spec.date = Time.now.strftime('%Y-%m-%d') +end + +# good +Gem::Specification.new do |spec| + s.name = 'your_cool_gem_name' +end +---- + +=== Configurable attributes + +|=== +| Name | Default value | Configurable values + +| Include +| `+**/*.gemspec+` +| Array +|=== + == Gemspec/DuplicatedAssignment |=== diff --git a/docs/modules/ROOT/pages/cops_layout.adoc b/docs/modules/ROOT/pages/cops_layout.adoc index cb9019235d3..8b933eb9e0d 100644 --- a/docs/modules/ROOT/pages/cops_layout.adoc +++ b/docs/modules/ROOT/pages/cops_layout.adoc @@ -4181,6 +4181,39 @@ foo = if expression end ---- +==== SupportedTypes: ['block', 'case', 'class', 'if', 'kwbegin', 'module'] (default) + +[source,ruby] +---- +# good +foo = + if expression + 'bar' + end + +# good +foo = + [1].map do |i| + i + 1 + end +---- + +==== SupportedTypes: ['block'] + +[source,ruby] +---- +# good +foo = if expression + 'bar' +end + +# good +foo = + [1].map do |i| + 'bar' * i + end +---- + === Configurable attributes |=== diff --git a/docs/modules/ROOT/pages/cops_lint.adoc b/docs/modules/ROOT/pages/cops_lint.adoc index dca3d396a3f..e09ea816ec7 100644 --- a/docs/modules/ROOT/pages/cops_lint.adoc +++ b/docs/modules/ROOT/pages/cops_lint.adoc @@ -579,11 +579,23 @@ Login | Yes | No | 0.14 -| 0.49 +| 1.10 |=== -This cop checks for calls to debugger or pry. -The cop can be configured to define which methods and receivers must be fixed. +This cop checks for debug calls (such as `debugger` or `binding.pry`) that should +not be kept for production code. + +The cop can be configured using `DebuggerMethods`. By default, a number of gems +debug entrypoints are configured (`Kernel`, `Byebug`, `Capybara`, `Pry`, `Rails`, +and `WebConsole`). Additional methods can be added. + +Specific default groups can be disabled if necessary: + +[source,yaml] +---- +Lint/Debugger: + WebConsole: ~ +--- === Examples @@ -618,18 +630,29 @@ def some_method end ---- +==== DebuggerMethods: [my_debugger] + +[source,ruby] +---- +# bad (ok during development) + +def some_method + my_debugger +end +---- + === Configurable attributes |=== | Name | Default value | Configurable values | DebuggerReceivers -| `binding`, `Kernel`, `Pry` +| `[]` | Array | DebuggerMethods -| `debugger`, `byebug`, `remote_byebug`, `pry`, `remote_pry`, `pry_remote`, `console`, `rescue`, `save_and_open_page`, `save_and_open_screenshot`, `irb` -| Array +| `{"Kernel"=>["binding.irb"], "Byebug"=>["byebug", "remote_byebug", "Kernel.byebug", "Kernel.remote_byebug"], "Capybara"=>["save_and_open_page", "save_and_open_screenshot"], "Pry"=>["binding.pry", "binding.remote_pry", "binding.pry_remote", "Pry.rescue"], "Rails"=>["debugger", "Kernel.debugger"], "WebConsole"=>["binding.console"]}` +| |=== == Lint/DeprecatedClassMethods @@ -2760,15 +2783,10 @@ comparison operators. [source,ruby] ---- # bad - x < y < z 10 <= x <= 20 ----- -[source,ruby] ----- # good - x < y && y < z 10 <= x && x <= 20 ---- diff --git a/docs/modules/ROOT/pages/cops_style.adoc b/docs/modules/ROOT/pages/cops_style.adoc index 69b1a16c875..5010ba24347 100644 --- a/docs/modules/ROOT/pages/cops_style.adoc +++ b/docs/modules/ROOT/pages/cops_style.adoc @@ -1989,7 +1989,7 @@ end | Yes | No | 0.66 -| - +| 1.10 |=== This cop checks that constants defined in classes and modules have @@ -2018,6 +2018,42 @@ class Foo end ---- +==== IgnoreModules: false (default) + +[source,ruby] +---- +# bad +class Foo + MyClass = Struct.new() +end + +# good +class Foo + MyClass = Struct.new() + public_constant :MyClass +end +---- + +==== IgnoreModules: true + +[source,ruby] +---- +# good +class Foo + MyClass = Struct.new() +end +---- + +=== Configurable attributes + +|=== +| Name | Default value | Configurable values + +| IgnoreModules +| `false` +| Boolean +|=== + == Style/Copyright |=== @@ -2614,8 +2650,8 @@ end This cop checks for uses of double negation (`!!`) to convert something to a boolean value. -When using `EnforcedStyle: allowed_in_returns`, allow double nagation in contexts -that use boolean as a return value. When using `EnforcedStyle: forbidden`, double nagation +When using `EnforcedStyle: allowed_in_returns`, allow double negation in contexts +that use boolean as a return value. When using `EnforcedStyle: forbidden`, double negation should be forbidden always. Please, note that when something is a boolean value @@ -3228,7 +3264,7 @@ def my_method() = x.foo | Enabled | Yes -| No +| Yes | 0.52 | - |=== @@ -3242,6 +3278,14 @@ in a backtrace. The cop also checks that the line number given relative to `__LINE__` is correct. +This cop will autocorrect incorrect or missing filename and line number +values. However, if `eval` is called without a binding argument, the cop +will not attempt to automatically add a binding, or add filename and +line values. + +This cop works only when a string literal is given as a code string. +No offence is reported if a string variable is given as below: + === Examples [source,ruby] @@ -3271,6 +3315,16 @@ C.class_eval <<-RUBY, __FILE__, __LINE__ + 1 RUBY ---- +[source,ruby] +---- +# not checked +code = <<-RUBY + def do_something + end +RUBY +eval code +---- + == Style/EvenOdd |=== @@ -3425,13 +3479,12 @@ end This cop enforces consistency when using exponential notation for numbers in the code (eg 1.2e4). Different styles are supported: -* `scientific` which enforces a mantissa between 1 (inclusive) - and 10 (exclusive). -* `engineering` which enforces the exponent to be a multiple of 3 - and the mantissa to be between 0.1 (inclusive) - and 10 (exclusive). -* `integral` which enforces the mantissa to always be a whole number - without trailing zeroes. + +* `scientific` which enforces a mantissa between 1 (inclusive) and 10 (exclusive). +* `engineering` which enforces the exponent to be a multiple of 3 and the mantissa + to be between 0.1 (inclusive) and 10 (exclusive). +* `integral` which enforces the mantissa to always be a whole number without + trailing zeroes. === Examples @@ -4183,6 +4236,38 @@ EnforcedStyle. * https://rubystyle.guide#hash-literal-as-last-array-item +== Style/HashConversion + +|=== +| Enabled by default | Safe | Supports autocorrection | VersionAdded | VersionChanged + +| Pending +| Yes +| Yes +| 1.10 +| - +|=== + +This cop checks the usage of pre-2.1 `Hash[args]` method of converting enumerables and +sequences of values to hashes. + +=== Examples + +[source,ruby] +---- +# bad +Hash[ary] + +# good +ary.to_h + +# bad +Hash[key1, value1, key2, value2] + +# good +{key1 => value1, key2 => value2} +---- + == Style/HashEachMethods |=== diff --git a/docs/modules/ROOT/pages/installation.adoc b/docs/modules/ROOT/pages/installation.adoc index 45fc4ac0f93..413da4a94e3 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.9', require: false +gem 'rubocop', '~> 1.10', require: false ---- NOTE: You can check out our progress on the road to version 1.0 https://github.com/rubocop-hq/rubocop/milestone/4[here]. diff --git a/lib/rubocop/version.rb b/lib/rubocop/version.rb index 6357ccfc23d..b649928e1bb 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.9.1' + STRING = '1.10.0' MSG = '%s (using Parser %s, '\ 'rubocop-ast %s, ' \ diff --git a/relnotes/v1.10.0.md b/relnotes/v1.10.0.md new file mode 100644 index 00000000000..b45d3f0b0de --- /dev/null +++ b/relnotes/v1.10.0.md @@ -0,0 +1,29 @@ +### New features + +* [#9478](https://github.com/rubocop-hq/rubocop/pull/9478): Add new `Style/HashConversion` cop. ([@zverok][]) +* [#9496](https://github.com/rubocop-hq/rubocop/pull/9496): Add new `Gemspec/DateAssignment` cop. ([@koic][]) +* [#8724](https://github.com/rubocop-hq/rubocop/issues/8724): Add `IgnoreModules` configuration to `Style/ConstantVisibility` to not register offense for module definitions. ([@tejasbubane][]) +* [#9403](https://github.com/rubocop-hq/rubocop/issues/9403): Add autocorrect for `Style/EvalWithLocation` cop. ([@cteece][]) + +### Bug fixes + +* [#9500](https://github.com/rubocop-hq/rubocop/issues/9500): Update `Lint/Debugger` so that only specific receivers for debug methods lead to offenses. ([@dvandersluis][]) +* [#9499](https://github.com/rubocop-hq/rubocop/issues/9499): Fix a false positive for `Layout/SpaceBeforeBrackets` when multiple spaces are inserted inside the left bracket. ([@koic][]) +* [#9507](https://github.com/rubocop-hq/rubocop/issues/9507): Fix an incorrect auto-correct for `Lint/RedundantSplatExpansion` when expanding `Array.new` call on method argument. ([@koic][]) +* [#9490](https://github.com/rubocop-hq/rubocop/issues/9490): Fix incorrect auto-correct for `Layout/FirstArgumentIndentation` when specifying `EnforcedStyle: with_fixed_indentation` of `Layout/ArgumentAlignment` and `EnforcedStyle: consistent` of `Layout/FirstArgumentIndentation`. ([@koic][]) +* [#9497](https://github.com/rubocop-hq/rubocop/issues/9497): Fix an error for `Style/ExplicitBlockArgument` when `yield` is inside block of `super`. ([@koic][]) +* [#9349](https://github.com/rubocop-hq/rubocop/issues/9349): Fix a false positive for `Lint/MultipleComparison` when using `&`, `|`, and `^` set operation operators in multiple comparison. ([@koic][]) +* [#9511](https://github.com/rubocop-hq/rubocop/pull/9511): Fix a false negative for `Lint/ElseLayout` when using multiple `elsif`s. ([@koic][]) +* [#9513](https://github.com/rubocop-hq/rubocop/issues/9513): Fix an incorrect auto-correct for `Style/HashConversion` when using hash argument `Hash[]`. ([@koic][]) +* [#9492](https://github.com/rubocop-hq/rubocop/issues/9492): Fix an incorrect auto-correct for `Lint/DeprecatedOpenSSLConstant` when using no argument algorithm. ([@koic][]) + +### Changes + +* [#9405](https://github.com/rubocop-hq/rubocop/pull/9405): Improve documentation for `Style/EvalWithLocation` cop. ([@taichi-ishitani][]) + +[@zverok]: https://github.com/zverok +[@koic]: https://github.com/koic +[@tejasbubane]: https://github.com/tejasbubane +[@cteece]: https://github.com/cteece +[@dvandersluis]: https://github.com/dvandersluis +[@taichi-ishitani]: https://github.com/taichi-ishitani