Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add --mask-directive option #1459

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 6 additions & 0 deletions lib/yard/cli/yardoc.rb
Original file line number Diff line number Diff line change
Expand Up @@ -785,6 +785,12 @@ def tag_options(opts)
opts.on('--non-transitive-tag TAG', 'Marks a tag as not transitive') do |tag|
Tags::Library.transitive_tags -= [tag.to_sym]
end

opts.on('--mask-directive DIRECTIVE',
'Masks a directive to suppress any callback ' \
' and the "unknown directive" warning') do |tag|
Tags::Library.define_directive(tag, Tags::NilDirective)
end
end
end
end
Expand Down
6 changes: 6 additions & 0 deletions lib/yard/tags/directives.rb
Original file line number Diff line number Diff line change
Expand Up @@ -621,5 +621,11 @@ def call
end
end
end

# Does nothing but suppresses "unknown directive" warnings, if
# a missing directive definition was masked with this class.
class NilDirective < Directive
def call; end
end
end
end
5 changes: 5 additions & 0 deletions spec/cli/yardoc_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -806,6 +806,11 @@ def tag_hidden(tag)
@yardoc.parse_arguments('--non-transitive-tag', 'foo')
expect(Tags::Library.transitive_tags).not_to include(:foo)
end

it "accepts --mask-directive" do
@yardoc.parse_arguments('--mask-directive', 'foo')
expect(Tags::Library.factory_method_for_directive(:foo)).to eq Tags::NilDirective
end
end

describe "Safe mode" do
Expand Down
12 changes: 12 additions & 0 deletions spec/tags/directives_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -461,3 +461,15 @@ def baz; end
end if YARD::Parser::SourceParser.parser_type == :ruby
end
end

RSpec.describe YARD::Tags::NilDirective do
describe '#call' do
before { Tags::Library.define_directive(:unknown, YARD::Tags::NilDirective) }

after { Registry.clear }

it "does nothing if directive is unknown" do
tag_parse("@!unknown")
end
end
end