Linux command
stylua 命令
网络
复制后可按需替换文件名、目录或参数。
常用示例
Format file
stylua [script.lua]
Format multiple files
stylua [file1.lua] [file2.lua]
Format directory
stylua [src/]
Check formatting
stylua --check [script.lua]
Show diff
stylua --diff [script.lua]
Format from stdin
cat [script.lua] | stylua -
Use specific config
stylua --config [stylua.toml] [script.lua]
说明
stylua formats Lua code according to configurable style rules. It enforces consistent formatting automatically. Configuration in stylua.toml or .stylua.toml sets project preferences. Options include indentation, line width, quote style, and more. If no config file is found, StyLua also checks for an .editorconfig file. Check mode verifies formatting without changes. It returns non-zero exit code if files would be reformatted, suitable for CI. Diff mode shows what would change. This helps review formatting before applying it. The formatter handles various Lua versions and can be configured for game-specific variants like Roblox Luau via the --syntax flag or syntax option in the config file. Integration with editors enables format-on-save. CI integration ensures consistent style across contributions. A .styluaignore file (with .gitignore-like syntax) can be used to exclude files from formatting.
参数
- --check
- Check without formatting.
- --diff
- Show diff without formatting.
- --config _FILE_
- Configuration file.
- --search-parent-directories
- Search for config in parents.
- --stdin-filepath _PATH_
- Path for stdin input.
- --column-width _N_
- Line width.
- --indent-type _TYPE_
- Tabs or spaces.
- --indent-width _N_
- Indent width.
- --line-endings _TYPE_
- Unix or windows.
- --quote-style _STYLE_
- String quote style.
- --call-parentheses _STYLE_
- Call parentheses style.
- -g, --glob _PATTERN_
- Glob pattern for filtering files. Use -- to separate glob patterns from file arguments.
- --verify
- Verify output by re-parsing formatted code to ensure no syntax errors were introduced.
- --syntax _SYNTAX_
- Lua syntax version: All (default), Lua51, Lua52, Lua53, Lua54, LuaJIT, Luau, CfxLua.
- --respect-ignores
- Respect .styluaignore rules even for files passed directly on the command line.
- -v, --verbose
- Verbose output.
FAQ
What is the stylua command used for?
stylua formats Lua code according to configurable style rules. It enforces consistent formatting automatically. Configuration in stylua.toml or .stylua.toml sets project preferences. Options include indentation, line width, quote style, and more. If no config file is found, StyLua also checks for an .editorconfig file. Check mode verifies formatting without changes. It returns non-zero exit code if files would be reformatted, suitable for CI. Diff mode shows what would change. This helps review formatting before applying it. The formatter handles various Lua versions and can be configured for game-specific variants like Roblox Luau via the --syntax flag or syntax option in the config file. Integration with editors enables format-on-save. CI integration ensures consistent style across contributions. A .styluaignore file (with .gitignore-like syntax) can be used to exclude files from formatting.
How do I run a basic stylua example?
Run `stylua [script.lua]` in a terminal, then adjust file names, paths, flags, or remote targets for your system.
What does --check do in stylua?
Check without formatting.