Formatter

Lua Formatter

Format No sign in

Formatter example

Compare the exact input shape with the cleaned output before opening the editor.

Local preview

Before

input
function lua(){return true}

After

formatted
function lua() {
  return true
}

Workflow

Use Lua without sending code.

Paste a snippet, run the action, review any highlighted issue, then copy the result back to your work.

Current language
Lua
Current action
Formatter
  1. 01

    Start

    Paste a snippet or full file into the editor.

  2. 02

    Run

    Use Run Formatter from the action bar.

  3. 03

    Review

    Fix syntax issues if processing stops.

  4. 04

    Move

    Use Copy code when the result is ready.

Files
.lua
Paste a Lua snippet or a full source file.
Engine
lua-fmt
Runs the browser-side formatter for readable output.
Privacy
Local run
The editor does not send pasted code to a formatting API.
Result
Readable output
Move the formatted code back to your editor.

Lua formatting guide

Lua formatting, explained.

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.

How the Lua formatter works

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.

EcosystemCommon styleNotes
Roblox / LuauStyLua defaultsLuau adds type annotations and compound assignments; a Luau-aware parser keeps them intact.
Love2D2 or 4 spacesMost Love2D projects follow the Lua-users style guide.
Neovim config2 spaces, styluaNeovim's own codebase and most plugin authors use StyLua.
OpenResty / nginx4 spacesMatch the nginx C style that most OpenResty modules follow.

Formatting Lua in your editor

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.

  • VS Code: StyLua extension, format on save.
  • Neovim: conform.nvim with the stylua source.
  • CLI: stylua . in a terminal for whole projects.
  • This page: paste, format, copy - nothing is uploaded.

Lua style decisions worth knowing

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.