You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+26-4Lines changed: 26 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -21,23 +21,27 @@ There are multiple ways to install StyLua:
21
21
22
22
Pre-built binaries are available on the [GitHub Releases Page](https://github.com/JohnnyMorganz/StyLua/releases).
23
23
24
-
By default, these are built with **all syntax variants enabled (Lua 5.2, 5.3, 5.4 and Luau)**, to cover all possible codebases.
25
-
If you would like to format a specific Lua version only, see [installing from crates.io](#from-cratesio).
24
+
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.
25
+
See [configuring runtime syntax selection](#configuring-runtime-syntax-selection) if you need to select a particular syntax of Lua to format.
26
+
Alternatively, see [installing from crates.io](#from-cratesio) on how to install a particular flavour of StyLua.
26
27
27
28
### From Crates.io
28
29
29
30
If you have [Rust](https://www.rust-lang.org/) installed, you can install StyLua using cargo.
30
31
By default, this builds for just Lua 5.1.
31
-
You can pass the `--features <flag>` argument to build for Lua 5.2 (`lua52`), Lua 5.3 (`lua53`), Lua 5.4 (`lua54`) or Luau (`luau`)
32
+
You can pass the `--features <flag>` argument to build for Lua 5.2 (`lua52`), Lua 5.3 (`lua53`), Lua 5.4 (`lua54`), LuaJIT (`luajit`) or Luau (`luau`)
32
33
33
34
```sh
34
35
cargo install stylua
35
36
cargo install stylua --features lua52
36
37
cargo install stylua --features lua53
37
38
cargo install stylua --features lua54
39
+
cargo install stylua --features luajit
38
40
cargo install stylua --features luau
39
41
```
40
42
43
+
You can specify multiple features in a single installation, and then use [configuration in a `.stylua.toml` file](#configuring-runtime-syntax-selection) to defer syntax selection to runtime.
44
+
41
45
### GitHub Actions
42
46
43
47
You can use the [stylua-action](https://github.com/marketplace/actions/stylua) GitHub Action in your CI to install and run StyLua.
@@ -50,7 +54,7 @@ There are 3 possible pre-commit hooks available:
50
54
51
55
-`stylua`: installs via cargo - requires the Rust toolchain
52
56
-`stylua-system`: runs a `stylua` binary available on the PATH. The binary must be pre-installed
53
-
-`stylua-github`: automatically installs the relevant prebuilt binary from GitHub Actions
57
+
-`stylua-github`: automatically installs the relevant prebuilt binary from GitHub Releases
54
58
55
59
Add the following to your `.pre-commit-config.yaml` file:
56
60
@@ -248,12 +252,29 @@ It is recommended to keep a `.stylua.toml` file in your project root so that oth
248
252
249
253
If a project uses the default configuration of StyLua without a configuration file present, enabling external searching may cause conflicting formatting.
250
254
255
+
### Configuring Runtime Syntax Selection
256
+
257
+
By default, StyLua releases comes with all flavours of Lua bundled into one binary, with a union of all syntax styles.
258
+
We do this to make it easier to get started with StyLua on any codebase or project using Lua.
259
+
260
+
However, there are times where the union of syntaxes collide, causing issues. For example, Lua 5.2's goto label syntax
261
+
(`::label::`) conflicts with Luau's type assertion syntax (`x :: number`), and the latter ends up taking priority.
262
+
263
+
To disambiguate a particular syntax style for your codebase, set `syntax = "Style"` in your `.stylua.toml` file, e.g.:
264
+
265
+
```toml
266
+
syntax = "Lua52"
267
+
```
268
+
269
+
Alternatively, you can specify it on the command line, with `stylua --syntax lua52 ...`
|`syntax`|`All`| Specify a disambiguation for the style of Lua syntax being formatted. Possible options: `All` (default), `Lua51`, `Lua52`, `Lua53`, `Lua54`, `LuaJIT`, `Luau`|
257
278
|`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. |
258
279
|`line_endings`|`Unix`| Line endings type. Possible options: `Unix` (LF) or `Windows` (CRLF) |
259
280
|`indent_type`|`Tabs`| Indent type. Possible options: `Tabs` or `Spaces`|
@@ -266,6 +287,7 @@ StyLua only offers the following options:
266
287
Default `stylua.toml`, note you do not need to explicitly specify each option if you want to use the defaults:
0 commit comments