<div align="center" <h1 StyLua<br <a href="https://crates.io/crates/stylua"<img src="https://img.shields.io/crates/v/stylua.svg"</a <a href="https://github.com/JohnnyMorganz/StyLua/actions/workflows/ci.yml"<img src="https://github.com/JohnnyMorganz/StyLua/actions/workflows/ci.yml/badge.svg"</a <a href="https://codecov.io/gh/JohnnyMorganz/StyLua"<img src="https://codecov.io/gh/JohnnyMorganz/StyLua/branch/main/graph/badge.svg"/</a </h1 </div
A deterministic code formatter for Lua 5.1, 5.2, 5.3, 5.4, LuaJIT, Luau and CfxLua/FiveM Lua, built using full-moon. StyLua is inspired by the likes of prettier, it parses your Lua codebase, and prints it back out from scratch, enforcing a consistent code style.
StyLua mainly follows the Roblox Lua Style Guide, with a few deviations.
Installation
There are multiple ways to install StyLua:
With Github Releases
Pre-built binaries are available on the GitHub Releases Page.
By default, these are built with all syntax variants enabled (Lua 5.2, 5.3, 5.4, LuaJIT and Luau), to cover all possible codebases. See configuring runtime syntax selection if you need to select a particular syntax of Lua to format. Alternatively, see installing from crates.io on how to install a particular flavour of StyLua.
From Crates.io
If you have Rust installed, you can install StyLua using cargo. By default, this builds for just Lua 5.1. You can pass the --features <flag argument to add extra syntax variants:
cargo install stylua
cargo install stylua --features lua52
cargo install stylua --features lua53
cargo install stylua --features lua54
cargo install stylua --features luajit
cargo install stylua --features luauYou can specify multiple features at once, and then use configuration in a .stylua.toml file to defer syntax selection to runtime.
GitHub Actions
The stylua-action GitHub Action can install and run StyLua. This action uses the prebuilt GitHub release binaries, instead of running cargo install, for faster CI startup times.
pre-commit
You can use StyLua with pre-commit. There are 3 possible pre-commit hooks available:
- stylua: installs via cargo - requires the Rust toolchain
- stylua-system: runs a stylua binary available on the PATH. The binary must be pre-installed
- stylua-github: automatically installs the relevant prebuilt binary from GitHub Releases
Add the following to your .pre-commit-config.yaml file: