Skip to content

Commit 02aebff

Browse files
authored
Merge pull request #12866 from amomchilov/rescue-GemfileNotFound
[Fix #12865] `require 'bundler'` if possible and rescue `Bundler::GemfileNotFound`
2 parents a8ef19c + 45bbf67 commit 02aebff

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
* [#12865](https://github.com/rubocop/rubocop/issues/12865): Fix Rails Cops, which weren't reporting any violations unless running with `bundle exec`. ([@amomchilov][])

lib/rubocop/lockfile.rb

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,25 @@
11
# frozen_string_literal: true
22

3+
begin
4+
# We might not be running with `bundle exec`, so we need to pull in Bundler ourselves,
5+
# in order to use `Bundler::LockfileParser`.
6+
require 'bundler'
7+
rescue LoadError
8+
nil
9+
end
10+
311
module RuboCop
412
# Encapsulation of a lockfile for use when checking for gems.
513
# Does not actually resolve gems, just parses the lockfile.
614
# @api private
715
class Lockfile
816
# @param [String, Pathname, nil] lockfile_path
917
def initialize(lockfile_path = nil)
10-
lockfile_path ||= Bundler.default_lockfile if bundler_lock_parser_defined?
18+
lockfile_path ||= begin
19+
::Bundler.default_lockfile if bundler_lock_parser_defined?
20+
rescue ::Bundler::GemfileNotFound
21+
nil # We might not be a folder with a Gemfile, but that's okay.
22+
end
1123

1224
@lockfile_path = lockfile_path
1325
end

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy