Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix rubocop#12873. This PR fixes an error for `Metrics/BlockLength` when the `CountAsOne` config is invalid. ## Before Without the `-d` option, the cause is unclear: ```console $ bundle exec rubocop --only Metrics/BlockLength Inspecting 1 file An error occurred while Metrics/BlockLength cop was inspecting /Users/koic/src/github.com/koic/rubocop-issues/12873/example.rb:2:2. To see the complete backtrace run rubocop -d. . 1 file inspected, no offenses detected 1 error occurred: An error occurred while Metrics/BlockLength cop was inspecting /Users/koic/src/github.com/koic/rubocop-issues/12873/example.rb:2:2. Errors are usually caused by RuboCop bugs. Please, report your problems to RuboCop's issue tracker. https://github.com/rubocop/rubocop/issues Mention the following information in the issue report: 1.63.4 (using Parser 3.3.0.5, rubocop-ast 1.31.2, running on ruby 3.3.0) [x86_64-darwin22] ``` When the `-d` option is used, hint appears hidden within the backtrace: ```console $ bundle exec rubocop --only Metrics/BlockLength -d For /Users/koic/src/github.com/koic/rubocop-issues/12873: configuration from /Users/koic/src/github.com/koic/rubocop-issues/12873/.rubocop.yml Default configuration from /Users/koic/src/github.com/rubocop/rubocop/config/default.yml AllCops/Exclude configuration from /Users/koic/src/github.com/koic/rubocop-issues/.rubocop.yml configuration from /Users/koic/.rbenv/versions/3.3.0/lib/ruby/gems/3.3.0/gems/rubocop-minitest-0.35.0/config/default.yml configuration from /Users/koic/.rbenv/versions/3.3.0/lib/ruby/gems/3.3.0/gems/rubocop-minitest-0.35.0/config/default.yml configuration from /Users/koic/src/github.com/rubocop/rubocop-performance/config/default.yml configuration from /Users/koic/src/github.com/rubocop/rubocop-performance/config/default.yml configuration from /Users/koic/src/github.com/rubocop/rubocop-rails/config/default.yml configuration from /Users/koic/src/github.com/rubocop/rubocop-rails/config/default.yml Use parallel by default. Skipping parallel inspection: only a single file needs inspection Inspecting 1 file Scanning /Users/koic/src/github.com/koic/rubocop-issues/12873/example.rb An error occurred while Metrics/BlockLength cop was inspecting /Users/koic/src/github.com/koic/rubocop-issues/12873/example.rb:2:2. Unknown foldable type: :config. Valid foldable types are: array, hash, heredoc, send, csend. /Users/koic/src/github.com/rubocop/rubocop/lib/rubocop/cop/metrics/utils/code_length_calculator.rb:54:in `block in build_foldable_checks' ``` ## After Even without the `-d` option, only the hint is displayed: ```console $ bundle exec rubocop --only Metrics/BlockLength Inspecting 1 file Unknown foldable type: :config. Valid foldable types are: array, hash, heredoc, send, csend. (from file: /Users/koic/src/github.com/koic/rubocop-issues/12873/example.rb:2:2) . 1 file inspected, no offenses detected ``` This behavior is the same as when the `Notice` config in the `Style/Copyright` cop is not valid. This clarifies what needs to be addressed first to achieve the expected behavior.
- Loading branch information