From 30f14e8271d4b4eafcb096d7954dba372bc36ad3 Mon Sep 17 00:00:00 2001 From: Petrik Date: Thu, 8 Feb 2024 21:58:56 +0100 Subject: [PATCH] Don't document aliases with trailing `:nodoc` directive Attribute readers and writers can be marked as `:nodoc` to keep them undocumented: ```ruby attr_reader :name # :nodoc: ``` For aliases this behaviour should be the same: ```ruby alias_method :old :new # :nodoc: ``` --- lib/rdoc/parser/ruby.rb | 6 ++++-- test/rdoc/test_rdoc_parser_ruby.rb | 22 ++++++++++++++++++++++ 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/lib/rdoc/parser/ruby.rb b/lib/rdoc/parser/ruby.rb index 2cc629ebdf..85f1cd0391 100644 --- a/lib/rdoc/parser/ruby.rb +++ b/lib/rdoc/parser/ruby.rb @@ -789,8 +789,10 @@ def parse_alias(context, single, tk, comment) al.line = line_no read_documentation_modifiers al, RDoc::ATTR_MODIFIERS - context.add_alias al - @stats.add_alias al + if al.document_self or not @track_visibility + context.add_alias al + @stats.add_alias al + end al end diff --git a/test/rdoc/test_rdoc_parser_ruby.rb b/test/rdoc/test_rdoc_parser_ruby.rb index 1f75ba7c6e..3e2a85ffba 100644 --- a/test/rdoc/test_rdoc_parser_ruby.rb +++ b/test/rdoc/test_rdoc_parser_ruby.rb @@ -3065,6 +3065,28 @@ def test_parse_statements_identifier_yields assert_nil m.params, 'Module parameter not removed' end + def test_parse_statements_nodoc_identifier_alias + klass = @top_level.add_class RDoc::NormalClass, 'Foo' + + util_parser "\nalias :old :new # :nodoc:" + + @parser.parse_statements klass, RDoc::Parser::Ruby::NORMAL, nil + + assert_empty klass.aliases + assert_empty klass.unmatched_alias_lists + end + + def test_parse_statements_nodoc_identifier_alias_method + klass = @top_level.add_class RDoc::NormalClass, 'Foo' + + util_parser "\nalias_method :old :new # :nodoc:" + + @parser.parse_statements klass, RDoc::Parser::Ruby::NORMAL, nil + + assert_empty klass.aliases + assert_empty klass.unmatched_alias_lists + end + def test_parse_statements_stopdoc_alias klass = @top_level.add_class RDoc::NormalClass, 'Foo'