codingjoe/relint

GitHub annotations are marking the wrong (shifted) line

Closed this issue · 3 comments

Hey!
Thank you for the package and for fixing #91, which introduced GitHub annotations! This is very neat.
I noticed a bug that, in some cases, it fails to assign an annotation to the right line. Here is an example:

- name: Do not use types in your names
  pattern: '_(date|time|datetime|duration)\s+'
  filePattern: (.*\.py)
  hint: |
    Please do not use types in your names.
    Instead, use the type hinting provided by Python.
    See also: https://www.youtube.com/watch?v=-J3wNP6u5YU&t=126s
  error: false

CleanShot 2024-11-08 at 14 08 29@2x

We can see that the warning is about the line 7; however, the annotation is set to line 8.
I am not yet sure what led to that, but maybe you have a quick idea.

\s matches any whitespace or line terminator character, which means that it matches the newline between line 7 and 8. As a result, line 8 is included in the error.

Even if you run it on the CLI, the same thing will happen. It has nothing to do with the GitHub annotations themselves, as they surface the exact same lines anyway.

image

Try with this instead:

- name: Do not use types in your names
  pattern: '(?m)_(date|time|datetime|duration)$'
  filePattern: (.*\.py)
  hint: |
    Please do not use types in your names.
    Instead, use the type hinting provided by Python.
    See also: https://www.youtube.com/watch?v=-J3wNP6u5YU&t=126s
  error: false

(?m) is a flag which allows start (^) and end ($) characters to match on line start & end instead of the entire file start & end. See this issue for more details.

Result:
image

Thanks @mroy-seedbox, your swift help is much appreciated <3