Unformatted Lua code accumulates fast — inconsistent indentation, mismatched spacing around operators, and blocks that differ between team members. The right VS Code extension fixes all of that automatically. This guide covers the top Lua formatter extensions for VS Code in 2026, how to set each one up, how to configure format-on-save, and what to use when you cannot install extensions at all.
Why formatting matters for Lua
Lua has no enforced style standard. The language parser accepts any valid indentation, any operator spacing, and any block layout — which means every developer defaults to their own habits. In a solo project that is fine. In a shared codebase, game mod, or team script repository, inconsistent formatting creates noise in every diff, slows down code review, and makes debugging harder than it needs to be.
The cost of inconsistent Lua style
When two people write Lua differently — one uses four-space indentation, one uses tabs; one spaces around operators, one does not — every commit contains formatting changes mixed with logic changes. Reviewers spend time reading style diffs instead of logic diffs. Merge conflicts spike. A formatter solves this by normalising every file to the same style on save, making diffs clean and reviewable.
- Consistent indentation — `do`/`end`, `if`/`end`, `function`/`end` blocks all indent the same way every time
- Uniform spacing — spaces around `=`, `+`, `-`, `..` and other operators are applied consistently
- Blank line discipline — extra blank lines between functions and inside loops are normalised automatically
- Readable string handling — long string concatenations and multiline strings are laid out predictably
- Team-wide enforcement — a shared `.luarc.json` or `stylua.toml` in version control guarantees everyone uses the same rules
Note
Top Lua formatter extensions for VS Code
The VS Code Marketplace has several Lua extensions, but only a handful are actively maintained and provide reliable formatting. Here are the three worth knowing in 2026, in order of recommendation.
1. Lua Language Server (sumneko.lua) — recommended
The Lua Language Server, published as `sumneko.lua` on the VS Code Marketplace, is the single most complete Lua development tool available for VS Code. It installs a full Language Server Protocol (LSP) implementation that provides diagnostics, type inference, go-to-definition, hover documentation, workspace-wide find references, and a built-in formatter — all in one extension.
- Publisher: sumneko (Tang Liu)
- Marketplace ID: `sumneko.lua`
- Active installs: 1M+ (as of 2026)
- Lua versions supported: 5.1, 5.2, 5.3, 5.4, LuaJIT
- Formatter: Built-in, configured via `.luarc.json`
- Format-on-save: Supported natively
- Best for: Most Lua workflows — game scripting, standalone tools, embedded systems
Tip
2. StyLua (jq-steuersoftware.stylua) — opinionated alternative
StyLua is an opinionated Lua code formatter written in Rust, inspired by Prettier. The VS Code extension wraps the StyLua binary and integrates it as a document formatter. Unlike Lua Language Server, StyLua is a formatter-only tool — it does not provide diagnostics, hover documentation, or code completion. What it does provide is a deterministic, zero-debate style: you agree to the style and commit to it, the same way Prettier works for JavaScript.
- Publisher: jq-steuersoftware
- Marketplace ID: `jq-steuersoftware.stylua`
- Lua versions supported: 5.1, 5.2, 5.3, 5.4, LuaJIT, Luau (Roblox)
- Config file: `stylua.toml` (optional — works well with defaults)
- Format-on-save: Supported natively
- Best for: New projects, teams that want Prettier-style zero-config formatting, Roblox Luau development
3. LuaFormatter (Koihik.vscode-lua-format) — configurable legacy option
LuaFormatter is an older extension that wraps the `lua-format` command-line tool. It provides extensive configuration — you can tune indent width, max line length, operator spacing, continuation indent, and many other rules individually. This level of control makes it useful when migrating an existing codebase that already has an established style convention you need the formatter to honour. However, development has slowed since StyLua emerged, and the underlying `lua-format` binary requires a separate install step on some platforms.
- Publisher: Koihik
- Marketplace ID: `Koihik.vscode-lua-format`
- Config file: `.lua-format` (YAML format)
- Best for: Existing codebases with complex style requirements, granular per-rule control
- Caveat: Requires `lua-format` binary installed separately on Linux/Mac
Warning
How to set up Lua LS in VS Code
Installing Lua Language Server takes under two minutes. Here is the complete setup path from a fresh VS Code install to working format-on-save.
Install Lua Language Server from the Marketplace
Open VS Code and press Ctrl+P (Cmd+P on Mac) to open the Quick Open bar. Type `ext install sumneko.lua` and press Enter. VS Code downloads and installs the extension automatically. No additional binaries are required — the language server binary is bundled with the extension.
Open a .lua file and trigger formatting
Open any `.lua` file in your project. Press Shift+Alt+F (Shift+Option+F on Mac) to run Format Document. On first use, VS Code displays a prompt asking you to select a default formatter for Lua files — choose Lua Language Server. The file formats immediately and the selection is saved to your user settings.
Create a .luarc.json for project-level configuration
Create a `.luarc.json` file at your project root to control formatting rules and language server behaviour consistently across your team. Commit this file to version control so every contributor gets identical settings. A minimal starting config targets Lua 5.4 and disables the undefined-global diagnostic for projects with custom globals.
{
"Lua.runtime.version": "Lua 5.4",
"Lua.diagnostics.globals": ["myGlobal", "anotherGlobal"],
"Lua.format.enable": true,
"Lua.format.defaultConfig": {
"indent_style": "space",
"indent_size": "4",
"max_line_length": "120",
"trailing_table_separator": "smart"
}
}Enable format-on-save
Open VS Code settings with Ctrl+, (Cmd+, on Mac), search for `format on save`, and toggle Editor: Format On Save to enabled. From now on, every time you save a `.lua` file, the formatter runs automatically. To scope this setting only to Lua files without enabling it globally, add it to your project's `.vscode/settings.json` instead.
{
"editor.formatOnSave": true,
"[lua]": {
"editor.defaultFormatter": "sumneko.lua"
}
}Lua Formatter — Browser-Based
Format Lua code instantly in your browser with no extensions or installs needed — paste your code and get clean, indented output in seconds.
Configuring format-on-save
Format-on-save is the most impactful single setting you can enable for Lua development in VS Code. Once active, you never manually trigger the formatter — it runs every time you hit Ctrl+S. Here is how to configure it correctly for different team scenarios.
User-level vs. workspace-level settings
VS Code has two levels of settings: user-level (applies to all projects) and workspace-level (applies only to the current project). For formatting, the workspace level is almost always the right choice — it ensures every contributor on the project uses the same formatter, regardless of their personal user-level preferences. Workspace settings live in `.vscode/settings.json` at the project root and should be committed to version control.
Format-on-save for StyLua
StyLua's VS Code extension uses the same format-on-save mechanism. Set the default formatter to `jq-steuersoftware.stylua` in your workspace settings. StyLua reads a `stylua.toml` config file if present — this is where you set column_width, indent_type, indent_width, and quote_style. Without a `stylua.toml`, StyLua applies its default rules (two-space indent, 120-character line length, double quotes).
column_width = 120
line_endings = "Unix"
indent_type = "Spaces"
indent_width = 4
quote_style = "AutoPreferDouble"
call_parentheses = "Always"Tip
Excluding files from formatting
Some Lua files should not be reformatted — vendor libraries, generated code, or minified scripts. In StyLua, add a `.styluaignore` file (same syntax as `.gitignore`) to exclude paths. In Lua Language Server, you can scope the formatter to specific directories using the `Lua.workspace.ignoreDir` setting in `.luarc.json`.
LuaFormatter vs StyLua compared
The two most-discussed Lua formatters are LuaFormatter and StyLua. They take fundamentally different approaches to formatting philosophy, and the right choice depends on your project context. Here is a direct comparison.
| Aspect | LuaFormatter (Koihik) | StyLua |
|---|---|---|
| Philosophy | Highly configurable | Opinionated (Prettier-style) |
| Config file | `.lua-format` (YAML) | `stylua.toml` (TOML, optional) |
| Config rules | 30+ individual options | ~6 core options |
| Luau / Roblox | ✗ Not supported | ✓ Native Luau support |
| Binary install | ✗ Separate step on some OS | ✓ Bundled with VS Code ext |
| CI/CD use | ✓ Via lua-format CLI | ✓ Standalone binary |
| Active maintenance | ✗ Slowed since 2023 | ✓ Actively maintained |
| Best for | Existing codebases with existing style | New projects, Roblox Luau |
If you are starting a new project, pick StyLua and commit the config. If you are inheriting a codebase with an existing style, configure LuaFormatter to match it. Never mix both formatters on the same codebase.
Lua Language Server vs. StyLua: can they coexist?
Lua Language Server and StyLua serve different primary purposes — Lua LS is a full language server for diagnostics and intellisense, StyLua is a formatter only. They can coexist in the same VS Code setup: install Lua LS for diagnostics and code intelligence, then set StyLua as the default formatter for document formatting. This combination gives you the best of both tools. Configure it in .vscode/settings.json by setting the [lua] defaultFormatter to jq-steuersoftware.stylua while keeping Lua LS installed for its LSP features.
Lua LS built-in formatter: when it is enough
For most developers, the Lua Language Server's built-in formatter is sufficient and removes the need to install a second extension. It handles all standard formatting tasks and integrates cleanly with `.luarc.json`. The main reason to add StyLua on top is if your team wants stronger style enforcement (e.g. enforcing specific quote style or call parentheses conventions) that Lua LS's formatter does not currently support.
Online Lua formatter as a fallback
VS Code extensions are the right solution for day-to-day development. But there are scenarios where you need to format Lua code without installing anything at all — and that is where a browser-based tool fills the gap cleanly.
When you cannot install extensions
- Shared or locked-down machines — corporate workstations, lab computers, or CI environments where you cannot install VS Code extensions
- Quick one-off cleanup — a colleague sends you a Lua snippet to review and you want it formatted without switching context
- Code review without a dev environment — reviewing a pull request on a machine where your full Lua setup is not configured
- Onboarding checks — verifying a file looks correctly formatted before committing without waiting for the full toolchain to install
- Minified code inspection — you have a Lua minifier output and want to reformat it for readability
The Quasar Tools Lua Formatter handles all of these cases. Paste your Lua code into the editor and the formatter applies consistent indentation, normalises operator spacing, and cleans up blank lines in your browser — with no signup, no install, and no data ever leaving your device.
Complementary online Lua tools
Formatting is one step in a complete Lua code quality workflow. Several other browser-based tools cover adjacent tasks you will regularly need alongside formatting:
- **Lua Beautifier** — focuses on improving the visual layout of code that is syntactically correct but hard to read
- **Lua Syntax Validator** — checks code for parser-level errors with line-level diagnostics before you run it
- **Lua Minifier** — strips comments, whitespace, and blank lines for production deployment to reduce script file size
- **Lua Obfuscator** — renames variables and encodes strings to protect game scripts from casual reverse engineering
- **Lua Deobfuscator Helper** — improves readability of obfuscated scripts for debugging and analysis workflows
Lua Beautifier
Clean up Lua code with proper indentation, spacing, and line breaks in your browser — no extensions, no install, no uploads.
Lua formatting best practices
A formatter handles whitespace, but good Lua code quality goes further. These practices work alongside your formatter to keep Lua codebases consistent, readable, and maintainable at any scale.
Commit your formatter config to version control
A `.luarc.json` for Lua LS, `stylua.toml` for StyLua, or `.lua-format` for LuaFormatter should all live at the project root and be committed to your repository. This ensures every contributor — and every CI run — uses identical formatting rules. Without a committed config, each developer defaults to their own extension settings and formatting divergence creeps back in over time.
Add a CI formatting check
Format-on-save in VS Code only helps people who use VS Code and have the extension installed. A CI check catches anything that slips through — contributors using other editors, quickly patched files, or generated Lua code. StyLua's `--check` flag exits with a non-zero code if any file is not correctly formatted, making it easy to fail a GitHub Actions or GitLab CI job on style violations.
Separate formatting commits from logic commits
If you are introducing a formatter to an existing codebase for the first time, run the formatter across all files in a single dedicated commit with no other changes. Label it clearly (e.g. `chore: apply lua formatter to all files`). This keeps the formatting noise in one commit so that all subsequent commits contain only logic changes — and `git blame` remains useful on every line.
Tip
Use consistent local variable naming
Formatters do not rename variables — that is your responsibility. The Lua community largely follows `snake_case` for variables and functions and `PascalCase` for module-level tables and class-like constructs. Agree on a convention with your team and document it in your project's `CONTRIBUTING.md`. If you work with Roblox Luau, the Roblox style guide specifies `PascalCase` for instances and services and `camelCase` for local variables — be aware of the distinction before applying Lua-community conventions blindly.
Warning
Key takeaways
- The Lua Language Server (sumneko.lua) is the best all-round Lua extension for VS Code — it includes formatting, diagnostics, type inference, and code intelligence in one install.
- StyLua is the best formatter-only choice for new projects and Roblox Luau development, offering opinionated Prettier-style consistency with minimal config.
- LuaFormatter is a configurable legacy option suited to existing codebases that need granular style control, but it is less actively maintained than the alternatives.
- Commit your formatter config (.luarc.json or stylua.toml) to version control so all contributors get identical formatting behaviour automatically.
- Add a CI formatting check with StyLua --check to catch unformatted files before they merge, regardless of which editor contributors use.
- The Quasar Tools Lua Formatter handles quick one-off formatting in a browser tab — no extensions, no installs, no server uploads required.
- Never run a standard formatter on obfuscated Lua; use the Lua Deobfuscator Helper first to restore readability before formatting.