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
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.
43
+
You can specify multiple features at once, and then use [configuration in a `.stylua.toml` file](#configuring-runtime-syntax-selection) to defer syntax selection to runtime.
44
44
45
45
### GitHub Actions
46
46
47
-
You can use the [stylua-action](https://github.com/marketplace/actions/stylua) GitHub Action in your CI to install and run StyLua.
48
-
This action uses the prebuilt GitHub release binaries, instead of running cargo install, for faster CI times.
47
+
The [stylua-action](https://github.com/marketplace/actions/stylua) GitHub Action can install and run StyLua.
48
+
This action uses the prebuilt GitHub release binaries, instead of running cargo install, for faster CI startup times.
49
49
50
50
### pre-commit
51
51
@@ -68,7 +68,7 @@ Add the following to your `.pre-commit-config.yaml` file:
68
68
### npm
69
69
70
70
StyLua is available as a binary [published to npm](https://www.npmjs.com/package/@johnnymorganz/stylua-bin) as `@johnnymorganz/stylua-bin`.
71
-
This is a thin wrapper which installs the binary and allows it to be run through npm.
71
+
This is a thin wrapper that installs the binary and makes it available through npm / npx.
72
72
73
73
```sh
74
74
npx @johnnymorganz/stylua-bin --help
@@ -136,16 +136,16 @@ stylua --glob '**/*.luau' -- src # format all files in src matching **/*.luau
136
136
stylua -g '*.lua' -g '!*.spec.lua' -- . # format all Lua files except test files ending with `.spec.lua`
137
137
```
138
138
139
-
Note, if you are using the glob argument, it can take in multiple strings, so `--` is required to break between the glob pattern and the files to format.
139
+
Note that the `-g/--glob` argumentcan take multiple strings at once, so `--` is required to separate between the glob patterns and the files to format.
140
140
141
-
By default, glob filtering (and `.styluaignore` files) are only applied for directory traversal and searching.
141
+
By default, glob filtering (and `.styluaignore` files) are only applied during directory traversal and searching.
142
142
Files passed directly (e.g. `stylua foo.txt`) will override the glob / ignore and always be formatted.
143
143
To disable this behaviour, pass the `--respect-ignores` flag (`stylua --respect-ignores foo.txt`).
144
144
145
145
### Filtering using `.styluaignore`
146
146
147
147
You can create a `.styluaignore` file, with a format similar to `.gitignore`.
148
-
Any files matching the globs in the ignore file will be ignored by StyLua.
148
+
Any files matching the globs in the ignore file are ignored by StyLua.
149
149
For example, for a `.styluaignore` file with the following contents:
150
150
151
151
```
@@ -156,31 +156,30 @@ running `stylua .` will ignore the `vendor/` directory.
156
156
157
157
### `--check`: Checking files for formatting
158
158
159
-
To check whether files have been formatted (but not write directly to them), use the `--check` flag.
159
+
To check whether files require formatting (but not write directly to them), use the `--check` flag.
160
160
It will take files as input, and output a diff to stdout instead of rewriting the file contents.
161
-
If there are files which haven't been fully formatted, StyLua will exit with status code 1.
161
+
If there are any files that require formatting, StyLua will exit with status code 1.
162
162
163
-
There are different styles of output that are available:
163
+
There are different styles of output available:
164
164
165
-
-`--output-format=standard`: output a custom pretty diff (default)
166
-
-`--output-format=unified`: output a unified diff, which can be consumed by tools like `patch` or `delta`
167
-
-`--output-format=json`: output JSON representing the changes, useful for machine-readable output (usable in non-check mode as well)
165
+
-`--output-format=standard`: output a custom diff (default)
166
+
-`--output-format=unified`: output a unified diff, consumable by tools like `patch` or `delta`
167
+
-`--output-format=json`: output JSON representing the changes, useful for machine-readable output
168
168
-`--output-format=summary`: output a summary list of file paths that are incorrectly formatted
169
169
170
170
### `--verify`: Verifying formatting output
171
171
172
-
As a safety measure, the `--verify` flag can be passed to StyLua, and StyLua will verify the output of all formatting
173
-
before saving it to a file.
172
+
As a safety measure, you can use the `--verify` flag to verify the output of all formatting before saving the file.
174
173
175
174
If enabled, the tool will re-parse the formatted output to verify if the AST is still valid (no syntax errors) and is similar to the input (possible semantic changes).
176
175
177
-
Useful when adopting StyLua in a large codebase, where it is difficult to verify all formatting is correct.
176
+
This is useful when adopting StyLua in a large codebase, where it is difficult to manually check all formatting is correct.
178
177
Note that this may produce false positives and negatives - we recommend manual verification as well as running tests to confirm.
179
178
180
179
### Ignoring parts of a file
181
180
182
181
To skip formatting a particular part of a file, you can add `-- stylua: ignore` before it.
183
-
This may be useful if there is a particular style you want to preseve for readability, e.g.:
182
+
This is useful if there is a particular style you want to preseve for readability, e.g.:
184
183
185
184
```lua
186
185
-- stylua: ignore
@@ -191,7 +190,7 @@ local matrix = {
191
190
}
192
191
```
193
192
194
-
Formatting can also be skipped over a block of code using`-- stylua: ignore start` and `-- stylua: ignore end`:
193
+
To skip a block of code, use`-- stylua: ignore start` and `-- stylua: ignore end`:
195
194
196
195
```lua
197
196
localfoo=true
@@ -202,15 +201,15 @@ local baz = 0
202
201
localfoobar=false
203
202
```
204
203
205
-
Note that ignoring cannot cross scope boundaries - once a block is exited, formatting will be re-enabled.
204
+
Note that ignoring cannot cross scope boundaries - once a block is exited, formatting is re-enabled.
206
205
207
206
### Formatting Ranges
208
207
209
208
To format a specific range within a file, use `--range-start <num>` and/or `--range-end <num>`.
210
-
Both arguments are inclusive and optional - if an argument is not provided, the start/end of the file will be used respectively.
209
+
Both arguments are inclusive and optional - if an argument is not provided, the start/end of the file is used respectively.
211
210
212
-
Only whole statements lying within the range will be formatted.
213
-
If part of a statement falls outside the range, the statement will be ignored.
211
+
Only whole statements lying within the range are formatted.
212
+
If part of a statement falls outside the range, the statement is ignored.
214
213
215
214
In editors, `Format Selection` is supported.
216
215
@@ -219,8 +218,8 @@ In editors, `Format Selection` is supported.
219
218
StyLua has built-in support for sorting require statements. We group consecutive require statements into a single "block",
220
219
and then requires are sorted only within that block. Blocks of requires do not move around the file.
221
220
222
-
We only include requires of the form `local NAME = require(EXPR)`, and sort lexicographically based on `NAME`.
223
-
(We also sort Roblox services of the form `local NAME = game:GetService(EXPR)`)
221
+
StyLua only considers requires of the form `local NAME = require(EXPR)`, and sorts lexicographically based on `NAME`.
222
+
(StyLua can also sort Roblox services of the form `local NAME = game:GetService(EXPR)`)
224
223
225
224
Requires sorting is off by default. To enable it, add the following to your `stylua.toml`:
226
225
@@ -241,12 +240,12 @@ If not found, we search for an `.editorconfig` file, otherwise fall back to the
241
240
This feature can be disabled using `--no-editorconfig`.
242
241
See [EditorConfig](https://editorconfig.org/) for more details.
243
242
244
-
A custom path can be provided using `--config-path <path>`.
245
-
If the path provided is not found/malformed, StyLua will exit with an error.
243
+
Use `--config-path <path>` to provide a custom path to the configuration.
244
+
If the file provided is not found/malformed, StyLua will exit with an error.
246
245
247
-
By default, the tool does not search further than the current directory.
248
-
Recursively searching parent directories can be enabled using `--search-parent-directories`.
249
-
This will keep searching ancestors. If not found, it will then look in `$XDG_CONFIG_HOME` / `$XDG_CONFIG_HOME/stylua`.
246
+
By default, StyLua does not search further than the current directory.
247
+
Use `--search-parent-directories` to recursively search parent directories.
248
+
This will keep searching ancestors and, if not found, will then look in `$XDG_CONFIG_HOME` / `$XDG_CONFIG_HOME/stylua` / `$HOME/.config` and `$HOME/.config/stylua`.
250
249
251
250
**Note: enabling searching outside of the current directory is NOT recommended due to possibilities of conflicting formatting:**
0 commit comments