Skip to content

Commit ef4ae37

Browse files
Update contents of readme about syntax selection (#914)
1 parent d8f820e commit ef4ae37

File tree

1 file changed

+26
-4
lines changed

1 file changed

+26
-4
lines changed

README.md

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,23 +21,27 @@ There are multiple ways to install StyLua:
2121

2222
Pre-built binaries are available on the [GitHub Releases Page](https://github.com/JohnnyMorganz/StyLua/releases).
2323

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.
2627

2728
### From Crates.io
2829

2930
If you have [Rust](https://www.rust-lang.org/) installed, you can install StyLua using cargo.
3031
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`)
3233

3334
```sh
3435
cargo install stylua
3536
cargo install stylua --features lua52
3637
cargo install stylua --features lua53
3738
cargo install stylua --features lua54
39+
cargo install stylua --features luajit
3840
cargo install stylua --features luau
3941
```
4042

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+
4145
### GitHub Actions
4246

4347
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:
5054

5155
- `stylua`: installs via cargo - requires the Rust toolchain
5256
- `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
5458

5559
Add the following to your `.pre-commit-config.yaml` file:
5660

@@ -248,12 +252,29 @@ It is recommended to keep a `.stylua.toml` file in your project root so that oth
248252

249253
If a project uses the default configuration of StyLua without a configuration file present, enabling external searching may cause conflicting formatting.
250254

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 ...`
270+
251271
### Options
252272

253273
StyLua only offers the following options:
254274

255275
| Option | Default | Description |
256276
| ---------------------------- | ------------------ | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
277+
| `syntax` | `All` | Specify a disambiguation for the style of Lua syntax being formatted. Possible options: `All` (default), `Lua51`, `Lua52`, `Lua53`, `Lua54`, `LuaJIT`, `Luau` |
257278
| `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. |
258279
| `line_endings` | `Unix` | Line endings type. Possible options: `Unix` (LF) or `Windows` (CRLF) |
259280
| `indent_type` | `Tabs` | Indent type. Possible options: `Tabs` or `Spaces` |
@@ -266,6 +287,7 @@ StyLua only offers the following options:
266287
Default `stylua.toml`, note you do not need to explicitly specify each option if you want to use the defaults:
267288

268289
```toml
290+
syntax = "All"
269291
column_width = 120
270292
line_endings = "Unix"
271293
indent_type = "Tabs"

0 commit comments

Comments
 (0)