Skip to content

citry check --format json counts template lines from 0 for some rules and from 1 for others #203

Closed

Description

@JuroOravec

What happens

In the JSON report, range.start.line and range.start.column for a template
finding start at 1 for some rules and at 0 for others. Two findings on the
same template line get different line numbers, so a tool that reads the
report (an editor, CI annotations, the benchmark) puts one of them on the
wrong line.

Rule Line and column
citry.parse.* (template syntax errors) from 1
citry.template.unknown-variable from 1
citry.vue.*, Alpine and attribute-value rules, marker names, i18n template rules from 0
citry.python.* (ty) from 0, but in .py file coordinates, while origin is file:line:col from 1

Expected

Every finding uses the same numbering, and the JSON output docs say which
one. Template-relative and file-relative ranges should also be labeled, since
citry.python.* findings use the .py file while the others use the
template.

Repro

Citry 0.6.0. All three problems are on the second line of the template string
(line index 1 after dedent):

class Greeting(Component):
    citry = citry_app

    class Kwargs:
        owner: Owner

    def template_data(self, kwargs: Kwargs, slots):
        return {"owner": kwargs.owner}

    template = """
      <p>{{ owner.nmae }} {{ missing }} <span v-text="nope"></span></p>
    """
$ citry --app app.citry_app:citry_app check --types --format json

The output, cut down:

citry.template.unknown-variable  start {line: 2, column: 24}  start_index 24
citry.vue.unknown-variable       start {line: 1, column: 48}  start_index 49
citry.python.unresolved-attribute
    origin .../greeting.py:22:13
    start {line: 21, column: 12}  start_index 354

missing starts at template index 24, which is column 23 counted from 0 on
line 1, but the report says line 2, column 24. nope at index 49 is reported
as line 1, column 48. A template that fails to parse (<c-if cond="x"> with
no closing tag on template line index 2) is reported at line 3, column 1.

Cause

Line numbers are on origin/main (695bd31).

  • The parse-error and unknown-variable findings copy Pest's line_col(),
    which counts from 1: packages/py/citry/citry/_checker.py:578 (parse
    diagnostic, documented as 1-based in
    crates/citry_template_parser/src/error.rs:28-37) and
    packages/py/citry/citry/_checker.py:636-639, fed by
    packages/py/citry/citry/analysis.py:685 (line_col[0], from
    crates/citry_template_parser/src/ast.rs:77).
  • The other template rules convert the byte offset with
    _byte_offset_coordinates() (packages/py/citry/citry/_checker.py:2315-2319),
    which counts from 0. It is called at :591, :652, :701, :730, and in
    the i18n helpers around :2049.
  • The JSON writer copies these values without changing them
    (packages/py/citry/citry/commands/check.py:159-166).

Found by

The error-prevention benchmark, issue #158.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions