在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称(OpenSource Name):JohnnyMorganz/StyLua开源软件地址(OpenSource Url):https://github.com/JohnnyMorganz/StyLua开源编程语言(OpenSource Language):Rust 82.3%开源软件介绍(OpenSource Introduction):An opinionated code formatter for Lua 5.1, Lua 5.2 and Luau, 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. InstallationThere are multiple ways to install StyLua: With Github ReleasesPre-built binaries are available on the GitHub Releases Page. By default, these are built with both Luau and Lua 5.2 features enabled, to cover all possible codebases. If you would like to format a specific Lua version only, see installing from crates.io. From Crates.ioIf you have Rust installed, you can install StyLua using cargo.
By default, this builds for just Lua 5.1.
You can pass the cargo install stylua
cargo install stylua --features lua52
cargo install stylua --features luau GitHub ActionsYou can use the stylua-action GitHub Action in your CI to install and run StyLua. This action uses the prebuilt GitHub release binaries, instead of running cargo install, for faster CI times. pre-commitYou can use StyLua with pre-commit. There are 3 possible pre-commit hooks available:
Add the following to your - repo: https://github.com/JohnnyMorganz/StyLua
rev: v0.14.2
hooks:
- id: stylua # or stylua-system / stylua-github npm (wasm build)StyLua is available as a wasm package, and is published to npm. It is usable in Node.js, or the in the browser (using a bundler). Other Installation Methodsaftman add johnnymorganz/[email protected]
Other Editor IntegrationsNote that these integrations require the StyLua binary to already be installed and available on your system.
UsageOnce installed, pass the files to format to the CLI: stylua src/ foo.lua bar.lua This command will format the Glob FilteringBy default, when searching through a directory, StyLua looks for all files matching the glob stylua --glob '**/*.luau' -- src # format all files in src matching **/*.luau
stylua -g '*.lua' -g '!*.spec.lua' -- . # format all Lua files except test files ending with `.spec.lua` Note, if you are using the glob argument, it can take in multiple strings, so Glob Filtering is only used for directory searching - passing a file directly (e.g.
Filtering using |
Option | Default | Description |
---|---|---|
column_width |
120 |
Approximate line length for printing. Used as a guide for line wrapping - this is not a hard requirement: lines may fall under or over the limit. |
line_endings |
Unix |
Line endings type. Possible options: Unix (LF) or Windows (CRLF) |
indent_type |
Tabs |
Indent type. Possible options: Tabs or Spaces |
indent_width |
4 |
Character size of single indentation. If indent_type is set to Tabs , this option is used as a heuristic to determine column width only. |
quote_style |
AutoPreferDouble |
Quote style for string literals. Possible options: AutoPreferDouble , AutoPreferSingle , ForceDouble , ForceSingle . AutoPrefer styles will prefer the specified quote style, but fall back to the alternative if it has fewer string escapes. Force styles always use the specified style regardless of escapes. |
call_parentheses |
Always |
Whether parentheses should be applied on function calls with a single string/table argument. Possible options: Always , NoSingleString , NoSingleTable , None . Always applies parentheses in all cases. NoSingleString omits parentheses on calls with a single string argument. Similarly, NoSingleTable omits parentheses on calls with a single table argument. None omits parentheses in both cases. Note: parentheses are still kept in situations where removal can lead to obscurity (e.g. foo "bar".setup -> foo("bar").setup , since the index is on the call result, not the string). |
Default stylua.toml
, note you do not need to explicitly specify each option if you want to use the defaults:
column_width = 120
line_endings = "Unix"
indent_type = "Tabs"
indent_width = 4
quote_style = "AutoPreferDouble"
call_parentheses = "Always"
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论