make sure disable comments have content

This commit is contained in:
Kristján Oddsson 2025-01-31 20:37:00 +01:00
parent d7af1e3527
commit 7b01442273
2 changed files with 11 additions and 1 deletions

View File

@ -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

View File

@ -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