Skip to main content
The built-in formatter reprints your Lua files with consistent indentation and spacing, and follows two safety rules:
  1. Refuses unparseable files — If your file contains a syntax error, the formatter exits without making changes.
  2. 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.
These patterns stay compact because the formatter knows they are idiomatic in Garry’s Mod code.

Leaving code alone

Some code reads worse after any formatter touches it — a hand-aligned lookup table, a block of generated data. Say so, and it is left exactly as written:
The directive protects the statement on the line below it, and nothing else — the rest of the file is formatted normally. It has to sit on its own line; local x = 1 -- glua-format-ignore is a comment about x, not a directive about whatever follows. For a whole file, usually one that is generated:
The file is then reported as unchanged by glua fmt and never rewritten.

Setting up

To make the GLua formatter the default for Lua files in your workspace, add it to your VS Code settings:
You can also format manually with the Format Document command (Shift+Alt+F or Shift+Option+F).

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. See the gluafmtrc.schema.json reference for every property this file accepts, including the ones left out of the table above.
Run the GLua: Create Formatter Config File command from the Command Palette to generate a .gluafmtrc.json with sensible defaults in your workspace root.