-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
class Foo; bar do
will crash Metrics/BlockLength
#12873
Comments
Hmmm, not a bug, I think that the issue pointed in the error. It comes from the
It's rather confusing it doesn't just crash when parsing the config file? (rather than throwing the error when actually inspecting the ruby code) |
koic
added a commit
to koic/rubocop
that referenced
this issue
Apr 29, 2024
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.
koic
added a commit
to koic/rubocop
that referenced
this issue
Apr 29, 2024
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 `Style/Copyright` cop is not valid. This clarifies what needs to be addressed first to achieve the expected behavior.
8 tasks
Yes, it's not a bug, but I've opened issue #12874 to make some adjustments to the unclear parts. |
koic
added a commit
to koic/rubocop
that referenced
this issue
Apr 29, 2024
Fixes 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 `Style/Copyright` cop is not valid. This clarifies what needs to be addressed first to achieve the expected behavior.
koic
added a commit
that referenced
this issue
Apr 29, 2024
…ngth [Fix #12873] Fix an error for `Metrics/BlockLength`
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Running rubocop on Windows 11 against a file named (
rubocop_fails.rb
) with the content below:The
.rubocop.yml
file (in the same folder) contains this:Expected behavior
Rubocop should just say that the block is too long
Actual behavior
It displays the results of some cops an when inspecting
Metrics/BlockLength
fails with error:Full result:
Steps to reproduce the problem
Prepare the sample ruby file and the
.rubocop.yml
as outlined at the beginning of this report.Next run:
You should see the same result as outlined in the Actual behaviour section above
RuboCop version
ruby 3.2.2
(tested)The text was updated successfully, but these errors were encountered: