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

Rails/Present Autocorrect breaks bin/bundle #104

Closed
MatthiasWinkelmann opened this issue Aug 14, 2019 · 6 comments · Fixed by #108
Closed

Rails/Present Autocorrect breaks bin/bundle #104

MatthiasWinkelmann opened this issue Aug 14, 2019 · 6 comments · Fixed by #108

Comments

@MatthiasWinkelmann
Copy link

Autocorrect for Rails/Present introduces an error in a default rails bin/bundle because the Rails libraries are not loaded at that point in the loading process.

Note that this is using ruby 2.7.0-preview1 and edge rails.


Actual behavior

~/p/Test ./bin/bundle
Traceback (most recent call last):
	2: from ./bin/bundle:107:in `<main>'
	1: from ./bin/bundle:75:in `load_bundler!'
./bin/bundle:44:in `gemfile': undefined method `present?' for nil:NilClass (NoMethodError)

Steps to reproduce the problem

  1. Initialise a new Rails application (somewhat minimised here):
~/projects  rails new --skip-webpack-install --edge --skip-test --skip-system-test --skip-turbolinks --skip-javascript --skip-spring --skip-sprockets --skip-action-cable --skip-puma --skip-active-storage --skip-action-text --skip-action-mailbox --skip-action-mailer --skip-keeps Test
      create
      create  README.md
      create  Rakefile
      create  .ruby-version
     [...]

At this point, bin/bundle works:

~/p/Test ❯ ./bin/bundle update
[DEPRECATED] Pass --all to `bundle update` to update everything
Fetching https://github.com/rails/rails.git
Fetching https://github.com/rails/web-console.git
[...]
  1. Initialising a minimal configuration:
~/projects ❯ cd Test
~/p/Test ❯ rubocop --init
Writing new .rubocop.yml to /Users/matthi/projects/Test/.rubocop.yml
~/p/Test ❯ echo "require:
             - rubocop-rails" > .rubocop.yml
  1. Running --auto-correct changes bin/bundle:
~/p/Test ❯ rubocop --auto-correct --debug --config .ruboco~/p/Test ❯ rubocop --auto-correct --debug --config .rubocop.yml
configuration from /Users/matthi/projects/Test/.rubocop.yml
configuration from /Users/matthi/.rbenv/versions/2.7.0-preview1/lib/ruby/gems/2.7.0/gems/rubocop-rails-2.3.0/config/default.yml
configuration from /Users/matthi/.rbenv/versions/2.7.0-preview1/lib/ruby/gems/2.7.0/gems/rubocop-rails-2.3.0/config/default.yml
Default configuration from /Users/matthi/.rbenv/versions/2.7.0-preview1/lib/ruby/gems/2.7.0/gems/rubocop-0.74.0/config/default.yml
Inspecting 27 files
Scanning /Users/matthi/projects/Test/Gemfile
CScanning /Users/matthi/projects/Test/Rakefile
[...]
bin/bundle:42:23: C: [Corrected] Rails/Present: Use gemfile.present? instead of gemfile && !gemfile.empty?.
    return gemfile if gemfile && !gemfile.empty?

RuboCop version

~/p/Test ❯ rubocop -V
0.74.0 (using Parser 2.6.3.0, running on ruby 2.7.0 x86_64-darwin18)

~/p/Test ❯ gem list | rg rubocop
rubocop (0.74.0)
rubocop-performance (1.4.1, 1.4.0)
rubocop-rails (2.3.0)
@andyw8
Copy link
Contributor

andyw8 commented Aug 14, 2019

Perhaps rubocop-rails should ignore anything in bin/ since those are typically auto-generated files.

koic added a commit to koic/rubocop-rails that referenced this issue Aug 16, 2019
Resolves rubocop#104.

`bin/bundle` was generated by Bundler. And Bundler doesn't
depend on Active Support (Rails).

This PR prevents the following error.

```console
% cd path/to/new-rails-app
% bin/rails -v
Rails 6.0.0.rc2
% bundle exec rubocop -a --only Rails/Present
% g diff
diff --git a/bin/bundle b/bin/bundle
index 4f5e057..fa7b83b 100755
--- a/bin/bundle
+++ b/bin/bundle
@@ -39,7 +39,7 @@ m = Module.new do

   def gemfile
     gemfile = ENV["BUNDLE_GEMFILE"]
-    return gemfile if gemfile && !gemfile.empty?
+    return gemfile if gemfile.present?

     File.expand_path("../../Gemfile", __FILE__)
   end
% ./bin/bundle
Traceback (most recent call last):
        2: from ./bin/bundle:101:in `<main>'
        1: from ./bin/bundle:71:in `load_bundler!'
./bin/bundle:42:in `gemfile': undefined method `present?' for
   nil:NilClass (NoMethodError)
```
@koic
Copy link
Member

koic commented Aug 16, 2019

I agreed and opened a PR #108.

@koic koic closed this as completed in #108 Aug 19, 2019
koic added a commit that referenced this issue Aug 19, 2019
[Fix #104] Exclude Rails-independent `bin/bundle` by default
@koic
Copy link
Member

koic commented Aug 26, 2019

RuboCop Rails 2.3.1 has been released to resolve this issue. Thank you.

@jcoyne
Copy link
Contributor

jcoyne commented Sep 11, 2019

I'm not sure that #108 is sufficient if you have already have an AllCops.Exclude line in your .rubocop.yml

I hit this very problem and I'm on rubocop-rails 2.3.1

jcoyne added a commit to sul-dlss/argo that referenced this issue Sep 11, 2019
Rubocop autocorrect previously mangled this file which caused deploys to break.

See rubocop/rubocop-rails#104
mjgiarlo added a commit to sul-dlss/suri-rails that referenced this issue Apr 9, 2020
Rubocop auto-correction breaks some binstubs. See: rubocop/rubocop-rails#104 and https://github.com/sul-dlss/argo/pull/1585/files

This is preventing Puma from running in containerland.
@ismailarilik
Copy link

Same here, I am using rubocop-rails (2.23.1)

@andyw8
Copy link
Contributor

andyw8 commented Jan 30, 2024

👋 @ismailarilik this was closed over 4 years ago – it would be better to open a new issue.

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 a pull request may close this issue.

5 participants