Skip to content

stylua

GitHub stars GitHub release (latest SemVer) GitHub last commit GitHub commit activity GitHub contributors

stylua documentation

StyLua - GitHub

Configuration in MegaLinter

Variable Description Default value
LUA_STYLUA_ARGUMENTS User custom arguments to add in linter CLI call
Ex: -s --foo "bar"
LUA_STYLUA_COMMAND_REMOVE_ARGUMENTS User custom arguments to remove from command line before calling the linter
Ex: -s --foo "bar"
LUA_STYLUA_FILTER_REGEX_INCLUDE Custom regex including filter
Ex: (src\|lib)
Include every file
LUA_STYLUA_FILTER_REGEX_EXCLUDE Custom regex excluding filter
Ex: (test\|examples)
Exclude no file
LUA_STYLUA_CLI_LINT_MODE Override default CLI lint mode
- file: Calls the linter for each file
- project: Call the linter from the root of the project
file
LUA_STYLUA_FILE_EXTENSIONS Allowed file extensions. "*" matches any extension, "" matches empty extension. Empty list excludes all files
Ex: [".py", ""]
[".lua"]
LUA_STYLUA_FILE_NAMES_REGEX File name regex filters. Regular expression list for filtering files by their base names using regex full match. Empty list includes all files
Ex: ["Dockerfile(-.+)?", "Jenkinsfile"]
Include every file
LUA_STYLUA_PRE_COMMANDS List of bash commands to run before the linter None
LUA_STYLUA_POST_COMMANDS List of bash commands to run after the linter None
LUA_STYLUA_UNSECURED_ENV_VARIABLES List of env variables explicitly not filtered before calling LUA_STYLUA and its pre/post commands None
LUA_STYLUA_CONFIG_FILE stylua configuration file nameUse LINTER_DEFAULT to let the linter find it stylua.toml
LUA_STYLUA_RULES_PATH Path where to find linter configuration file Workspace folder, then MegaLinter default rules
LUA_STYLUA_DISABLE_ERRORS Run linter but consider errors as warnings false
LUA_STYLUA_DISABLE_ERRORS_IF_LESS_THAN Maximum number of errors allowed 0
LUA_STYLUA_CLI_EXECUTABLE Override CLI executable ['stylua']

IDE Integration

Use stylua in your favorite IDE to catch errors before MegaLinter !

IDE Extension Name Install
neovim ['nvim-lint', 'none-ls', 'stylua-nvim', 'stylua.nvim'] Visit Web Site
Visual Studio Code Stylua Install in VSCode
Sublime Text Sublime-Pretty-Lua Visit Web Site

MegaLinter Flavors

This linter is available in the following flavors

Flavor Description Embedded linters Info
all Default MegaLinter Flavor 124 Docker Image Size (tag) Docker Pulls

Behind the scenes

How are identified applicable files

  • File extensions: .lua

How the linting is performed

  • stylua is called one time by identified file (file CLI lint mode)

Example calls

stylua --check myfile.lua
stylua --config-path chktexrc.toml --check myfile.lua

Help content

stylua 0.20.0
A utility to format Lua code

USAGE:
    stylua [OPTIONS] [FILES]...

ARGS:
    <FILES>...    A list of files to format

OPTIONS:
    -a, --allow-hidden
            Whether to traverse hidden files/directories

    -c, --check
            Runs in 'check' mode

        --color <COLOR>
            Use colored output [default: Auto] [possible values: Always, Auto, Never]

    -f, --config-path <CONFIG_PATH>
            Specify path to stylua.toml configuration file

    -g, --glob <GLOB>
            Glob patterns to test against which files to check

    -h, --help
            Print help information

        --no-editorconfig
            Disables the EditorConfig feature

        --num-threads <NUM_THREADS>
            The number of threads to use to format files in parallel [default: 4]

        --output-format <OUTPUT_FORMAT>
            Configures the diff output when using 'check' mode [default: Standard] [possible values:
            Standard, Unified, Json, Summary]

        --range-end <RANGE_END>
            An ending range to format files, given as a byte offset from the beginning of the file

        --range-start <RANGE_START>
            A starting range to format files, given as a byte offset from the beginning of the file

        --respect-ignores
            Respect .styluaignore and glob matching for file paths provided directly to the tool

    -s, --search-parent-directories
            Search parent directories for stylua.toml, if not found in current directory. Ignored if
            config_path is provided

        --stdin-filepath <STDIN_FILEPATH>
            Specify the location of the file that is being passed into stdin. Ignored if not taking
            in input from stdin

    -v, --verbose
            Enables verbose output

    -V, --version
            Print version information

        --verify
            Verifies the output correctness after formatting

FORMATTING OPTIONS:
        --call-parentheses <CALL_PARENTHESES>
            Specify whether to apply parentheses on function calls with single string or table arg
            [possible values: Always, NoSingleString, NoSingleTable, None, Input]

        --collapse-simple-statement <COLLAPSE_SIMPLE_STATEMENT>
            Specify whether to collapse simple statements [possible values: Never, FunctionOnly,
            ConditionalOnly, Always]

        --column-width <COLUMN_WIDTH>
            The column width to use to attempt to wrap lines

        --indent-type <INDENT_TYPE>
            The type of indents to use [possible values: Tabs, Spaces]

        --indent-width <INDENT_WIDTH>
            The width of a single indentation level

        --line-endings <LINE_ENDINGS>
            The type of line endings to use [possible values: Unix, Windows]

        --quote-style <QUOTE_STYLE>
            The style of quotes to use in string literals [possible values: AutoPreferDouble,
            AutoPreferSingle, ForceDouble, ForceSingle]

        --sort-requires
            Enable requires sorting

Installation on mega-linter Docker image

  • Dockerfile commands :
# Parent descriptor install
RUN wget --tries=5 https://www.lua.org/ftp/lua-5.3.5.tar.gz -O - -q | tar -xzf - \
    && cd lua-5.3.5 \
    && make linux \
    && make install \
    && cd .. && rm -r lua-5.3.5/

# Linter install
# renovate: datasource=crate depName=stylua
ARG LUA_STYLUA_VERSION=0.20.0