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

Unexpected token 'goto' using stylua from pre-commit #867

Open
Terseus opened this issue Jun 12, 2024 · 6 comments
Open

Unexpected token 'goto' using stylua from pre-commit #867

Terseus opened this issue Jun 12, 2024 · 6 comments

Comments

@Terseus
Copy link

Terseus commented Jun 12, 2024

I've readed the problem with stylua prebuilt binaries in #240 and #407 , however AFAIK this error isn't expected in the stylua compiled by pre-commit using the repo's file Cargo.toml.

My relevant pre-commit config:

- repo: https://github.com/JohnnyMorganz/StyLua
  rev: v0.20.0
  hooks:
    - id: stylua

But still it doesn't work:

❯ pre-commit run --files nvim/.config/nvim/lua/modules/neotest/consumers/fidget.lua
Trim Trailing Whitespace.................................................Passed
Fix End of Files.........................................................Passed
Check Yaml...........................................(no files to check)Skipped
Check JSON...........................................(no files to check)Skipped
Check for added large files..............................................Passed
Git Secrets..............................................................Passed
StyLua (cargo)...........................................................Failed
- hook id: stylua
- exit code: 2

error: could not format file nvim/.config/nvim/lua/modules/neotest/consumers/fidget.lua: error parsing: error occurred while creating ast: unexpected token `goto`. (starting from line 70, character 13 and ending on line 70, character 17)
additional information: expected 'end'

Is this error expected?
If it is, is there any workaround apart from using the stylua-system hook?

@JohnnyMorganz
Copy link
Owner

I think this is actually the other way round. In this case, the stylua cargo hook is built with the default features, which is just lua51.

We need to somehow add a --features lua52 to the cargo install. Unsure if that is doable on user side or whether i need to change something

@Terseus
Copy link
Author

Terseus commented Jun 12, 2024

After fiddling for a while with pre-commit looks like there's no way to do this without changing the default features 😞 I'll open an issue in pre-commit for passing features to rust hooks.

If I find a workaround I'll post it here.

@vague2k
Copy link

vague2k commented Jul 8, 2024

Any updates on the mentioned issue/pr associated with it? I have a codebase with a workflow using stylua and every commit is saying format fails with the goto statement, it's becoming quite a bother

@jacksonneal
Copy link

jacksonneal commented Jul 14, 2024

Just ran into this same issue, using stylua v0.18.2

@JohnnyMorganz
Copy link
Owner

Unfortunately not much I can do on my side, since pre-commit needs to give options to enable features I think. Your alternative right now is to use stylua-github (has all features, but you might hit #407) or stylua-system.

That being said, I am working on #854 that will move syntax selection from compile time to run time, which will solve this problem

@jacksonneal
Copy link

Gotchya. Installing with cargo and --features lua52 is working with stylua-system hook.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants