How it works
The formatter reads your file into a syntax tree and then prints it back with consistent indentation and spacing. It follows two safety rules:- Refuses unparseable files — If your file contains a syntax error, the formatter exits without making changes.
- Never drops a comment — If the formatter cannot determine where to place a comment in the output, it falls back to the original text for that statement rather than discarding it.
Idiomatic one-liners
The formatter recognises common GLua guard clauses and keeps them on a single line instead of expanding them.Setting up
To make the GLua formatter the default for Lua files in your workspace, add it to your VS Code settings:Config file
Create a.gluafmtrc.json file in your workspace root to share formatting rules with your team.
Existing config files
The formatter also reads settings from.editorconfig and .prettierrc if they exist in your workspace.
Values in
.gluafmtrc.json take precedence over .editorconfig and .prettierrc.
Run the GLua: Create Formatter Config File command from the Command Palette to generate a
.gluafmtrc.json with sensible defaults in your workspace root.