`tag.raw` and `line_number` issues
Nobody has claimed this yet.
- Dominant language
- Ruby
- Stars
- 11.9k
- Forks
- 1.5k
- Avg merge
- 17h 55m
- Merged PRs (30d)
- 3
Description
In theme-check, we're going through excessive lengths to attempt to figure out what the true tag.raw value is.
TL;DR few issues:
tag.rawneeds work.line_numberis not enough to identify the location of a tag in a file. We'd need the col as well, or better thestart_index,end_indexrange in the string.
The source of tag.raw right now is the following:
def raw
"#{tag_name} #{markup}"
end
This is wrong for any of the following tags:
// missing newline and spaces between 'render' and '"mysnippet"'
{%
render
"mysnippet"
%}
// tag.raw is "schema ", there's no space in the source
{%schema%}
To further complicate things on our end, the line_number is the line_number of the start of the markup (not the tag_name!).
// line number is 3 for this tag
1 {%
2 render
3 'snippet'
4 %}
So any attempt at finding the true location of the tag has to do the following
- Find the start of the line for the markup
- Find the markup on the line, backtrack on whitespace till you find the tag
- Return the markup with the correct whitespace, and remember the offset in line_number.
Which causes more problem, because it could be that the markup exists outside of the tag on the same line. Consider the following:
1 {%
2 comment
3 %}comment{% endcomment %}
We have a couple of issues:
- Searching for "" on line 3 returns the start of line. Could either backtrack or look ahead.
- If looking ahead, we will find comment outside of the tag.
Also, consider the following situation:
1 {%
2 comment
3 %}{% endcomment %}{%comment%}{% endcomment %}
More issues
- Both comments have
line_number=3, both comments havemarkup == "" - markup="" is found on the beginning of the line could either look for
tag_namebackwards or forward till end of line
As you can see by now, trying to account for all those edge cases is not only painful on our end, it also makes everything slower because we need to recalculate the true location of everything.
My life would be a lot easier if we had the correct value for tag.raw (with appropriate whitespace), better if we also had col numbers, and even better if we had start_index/end_index ranges inside the template.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the linked theme-check/liquid_node.rb code and trace how Liquid nodes obtain tag.raw and line_number. Determine where source whitespace and positions are lost, then define how exact tag ranges and corrected raw values should be exposed; the issue names no repository tests, so completion would require adding coverage for the multiline and adjacent-tag examples.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- ruby
- Domain
- compilers
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 25/100