Skip to content

Commit

Permalink
Merge pull request #12901 from Earlopain/bundler-gemfile-error
Browse files Browse the repository at this point in the history
[Fix #12876] Fix lockfile parsing if only the gemfile exists
  • Loading branch information
koic committed May 15, 2024
2 parents 2fee855 + 63737e2 commit 5e25d8f
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
1 change: 1 addition & 0 deletions changelog/fix_lockfile_parser_without_lockfile.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* [#12876](https://github.com/rubocop/rubocop/issues/12876): Fix an error for the lockfile parser if a gemfile exists but a lockfile doesn't. ([@earlopain][])
2 changes: 1 addition & 1 deletion lib/rubocop/lockfile.rb
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def includes_gem?(name)
def parser
return @parser if defined?(@parser)

@parser = if @lockfile_path && bundler_lock_parser_defined?
@parser = if @lockfile_path && File.exist?(@lockfile_path) && bundler_lock_parser_defined?
begin
lockfile = ::Bundler.read_file(@lockfile_path)
::Bundler::LockfileParser.new(lockfile) if lockfile
Expand Down
13 changes: 13 additions & 0 deletions spec/rubocop/lockfile_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,19 @@

it { is_expected.to eq([]) }
end

context 'when there is a gemfile without lockfile' do
let(:lockfile) { nil }

before do
allow(Bundler).to receive(:default_lockfile).and_return('Gemfile.lock')
create_file('Gemfile', <<~GEMFILE)
gem 'rubocop', '~> 1.65.0'
GEMFILE
end

it { is_expected.to eq([]) }
end
end

describe '#dependencies' do
Expand Down

0 comments on commit 5e25d8f

Please sign in to comment.