Skip to content

luacheck

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

luacheck documentation

luacheck - GitHub

Configuration in MegaLinter

Variable Description Default value
LUA_LUACHECK_ARGUMENTS User custom arguments to add in linter CLI call
Ex: -s --foo "bar"
LUA_LUACHECK_FILTER_REGEX_INCLUDE Custom regex including filter
Ex: (src\|lib)
Include every file
LUA_LUACHECK_FILTER_REGEX_EXCLUDE Custom regex excluding filter
Ex: (test\|examples)
Exclude no file
LUA_LUACHECK_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_LUACHECK_FILE_EXTENSIONS Allowed file extensions. "*" matches any extension, "" matches empty extension. Empty list excludes all files
Ex: [".py", ""]
[".lua"]
LUA_LUACHECK_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_LUACHECK_PRE_COMMANDS List of bash commands to run before the linter None
LUA_LUACHECK_POST_COMMANDS List of bash commands to run after the linter None
LUA_LUACHECK_UNSECURED_ENV_VARIABLES List of env variables explicitly not filtered before calling LUA_LUACHECK and its pre/post commands None
LUA_LUACHECK_CONFIG_FILE luacheck configuration file nameUse LINTER_DEFAULT to let the linter find it .luacheckrc
LUA_LUACHECK_RULES_PATH Path where to find linter configuration file Workspace folder, then MegaLinter default rules
LUA_LUACHECK_DISABLE_ERRORS Run linter but consider errors as warnings false
LUA_LUACHECK_DISABLE_ERRORS_IF_LESS_THAN Maximum number of errors allowed 0
LUA_LUACHECK_CLI_EXECUTABLE Override CLI executable ['luacheck']

IDE Integration

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

IDE Extension Name Install
Atom linter-luacheck Visit Web Site
Brackets brackets-luacheck Visit Web Site
Emacs flycheck Visit Web Site
Sublime Text SublimeLinter-luacheck Visit Web Site
vim Syntastic Visit Web Site
Visual Studio Code vscode-luacheck Install in VSCode

MegaLinter Flavours

This linter is available in the following flavours

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

Behind the scenes

How are identified applicable files

  • File extensions: .lua

How the linting is performed

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

Example calls

luacheck myfile.lua
luacheck --config .chktexrc myfile.lua

Help content

Usage: luacheck ([--config <config>] | [--no-config])
       ([--default-config <default_config>] | [--no-default-config])
       [-h] [-g] [-u] [-r] [-a] [-s] [--no-self] [--std <std>] [-c]
       [-d] [-t] [-m] [--max-line-length <length>]
       [--no-max-line-length] [--max-code-line-length <length>]
       [--no-max-code-line-length] [--max-string-line-length <length>]
       [--no-max-string-line-length]
       [--max-comment-line-length <length>]
       [--no-max-comment-line-length]
       [--max-cyclomatic-complexity <complexity>]
       [--no-max-cyclomatic-complexity] [--filename <filename>]
       [-j <jobs>] [--formatter <formatter>] [-q] [--codes] [--ranges]
       [--no-color] [-v] <file> [<file>] ...
       ([--cache [<cache>]] | [--no-cache])
       [--ignore <patt> [<patt>] ...] [--enable <patt> [<patt>] ...]
       [--only <patt> [<patt>] ...] [--operators <patt> [<patt>] ...]
       [--globals [<name>] ...] [--read-globals [<name>] ...]
       [--new-globals [<name>] ...] [--new-read-globals [<name>] ...]
       [--not-globals [<name>] ...]
       [--exclude-files <glob> [<glob>] ...]
       [--include-files <glob> [<glob>] ...]

luacheck 1.1.1, a linter and a static analyzer for Lua.

Arguments:
   files                 List of files, directories and rockspecs to check. Pass
                         '-' to check stdin.

Options for filtering warnings:
   -g, --no-global       Filter out warnings related to global variables.
                         Equivalent to --ignore 1.
   -u, --no-unused       Filter out warnings related to unused variables and
                         values. Equivalent to --ignore [23].
   -r, --no-redefined    Filter out warnings related to redefined variables.
                         Equivalent to --ignore 4.
   -a, --no-unused-args  Filter out warnings related to unused arguments and
                         loop variables. Equivalent to --ignore 21[23].
   -s, --no-unused-secondaries
                         Filter out warnings related to unused variables set
                         together with used ones.
   --no-self             Filter out warnings related to implicit self argument.
   --ignore <patt> [<patt>] ...,
         -i <patt> [<patt>] ...
                         Filter out warnings matching these patterns.
                         If a pattern contains slash, part before slash matches
                         warning code and part after it matches name of related
                         variable. Otherwise, if the pattern contains letters or
                         underscore, it matches name of related variable.
                         Otherwise, the pattern matches warning code.
   --enable <patt> [<patt>] ...,
         -e <patt> [<patt>] ...
                         Do not filter out warnings matching these patterns.
   --only <patt> [<patt>] ...,
       -o <patt> [<patt>] ...
                         Filter out warnings not matching these patterns.
   --operators <patt> [<patt>] ...
                         Allow compound operators matching patterns

Options for configuring allowed globals:
   --std <std>           Set standard globals, default is max. <std> can be one
                         of:
                            max - union of globals of Lua 5.1, Lua 5.2, Lua 5.3
                            and LuaJIT 2.x;
                            min - intersection of globals of Lua 5.1, Lua 5.2,
                            Lua 5.3 and LuaJIT 2.x;
                            lua51 - globals of Lua 5.1 without deprecated ones;
                            lua51c - globals of Lua 5.1;
                            lua52 - globals of Lua 5.2;
                            lua52c - globals of Lua 5.2 with LUA_COMPAT_ALL;
                            lua53 - globals of Lua 5.3;
                            lua53c - globals of Lua 5.3 with LUA_COMPAT_5_2;
                            lua54 - globals of Lua 5.4;
                            lua54c - globals of Lua 5.4 with LUA_COMPAT_5_3;
                            luajit - globals of LuaJIT 2.x;
                            ngx_lua - globals of Openresty lua-nginx-module
                            0.10.10, including standard LuaJIT 2.x globals;
                            love - globals added by LÖVE;
                            playdate - globals added by the Playdate SDK;
                            busted - globals added by Busted 2.0, by default
                            added for files ending with _spec.lua within spec,
                            test, and tests subdirectories;
                            rockspec - globals allowed in rockspecs, by default
                            added for files ending with .rockspec;
                            luacheckrc - globals allowed in Luacheck configs, by
                            default added for files ending with .luacheckrc;
                            none - no standard globals.

                         Sets can be combined using '+'. Extra sets can be
                         defined in config by adding to `stds` global in config.
   -c, --compat          Equivalent to --std max.
   --globals [<name>] ...
                         Add custom global variables (e.g. foo) or fields (e.g.
                         foo.bar) on top of standard ones.
   --read-globals [<name>] ...
                         Add read-only global variables or fields.
   --new-globals [<name>] ...
                         Set custom global variables or fields. Removes custom
                         globals added previously.
   --new-read-globals [<name>] ...
                         Set read-only global variables or fields. Removes
                         read-only globals added previously.
   --not-globals [<name>] ...
                         Remove custom and standard global variables or fields.
   -d, --allow-defined   Allow defining globals implicitly by setting them.
   -t, --allow-defined-top
                         Allow defining globals implicitly by setting them in
                         the top level scope.
   -m, --module          Limit visibility of implicitly defined globals to their
                         files.

Options for configuring line length limits:
   --max-line-length <length>
                         Set maximum allowed line length (default: 120).
   --no-max-line-length  Do not limit line length.
   --max-code-line-length <length>
                         Set maximum allowed length for lines ending with code
                         (default: 120).
   --no-max-code-line-length
                         Do not limit code line length.
   --max-string-line-length <length>
                         Set maximum allowed length for lines within a string
                         (default: 120).
   --no-max-string-line-length
                         Do not limit string line length.
   --max-comment-line-length <length>
                         Set maximum allowed length for comment lines (default:
                         120).
   --no-max-comment-line-length
                         Do not limit comment line length.

Configuration file options:
   --config <config>     Path to configuration file. (default: .luacheckrc)
   --no-config           Do not look up configuration file.
   --default-config <default_config>
                         Path to configuration file to use if --[no-]config is
                         not used and project-specific .luacheckrc is not found.
                         (default: /root/.config/luacheck/.luacheckrc)
   --no-default-config   Do not use default configuration file.

File filtering options:
   --exclude-files <glob> [<glob>] ...
                         Do not check files matching these globbing patterns.
   --include-files <glob> [<glob>] ...
                         Do not check files not matching these globbing
                         patterns.

Performance optimization options:
   --cache [<cache>]     Path to cache directory. (default:
                         /root/.cache/luacheck)
   --no-cache            Do not use cache.
       -j <jobs>,        Check <jobs> files in parallel (default: 1).
   --jobs <jobs>         Warning: LuaLanes not found, parallel checking
                         disabled.

Output formatting options:
   --formatter <formatter>
                         Use custom formatter. <formatter> must be a module name
                         or one of:
                            TAP - Test Anything Protocol formatter;
                            JUnit - JUnit XML formatter;
                            visual_studio - MSBuild/Visual Studio aware
                            formatter;
                            plain - simple warning-per-line formatter;
                            default - standard formatter.
   -q, --quiet           Suppress output for files without warnings.
                         -qq: Suppress output of warnings.
                         -qqq: Only print total number of warnings and errors.
   --codes               Show warning codes.
   --ranges              Show ranges of columns related to warnings.
   --no-color            Do not color output.

Other options:
   -h, --help            Show this help message and exit.
   --max-cyclomatic-complexity <complexity>
                         Set maximum cyclomatic complexity for functions.
   --no-max-cyclomatic-complexity
                         Do not limit function cyclomatic complexity (default).
   --filename <filename> Use another filename in output and for selecting
                         configuration overrides.
   -v, --version         Show version info and exit.

Links:

   Luacheck on GitHub: https://github.com/lunarmodules/luacheck
   Luacheck documentation: https://luacheck.readthedocs.org

Installation on mega-linter Docker image

  • Dockerfile commands :
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/ \
    && wget --tries=5 https://github.com/cvega/luarocks/archive/v3.3.1-super-linter.tar.gz -O - -q | tar -xzf - \
    && cd luarocks-3.3.1-super-linter \
    && ./configure --with-lua-include=/usr/local/include \
    && make \
    && make -b install \
    && cd .. && rm -r luarocks-3.3.1-super-linter/ \
    && luarocks install luacheck \
    && cd /