Skip to content
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

Suppress errors on RuboCop 0.50.0 & Ruby 3.1+ #1256

Closed

Conversation

mishina2228
Copy link
Contributor

This PR suppress errors on RuboCop 0.50.0 & Ruby 3.1+.

RuboCop raises errors in fedora fedora:rawhide workflow.
https://github.com/brianmario/mysql2/runs/6070946568?check_suite_focus=true

Running RuboCop...
Inspecting 36 files
...............An error occurred while Lint/BlockAlignment cop was inspecting /build/lib/mysql2/console.rb:3:20.
To see the complete backtrace run rubocop -d.
..................An error occurred while Lint/BlockAlignment cop was inspecting /build/tasks/generate.rake:1:0.
To see the complete backtrace run rubocop -d.
...

36 files inspected, no offenses detected

2 errors occurred:
An error occurred while Lint/BlockAlignment cop was inspecting /build/lib/mysql2/console.rb:3:20.
An error occurred while Lint/BlockAlignment cop was inspecting /build/tasks/generate.rake:1:0.
Errors are usually caused by RuboCop bugs.
Please, report your problems to RuboCop's issue tracker.
Mention the following information in the issue report:
0.50.0 (using Parser 2.7.2.0, running on ruby 3.1.1 x86_64-linux)
RuboCop failed!

The latest RuboCop (v1.27.0) with Ruby 3.1 does not raise the error.
But this gem still supports Ruby 2.0, so we can't update RuboCop.
That's why I just excluded files that caused the error.

This change suppresses the following error:

```
$ bundle exec rubocop
Inspecting 36 files
...............An error occurred while Lint/BlockAlignment cop was inspecting /build/lib/mysql2/console.rb:3:20.
To see the complete backtrace run rubocop -d.
..................An error occurred while Lint/BlockAlignment cop was inspecting /build/tasks/generate.rake:1:0.
To see the complete backtrace run rubocop -d.
...

36 files inspected, no offenses detected

2 errors occurred:
An error occurred while Lint/BlockAlignment cop was inspecting /build/lib/mysql2/console.rb:3:20.
An error occurred while Lint/BlockAlignment cop was inspecting /build/tasks/generate.rake:1:0.
Errors are usually caused by RuboCop bugs.
Please, report your problems to RuboCop's issue tracker.
Mention the following information in the issue report:
0.50.0 (using Parser 2.7.2.0, running on ruby 3.1.0 x86_64-linux)
```
@sodabrew
Copy link
Collaborator

I'd rather update Rubocop. Is there less-recent version that spans the same Ruby support window? If not, it's on the list of reasons to drop Ruby 2.0 soon.

@mishina2228
Copy link
Contributor Author

mishina2228 commented Apr 20, 2022

Is there less-recent version that spans the same Ruby support window?

No, RuboCop v0.50.0 is the final version to support Ruby 2.0.
The next version is v0.51.0, which dropped support for Ruby 2.0.

I've found that RuboCop v0.49.1 does not raise errors,
but I think downgrading RuboCop is not an ideal solution.

$ ruby -v
ruby 3.1.0p0 (2021-12-25 revision fb4df44d16) [x86_64-linux]
$ bundle info rubocop
  * rubocop (0.49.1)
$ bundle exec rubocop
Warning: unrecognized cop Naming/HeredocDelimiterNaming found in /home/owner/git-repos/mysql2/.rubocop_todo.yml
Warning: unrecognized cop Naming/HeredocDelimiterNaming found in /home/owner/git-repos/mysql2/.rubocop.yml
Inspecting 36 files
....................................

36 files inspected, no offenses detected

So is it time to move forward with #917 and drop support for Ruby 2.0?

@junaruga
Copy link
Contributor

As you may know, there is a way to use a specific rubocop version conditionally for each Ruby version in Gemfile. E.g. rake.

mysql2/Gemfile

Lines 5 to 9 in ffdd8c6

gem 'rake', if Gem::Version.new(RUBY_VERSION) >= Gem::Version.new("2.2")
'~> 13.0.1'
else
'< 13'
end

@mishina2228
Copy link
Contributor Author

Yeah, but unfortunately, TargetRubyVersion is set to 2.0 in .rubocop.yml.
It's not available in v0.51.0...
That's why we cannot update RuboCop to >= 0.51.0.

$ bundle exec rubocop --version
0.51.0
$ bundle exec rubocop
Error: Unsupported Ruby version 2.0 found in `TargetRubyVersion` parameter (in .rubocop.yml). 2.0-compatible analysis was dropped after version 0.50.
Supported versions: 2.1, 2.2, 2.3, 2.4

Until now, when the Runtime version of RuboCop was bumped,
the minimum version of Ruby that could be parsed was also bumped.
However, it seems that this behavior was a mistake, and it should have been possible to parse older Ruby version code.

In the future, it's likely that the latest RuboCop will be able to parse Ruby 2.0 code.
When that happens, we'll be able to upgrade RuboCop to the latest version.

@koic
Copy link
Contributor

koic commented May 26, 2022

@mishina2228 RuboCop 1.13 has been released that can analyze code from Ruby 2.0 to 3.1 (and 3.2 is an experimental). The runtime Ruby version requires Ruby 2.6 or higher. https://github.com/rubocop/rubocop/releases/tag/v1.30.0

@mishina2228
Copy link
Contributor Author

Thank you @koic !
I'll try to upgrade RuboCop to v1.13.

@mishina2228
Copy link
Contributor Author

#1268 will fix the errors. So I close this PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants