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

Handle invalid option tag with name only #1481

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

naveg
Copy link

@naveg naveg commented Feb 8, 2023

We have some of these in our codebase:

@option :foo

Handle them gracefully, even though they are invalid.

These were causing errors in VSCode, via Solargraph:

[WARN] Error processing request: [NoMethodError] undefined method `length' for nil:NilClass
[WARN] /Users/Evan.Goldenberg/.asdf/installs/ruby/2.7.3/lib/ruby/gems/2.7.0/gems/yard-0.9.28/lib/yard/tags/default_factory.rb:148:in `extract_types_and_name_from_text_unstripped'
/Users/Evan.Goldenberg/.asdf/installs/ruby/2.7.3/lib/ruby/gems/2.7.0/gems/yard-0.9.28/lib/yard/tags/default_factory.rb:132:in `extract_types_and_name_from_text'
/Users/Evan.Goldenberg/.asdf/installs/ruby/2.7.3/lib/ruby/gems/2.7.0/gems/yard-0.9.28/lib/yard/tags/default_factory.rb:79:in `parse_tag_with_types_name_and_default'
/Users/Evan.Goldenberg/.asdf/installs/ruby/2.7.3/lib/ruby/gems/2.7.0/gems/yard-0.9.28/lib/yard/tags/default_factory.rb:93:in `parse_tag_with_options'
/Users/Evan.Goldenberg/.asdf/installs/ruby/2.7.3/lib/ruby/gems/2.7.0/gems/yard-0.9.28/lib/yard/tags/library.rb:237:in `send_to_factory'
/Users/Evan.Goldenberg/.asdf/installs/ruby/2.7.3/lib/ruby/gems/2.7.0/gems/yard-0.9.28/lib/yard/tags/library.rb:169:in `option_tag'
/Users/Evan.Goldenberg/.asdf/installs/ruby/2.7.3/lib/ruby/gems/2.7.0/gems/yard-0.9.28/lib/yard/tags/library.rb:274:in `tag_create'
/Users/Evan.Goldenberg/.asdf/installs/ruby/2.7.3/lib/ruby/gems/2.7.0/gems/yard-0.9.28/lib/yard/docstring_parser.rb:215:in `create_tag'
/Users/Evan.Goldenberg/.asdf/installs/ruby/2.7.3/lib/ruby/gems/2.7.0/gems/yard-0.9.28/lib/yard/docstring_parser.rb:156:in `block in parse_content'
/Users/Evan.Goldenberg/.asdf/installs/ruby/2.7.3/lib/ruby/gems/2.7.0/gems/yard-0.9.28/lib/yard/docstring_parser.rb:142:in `each'
/Users/Evan.Goldenberg/.asdf/installs/ruby/2.7.3/lib/ruby/gems/2.7.0/gems/yard-0.9.28/lib/yard/docstring_parser.rb:142:in `each_with_index'
/Users/Evan.Goldenberg/.asdf/installs/ruby/2.7.3/lib/ruby/gems/2.7.0/gems/yard-0.9.28/lib/yard/docstring_parser.rb:142:in `parse_content'
/Users/Evan.Goldenberg/.asdf/installs/ruby/2.7.3/lib/ruby/gems/2.7.0/gems/yard-0.9.28/lib/yard/docstring_parser.rb:117:in `parse'
/Users/Evan.Goldenberg/.asdf/installs/ruby/2.7.3/lib/ruby/gems/2.7.0/gems/solargraph-0.48.0/lib/solargraph/source.rb:518:in `parse_docstring'
/Users/Evan.Goldenberg/.asdf/installs/ruby/2.7.3/lib/ruby/gems/2.7.0/gems/solargraph-0.48.0/lib/solargraph/pin/base.rb:246:in `parse_comments'
/Users/Evan.Goldenberg/.asdf/installs/ruby/2.7.3/lib/ruby/gems/2.7.0/gems/solargraph-0.48.0/lib/solargraph/pin/base.rb:99:in `docstring'
/Users/Evan.Goldenberg/.asdf/installs/ruby/2.7.3/lib/ruby/gems/2.7.0/gems/solargraph-0.48.0/lib/solargraph/pin/base.rb:129:in `deprecated?'
/Users/Evan.Goldenberg/.asdf/installs/ruby/2.7.3/lib/ruby/gems/2.7.0/gems/solargraph-0.48.0/lib/solargraph/language_server/message/workspace/workspace_symbol.rb:18:in `block in process'
/Users/Evan.Goldenberg/.asdf/installs/ruby/2.7.3/lib/ruby/gems/2.7.0/gems/solargraph-0.48.0/lib/solargraph/language_server/message/workspace/workspace_symbol.rb:8:in `map'
/Users/Evan.Goldenberg/.asdf/installs/ruby/2.7.3/lib/ruby/gems/2.7.0/gems/solargraph-0.48.0/lib/solargraph/language_server/message/workspace/workspace_symbol.rb:8:in `process'
/Users/Evan.Goldenberg/.asdf/installs/ruby/2.7.3/lib/ruby/gems/2.7.0/gems/solargraph-0.48.0/lib/solargraph/language_server/host.rb:112:in `receive'
/Users/Evan.Goldenberg/.asdf/installs/ruby/2.7.3/lib/ruby/gems/2.7.0/gems/solargraph-0.48.0/lib/solargraph/language_server/host/message_worker.rb:53:in `tick'
/Users/Evan.Goldenberg/.asdf/installs/ruby/2.7.3/lib/ruby/gems/2.7.0/gems/solargraph-0.48.0/lib/solargraph/language_server/host/message_worker.rb:44:in `block in start'

Completed Tasks

  • I have read the Contributing Guide.
  • The pull request is complete (implemented / written).
  • Git commits have been cleaned up (squash WIP / revert commits).
  • I wrote tests and ran bundle exec rake locally (if code is attached to PR).

@lsegal
Copy link
Owner

lsegal commented Apr 8, 2023

I think "gracefully" would require at least a warning for the invalid tags.

@@ -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
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. I would expect to see a warning being generated either here or somewhere in this code path.
  2. You can return instead of return nil
  3. I would recommend adding a newline of space after the end of this block (code style aesthetic)

@@ -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
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Realistically this test should be more descriptive-- technically these aren't "allowed".

We have some of these in our codebase:

```
@option :foo
```

Handle them gracefully, even though they are invalid.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants