JohnnyMorganz / StyLua

An opinionated Lua code formatter
Mozilla Public License 2.0
1.53k stars 68 forks source link

Unable to format lua 5.4 code #860

Closed mikavilpas closed 4 months ago

mikavilpas commented 4 months ago

Hi! I'm working on a project and trying to add support for checking lua formatting using stylua here https://github.com/sxyazi/yazi/pull/1029

Here are some findings:

This is reproducible using this repository (StyLua itself). Example:

❯ ~/Downloads/stylua --version
stylua 0.20.0

$ ~/Downloads/stylua .
error: could not format file ./tests/inputs-full_moon/goto-as-identifier.lua: error parsing: error occurred while creating ast: unexpected token `goto`. (starting from line 2, character 6 and ending on line 2, character 10)
additional information: expected name
-- Note: fragment variable definitions are experimental and may be changed
-- or removed in the future.
-- Note: fragment variable definitions are experimental and may be changed
-- or removed in the future.
-- Note: fragment variable definitions are experimental and may be changed
-- or removed in the future.
JohnnyMorganz commented 4 months ago

Sounds like you are experiencing the same problem as https://github.com/JohnnyMorganz/StyLua/issues/407

Unfortunately the stylua release binaries are built with all feature flags enabled, and the Luau type assertion syntax conflicts with Lua 5.2 label syntax.

You can use cargo to build a binary with only lua54 enabled and that should hopefully work

mikavilpas commented 4 months ago

Thank you for the response! My issue is resolved.