Before
inputfunction lua(){return true}Formatter
Compare the exact input shape with the cleaned output before opening the editor.
Before
inputfunction lua(){return true}After
formattedfunction lua() {
return true
}Workflow
Paste a snippet, run the action, review any highlighted issue, then copy the result back to your work.
Paste a snippet or full file into the editor.
Use Run Formatter from the action bar.
Fix syntax issues if processing stops.
Use Copy code when the result is ready.
Lua formatting guide
Lua ships inside Roblox, Love2D, Neovim, OpenResty, and thousands of game engines - and almost every one of those communities formats Lua differently. This page runs a WebAssembly build of a real Lua parser, so formatting happens locally: your code never leaves the tab.
The formatter parses your file into a syntax tree, then reprints it with consistent rules: uniform indentation, normalized spacing around operators, one statement per line, and balanced block keywords. Parsing first means broken files stop with a clear error instead of printing mangled code.
You can switch between 2, 3, and 4 spaces or tabs before every run. Lua itself is whitespace-insensitive, so the choice is purely team style - pick one and let the tool apply it everywhere.
| Ecosystem | Common style | Notes |
|---|---|---|
| Roblox / Luau | StyLua defaults | Luau adds type annotations and compound assignments; a Luau-aware parser keeps them intact. |
| Love2D | 2 or 4 spaces | Most Love2D projects follow the Lua-users style guide. |
| Neovim config | 2 spaces, stylua | Neovim's own codebase and most plugin authors use StyLua. |
| OpenResty / nginx | 4 spaces | Match the nginx C style that most OpenResty modules follow. |
For day-to-day work, format on save. In VS Code, install the StyLua extension and set it as the default formatter for Lua. In Neovim, conform.nvim and null-ls both expose StyLua as a formatter source.
Use this page when the code is not on your machine: pasting a snippet from a chat, cleaning a script from a Roblox model, or checking how a formatter treats a file before adding one to a project.
Two decisions cause most Lua formatting debates: tabs versus spaces, and how wide a line may run before wrapping. StyLua made 2 spaces and an 80-column wrap the community default, which is why most Roblox and Neovim code now looks the same.
The formatter does not rename variables or reorder functions. It only changes whitespace and layout, so a formatted file parses to the same tree and runs identically.