-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
error details are misaligned when using tabs #1129
Comments
Thanks for filing this. I noticed it a while ago but failed to open a ticket 😅 In this case, the error is reported by the parser. The ^ is generated here: https://github.com/open-policy-agent/opa/blob/master/ast/parser_ext.go#L752 (not in check.go). I was suspicious of the location you linked to but upon reflection, I don't think there's a problem. The padding is constructed based on the String representation of the ref -- which will not contain tabs. I haven't thought about the best way to resolve the issue in parser_ext.go. Perhaps we could construct the padding with a mix of spaces & tabs? |
Yup, indeed, I was pointing at the wrong thing; I've too noticed that when I was attempting to fix this 😄 I think the real issue is somewhere in here, as there's nothing accounting for the fact that a char could be "wider" than 1 char when printed... Maybe this could be fixed bluntly by a pre-processing step that replaces tabs by n spaces (for some n) before feeding it into the parser? 🤔 |
Fixes open-policy-agent#1129 for the most part. What still is wrongly put, but also harder to fix, is the case where there's tabs INSIDE the line: p = TAB true TAB { TAB as } or a space before the tab, like SPACE TAB p = true { as } will still have a misaligned "^", as in that case, not all tabs are fully expanded. This merely trims leading tabs, and fixes the error maker location if there's no other tabs used in the line. However, that should fit common usage: Leading tabs is what `opa fmt` proposes; and I'm doubtful of too many uses of tabs in other places in Rego code. Signed-off-by: Stephan Renatus <srenatus@chef.io>
Fixes #1129 for the most part. What still is wrongly put, but also harder to fix, is the case where there's tabs INSIDE the line: p = TAB true TAB { TAB as } or a space before the tab, like SPACE TAB p = true { as } will still have a misaligned "^", as in that case, not all tabs are fully expanded. This merely trims leading tabs, and fixes the error maker location if there's no other tabs used in the line. However, that should fit common usage: Leading tabs is what `opa fmt` proposes; and I'm doubtful of too many uses of tabs in other places in Rego code. Signed-off-by: Stephan Renatus <srenatus@chef.io>
Actual Behavior
With
demo.rego
aswhere the line with
as
starts with a tab character, and I runopa run demo.rego
, I find:Expected Behavior
The pointer
^
should respect the tabs or remove them -- right now, it's position is calculated without accounting for the width of the characters that make up the offset here.The text was updated successfully, but these errors were encountered: