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 Feb 8, 2023
1 parent b51bf26 commit b7cb165
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lib/yard/tags/default_factory.rb
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@ 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?
return nil
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
5 changes: 5 additions & 0 deletions spec/tags/default_factory_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -164,5 +164,10 @@ def parse_options(text)
expect(t.pair).to be_instance_of(Tags::DefaultTag)
expect(t.pair.name).to eq "key"
end

it "allows name only" do
t = parse_options("xyz")
expect(t.pair).to be(nil)
end
end
end

0 comments on commit b7cb165

Please sign in to comment.