{"id":15038456,"url":"https://github.com/johnnymorganz/stylua","last_synced_at":"2025-04-23T20:59:02.847Z","repository":{"id":38693147,"uuid":"321792527","full_name":"JohnnyMorganz/StyLua","owner":"JohnnyMorganz","description":"A Lua code formatter","archived":false,"fork":false,"pushed_at":"2025-04-22T10:48:11.000Z","size":2769,"stargazers_count":1793,"open_issues_count":53,"forks_count":84,"subscribers_count":12,"default_branch":"main","last_synced_at":"2025-04-23T20:58:50.943Z","etag":null,"topics":["formatter","hacktoberfest","lua","luaformatter","luau","pretty-printer","printer","stylua"],"latest_commit_sha":null,"homepage":"","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mpl-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/JohnnyMorganz.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2020-12-15T21:24:43.000Z","updated_at":"2025-04-22T10:46:18.000Z","dependencies_parsed_at":"2023-02-09T22:15:27.615Z","dependency_job_id":"f238ce4d-1355-4064-a291-1d0222cc0696","html_url":"https://github.com/JohnnyMorganz/StyLua","commit_stats":{"total_commits":798,"total_committers":38,"mean_commits":21.0,"dds":"0.18045112781954886","last_synced_commit":"59be1c313b50d3ee72f988c840f9a178792a4c72"},"previous_names":[],"tags_count":54,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JohnnyMorganz%2FStyLua","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JohnnyMorganz%2FStyLua/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JohnnyMorganz%2FStyLua/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JohnnyMorganz%2FStyLua/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/JohnnyMorganz","download_url":"https://codeload.github.com/JohnnyMorganz/StyLua/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250514767,"owners_count":21443208,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["formatter","hacktoberfest","lua","luaformatter","luau","pretty-printer","printer","stylua"],"created_at":"2024-09-24T20:38:34.644Z","updated_at":"2025-04-23T20:59:02.840Z","avatar_url":"https://github.com/JohnnyMorganz.png","language":"Rust","readme":"\u003cdiv align=\"center\"\u003e\n\t\u003ch1\u003e\n\t\tStyLua\u003cbr\u003e\n\t\t\u003ca href=\"https://crates.io/crates/stylua\"\u003e\u003cimg src=\"https://img.shields.io/crates/v/stylua.svg\"\u003e\u003c/a\u003e\n    \u003ca href=\"https://github.com/JohnnyMorganz/StyLua/actions/workflows/ci.yml\"\u003e\u003cimg src=\"https://github.com/JohnnyMorganz/StyLua/actions/workflows/ci.yml/badge.svg\"\u003e\u003c/a\u003e\n    \u003ca href=\"https://codecov.io/gh/JohnnyMorganz/StyLua\"\u003e\u003cimg src=\"https://codecov.io/gh/JohnnyMorganz/StyLua/branch/main/graph/badge.svg\"/\u003e\u003c/a\u003e\n\t\u003c/h1\u003e\n\u003c/div\u003e\n\nA deterministic code formatter for Lua 5.1, 5.2, 5.3, 5.4, LuaJIT, [Luau](https://luau.org/) and [CfxLua/FiveM Lua](https://docs.fivem.net/docs/scripting-manual/runtimes/lua/), built using [full-moon](https://github.com/Kampfkarren/full-moon).\nStyLua is inspired by the likes of [prettier](https://github.com/prettier/prettier), it parses your Lua codebase, and prints it back out from scratch,\nenforcing a consistent code style.\n\nStyLua mainly follows the [Roblox Lua Style Guide](https://roblox.github.io/lua-style-guide/), with a few deviations.\n\n## Installation\n\nThere are multiple ways to install StyLua:\n\n### With Github Releases\n\nPre-built binaries are available on the [GitHub Releases Page](https://github.com/JohnnyMorganz/StyLua/releases).\n\nBy default, these are built with **all syntax variants enabled (Lua 5.2, 5.3, 5.4, LuaJIT and Luau)**, to cover all possible codebases.\nSee [configuring runtime syntax selection](#configuring-runtime-syntax-selection) if you need to select a particular syntax of Lua to format.\nAlternatively, see [installing from crates.io](#from-cratesio) on how to install a particular flavour of StyLua.\n\n### From Crates.io\n\nIf you have [Rust](https://www.rust-lang.org/) installed, you can install StyLua using cargo.\nBy default, this builds for just Lua 5.1.\nYou can pass the `--features \u003cflag\u003e` argument to add extra syntax variants:\n\n```sh\ncargo install stylua\ncargo install stylua --features lua52\ncargo install stylua --features lua53\ncargo install stylua --features lua54\ncargo install stylua --features luajit\ncargo install stylua --features luau\n```\n\nYou 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.\n\n### GitHub Actions\n\nThe [stylua-action](https://github.com/marketplace/actions/stylua) GitHub Action can install and run StyLua.\nThis action uses the prebuilt GitHub release binaries, instead of running cargo install, for faster CI startup times.\n\n### pre-commit\n\nYou can use StyLua with [pre-commit](https://pre-commit.com/).\nThere are 3 possible pre-commit hooks available:\n\n- `stylua`: installs via cargo - requires the Rust toolchain\n- `stylua-system`: runs a `stylua` binary available on the PATH. The binary must be pre-installed\n- `stylua-github`: automatically installs the relevant prebuilt binary from GitHub Releases\n\nAdd the following to your `.pre-commit-config.yaml` file:\n\n```yaml\n- repo: https://github.com/JohnnyMorganz/StyLua\n  rev: v2.1.0\n  hooks:\n    - id: stylua # or stylua-system / stylua-github\n```\n\n### npm\n\nStyLua is available as a binary [published to npm](https://www.npmjs.com/package/@johnnymorganz/stylua-bin) as `@johnnymorganz/stylua-bin`.\nThis is a thin wrapper that installs the binary and makes it available through npm / npx.\n\n```sh\nnpx @johnnymorganz/stylua-bin --help\n```\n\nStyLua is also available as a WASM library at [@johnnymorganz/stylua](https://www.npmjs.com/package/@johnnymorganz/stylua).\nIt is usable in Node.js, or in the browser (using a bundler).\n\n### Docker\n\nStyLua is available on the [Docker Hub](https://hub.docker.com/r/johnnymorganz/stylua).\n\nIf you are using Docker, the easiest way to install StyLua is:\n\n```dockerfile\nCOPY --from=JohnnyMorganz/StyLua:2.1.0 /stylua /usr/bin/stylua\n```\n\n### Homebrew\n\nStyLua is available on macOS via the [Homebrew](https://brew.sh) package manager.\n\n```sh\nbrew install stylua\n```\n\n### Other Installation Methods\n\n- [VSCode Extension](https://marketplace.visualstudio.com/items?itemName=JohnnyMorganz.stylua)\n- [Aftman](https://github.com/LPGhatguy/aftman)\n\n```sh\naftman add johnnymorganz/stylua@2.1.0\n```\n\n- A community maintained package repository. Please note, these packages are maintained by third-parties and we do not control their packaging manifests.\n\n[![Community Packages](https://repology.org/badge/vertical-allrepos/stylua.svg?header=Community%20Packages)](https://repology.org/project/stylua/versions)\n\n### Other Editor Integrations\n\nNote that these integrations require the StyLua binary to already be installed and available on your system.\n\n- Sublime: [Sublime Text Package](https://github.com/aerobounce/Sublime-Pretty-Lua)\n- Neovim: [stylua-nvim](https://github.com/ckipp01/stylua-nvim) / [stylua.nvim](https://github.com/wesleimp/stylua.nvim)\n- Zed: [Zed Lua StyLua formatter settings](https://zed.dev/docs/languages/lua#stylua)\n\n## Usage\n\nOnce installed, pass the files to format to the CLI:\n\n```sh\nstylua src/ foo.lua bar.lua\n```\n\nThis command will format the `foo.lua` and `bar.lua` file, and search down the `src` directory to format any files within it.\nStyLua can also read from stdin, by using `-` as the file name.\n\n### Glob Filtering\n\nBy default, when searching through a directory, StyLua looks for all files matching the glob `**/*.lua` (or `**/*.luau` when `luau` is enabled) to format.\nYou can also specify an explicit glob pattern to match against when searching:\n\n```sh\nstylua --glob '**/*.luau' -- src # format all files in src matching **/*.luau\nstylua -g '*.lua' -g '!*.spec.lua' -- . # format all Lua files except test files ending with `.spec.lua`\n```\n\nNote that the `-g/--glob` argument can take multiple strings at once, so `--` is required to separate between the glob patterns and the files to format.\n\nBy default, glob filtering (and `.styluaignore` files) are only applied during directory traversal and searching.\nFiles passed directly (e.g. `stylua foo.txt`) will override the glob / ignore and always be formatted.\nTo disable this behaviour, pass the `--respect-ignores` flag (`stylua --respect-ignores foo.txt`).\n\n### Filtering using `.styluaignore`\n\nYou can create a `.styluaignore` file, with a format similar to `.gitignore`.\nAny files matching the globs in the ignore file are ignored by StyLua.\nFor example, for a `.styluaignore` file with the following contents:\n\n```\nvendor/\n```\n\nrunning `stylua .` will ignore the `vendor/` directory.\n\n### Filtering when using stdin\n\nIf you are formatting stdin by specifying `-` as the filename (usually as part of an editor integration)\nyou can optionally provide the filename via `--stdin-filepath`. To respect glob or `.styluaignore` filtering, pass `--respect-ignores`.\n\n```stylua\nstylua --respect-ignores --stdin-filepath src/foo.lua -\n```\n\n### `--check`: Checking files for formatting\n\nTo check whether files require formatting (but not write directly to them), use the `--check` flag.\nIt will take files as input, and output a diff to stdout instead of rewriting the file contents.\nIf there are any files that require formatting, StyLua will exit with status code 1.\n\nThere are different styles of output available:\n\n- `--output-format=standard`: output a custom diff (default)\n- `--output-format=unified`: output a unified diff, consumable by tools like `patch` or `delta`\n- `--output-format=json`: output JSON representing the changes, useful for machine-readable output\n- `--output-format=summary`: output a summary list of file paths that are incorrectly formatted\n\n### `--verify`: Verifying formatting output\n\nAs a safety measure, you can use the `--verify` flag to verify the output of all formatting before saving the file.\n\nIf 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).\n\nThis is useful when adopting StyLua in a large codebase, where it is difficult to manually check all formatting is correct.\nNote that this may produce false positives and negatives - we recommend manual verification as well as running tests to confirm.\n\n### Ignoring parts of a file\n\nTo skip formatting a particular part of a file, you can add `-- stylua: ignore` before it.\nThis is useful if there is a particular style you want to preseve for readability, e.g.:\n\n```lua\n-- stylua: ignore\nlocal matrix = {\n    { 0, 0, 0 },\n    { 0, 0, 0 },\n    { 0, 0, 0 },\n}\n```\n\nTo skip a block of code, use `-- stylua: ignore start` and `-- stylua: ignore end`:\n\n```lua\nlocal foo = true\n-- stylua: ignore start\nlocal   bar   =   false\nlocal  baz      = 0\n-- stylua: ignore end\nlocal foobar = false\n```\n\nNote that ignoring cannot cross scope boundaries - once a block is exited, formatting is re-enabled.\n\n### Formatting Ranges\n\nTo format a specific range within a file, use `--range-start \u003cnum\u003e` and/or `--range-end \u003cnum\u003e`.\nBoth arguments are inclusive and optional - if an argument is not provided, the start/end of the file is used respectively.\n\nOnly whole statements lying within the range are formatted.\nIf part of a statement falls outside the range, the statement is ignored.\n\nIn editors, `Format Selection` is supported.\n\n### Requires Sorting\n\nStyLua has built-in support for sorting require statements. We group consecutive require statements into a single \"block\",\nand then requires are sorted only within that block. Blocks of requires do not move around the file.\n\nStyLua only considers requires of the form `local NAME = require(EXPR)`, and sorts lexicographically based on `NAME`.\n(StyLua can also sort Roblox services of the form `local NAME = game:GetService(EXPR)`)\n\nRequires sorting is off by default. To enable it, add the following to your `stylua.toml`:\n\n```toml\n[sort_requires]\nenabled = true\n```\n\n## Configuration\n\nStyLua has opinionated defaults, but also provides a few options that can be set per project.\n\n### Finding the configuration\n\nThe CLI looks for a `stylua.toml` or `.stylua.toml` starting from the directory of the file being formatted.\nIt will keep searching upwards until it reaches the current directory where the tool was executed.\nIf not found, we search for an `.editorconfig` file, otherwise fall back to the default configuration.\nThis feature can be disabled using `--no-editorconfig`.\nSee [EditorConfig](https://editorconfig.org/) for more details.\n\nUse `--config-path \u003cpath\u003e` to provide a custom path to the configuration.\nIf the file provided is not found/malformed, StyLua will exit with an error.\n\nBy default, StyLua does not search further than the current directory.\nUse `--search-parent-directories` to recursively search parent directories.\nThis 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`.\n\n**Note: enabling searching outside of the current directory is NOT recommended due to possibilities of conflicting formatting:**\n\nIt is recommended to keep a `.stylua.toml` file in your project root so that other developers can make use of the same configuration.\n\nIf a project uses the default configuration of StyLua without a configuration file present, enabling external searching may cause conflicting formatting.\n\n### Configuring Runtime Syntax Selection\n\nBy default, StyLua releases comes with all flavours of Lua bundled into one binary, with a union of all syntax styles.\nWe do this to make it easier to get started with StyLua on any codebase or project using Lua.\n\nHowever, there are times where the union of syntaxes collide, causing issues. For example, Lua 5.2's goto label syntax\n(`::label::`) conflicts with Luau's type assertion syntax (`x :: number`), and the latter ends up taking priority.\n\nTo disambiguate a particular syntax style for your codebase, set `syntax = \"Style\"` in your `.stylua.toml` file, e.g.:\n\n```toml\nsyntax = \"Lua52\"\n```\n\nAlternatively, you can specify it on the command line, with `stylua --syntax lua52 ...`\n\n### Options\n\nStyLua only offers the following options:\n\n| Option                       | Default            | Description                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           |\n| ---------------------------- | ------------------ | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |\n| `syntax`                     | `All`              | Specify a disambiguation for the style of Lua syntax being formatted. Possible options: `All` (default), `Lua51`, `Lua52`, `Lua53`, `Lua54`, `LuaJIT`, `Luau`, `CfxLua`                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               |\n| `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.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     |\n| `line_endings`               | `Unix`             | Line endings type. Possible options: `Unix` (LF) or `Windows` (CRLF)                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  |\n| `indent_type`                | `Tabs`             | Indent type. Possible options: `Tabs` or `Spaces`                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     |\n| `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.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           |\n| `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.                                                                                                                                                                                                                                                                                                                                                                                                                             |\n| `call_parentheses`           | `Always`           | Whether parentheses should be applied on function calls with a single string/table argument. Possible options: `Always`, `NoSingleString`, `NoSingleTable`, `None`, `Input`. `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 -\u003e foo(\"bar\").setup`, since the index is on the call result, not the string). `Input` removes all automation and preserves parentheses only if they were present in input code: consistency is not enforced. |\n| `space_after_function_names` | `Never`            | Specify whether to add a space between the function name and parentheses. Possible options: `Never`, `Definitions`, `Calls`, or `Always`                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              |\n| `collapse_simple_statement`  | `Never`            | Specify whether to collapse simple statements. Possible options: `Never`, `FunctionOnly`, `ConditionalOnly`, or `Always`                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              |\n\nDefault `stylua.toml`, note you do not need to explicitly specify each option if you want to use the defaults:\n\n```toml\nsyntax = \"All\"\ncolumn_width = 120\nline_endings = \"Unix\"\nindent_type = \"Tabs\"\nindent_width = 4\nquote_style = \"AutoPreferDouble\"\ncall_parentheses = \"Always\"\ncollapse_simple_statement = \"Never\"\nspace_after_function_names = \"Never\"\n\n[sort_requires]\nenabled = false\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjohnnymorganz%2Fstylua","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjohnnymorganz%2Fstylua","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjohnnymorganz%2Fstylua/lists"}