Skip to content

Conversation

@apiology
Copy link
Contributor

@apiology apiology commented Feb 1, 2025

Description

When yard saw a constant like:

FOO = [%w[bar baz]]

it cut off the array at the first closing bracket in the resulting documentation:

[%w[bar baz]

Fix by ensuring that these types of arrays, which don't have a
starting :lbracket, don't pop off :lbracket state in @map

Drop dead code and add a variety of related regression cases found in
my application using sord after trying different fixes.

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).

@apiology
Copy link
Contributor Author

apiology commented Feb 1, 2025

Hmmm, it looks like ['1', %w[]] fails as well.

I'll work through the sord results on my code, track down any other interesting cases, and at least suggest failing specs if not fixes - suggest we hold off on this fix for a minute to see if I find anything that affects the current change.

@apiology apiology force-pushed the fix_word_array_in_array_parsing branch 2 times, most recently from 88e7395 to f8e75b9 Compare February 2, 2025 22:26
@apiology
Copy link
Contributor Author

apiology commented Feb 2, 2025

All right, added simplified regression test cases, found a different fix which seems more robust, and verified it passed tests as well as sord on my application.

sord is useful for regression against a codebase here as it uses the output of yard's parse of e.g. constants and feeds the results into sorbet, which parses it again, complaining about syntax errors when yard doesn't give the correct source range.

sstart = other.source_range.begin
lstart = other.line_range.begin
node.source_range = Range.new(sstart, @ns_charno - 1)
node.line_range = Range.new(lstart, lineno)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Unless I'm missing something, this is dead code. Let me know if I'm wrong.

Copy link
Owner

Choose a reason for hiding this comment

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

This is not dead code per se. This is meant to future-proof the implementation for new node types which happens fairly often.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Gotcha. Just seemed strange those two assignments were immediately overridden. I'll revert that, but definitely curious to hear what I'm misunderstanding there.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Reverted

When yard saw a constant like:

```ruby
FOO = [%w[bar baz]]
```

it cut off the array at the first closing bracket:

```ruby
[%w[bar baz]
```

Fix by ensuring that these types of arrays, which don't have a
starting :lbracket, don't pop off :lbracket state in @Map.

Drop dead code and add a variety of related regression cases found in
my application using sord after trying different fixes.
@apiology apiology force-pushed the fix_word_array_in_array_parsing branch from f8e75b9 to a5dcc55 Compare February 3, 2025 01:37
@apiology apiology requested a review from lsegal February 3, 2025 23:30
@lsegal lsegal merged commit a900652 into lsegal:main May 9, 2025
@lsegal
Copy link
Owner

lsegal commented May 9, 2025

Thanks for the fix!

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.

2 participants