Skip to content

tag.raw and line_number issues #1475

Open
@charlespwd

Description

@charlespwd

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:

  1. tag.raw needs work.
  2. line_number is not enough to identify the location of a tag in a file. We'd need the col as well, or better the start_index,end_index range 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

  1. Find the start of the line for the markup
  2. Find the markup on the line, backtrack on whitespace till you find the tag
  3. 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:

  1. Searching for "" on line 3 returns the start of line. Could either backtrack or look ahead.
  2. 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

  1. Both comments have line_number=3, both comments have markup == ""
  2. markup="" is found on the beginning of the line could either look for tag_name backwards 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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions