Skip to content

Commit

Permalink
Handle invalid option tag with name only
Browse files Browse the repository at this point in the history
We have some of these in our codebase:

```
@option :foo
```

Handle them gracefully, even though they are invalid.
  • Loading branch information
naveg committed Apr 10, 2023
1 parent b51bf26 commit 1d79952
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
5 changes: 5 additions & 0 deletions lib/yard/tags/default_factory.rb
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,11 @@ def parse_tag_with_title_and_text(tag_name, text)
end

def parse_tag_with_types_name_and_default(tag_name, text)
if text.nil?
log.warn "Encountered #{tag_name} tag with no text"
return
end

# Can't allow () in a default tag, otherwise the grammar is too ambiguous when types is omitted.
open = TYPELIST_OPENING_CHARS.delete('(')
close = TYPELIST_CLOSING_CHARS.delete(')')
Expand Down
6 changes: 6 additions & 0 deletions spec/tags/default_factory_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -164,5 +164,11 @@ def parse_options(text)
expect(t.pair).to be_instance_of(Tags::DefaultTag)
expect(t.pair.name).to eq "key"
end

it "returns nil when only name is present" do
expect(log).to receive(:warn).with("Encountered option tag with no text")
t = parse_options("xyz")
expect(t.pair).to be(nil)
end
end
end

0 comments on commit 1d79952

Please sign in to comment.