Unexpected token 'goto' using stylua from pre-commit
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?
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
After fiddling for a while with pre-commit looks like there's no way to do this without changing the default features :disappointed: I'll open an issue in pre-commit for passing features to rust hooks.
If I find a workaround I'll post it here.
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
Just ran into this same issue, using stylua v0.18.2
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
Gotchya. Installing with cargo and --features lua52 is working with stylua-system hook.
The next release of StyLua will give the ability to configure the syntax at runtime in your .stylua.toml file.
syntax = "Lua52"
Or alternatively specify it on the command line, stylua --syntax lua52 file.lua
This should resolve this issue