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

Error while parsing Gemfile #6917

Closed
ryz310 opened this issue Apr 10, 2019 · 2 comments · Fixed by #6919 or #6944
Closed

Error while parsing Gemfile #6917

ryz310 opened this issue Apr 10, 2019 · 2 comments · Fixed by #6919 or #6944
Labels

Comments

@ryz310
Copy link

ryz310 commented Apr 10, 2019

An error occurred executing RuboCop v0.67.2.
Outputs error as following:

/usr/local/bundle/gems/rubocop-0.67.2/exe/rubocop:16:in `[]': no implicit conversion of String into Integer (TypeError)
	from /usr/local/bundle/gems/rubocop-0.67.2/exe/rubocop:16:in `<top (required)>'
	from /usr/local/bundle/bin/rubocop:29:in `load'
	from /usr/local/bundle/bin/rubocop:29:in `<main>'

And the related code is following:

https://github.com/rubocop-hq/rubocop/blob/1ec76b9251edb0e3edd159a72ec7fde58e1a22f8/exe/rubocop#L12-L16

I'm using Bundler in version v1.14 and the implement of LockFileParser#dependencies looks different between v1.14 and v1.15.

rubygems/bundler@9febe9a#diff-3c625d3cd7d7604b3e2e3c5487a5ede6L64

So I thought it should be changed requirement version for bundler in RuboCop gemspec.

https://github.com/rubocop-hq/rubocop/blob/1ec76b9251edb0e3edd159a72ec7fde58e1a22f8/rubocop.gemspec#L44

smortex referenced this issue Apr 10, 2019
### Summary

This PR warns for Performance Cops.

The following warning is displayed when the next released rubocop gem is installed.

```console
# The following is an example for operation check.
% rake build
% gem install pkg/rubocop-0.66.0.gem
Performance Cops will be removed from RuboCop 0.68. Use
rubocop-performance gem instead.

Put this in your Gemfile.

  gem 'rubocop-performance'

And then execute:

  $ bundle install

Put this into your .rubocop.yml.

  require: rubocop-performance

More information: https://github.com/rubocop-hq/rubocop-performance
Successfully installed rubocop-0.66.0
1 gem installed
```

The following warning is displayed if RuboCop is used with Bundler.

```consle
% bundle exec rubocop
[Warn] Performance Cops will be removed from RuboCop 0.68. Use rubocop-performance gem instead.
       https://github.com/rubocop-hq/rubocop/tree/master/manual/migrate_performance_cops.md
```

The above warning will disappear when rubocop-performance gem is written to Gemfile.
The rubocop-performance implementation takes precedence when rubocop-performance is
written in Gemfile.

And I prepared a simple migration manual (migrate_performance_cops.md)
because I think that long warning sentences are not preferred.
I think that referring to the link is good when runnning rubocop command.

### Other Infromation

At first I tried to remove performance cops from RuboCop Core and
add rubocop-performance gem as a dependency because of fallback.

```diff
% git diff
diff --git a/rubocop.gemspec b/rubocop.gemspec
index bbbcca33f..09882b063 100644
--- a/rubocop.gemspec
+++ b/rubocop.gemspec
@@ -38,6 +38,7 @@ Gem::Specification.new do |s|
   s.add_runtime_dependency('parser', '>= 2.5', '!= 2.5.1.1')
   s.add_runtime_dependency('psych', '>= 3.1.0')
   s.add_runtime_dependency('rainbow', '>= 2.2.2', '< 4.0')
+  s.add_runtime_dependency('rubocop-performance')
   s.add_runtime_dependency('ruby-progressbar', '~> 1.7')
   s.add_runtime_dependency('unicode-display_width', '>= 1.4.0', '< 1.6')
```

However, this cannot be resolved because it is cyclic.

```console
% bundle install
Fetching gem metadata from https://rubygems.org/........
Fetching gem metadata from https://rubygems.org/.
Resolving dependencies...
Your bundle requires gems that depend on each other, creating an infinite loop.
Please remove either gem 'rubocop' or gem 'rubocop-performance' and try again.
```

So I'd like to display a warning before removing performance cops.

I'd like to mitigate the impact on users this way.

The next step is to remove performance cops and done #5977.
@bbatsov
Copy link
Collaborator

bbatsov commented Apr 10, 2019

@koic Can you check this out?

koic added a commit to koic/rubocop that referenced this issue Apr 11, 2019
Fixes rubocop#6917.

This PR bumps Bundler dependency to >= 1.15.0.

Bundler 2 has already been released.
This PR drops old Bundler versions (1.14 or lower) to prevent the following error.

## Bundler 1.14

An unexpected error occurs.

```console
% bundle _1.14.6_ exec rubocop
bundler: failed to load command:
rubocop (/Users/koic/.rbenv/versions/2.6.2/lib/ruby/gems/2.6.0/bin/rubocop)
TypeError: no implicit conversion of String into Integer
  /Users/koic/.rbenv/versions/2.6.2/lib/ruby/gems/2.6.0/gems/rubocop-0.67.1/exe/rubocop:16:in
  `<top (required)>'
  /Users/koic/.rbenv/versions/2.6.2/lib/ruby/gems/2.6.0/bin/rubocop:23:in
  `load'
  /Users/koic/.rbenv/versions/2.6.2/lib/ruby/gems/2.6.0/bin/rubocop:23:in
  `<top (required)>'
```

## Bundler 1.15

Errors does not occur as expected.

```console
% bundle _1.15.0_ exec rubocop
[Warn] Performance Cops will be removed from RuboCop 0.68. Use
rubocop-performance gem instead.
       https://github.com/rubocop-hq/rubocop/tree/master/manual/migrate_performance_cops.md

(snip)
```
@koic
Copy link
Member

koic commented Apr 11, 2019

I checked this issue and I opened a PR #6919.

@koic koic added the bug label Apr 11, 2019
bbatsov pushed a commit that referenced this issue Apr 11, 2019
Fixes #6917.

This PR bumps Bundler dependency to >= 1.15.0.

Bundler 2 has already been released.
This PR drops old Bundler versions (1.14 or lower) to prevent the following error.

## Bundler 1.14

An unexpected error occurs.

```console
% bundle _1.14.6_ exec rubocop
bundler: failed to load command:
rubocop (/Users/koic/.rbenv/versions/2.6.2/lib/ruby/gems/2.6.0/bin/rubocop)
TypeError: no implicit conversion of String into Integer
  /Users/koic/.rbenv/versions/2.6.2/lib/ruby/gems/2.6.0/gems/rubocop-0.67.1/exe/rubocop:16:in
  `<top (required)>'
  /Users/koic/.rbenv/versions/2.6.2/lib/ruby/gems/2.6.0/bin/rubocop:23:in
  `load'
  /Users/koic/.rbenv/versions/2.6.2/lib/ruby/gems/2.6.0/bin/rubocop:23:in
  `<top (required)>'
```

## Bundler 1.15

Errors does not occur as expected.

```console
% bundle _1.15.0_ exec rubocop
[Warn] Performance Cops will be removed from RuboCop 0.68. Use
rubocop-performance gem instead.
       https://github.com/rubocop-hq/rubocop/tree/master/manual/migrate_performance_cops.md

(snip)
```
koic added a commit to koic/rubocop that referenced this issue Apr 17, 2019
Fixes rubocop#6939.
Fixes rubocop#6917.

This warning should not be displayed if users don't use Performance cops
as follows:

- rubocop#6845 (comment)
- rubocop#6919 (comment)

In the future, it will be better to replace it with a mechanism that
displays a warning only when the user need Performance cops.

This PR removes a warning for rubocop-performance when runinng `rubocop`
command.

It just leave a warning just to `gem install rubocop`.
https://github.com/rubocop-hq/rubocop/blob/v0.67.2/rubocop.gemspec#L47
bbatsov pushed a commit that referenced this issue Apr 17, 2019
Fixes #6939.
Fixes #6917.

This warning should not be displayed if users don't use Performance cops
as follows:

- #6845 (comment)
- #6919 (comment)

In the future, it will be better to replace it with a mechanism that
displays a warning only when the user need Performance cops.

This PR removes a warning for rubocop-performance when running `rubocop`
command.

It leaves a warning just for `gem install rubocop`.
https://github.com/rubocop-hq/rubocop/blob/v0.67.2/rubocop.gemspec#L47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
3 participants