Skip to content
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

Array index calls, e.g. "arr[0]" gets rewritten to "arr." #68

Closed
1 task done
fabianrichter opened this issue Apr 14, 2023 · 2 comments
Closed
1 task done

Array index calls, e.g. "arr[0]" gets rewritten to "arr." #68

fabianrichter opened this issue Apr 14, 2023 · 2 comments
Labels
bug Something isn't working

Comments

@fabianrichter
Copy link

Description

I was trying the code formatting plugin today and played around with it. I recognized a breaking rewrite:
When calling an index of an array, e.g. array[0] it gets rewritten to array..

Expected behavior

It should stay the same.

To Reproduce

Original Source Code:

{% set arr = ["foo", "bar"] %}
{{ arr[1] }}

Formatted Source Code:

{% set arr = [ "foo", "bar"] %}
{{ arr. }}

Checklist

  • I have checked the known issues to make sure this isn’t already a known issue.
@fabianrichter fabianrichter added the bug Something isn't working label Apr 14, 2023
@evelynn-causemic
Copy link

I've also been experiencing this bug, but it seems to be somewhat inconsistent. I believe it's related to a bug I just filed, though: #70

I think the formatter is interpreting the array index as an object bracket notation key, and trying to reformat to dot notation.

@j-malt
Copy link
Contributor

j-malt commented May 7, 2024

I'm not able to reproduce this bug, and I can't really see how it would be happening (since there is a check on the type of the value before the rewrite that caused #70), but in any case, there is a fix for #70 in PR #77 that should add some additional safety for this.

Do let us know if you have a consistent method to reproduce this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants