Script 'mail_helper' called by obssrc Hello community, here is the log from the commit of package rubygem-rubocop for openSUSE:Factory checked in at 2021-01-22 21:50:10 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Comparing /work/SRC/openSUSE:Factory/rubygem-rubocop (Old) and /work/SRC/openSUSE:Factory/.rubygem-rubocop.new.28504 (New) ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Package is "rubygem-rubocop" Fri Jan 22 21:50:10 2021 rev:21 rq:866024 version:1.8.1 Changes: -------- --- /work/SRC/openSUSE:Factory/rubygem-rubocop/rubygem-rubocop.changes 2021-01-04 19:10:18.887446603 +0100 +++ /work/SRC/openSUSE:Factory/.rubygem-rubocop.new.28504/rubygem-rubocop.changes 2021-01-22 21:50:26.897689466 +0100 @@ -1,0 +2,48 @@ +Wed Jan 20 13:16:40 UTC 2021 - Stephan Kulow <co...@suse.com> + +updated to version 1.8.1 + no changelog found + +------------------------------------------------------------------- +Fri Jan 8 08:28:48 UTC 2021 - Dan ??erm??k <dcer...@suse.com> + +- New upstream release 1.8.0 + +### New features + +* [#9324](https://github.com/rubocop-hq/rubocop/pull/9324): Add new `Lint/DeprecatedConstants` cop. ([@koic][]) +* [#9319](https://github.com/rubocop-hq/rubocop/pull/9319): Support asdf's .tool-versions file. ([@noon-ng][]) +* [#9301](https://github.com/rubocop-hq/rubocop/pull/9301): Add new `Lint/RedundantDirGlobSort` cop. ([@koic][]) +* [#9281](https://github.com/rubocop-hq/rubocop/pull/9281): Add new cop `Style/EndlessMethod`. ([@dvandersluis][]) + +### Bug fixes + +* [#9298](https://github.com/rubocop-hq/rubocop/issues/9298): Fix an incorrect auto-correct for `Lint/RedundantCopDisableDirective` when there is a blank line before inline comment. ([@koic][]) +* [#9233](https://github.com/rubocop-hq/rubocop/issues/9233): Fix `Style/SoleNestedConditional` copying non-relevant comments during auto-correction. ([@Darhazer][]) +* [#9312](https://github.com/rubocop-hq/rubocop/issues/9312): Fix `Layout/FirstHashElementLineBreak` to apply to multi-line hashes with only a single element. ([@muirdm][]) +* [#9316](https://github.com/rubocop-hq/rubocop/issues/9316): Fix `Style/EmptyLiteral` registering wrong offense when using a numbered block for Hash.new, i.e. `Hash.new { _1[_2] = [] }`. ([@agargiulo][]) +* [#9308](https://github.com/rubocop-hq/rubocop/issues/9308): Fix an error for `Layout/EmptyLineBetweenDefs` when using endless class method. ([@koic][]) +* [#9314](https://github.com/rubocop-hq/rubocop/issues/9314): Fix an incorrect auto-correct for `Style/RedundantReturn` when multiple return values have a parenthesized return value. ([@koic][]) +* [#9335](https://github.com/rubocop-hq/rubocop/issues/9335): Fix an incorrect auto-correct for `EnforcedStyle: require_parentheses` of `Style/MethodCallWithArgsParentheses` with `Style/NestedParenthesizedCalls`. ([@koic][]) +* [#9290](https://github.com/rubocop-hq/rubocop/issues/9290): Fix a false positive for `Layout/SpaceBeforeBrackets` when using array literal method argument. ([@koic][]) +* [#9333](https://github.com/rubocop-hq/rubocop/issues/9333): Fix an error for `Style/IfInsideElse` when using a modifier `if` nested inside an `else` after `elsif`. ([@koic][]) +* [#9303](https://github.com/rubocop-hq/rubocop/issues/9303): Fix an incorrect auto-correct for `Style/RaiseArgs` with `EnforcedStyle: compact` when using exception instantiation argument. ([@koic][]) + +### Changes + +* [#9300](https://github.com/rubocop-hq/rubocop/pull/9300): Make `Lint/NonDeterministicRequireOrder` not to register offense when using Ruby 3.0 or higher. ([@koic][]) +* [#9320](https://github.com/rubocop-hq/rubocop/pull/9320): Support unicode-display_width v2. ([@dduugg][]) +* [#9288](https://github.com/rubocop-hq/rubocop/pull/9288): Require Parser 3.0.0.0 or higher. ([@koic][]) +* [#9337](https://github.com/rubocop-hq/rubocop/issues/9337): Add `AllowedIdentifiers` to `Naming/VariableName`. ([@dvandersluis][]) +* [#9295](https://github.com/rubocop-hq/rubocop/pull/9295): Update `Style/SingleLineMethods` to correct to an endless method definition if they are allowed. ([@dvandersluis][]) +* [#9331](https://github.com/rubocop-hq/rubocop/pull/9331): Mark `Style/MutableConstant` as unsafe. ([@koic][]) + +[@koic]: https://github.com/koic +[@noon-ng]: https://github.com/noon-ng +[@dvandersluis]: https://github.com/dvandersluis +[@Darhazer]: https://github.com/Darhazer +[@muirdm]: https://github.com/muirdm +[@agargiulo]: https://github.com/agargiulo +[@dduugg]: https://github.com/dduugg + +------------------------------------------------------------------- Old: ---- rubocop-1.7.0.gem New: ---- rubocop-1.8.1.gem ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Other differences: ------------------ ++++++ rubygem-rubocop.spec ++++++ --- /var/tmp/diff_new_pack.cyN7uj/_old 2021-01-22 21:50:27.485690300 +0100 +++ /var/tmp/diff_new_pack.cyN7uj/_new 2021-01-22 21:50:27.493690312 +0100 @@ -16,28 +16,29 @@ # -%define mod_name rubocop -%define mod_full_name %{mod_name}-%{version} # # This file was generated with a gem2rpm.yml and not just plain gem2rpm. # All sections marked as MANUAL, license headers, summaries and descriptions # can be maintained in that file. Please consult this file before editing any # of those fields # + Name: rubygem-rubocop -Version: 1.7.0 +Version: 1.8.1 Release: 0 -Summary: Automatic Ruby code style checking tool -License: MIT -Group: Development/Languages/Ruby -URL: https://github.com/rubocop-hq/rubocop -Source: https://rubygems.org/gems/%{mod_full_name}.gem -Source1: gem2rpm.yml +%define mod_name rubocop +%define mod_full_name %{mod_name}-%{version} +BuildRoot: %{_tmppath}/%{name}-%{version}-build BuildRequires: %{ruby >= 2.4.0} BuildRequires: %{rubygem gem2rpm} BuildRequires: ruby-macros >= 5 BuildRequires: update-alternatives -# FIXME: use proper Requires(pre/post/preun/...) +URL: https://github.com/rubocop-hq/rubocop +Source: https://rubygems.org/gems/%{mod_full_name}.gem +Source1: gem2rpm.yml +Summary: Automatic Ruby code style checking tool +License: MIT +Group: Development/Languages/Ruby PreReq: update-alternatives %description ++++++ rubocop-1.7.0.gem -> rubocop-1.8.1.gem ++++++ diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/LICENSE.txt new/LICENSE.txt --- old/LICENSE.txt 2020-12-25 08:21:01.000000000 +0100 +++ new/LICENSE.txt 2021-01-11 12:18:17.000000000 +0100 @@ -1,4 +1,4 @@ -Copyright (c) 2012-20 Bozhidar Batsov +Copyright (c) 2012-21 Bozhidar Batsov Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/README.md new/README.md --- old/README.md 2020-12-25 08:21:01.000000000 +0100 +++ new/README.md 2021-01-11 12:18:17.000000000 +0100 @@ -51,7 +51,7 @@ in your `Gemfile`: ```rb -gem 'rubocop', '~> 1.7', require: false +gem 'rubocop', '~> 1.8', require: false ``` See [versioning](https://docs.rubocop.org/rubocop/1.0/versioning.html) for further details. @@ -109,6 +109,7 @@ * [Maxim Krizhanovski](https://github.com/darhazer) * [Benjamin Quorning](https://github.com/bquorning) * [Marc-Andr?? Lafortune](https://github.com/marcandre) +* [Daniel Vandersluis](https://github.com/dvandersluis) See the [team page](https://docs.rubocop.org/rubocop/about/team.html) for more details. @@ -241,5 +242,5 @@ ## Copyright -Copyright (c) 2012-2020 Bozhidar Batsov. See [LICENSE.txt](LICENSE.txt) for +Copyright (c) 2012-2021 Bozhidar Batsov. See [LICENSE.txt](LICENSE.txt) for further details. Binary files old/checksums.yaml.gz and new/checksums.yaml.gz differ diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/config/default.yml new/config/default.yml --- old/config/default.yml 2020-12-25 08:21:01.000000000 +0100 +++ new/config/default.yml 2021-01-11 12:18:17.000000000 +0100 @@ -132,12 +132,13 @@ # If a value is specified for TargetRubyVersion then it is used. Acceptable # values are specificed as a float (i.e. 2.5); the teeny version of Ruby # should not be included. If the project specifies a Ruby version in the - # .ruby-version file, Gemfile or gems.rb file, RuboCop will try to determine - # the desired version of Ruby by inspecting the .ruby-version file first, - # followed by the Gemfile.lock or gems.locked file. (Although the Ruby version - # is specified in the Gemfile or gems.rb file, RuboCop reads the final value - # from the lock file.) If the Ruby version is still unresolved, RuboCop will - # use the oldest officially supported Ruby version (currently Ruby 2.4). + # .tool-versions or .ruby-version files, Gemfile or gems.rb file, RuboCop will + # try to determine the desired version of Ruby by inspecting the + # .tool-versions file first, then .ruby-version, followed by the Gemfile.lock + # or gems.locked file. (Although the Ruby version is specified in the Gemfile + # or gems.rb file, RuboCop reads the final value from the lock file.) If the + # Ruby version is still unresolved, RuboCop will use the oldest officially + # supported Ruby version (currently Ruby 2.4). TargetRubyVersion: ~ # Determines if a notification for extension libraries should be shown when # rubocop is run. Keys are the name of the extension, and values are an array @@ -1197,7 +1198,6 @@ StyleGuide: '#space-in-brackets-access' Enabled: pending VersionAdded: '1.7' - Safe: false Layout/SpaceBeforeComma: Description: 'No spaces before commas.' @@ -1469,6 +1469,34 @@ Enabled: true VersionAdded: '0.19' +Lint/DeprecatedConstants: + Description: 'Checks for deprecated constants.' + Enabled: pending + VersionAdded: '1.8' + # You can configure deprecated constants. + # If there is an alternative method, you can set alternative value as `Alternative`. + # And you can set the deprecated version as `DeprecatedVersion`. + # These options can be omitted if they are not needed. + # + # DeprecatedConstants: + # 'DEPRECATED_CONSTANT': + # Alternative: 'alternative_value' + # DeprecatedVersion: 'deprecated_version' + # + DeprecatedConstants: + 'NIL': + Alternative: 'nil' + DeprecatedVersion: '2.4' + 'TRUE': + Alternative: 'true' + DeprecatedVersion: '2.4' + 'FALSE': + Alternative: 'false' + DeprecatedVersion: '2.4' + 'Random::DEFAULT': + Alternative: 'Random.new' + DeprecatedVersion: '3.0' + Lint/DeprecatedOpenSSLConstant: Description: "Don't use algorithm constants for `OpenSSL::Cipher` and `OpenSSL::Digest`." Enabled: true @@ -1674,6 +1702,11 @@ VersionAdded: '0.50' VersionChanged: '0.87' +Lint/LambdaWithoutLiteralBlock: + Description: 'Checks uses of lambda without a literal block.' + Enabled: pending + VersionAdded: '1.8' + Lint/LiteralAsCondition: Description: 'Checks of literals used in conditions.' Enabled: true @@ -1836,6 +1869,11 @@ Enabled: true VersionAdded: '0.76' +Lint/RedundantDirGlobSort: + Description: 'Checks for redundant `sort` method to `Dir.glob` and `Dir[]`.' + Enabled: pending + VersionAdded: '1.8' + Lint/RedundantRequireStatement: Description: 'Checks for unnecessary `require` statement.' Enabled: true @@ -2502,10 +2540,12 @@ StyleGuide: '#snake-case-symbols-methods-vars' Enabled: true VersionAdded: '0.50' + VersionChanged: '1.8' EnforcedStyle: snake_case SupportedStyles: - snake_case - camelCase + AllowedIdentifiers: [] Naming/VariableNumber: Description: 'Use the configured style when numbering symbols, methods and variables.' @@ -3197,6 +3237,17 @@ VersionAdded: '0.9' VersionChanged: '0.81' +Style/EndlessMethod: + Description: 'Avoid the use of multi-lined endless method definitions.' + StyleGuide: '#endless-methods' + Enabled: pending + VersionAdded: '1.8' + EnforcedStyle: allow_single_line + SupportedStyles: + - allow_single_line + - allow_always + - disallow + Style/EvalWithLocation: Description: 'Pass `__FILE__` and `__LINE__` to `eval` method, as they are used by backtraces.' Enabled: true @@ -3220,9 +3271,8 @@ that just passes its arguments to another block. StyleGuide: '#block-argument' Enabled: true - # May change the yielding arity. - Safe: false VersionAdded: '0.89' + VersionChanged: '1.8' Style/ExponentialNotation: Description: 'When using exponential notation, favor a mantissa between 1 (inclusive) and 10 (exclusive).' @@ -3726,7 +3776,8 @@ Description: 'Do not assign mutable objects to constants.' Enabled: true VersionAdded: '0.34' - VersionChanged: '0.65' + VersionChanged: '1.8' + SafeAutoCorrect: false EnforcedStyle: literals SupportedStyles: # literals: freeze literals assigned to constants @@ -4330,7 +4381,7 @@ StyleGuide: '#no-single-line-methods' Enabled: true VersionAdded: '0.9' - VersionChanged: '1.7' + VersionChanged: '1.8' AllowIfMethodIsEmpty: true Style/SlicingWithRange: diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/lib/rubocop/comment_config.rb new/lib/rubocop/comment_config.rb --- old/lib/rubocop/comment_config.rb 2020-12-25 08:21:01.000000000 +0100 +++ new/lib/rubocop/comment_config.rb 2021-01-11 12:18:17.000000000 +0100 @@ -47,6 +47,12 @@ ) end + def comment_only_line?(line_number) + non_comment_token_line_numbers.none? do |non_comment_line_number| + non_comment_line_number == line_number + end + end + private def extra_enabled_comments_with_names(extras:, names:) @@ -166,12 +172,6 @@ @all_cop_names ||= Cop::Registry.global.names - [REDUNDANT_DISABLE] end - def comment_only_line?(line_number) - non_comment_token_line_numbers.none? do |non_comment_line_number| - non_comment_line_number == line_number - end - end - def non_comment_token_line_numbers @non_comment_token_line_numbers ||= begin non_comment_tokens = processed_source.tokens.reject(&:comment?) diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/lib/rubocop/config_loader.rb new/lib/rubocop/config_loader.rb --- old/lib/rubocop/config_loader.rb 2020-12-25 08:21:01.000000000 +0100 +++ new/lib/rubocop/config_loader.rb 2021-01-11 12:18:17.000000000 +0100 @@ -175,7 +175,7 @@ end def loaded_features - @loaded_features.flatten.compact + @loaded_features.flatten.compact.uniq end # @api private diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/lib/rubocop/cop/layout/empty_line_between_defs.rb new/lib/rubocop/cop/layout/empty_line_between_defs.rb --- old/lib/rubocop/cop/layout/empty_line_between_defs.rb 2020-12-25 08:21:01.000000000 +0100 +++ new/lib/rubocop/cop/layout/empty_line_between_defs.rb 2021-01-11 12:18:17.000000000 +0100 @@ -210,7 +210,7 @@ end def end_loc(node) - if node.def_type? && node.endless? + if (node.def_type? || node.defs_type?) && node.endless? node.loc.expression.end else node.loc.end diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/lib/rubocop/cop/layout/multiline_operation_indentation.rb new/lib/rubocop/cop/layout/multiline_operation_indentation.rb --- old/lib/rubocop/cop/layout/multiline_operation_indentation.rb 2020-12-25 08:21:01.000000000 +0100 +++ new/lib/rubocop/cop/layout/multiline_operation_indentation.rb 2021-01-11 12:18:17.000000000 +0100 @@ -16,14 +16,14 @@ # if a + # b # something && - # something_else + # something_else # end # # # good # if a + # b # something && - # something_else + # something_else # end # # @example EnforcedStyle: indented diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/lib/rubocop/cop/layout/space_before_brackets.rb new/lib/rubocop/cop/layout/space_before_brackets.rb --- old/lib/rubocop/cop/layout/space_before_brackets.rb 2020-12-25 08:21:01.000000000 +0100 +++ new/lib/rubocop/cop/layout/space_before_brackets.rb 2021-01-11 12:18:17.000000000 +0100 @@ -6,10 +6,6 @@ # Checks for space between the name of a receiver and a left # brackets. # - # This cop is marked as unsafe because it can occur false positives - # for `do_something [this_is_an_array_literal_argument]` that take - # an array without parentheses as an argument. - # # @example # # # bad @@ -25,21 +21,23 @@ MSG = 'Remove the space before the opening brackets.' def on_send(node) - return if node.parenthesized? || node.parent&.send_type? return unless (first_argument = node.first_argument) begin_pos = first_argument.source_range.begin_pos - - return unless (range = offense_range(node, first_argument, begin_pos)) + return unless (range = offense_range(node, begin_pos)) register_offense(range) end private - def offense_range(node, first_argument, begin_pos) - if space_before_brackets?(node, first_argument) - range_between(node.loc.selector.end_pos, begin_pos) + def offense_range(node, begin_pos) + if reference_variable_with_brackets?(node) + receiver_end_pos = node.receiver.source_range.end_pos + selector_begin_pos = node.loc.selector.begin_pos + return if receiver_end_pos >= selector_begin_pos + + range_between(receiver_end_pos, selector_begin_pos) elsif node.method?(:[]=) end_pos = node.receiver.source_range.end_pos @@ -55,8 +53,8 @@ end end - def space_before_brackets?(node, first_argument) - node.receiver.nil? && first_argument.array_type? && node.arguments.size == 1 + def reference_variable_with_brackets?(node) + node.receiver&.variable? && node.method?(:[]) && node.arguments.size == 1 end end end diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/lib/rubocop/cop/lint/deprecated_constants.rb new/lib/rubocop/cop/lint/deprecated_constants.rb --- old/lib/rubocop/cop/lint/deprecated_constants.rb 1970-01-01 01:00:00.000000000 +0100 +++ new/lib/rubocop/cop/lint/deprecated_constants.rb 2021-01-11 12:18:17.000000000 +0100 @@ -0,0 +1,75 @@ +# frozen_string_literal: true + +module RuboCop + module Cop + module Lint + # This cop checks for deprecated constants. + # + # It has `DeprecatedConstants` config. If there is an alternative method, you can set + # alternative value as `Alternative`. And you can set the deprecated version as + # `DeprecatedVersion`. These options can be omitted if they are not needed. + # + # DeprecatedConstants: + # 'DEPRECATED_CONSTANT': + # Alternative: 'alternative_value' + # DeprecatedVersion: 'deprecated_version' + # + # By default, `NIL`, `TRUE`, `FALSE` and `Random::DEFAULT` are configured. + # + # @example + # + # # bad + # NIL + # TRUE + # FALSE + # Random::DEFAULT # Return value of Ruby 2 is `Random` instance, Ruby 3.0 is `Random` class. + # + # # good + # nil + # true + # false + # Random.new # `::DEFAULT` has been deprecated in Ruby 3, `.new` is compatible with Ruby 2. + # + class DeprecatedConstants < Base + extend AutoCorrector + + SUGGEST_GOOD_MSG = 'Use `%<good>s` instead of `%<bad>s`%<deprecated_message>s.' + DO_NOT_USE_MSG = 'Do not use `%<bad>s`%<deprecated_message>s.' + + def on_const(node) + constant = node.absolute? ? consntant_name(node, node.short_name.to_s) : node.source + return unless (deprecated_constant = deprecated_constants[constant]) + + alternative = deprecated_constant['Alternative'] + version = deprecated_constant['DeprecatedVersion'] + + add_offense(node, message: message(alternative, node.source, version)) do |corrector| + corrector.replace(node, alternative) + end + end + + private + + def consntant_name(node, nested_constant_name) + return nested_constant_name unless node.namespace.const_type? + + consntant_name(node.namespace, "#{node.namespace.short_name}::#{nested_constant_name}") + end + + def message(good, bad, deprecated_version) + deprecated_message = ", deprecated since Ruby #{deprecated_version}" if deprecated_version + + if good + format(SUGGEST_GOOD_MSG, good: good, bad: bad, deprecated_message: deprecated_message) + else + format(DO_NOT_USE_MSG, bad: bad, deprecated_message: deprecated_message) + end + end + + def deprecated_constants + cop_config.fetch('DeprecatedConstants', {}) + end + end + end + end +end diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/lib/rubocop/cop/lint/lambda_without_literal_block.rb new/lib/rubocop/cop/lint/lambda_without_literal_block.rb --- old/lib/rubocop/cop/lint/lambda_without_literal_block.rb 1970-01-01 01:00:00.000000000 +0100 +++ new/lib/rubocop/cop/lint/lambda_without_literal_block.rb 2021-01-11 12:18:17.000000000 +0100 @@ -0,0 +1,44 @@ +# frozen_string_literal: true + +module RuboCop + module Cop + module Lint + # This cop checks uses of lambda without a literal block. + # It emulates the following warning in Ruby 3.0: + # + # % ruby -vwe 'lambda(&proc {})' + # ruby 3.0.0p0 (2020-12-25 revision 95aff21468) [x86_64-darwin19] + # -e:1: warning: lambda without a literal block is deprecated; use the proc without + # lambda instead + # + # This way, proc object is never converted to lambda. + # Auto-correction replaces with compatible proc argument. + # + # @example + # + # # bad + # lambda(&proc { do_something }) + # lambda(&Proc.new { do_something }) + # + # # good + # proc { do_something } + # Proc.new { do_something } + # lambda { do_something } # If you use lambda. + # + class LambdaWithoutLiteralBlock < Base + extend AutoCorrector + + MSG = 'lambda without a literal block is deprecated; use the proc without lambda instead.' + RESTRICT_ON_SEND = %i[lambda].freeze + + def on_send(node) + return if node.parent&.block_type? || !node.first_argument + + add_offense(node) do |corrector| + corrector.replace(node, node.first_argument.source.delete('&')) + end + end + end + end + end +end diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/lib/rubocop/cop/lint/non_deterministic_require_order.rb new/lib/rubocop/cop/lint/non_deterministic_require_order.rb --- old/lib/rubocop/cop/lint/non_deterministic_require_order.rb 2020-12-25 08:21:01.000000000 +0100 +++ new/lib/rubocop/cop/lint/non_deterministic_require_order.rb 2021-01-11 12:18:17.000000000 +0100 @@ -11,6 +11,11 @@ # that are hard to debug. To ensure this doesn't happen, # always sort the list. # + # `Dir.glob` and `Dir[]` sort globbed results by default in Ruby 3.0. + # So all bad cases are acceptable when Ruby 3.0 or higher are used. + # + # This cop will be deprecated and removed when supporting only Ruby 3.0 and higher. + # # @example # # # bad @@ -23,8 +28,6 @@ # require file # end # - # @example - # # # bad # Dir.glob(Rails.root.join(__dir__, 'test', '*.rb')) do |file| # require file @@ -35,28 +38,28 @@ # require file # end # - # @example - # # # bad # Dir['./lib/**/*.rb'].each(&method(:require)) # # # good # Dir['./lib/**/*.rb'].sort.each(&method(:require)) # - # @example - # # # bad # Dir.glob(Rails.root.join('test', '*.rb'), &method(:require)) # # # good # Dir.glob(Rails.root.join('test', '*.rb')).sort.each(&method(:require)) # + # # good - Respect intent if `sort` keyword option is specified in Ruby 3.0 or higher. + # Dir.glob(Rails.root.join(__dir__, 'test', '*.rb'), sort: false).each(&method(:require)) + # class NonDeterministicRequireOrder < Base extend AutoCorrector MSG = 'Sort files before requiring them.' def on_block(node) + return if target_ruby_version >= 3.0 return unless node.body return unless unsorted_dir_loop?(node.send_node) @@ -70,6 +73,7 @@ end def on_block_pass(node) + return if target_ruby_version >= 3.0 return unless method_require?(node) return unless unsorted_dir_pass?(node.parent) diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/lib/rubocop/cop/lint/redundant_cop_disable_directive.rb new/lib/rubocop/cop/lint/redundant_cop_disable_directive.rb --- old/lib/rubocop/cop/lint/redundant_cop_disable_directive.rb 2020-12-25 08:21:01.000000000 +0100 +++ new/lib/rubocop/cop/lint/redundant_cop_disable_directive.rb 2021-01-11 12:18:17.000000000 +0100 @@ -61,7 +61,8 @@ end def comment_range_with_surrounding_space(range) - if previous_line_blank?(range) + if previous_line_blank?(range) && + processed_source.comment_config.comment_only_line?(range.line) # When the previous line is blank, it should be retained range_with_surrounding_space(range: range, side: :right) else diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/lib/rubocop/cop/lint/redundant_dir_glob_sort.rb new/lib/rubocop/cop/lint/redundant_dir_glob_sort.rb --- old/lib/rubocop/cop/lint/redundant_dir_glob_sort.rb 1970-01-01 01:00:00.000000000 +0100 +++ new/lib/rubocop/cop/lint/redundant_dir_glob_sort.rb 2021-01-11 12:18:17.000000000 +0100 @@ -0,0 +1,50 @@ +# frozen_string_literal: true + +module RuboCop + module Cop + module Lint + # Sort globbed results by default in Ruby 3.0. + # This cop checks for redundant `sort` method to `Dir.glob` and `Dir[]`. + # + # @example + # + # # bad + # Dir.glob('./lib/**/*.rb').sort.each do |file| + # end + # + # Dir['./lib/**/*.rb'].sort.each do |file| + # end + # + # # good + # Dir.glob('./lib/**/*.rb').each do |file| + # end + # + # Dir['./lib/**/*.rb'].each do |file| + # end + # + class RedundantDirGlobSort < Base + extend AutoCorrector + extend TargetRubyVersion + + minimum_target_ruby_version 3.0 + + MSG = 'Remove redundant `sort`.' + RESTRICT_ON_SEND = %i[sort].freeze + GLOB_METHODS = %i[glob []].freeze + + def on_send(node) + return unless (receiver = node.receiver) + return unless receiver.receiver&.const_type? && receiver.receiver.short_name == :Dir + return unless GLOB_METHODS.include?(receiver.method_name) + + selector = node.loc.selector + + add_offense(selector) do |corrector| + corrector.remove(selector) + corrector.remove(node.loc.dot) + end + end + end + end + end +end diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/lib/rubocop/cop/mixin/allowed_identifiers.rb new/lib/rubocop/cop/mixin/allowed_identifiers.rb --- old/lib/rubocop/cop/mixin/allowed_identifiers.rb 1970-01-01 01:00:00.000000000 +0100 +++ new/lib/rubocop/cop/mixin/allowed_identifiers.rb 2021-01-11 12:18:17.000000000 +0100 @@ -0,0 +1,18 @@ +# frozen_string_literal: true + +module RuboCop + module Cop + # This module encapsulates the ability to allow certain identifiers in a cop. + module AllowedIdentifiers + SIGILS = '@$' # if a variable starts with a sigil it will be removed + + def allowed_identifier?(name) + allowed_identifiers.include?(name.to_s.delete(SIGILS)) + end + + def allowed_identifiers + cop_config.fetch('AllowedIdentifiers', []) + end + end + end +end diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/lib/rubocop/cop/mixin/comments_help.rb new/lib/rubocop/cop/mixin/comments_help.rb --- old/lib/rubocop/cop/mixin/comments_help.rb 2020-12-25 08:21:01.000000000 +0100 +++ new/lib/rubocop/cop/mixin/comments_help.rb 2021-01-11 12:18:17.000000000 +0100 @@ -22,16 +22,7 @@ end def begin_pos_with_comment(node) - annotation_line = node.first_line - 1 - first_comment = nil - - processed_source.comments_before_line(annotation_line) - .reverse_each do |comment| - if comment.location.line == annotation_line - first_comment = comment - annotation_line -= 1 - end - end + first_comment = processed_source.ast_with_comments[node].first start_line_position(first_comment || node) end diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/lib/rubocop/cop/mixin/first_element_line_break.rb new/lib/rubocop/cop/mixin/first_element_line_break.rb --- old/lib/rubocop/cop/mixin/first_element_line_break.rb 2020-12-25 08:21:01.000000000 +0100 +++ new/lib/rubocop/cop/mixin/first_element_line_break.rb 2021-01-11 12:18:17.000000000 +0100 @@ -21,7 +21,7 @@ end def check_children_line_break(node, children, start = node) - return if children.size < 2 + return if children.empty? line = start.first_line diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/lib/rubocop/cop/mixin/uncommunicative_name.rb new/lib/rubocop/cop/mixin/uncommunicative_name.rb --- old/lib/rubocop/cop/mixin/uncommunicative_name.rb 2020-12-25 08:21:01.000000000 +0100 +++ new/lib/rubocop/cop/mixin/uncommunicative_name.rb 2021-01-11 12:18:17.000000000 +0100 @@ -24,7 +24,11 @@ name = full_name.gsub(/\A(_+)/, '') next if allowed_names.include?(name) - range = arg_range(arg, name.size) + length = full_name.size + length += 1 if arg.restarg_type? + length += 2 if arg.kwrestarg_type? + + range = arg_range(arg, length) issue_offenses(node, range, name) end end diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/lib/rubocop/cop/naming/variable_name.rb new/lib/rubocop/cop/naming/variable_name.rb --- old/lib/rubocop/cop/naming/variable_name.rb 2020-12-25 08:21:01.000000000 +0100 +++ new/lib/rubocop/cop/naming/variable_name.rb 2021-01-11 12:18:17.000000000 +0100 @@ -20,6 +20,7 @@ # # good # fooBar = 1 class VariableName < Base + include AllowedIdentifiers include ConfigurableNaming MSG = 'Use %<style>s for variable names.' @@ -27,6 +28,7 @@ def on_lvasgn(node) name, = *node return unless name + return if allowed_identifier?(name) check_name(node, name, node.loc.name) end diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/lib/rubocop/cop/naming/variable_number.rb new/lib/rubocop/cop/naming/variable_number.rb --- old/lib/rubocop/cop/naming/variable_number.rb 2020-12-25 08:21:01.000000000 +0100 +++ new/lib/rubocop/cop/naming/variable_number.rb 2021-01-11 12:18:17.000000000 +0100 @@ -97,6 +97,7 @@ # expect(Open3).to receive(:capture3) # class VariableNumber < Base + include AllowedIdentifiers include ConfigurableNumbering MSG = 'Use %<style>s for %<identifier_type>s numbers.' @@ -139,14 +140,6 @@ format(MSG, style: style, identifier_type: identifier_type) end - - def allowed_identifier?(name) - allowed_identifiers.include?(name.to_s.delete('@')) - end - - def allowed_identifiers - cop_config.fetch('AllowedIdentifiers', []) - end end end end diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/lib/rubocop/cop/style/empty_literal.rb new/lib/rubocop/cop/style/empty_literal.rb --- old/lib/rubocop/cop/style/empty_literal.rb 2020-12-25 08:21:01.000000000 +0100 +++ new/lib/rubocop/cop/style/empty_literal.rb 2021-01-11 12:18:17.000000000 +0100 @@ -32,8 +32,12 @@ def_node_matcher :str_node, '(send (const {nil? cbase} :String) :new)' def_node_matcher :array_with_block, '(block (send (const {nil? cbase} :Array) :new) args _)' - def_node_matcher :hash_with_block, - '(block (send (const {nil? cbase} :Hash) :new) args _)' + def_node_matcher :hash_with_block, <<~PATTERN + { + (block (send (const {nil? cbase} :Hash) :new) args _) + (numblock (send (const {nil? cbase} :Hash) :new) ...) + } + PATTERN def on_send(node) return unless (message = offense_message(node)) diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/lib/rubocop/cop/style/endless_method.rb new/lib/rubocop/cop/style/endless_method.rb --- old/lib/rubocop/cop/style/endless_method.rb 1970-01-01 01:00:00.000000000 +0100 +++ new/lib/rubocop/cop/style/endless_method.rb 2021-01-11 12:18:17.000000000 +0100 @@ -0,0 +1,102 @@ +# frozen_string_literal: true + +module RuboCop + module Cop + module Style + # This cop checks for endless methods. + # + # It can enforce either the use of endless methods definitions + # for single-lined method bodies, or disallow endless methods. + # + # Other method definition types are not considered by this cop. + # + # The supported styles are: + # * allow_single_line (default) - only single line endless method definitions are allowed. + # * allow_always - all endless method definitions are allowed. + # * disallow - all endless method definitions are disallowed. + # + # NOTE: Incorrect endless method definitions will always be + # corrected to a multi-line definition. + # + # @example EnforcedStyle: allow_single_line (default) + # # good + # def my_method() = x + # + # # bad, multi-line endless method + # def my_method() = x.foo + # .bar + # .baz + # + # @example EnforcedStyle: allow_always + # # good + # def my_method() = x + # + # # good + # def my_method() = x.foo + # .bar + # .baz + # + # @example EnforcedStyle: disallow + # # bad + # def my_method; x end + # + # # bad + # def my_method() = x.foo + # .bar + # .baz + # + class EndlessMethod < Base + include ConfigurableEnforcedStyle + extend TargetRubyVersion + extend AutoCorrector + + minimum_target_ruby_version 3.0 + + CORRECTION_STYLES = %w[multiline single_line].freeze + MSG = 'Avoid endless method definitions.' + MSG_MULTI_LINE = 'Avoid endless method definitions with multiple lines.' + + def on_def(node) + if style == :disallow + handle_disallow_style(node) + else + handle_allow_style(node) + end + end + + private + + def handle_allow_style(node) + return unless node.endless? + return if node.single_line? || style == :allow_always + + add_offense(node, message: MSG_MULTI_LINE) do |corrector| + correct_to_multiline(corrector, node) + end + end + + def handle_disallow_style(node) + return unless node.endless? + + add_offense(node) do |corrector| + correct_to_multiline(corrector, node) + end + end + + def correct_to_multiline(corrector, node) + replacement = <<~RUBY.strip + def #{node.method_name}#{arguments(node)} + #{node.body.source} + end + RUBY + + corrector.replace(node, replacement) + end + + def arguments(node, missing = '') + node.arguments.any? ? node.arguments.source : missing + end + end + end + end +end diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/lib/rubocop/cop/style/explicit_block_argument.rb new/lib/rubocop/cop/style/explicit_block_argument.rb --- old/lib/rubocop/cop/style/explicit_block_argument.rb 2020-12-25 08:21:01.000000000 +0100 +++ new/lib/rubocop/cop/style/explicit_block_argument.rb 2021-01-11 12:18:17.000000000 +0100 @@ -6,6 +6,9 @@ # This cop enforces the use of explicit block argument to avoid writing # block literal that just passes its arguments to another block. # + # NOTE: This cop only registers an offense if the block args match the + # yield args exactly. + # # @example # # bad # def with_tmp_dir @@ -75,7 +78,14 @@ private def yielding_arguments?(block_args, yield_args) + yield_args = yield_args.dup.fill( + nil, + yield_args.length, block_args.length - yield_args.length + ) + yield_args.zip(block_args).all? do |yield_arg, block_arg| + next false unless yield_arg && block_arg + block_arg && yield_arg.children.first == block_arg.children.first end end diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/lib/rubocop/cop/style/hash_like_case.rb new/lib/rubocop/cop/style/hash_like_case.rb --- old/lib/rubocop/cop/style/hash_like_case.rb 2020-12-25 08:21:01.000000000 +0100 +++ new/lib/rubocop/cop/style/hash_like_case.rb 2021-01-11 12:18:17.000000000 +0100 @@ -68,7 +68,8 @@ length = cop_config['MinBranchesCount'] || 3 return length if length.is_a?(Integer) && length.positive? - raise 'MinBranchesCount needs to be a positive integer!' + warn Rainbow('`MinBranchesCount` needs to be a positive integer!').red + exit! end end end diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/lib/rubocop/cop/style/if_inside_else.rb new/lib/rubocop/cop/style/if_inside_else.rb --- old/lib/rubocop/cop/style/if_inside_else.rb 2020-12-25 08:21:01.000000000 +0100 +++ new/lib/rubocop/cop/style/if_inside_else.rb 2021-01-11 12:18:17.000000000 +0100 @@ -82,12 +82,10 @@ def autocorrect(corrector, node) if node.modifier_form? correct_to_elsif_from_modifier_form(corrector, node) - end_range = node.parent.loc.end else correct_to_elsif_from_if_inside_else_form(corrector, node, node.condition) - end_range = node.loc.end end - corrector.remove(range_by_whole_lines(end_range, include_final_newline: true)) + corrector.remove(range_by_whole_lines(find_end_range(node), include_final_newline: true)) corrector.remove( range_by_whole_lines(node.if_branch.source_range, include_final_newline: true) ) @@ -110,6 +108,13 @@ corrector.remove(condition) end + def find_end_range(node) + end_range = node.loc.end + return end_range if end_range + + find_end_range(node.parent) + end + def allow_if_modifier_in_else_branch?(else_branch) allow_if_modifier? && else_branch&.modifier_form? end diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/lib/rubocop/cop/style/method_call_with_args_parentheses.rb new/lib/rubocop/cop/style/method_call_with_args_parentheses.rb --- old/lib/rubocop/cop/style/method_call_with_args_parentheses.rb 2020-12-25 08:21:01.000000000 +0100 +++ new/lib/rubocop/cop/style/method_call_with_args_parentheses.rb 2021-01-11 12:18:17.000000000 +0100 @@ -157,6 +157,10 @@ include OmitParentheses extend AutoCorrector + def self.autocorrect_incompatible_with + [Style::NestedParenthesizedCalls] + end + def on_send(node) send(style, node) # call require_parentheses or omit_parentheses end diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/lib/rubocop/cop/style/nested_parenthesized_calls.rb new/lib/rubocop/cop/style/nested_parenthesized_calls.rb --- old/lib/rubocop/cop/style/nested_parenthesized_calls.rb 2020-12-25 08:21:01.000000000 +0100 +++ new/lib/rubocop/cop/style/nested_parenthesized_calls.rb 2021-01-11 12:18:17.000000000 +0100 @@ -19,6 +19,10 @@ MSG = 'Add parentheses to nested method call `%<source>s`.' + def self.autocorrect_incompatible_with + [Style::MethodCallWithArgsParentheses] + end + def on_send(node) return unless node.parenthesized? diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/lib/rubocop/cop/style/raise_args.rb new/lib/rubocop/cop/style/raise_args.rb --- old/lib/rubocop/cop/style/raise_args.rb 2020-12-25 08:21:01.000000000 +0100 +++ new/lib/rubocop/cop/style/raise_args.rb 2021-01-11 12:18:17.000000000 +0100 @@ -81,11 +81,12 @@ return node.source if message_nodes.size > 1 argument = message_nodes.first.source + exception_class = exception_node.const_name || exception_node.receiver.source if node.parent && requires_parens?(node.parent) - "#{node.method_name}(#{exception_node.const_name}.new(#{argument}))" + "#{node.method_name}(#{exception_class}.new(#{argument}))" else - "#{node.method_name} #{exception_node.const_name}.new(#{argument})" + "#{node.method_name} #{exception_class}.new(#{argument})" end end diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/lib/rubocop/cop/style/redundant_return.rb new/lib/rubocop/cop/style/redundant_return.rb --- old/lib/rubocop/cop/style/redundant_return.rb 2020-12-25 08:21:01.000000000 +0100 +++ new/lib/rubocop/cop/style/redundant_return.rb 2021-01-11 12:18:17.000000000 +0100 @@ -66,7 +66,7 @@ end def correct_with_arguments(return_node, corrector) - if return_node.arguments.size > 1 + if return_node.children.size > 1 add_brackets(corrector, return_node) elsif hash_without_braces?(return_node.first_argument) add_braces(corrector, return_node.first_argument) diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/lib/rubocop/cop/style/single_line_methods.rb new/lib/rubocop/cop/style/single_line_methods.rb --- old/lib/rubocop/cop/style/single_line_methods.rb 2020-12-25 08:21:01.000000000 +0100 +++ new/lib/rubocop/cop/style/single_line_methods.rb 2021-01-11 12:18:17.000000000 +0100 @@ -8,6 +8,10 @@ # # Endless methods added in Ruby 3.0 are also accepted by this cop. # + # If `Style/EndlessMethod` is enabled with `EnforcedStyle: allow` or + # `allow_always`, single-line methods will be auto-corrected to endless + # methods if there is only one statement in the body. + # # @example # # bad # def some_method; body end @@ -47,6 +51,28 @@ private def autocorrect(corrector, node) + if correct_to_endless?(node.body) + correct_to_endless(corrector, node) + else + correct_to_multiline(corrector, node) + end + end + + def allow_empty? + cop_config['AllowIfMethodIsEmpty'] + end + + def correct_to_endless?(body_node) + endless_method_config = config.for_cop('Style/EndlessMethod') + + return false unless endless_method_config['Enabled'] + return false if endless_method_config['EnforcedStyle'] == 'disallow' + return false unless body_node + + !(body_node.begin_type? || body_node.kwbegin_type?) + end + + def correct_to_multiline(corrector, node) each_part(node.body) do |part| LineBreakCorrector.break_line_before( range: part, node: node, corrector: corrector, @@ -62,8 +88,10 @@ move_comment(node, corrector) end - def allow_empty? - cop_config['AllowIfMethodIsEmpty'] + def correct_to_endless(corrector, node) + arguments = node.arguments.any? ? node.arguments.source : '()' + replacement = "def #{node.method_name}#{arguments} = #{node.body.source}" + corrector.replace(node, replacement) end def each_part(body) diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/lib/rubocop/cop/style/sole_nested_conditional.rb new/lib/rubocop/cop/style/sole_nested_conditional.rb --- old/lib/rubocop/cop/style/sole_nested_conditional.rb 2020-12-25 08:21:01.000000000 +0100 +++ new/lib/rubocop/cop/style/sole_nested_conditional.rb 2021-01-11 12:18:17.000000000 +0100 @@ -63,13 +63,13 @@ end def autocorrect(corrector, node, if_branch) + corrector.wrap(node.condition, '(', ')') if node.condition.or_type? + if node.unless? corrector.replace(node.loc.keyword, 'if') corrector.insert_before(node.condition, '!') end - corrector.wrap(node.condition, '(', ')') if node.condition.or_type? - and_operator = if_branch.unless? ? ' && !' : ' && ' if if_branch.modifier_form? correct_for_guard_condition_style(corrector, node, if_branch, and_operator) @@ -100,7 +100,7 @@ def correct_for_comment(corrector, node, if_branch) return if config.for_cop('Style/IfUnlessModifier')['Enabled'] - comments = processed_source.comments_before_line(if_branch.source_range.line) + comments = processed_source.ast_with_comments[if_branch] comment_text = comments.map(&:text).join("\n") << "\n" corrector.insert_before(node.loc.keyword, comment_text) unless comments.empty? diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/lib/rubocop/cop/style/string_concatenation.rb new/lib/rubocop/cop/style/string_concatenation.rb --- old/lib/rubocop/cop/style/string_concatenation.rb 2020-12-25 08:21:01.000000000 +0100 +++ new/lib/rubocop/cop/style/string_concatenation.rb 2021-01-11 12:18:17.000000000 +0100 @@ -116,7 +116,7 @@ parts.map do |part| if part.str_type? if single_quoted?(part) - part.value.gsub('\\') { '\\\\' } + part.value.gsub(/(\\|")/, '\\\\\&') else part.value.inspect[1..-2] end diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/lib/rubocop/cop/style/while_until_modifier.rb new/lib/rubocop/cop/style/while_until_modifier.rb --- old/lib/rubocop/cop/style/while_until_modifier.rb 2020-12-25 08:21:01.000000000 +0100 +++ new/lib/rubocop/cop/style/while_until_modifier.rb 2021-01-11 12:18:17.000000000 +0100 @@ -41,12 +41,10 @@ 'having a single-line body.' def on_while(node) - return unless node.multiline? && single_line_as_modifier?(node) + return unless single_line_as_modifier?(node) add_offense(node.loc.keyword, message: format(MSG, keyword: node.keyword)) do |corrector| - oneline = "#{node.body.source} #{node.keyword} #{node.condition.source}" - - corrector.replace(node, oneline) + corrector.replace(node, to_modifier_form(node)) end end alias on_until on_while diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/lib/rubocop/target_ruby.rb new/lib/rubocop/target_ruby.rb --- old/lib/rubocop/target_ruby.rb 2020-12-25 08:21:01.000000000 +0100 +++ new/lib/rubocop/target_ruby.rb 2021-01-11 12:18:17.000000000 +0100 @@ -44,33 +44,61 @@ # The target ruby version may be found in a .ruby-version file. # @api private class RubyVersionFile < Source - FILENAME = '.ruby-version' + RUBY_VERSION_FILENAME = '.ruby-version' + RUBY_VERSION_PATTERN = /\A(?:ruby-)?(?<version>\d+\.\d+)/.freeze def name - "`#{FILENAME}`" + "`#{RUBY_VERSION_FILENAME}`" end private + def filename + RUBY_VERSION_FILENAME + end + + def pattern + RUBY_VERSION_PATTERN + end + def find_version - file = ruby_version_file + file = version_file return unless file && File.file?(file) - # rubocop:disable Lint/MixedRegexpCaptureTypes - # `(ruby-)` is not a capture type. - File.read(file).match(/\A(ruby-)?(?<version>\d+\.\d+)/) do |md| - # rubocop:enable Lint/MixedRegexpCaptureTypes + File.read(file).match(pattern) do |md| md[:version].to_f end end - def ruby_version_file - @ruby_version_file ||= - @config.find_file_upwards(FILENAME, + def version_file + @version_file ||= + @config.find_file_upwards(filename, @config.base_dir_for_path_parameters) end end + # The target ruby version may be found in a .tool-versions file, in a line + # starting with `ruby`. + # @api private + class ToolVersionsFile < RubyVersionFile + TOOL_VERSIONS_FILENAME = '.tool-versions' + TOOL_VERSIONS_PATTERN = /\Aruby (?:ruby-)?(?<version>\d+\.\d+)/.freeze + + def name + "`#{TOOL_VERSIONS_FILENAME}`" + end + + private + + def filename + TOOL_VERSIONS_FILENAME + end + + def pattern + TOOL_VERSIONS_PATTERN + end + end + # The lock file of Bundler may identify the target ruby version. # @api private class BundlerLockFile < Source @@ -194,7 +222,15 @@ KNOWN_RUBIES end - SOURCES = [RuboCopConfig, RubyVersionFile, BundlerLockFile, GemspecFile, Default].freeze + SOURCES = [ + RuboCopConfig, + RubyVersionFile, + ToolVersionsFile, + BundlerLockFile, + GemspecFile, + Default + ].freeze + private_constant :SOURCES def initialize(config) diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/lib/rubocop/version.rb new/lib/rubocop/version.rb --- old/lib/rubocop/version.rb 2020-12-25 08:21:01.000000000 +0100 +++ new/lib/rubocop/version.rb 2021-01-11 12:18:17.000000000 +0100 @@ -3,7 +3,7 @@ module RuboCop # This module holds the RuboCop version information. module Version - STRING = '1.7.0' + STRING = '1.8.1' MSG = '%<version>s (using Parser %<parser_version>s, '\ 'rubocop-ast %<rubocop_ast_version>s, ' \ diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/lib/rubocop.rb new/lib/rubocop.rb --- old/lib/rubocop.rb 2020-12-25 08:21:01.000000000 +0100 +++ new/lib/rubocop.rb 2021-01-11 12:18:17.000000000 +0100 @@ -7,7 +7,7 @@ require 'set' require 'forwardable' require 'regexp_parser' -require 'unicode/display_width/no_string_ext' +require 'unicode/display_width' # we have to require RuboCop's version, before rubocop-ast's require_relative 'rubocop/version' @@ -61,6 +61,7 @@ require_relative 'rubocop/cop/mixin/array_min_size' require_relative 'rubocop/cop/mixin/array_syntax' require_relative 'rubocop/cop/mixin/alignment' +require_relative 'rubocop/cop/mixin/allowed_identifiers' require_relative 'rubocop/cop/mixin/allowed_methods' require_relative 'rubocop/cop/mixin/auto_corrector' require_relative 'rubocop/cop/mixin/check_assignment' @@ -262,6 +263,7 @@ require_relative 'rubocop/cop/lint/constant_resolution' require_relative 'rubocop/cop/lint/debugger' require_relative 'rubocop/cop/lint/deprecated_class_methods' +require_relative 'rubocop/cop/lint/deprecated_constants' require_relative 'rubocop/cop/lint/deprecated_open_ssl_constant' require_relative 'rubocop/cop/lint/disjunctive_assignment_in_constructor' require_relative 'rubocop/cop/lint/duplicate_branch' @@ -295,6 +297,7 @@ require_relative 'rubocop/cop/lint/inherit_exception' require_relative 'rubocop/cop/lint/ineffective_access_modifier' require_relative 'rubocop/cop/lint/interpolation_check' +require_relative 'rubocop/cop/lint/lambda_without_literal_block' require_relative 'rubocop/cop/lint/literal_as_condition' require_relative 'rubocop/cop/lint/literal_in_interpolation' require_relative 'rubocop/cop/lint/loop' @@ -318,6 +321,7 @@ require_relative 'rubocop/cop/lint/rand_one' require_relative 'rubocop/cop/lint/redundant_cop_disable_directive' require_relative 'rubocop/cop/lint/redundant_cop_enable_directive' +require_relative 'rubocop/cop/lint/redundant_dir_glob_sort' require_relative 'rubocop/cop/lint/redundant_require_statement' require_relative 'rubocop/cop/lint/redundant_safe_navigation' require_relative 'rubocop/cop/lint/redundant_splat_expansion' @@ -446,6 +450,7 @@ require_relative 'rubocop/cop/style/empty_lambda_parameter' require_relative 'rubocop/cop/style/empty_literal' require_relative 'rubocop/cop/style/empty_method' +require_relative 'rubocop/cop/style/endless_method' require_relative 'rubocop/cop/style/encoding' require_relative 'rubocop/cop/style/end_block' require_relative 'rubocop/cop/style/eval_with_location' diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/metadata new/metadata --- old/metadata 2020-12-25 08:21:01.000000000 +0100 +++ new/metadata 2021-01-11 12:18:17.000000000 +0100 @@ -1,7 +1,7 @@ --- !ruby/object:Gem::Specification name: rubocop version: !ruby/object:Gem::Version - version: 1.7.0 + version: 1.8.1 platform: ruby authors: - Bozhidar Batsov @@ -10,7 +10,7 @@ autorequire: bindir: exe cert_chain: [] -date: 2020-12-25 00:00:00.000000000 Z +date: 2021-01-11 00:00:00.000000000 Z dependencies: - !ruby/object:Gem::Dependency name: parallel @@ -32,14 +32,14 @@ requirements: - - ">=" - !ruby/object:Gem::Version - version: 2.7.1.5 + version: 3.0.0.0 type: :runtime prerelease: false version_requirements: !ruby/object:Gem::Requirement requirements: - - ">=" - !ruby/object:Gem::Version - version: 2.7.1.5 + version: 3.0.0.0 - !ruby/object:Gem::Dependency name: rainbow requirement: !ruby/object:Gem::Requirement @@ -137,7 +137,7 @@ version: 1.4.0 - - "<" - !ruby/object:Gem::Version - version: '2.0' + version: '3.0' type: :runtime prerelease: false version_requirements: !ruby/object:Gem::Requirement @@ -147,7 +147,7 @@ version: 1.4.0 - - "<" - !ruby/object:Gem::Version - version: '2.0' + version: '3.0' - !ruby/object:Gem::Dependency name: bundler requirement: !ruby/object:Gem::Requirement @@ -368,6 +368,7 @@ - lib/rubocop/cop/lint/constant_resolution.rb - lib/rubocop/cop/lint/debugger.rb - lib/rubocop/cop/lint/deprecated_class_methods.rb +- lib/rubocop/cop/lint/deprecated_constants.rb - lib/rubocop/cop/lint/deprecated_open_ssl_constant.rb - lib/rubocop/cop/lint/disjunctive_assignment_in_constructor.rb - lib/rubocop/cop/lint/duplicate_branch.rb @@ -401,6 +402,7 @@ - lib/rubocop/cop/lint/ineffective_access_modifier.rb - lib/rubocop/cop/lint/inherit_exception.rb - lib/rubocop/cop/lint/interpolation_check.rb +- lib/rubocop/cop/lint/lambda_without_literal_block.rb - lib/rubocop/cop/lint/literal_as_condition.rb - lib/rubocop/cop/lint/literal_in_interpolation.rb - lib/rubocop/cop/lint/loop.rb @@ -424,6 +426,7 @@ - lib/rubocop/cop/lint/rand_one.rb - lib/rubocop/cop/lint/redundant_cop_disable_directive.rb - lib/rubocop/cop/lint/redundant_cop_enable_directive.rb +- lib/rubocop/cop/lint/redundant_dir_glob_sort.rb - lib/rubocop/cop/lint/redundant_require_statement.rb - lib/rubocop/cop/lint/redundant_safe_navigation.rb - lib/rubocop/cop/lint/redundant_splat_expansion.rb @@ -485,6 +488,7 @@ - lib/rubocop/cop/metrics/utils/repeated_csend_discount.rb - lib/rubocop/cop/migration/department_name.rb - lib/rubocop/cop/mixin/alignment.rb +- lib/rubocop/cop/mixin/allowed_identifiers.rb - lib/rubocop/cop/mixin/allowed_methods.rb - lib/rubocop/cop/mixin/annotation_comment.rb - lib/rubocop/cop/mixin/array_min_size.rb @@ -627,6 +631,7 @@ - lib/rubocop/cop/style/empty_method.rb - lib/rubocop/cop/style/encoding.rb - lib/rubocop/cop/style/end_block.rb +- lib/rubocop/cop/style/endless_method.rb - lib/rubocop/cop/style/eval_with_location.rb - lib/rubocop/cop/style/even_odd.rb - lib/rubocop/cop/style/expand_path_arguments.rb @@ -851,7 +856,7 @@ homepage_uri: https://rubocop.org/ changelog_uri: https://github.com/rubocop-hq/rubocop/blob/master/CHANGELOG.md source_code_uri: https://github.com/rubocop-hq/rubocop/ - documentation_uri: https://docs.rubocop.org/rubocop/1.7/ + documentation_uri: https://docs.rubocop.org/rubocop/1.8/ bug_tracker_uri: https://github.com/rubocop-hq/rubocop/issues post_install_message: rdoc_options: []