Skip to content

Commit 707c7cc

Browse files
Exclude magic comments from documentation
This commit ensures magic comments are excluded from documentation. They were already filtered out when eagerly indexing comments but the same logic wasn't applied when lazily loading comments.
1 parent ab75352 commit 707c7cc

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

lib/ruby_indexer/lib/ruby_indexer/entry.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ def comments
8686
correct_group.filter_map do |comment|
8787
content = comment.slice.chomp
8888

89-
if content.valid_encoding?
89+
if content.valid_encoding? && !content.match?(@configuration.magic_comment_regex)
9090
content.delete_prefix!("#")
9191
content.delete_prefix!(" ")
9292
content

lib/ruby_indexer/test/classes_and_modules_test.rb

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -766,5 +766,25 @@ class Foo
766766
FileUtils.rm(path)
767767
end
768768
end
769+
770+
def test_lazy_comments_ignores_magic_comments
771+
path = File.join(Dir.pwd, "lib", "foo.rb")
772+
source = <<~RUBY
773+
# frozen_string_literal: true
774+
775+
class Foo
776+
end
777+
RUBY
778+
File.write(path, source)
779+
@index.index_single(URI::Generic.from_path(path: path), source, collect_comments: false)
780+
781+
entry = @index["Foo"]&.first #: as !nil
782+
783+
begin
784+
assert_empty(entry.comments)
785+
ensure
786+
FileUtils.rm(path)
787+
end
788+
end
769789
end
770790
end

0 commit comments

Comments
 (0)