Skip to content

bundle/remover: Remove description comments#21735

Open
issyl0 wants to merge 2 commits intomainfrom
bundle-remove-comments
Open

bundle/remover: Remove description comments#21735
issyl0 wants to merge 2 commits intomainfrom
bundle-remove-comments

Conversation

@issyl0
Copy link
Member

@issyl0 issyl0 commented Mar 14, 2026

  • Have you followed the guidelines in our Contributing document?
  • Have you checked to ensure there aren't other open Pull Requests for the same change?
  • Have you added an explanation of what your changes do and why you'd like us to include them?
  • Have you written new tests for your changes? Here's an example.
  • Have you successfully run brew lgtm (style, typechecking and tests) with your changes locally?

  • AI was used to generate or assist with generating this PR. Please specify below how you used AI to help you, and what steps you have taken to manually verify the changes.

- Fixes #21732.
- When `brew bundle remove`ing, also clean up the directly preceding
  description comment (from `brew bundle dump --describe`, or any
  others).
@issyl0 issyl0 force-pushed the bundle-remove-comments branch from 4bdffd1 to 1974d89 Compare March 14, 2026 17:34
@issyl0 issyl0 marked this pull request as ready for review March 14, 2026 17:53
Copilot AI review requested due to automatic review settings March 14, 2026 17:53
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates brew bundle remove so that when an entry is removed from a Brewfile, any directly preceding description comment (typically produced by brew bundle dump --describe) is also cleaned up, addressing #21732.

Changes:

  • Update the Bundle remover logic to drop a directly preceding comment line when removing a matching entry.
  • Add an RSpec example asserting that a preceding description comment is removed along with the entry.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
Library/Homebrew/bundle/remover.rb Adjusts line-removal logic to also remove a preceding comment line when an entry is removed.
Library/Homebrew/test/bundle/commands/remove_spec.rb Adds coverage to ensure a preceding description comment is removed with the entry.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +37 to +52
let(:content) do
<<~BREWFILE
# Program providing model for GNU coding standards and practices
brew "hello"
# Get a file from an HTTP, HTTPS or FTP server
brew "curl"
BREWFILE
end

it "removes both the entry and its description comment" do
expect { remove }.not_to raise_error

expect(File.read(file)).to eq <<~BREWFILE
# Get a file from an HTTP, HTTPS or FTP server
brew "curl"
BREWFILE
Copy link
Member Author

@issyl0 issyl0 Mar 14, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is that a thing? I don't think that's a thing - descriptions are short?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's perhaps a thing in theory. Check homebrew/core and homebrew/cask. Might be worth adding an audit/rubocop for this afterwards if not.

Copy link
Member

@MikeMcQuaid MikeMcQuaid left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, looking good so far!

Comment on lines +32 to +33
content.split("\n").each do |line|
if line&.match?(entry_regex)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
content.split("\n").each do |line|
if line&.match?(entry_regex)
content.split("\n").compact.each do |line|
if line.match?(entry_regex)

Comment on lines +38 to +42
new_lines << line
end
end

new_content = "#{new_lines.join("\n")}\n"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

.filter_map might be nicer here

Comment on lines +37 to +52
let(:content) do
<<~BREWFILE
# Program providing model for GNU coding standards and practices
brew "hello"
# Get a file from an HTTP, HTTPS or FTP server
brew "curl"
BREWFILE
end

it "removes both the entry and its description comment" do
expect { remove }.not_to raise_error

expect(File.read(file)).to eq <<~BREWFILE
# Get a file from an HTTP, HTTPS or FTP server
brew "curl"
BREWFILE
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's perhaps a thing in theory. Check homebrew/core and homebrew/cask. Might be worth adding an audit/rubocop for this afterwards if not.


content.split("\n").each do |line|
if line&.match?(entry_regex)
# Remove any directly preceding comment - it could be a description
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It also could not be 😁. Worth directly comparing with the description from both the tab and the current formula/cask/JSON I think.

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.

brew bundle remove does not clean up descriptions in Brewfile

3 participants