From 7b014422738dcd5c8428b606d5429223371c87d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kristj=C3=A1n=20Oddsson?= Date: Fri, 31 Jan 2025 20:37:00 +0100 Subject: [PATCH] make sure disable comments have content --- Library/Homebrew/rubocops/disable_comment.rb | 2 +- Library/Homebrew/test/rubocops/disable_comment_spec.rb | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/Library/Homebrew/rubocops/disable_comment.rb b/Library/Homebrew/rubocops/disable_comment.rb index 9752e28535..0498f947bc 100644 --- a/Library/Homebrew/rubocops/disable_comment.rb +++ b/Library/Homebrew/rubocops/disable_comment.rb @@ -28,7 +28,7 @@ module RuboCop sig { params(line: String).returns(T::Boolean) } def comment?(line) - line.strip.start_with? "#" + line.strip.start_with?("#") && line.strip.delete_prefix("#") != "" end end end diff --git a/Library/Homebrew/test/rubocops/disable_comment_spec.rb b/Library/Homebrew/test/rubocops/disable_comment_spec.rb index f27b7716b0..0c3e0d2858 100644 --- a/Library/Homebrew/test/rubocops/disable_comment_spec.rb +++ b/Library/Homebrew/test/rubocops/disable_comment_spec.rb @@ -25,6 +25,16 @@ RSpec.describe RuboCop::Cop::DisableComment, :config do RUBY end + it "registers an offense if the comment is empty" do + expect_offense(<<~RUBY) + def something; end + # + # rubocop:disable Naming/AccessorMethodName + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Add a clarifying comment to the RuboCop disable comment + def get_decrypted_io; end + RUBY + end + it "doesn't register an offense" do expect_no_offenses(<<~RUBY) def something; end