From 31cf8b43a92a178e65f99f4d43756c435b8bf9c0 Mon Sep 17 00:00:00 2001 From: Sam Ford <1584702+samford@users.noreply.github.com> Date: Tue, 2 Sep 2025 11:49:27 -0400 Subject: [PATCH] livecheck: support trailing comments in watchlist I ran `brew livecheck` today to check the packages in my watchlist and realized that it wasn't checking one package because I had added a trailing comment after the name (and `package # Comment` isn't a valid package name). I thought we had added support for trailing comments when we originally added comment support years back but I must have been mistaken. This adds support for trailing comments in livecheck watchlist files as part of refactoring the watchlist line parsing logic to only use one pass (instead of multiple `#map` and `#reject` calls). This maintains the existing behavior, where blank lines and lines starting with `#` are skipped, but does so in a more flexible manner. For example, the existing logic wouldn't skip a comment line that has one or more spaces before the `#` character but this new logic will correctly skip it. --- Library/Homebrew/dev-cmd/livecheck.rb | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/Library/Homebrew/dev-cmd/livecheck.rb b/Library/Homebrew/dev-cmd/livecheck.rb index 2685367a22..2c3a36584b 100644 --- a/Library/Homebrew/dev-cmd/livecheck.rb +++ b/Library/Homebrew/dev-cmd/livecheck.rb @@ -78,9 +78,15 @@ module Homebrew formulae + casks elsif File.exist?(watchlist_path) begin + # This removes blank lines, comment lines, and trailing comments names = Pathname.new(watchlist_path).read.lines - .reject { |line| line.start_with?("#") || line.blank? } - .map(&:strip) + .filter_map do |line| + comment_index = line.index("#") + next if comment_index&.zero? + + line = line[0...comment_index] if comment_index + line&.strip.presence + end named_args = CLI::NamedArgs.new(*names, parent: args) named_args.to_formulae_and_casks(ignore_unavailable: true)