### Luacheck Build and Install Command Source: https://github.com/tradeskillmaster/luacheck/blob/master/README.md Command to build and install the development version of Luacheck from its repository. ```shell luarocks make ``` -------------------------------- ### Example luacheck Configuration Source: https://github.com/tradeskillmaster/luacheck/blob/master/docsrc/config.rst A sample luacheck configuration file demonstrating how to set standard globals and ignore specific error codes. ```lua std = "min" ignore = {"212"} ``` -------------------------------- ### luacheck Output Example Source: https://github.com/tradeskillmaster/luacheck/blob/master/docsrc/cli.rst Demonstrates the typical output format of luacheck, showing warnings and errors per file, followed by a summary. ```shell $ luacheck src Checking src/bad_code.lua 5 warnings src/bad_code.lua:3:16: unused variable helper src/bad_code.lua:3:23: unused variable length argument src/bad_code.lua:7:10: setting non-standard global variable embrace src/bad_code.lua:8:10: variable opt was previously defined as an argument on line 7 src/bad_code.lua:9:11: accessing undefined variable hepler Checking src/good_code.lua OK Checking src/python_code.lua 1 error src/python_code.lua:1:6: expected "=" near "__future__" Checking src/unused_code.lua 9 warnings src/unused_code.lua:3:18: unused argument baz src/unused_code.lua:4:8: unused loop variable i src/unused_code.lua:5:13: unused variable q src/unused_code.lua:7:11: unused loop variable a src/unused_code.lua:7:14: unused loop variable b src/unused_code.lua:7:17: unused loop variable c src/unused_code.lua:13:7: value assigned to variable x is unused src/unused_code.lua:14:1: value assigned to variable x is unused src/unused_code.lua:22:1: value assigned to variable z is unused Total: 14 warnings / 1 error in 4 files ``` -------------------------------- ### Luacheck Analysis Output Example Source: https://github.com/tradeskillmaster/luacheck/blob/master/README.md Example output from Luacheck showing warnings and errors detected in Lua code files, including file paths, line numbers, and specific issue descriptions. ```text Checking src/good_code.lua OK Checking src/bad_code.lua 3 warnings src/bad_code.lua:3:23: unused variable length argument src/bad_code.lua:7:10: setting non-standard global variable embrace src/bad_code.lua:8:10: variable opt was previously defined as an argument on line 7 Checking src/python_code.lua 1 error src/python_code.lua:1:6: expected '=' near '__future__' Checking extra_file.lua 5 warnings extra_file.lua:3:18: unused argument baz extra_file.lua:4:8: unused loop variable i extra_file.lua:13:7: accessing uninitialized variable a extra_file.lua:14:1: value assigned to variable x is unused extra_file.lua:21:7: variable z is never accessed Checking another_file.lua 2 warnings another_file.lua:2:7: unused variable height another_file.lua:3:7: accessing undefined variable heigth Total: 10 warnings / 1 error in 5 files ``` -------------------------------- ### Install Luacheck with LuaRocks Source: https://github.com/tradeskillmaster/luacheck/blob/master/README.md Installs Luacheck using the LuaRocks package manager. For parallel checking, LuaLanes is also required and can be installed separately. ```shell luarocks install luacheck ``` ```shell luarocks install lanes ``` -------------------------------- ### Run Luacheck from Source Source: https://github.com/tradeskillmaster/luacheck/blob/master/README.md Command to run Luacheck using sources in the current directory without installing it. It sets up the package path to include local source files. ```shell lua -e "package.path='./src/?.lua;./src/?/init.lua;'..package.path" bin/luacheck.lua ... ``` -------------------------------- ### Luacheck Testing Command Source: https://github.com/tradeskillmaster/luacheck/blob/master/README.md Command to run Luacheck's tests, requiring the 'busted' test framework and 'luautf8' library to be installed. ```shell busted ``` -------------------------------- ### Luacheck Line Length Limits Source: https://github.com/tradeskillmaster/luacheck/blob/master/docsrc/cli.rst Options to enforce maximum line length constraints for different types of lines in Lua code. This helps maintain code readability and adherence to style guides. ```APIDOC --max-line-length Set maximum allowed line length (default: 120). --no-max-line-length Do not limit line length. --max-code-line-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 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 Set maximum allowed length for comment lines (default: 120). --no-max-comment-line-length Do not limit comment line length. ``` -------------------------------- ### Unreachable Code Source: https://github.com/tradeskillmaster/luacheck/blob/master/docsrc/warnings.rst Detects unreachable code within blocks. This example shows how a break statement outside an if block can make the end of a loop unreachable after the first iteration. ```lua for i = 1, 100 do -- Break statement is outside the `if` block, -- so that the loop always stops after the first iteration. if cond(i) then f() end break end ``` -------------------------------- ### luacheck Input Handling Source: https://github.com/tradeskillmaster/luacheck/blob/master/docsrc/cli.rst Describes how luacheck processes files, directories, stdin, and rockspecs. It highlights dependencies like LuaFileSystem for directory scanning. ```APIDOC luacheck accepts files, directories, and rockspecs as arguments. - ``luacheck``: Checks the specified files or directories. - ``luacheck -``: Checks standard input (stdin). - ``luacheck ``: Checks all files with a ".lua" extension within the specified directory. This requires LuaFileSystem. - ``luacheck ``: Checks all ".lua" files mentioned in the provided rockspec file. ``` -------------------------------- ### Import Luacheck Module and Version Source: https://github.com/tradeskillmaster/luacheck/blob/master/docsrc/module.rst Demonstrates how to import the luacheck module and access its version string. ```Lua local luacheck = require "luacheck" -- luacheck._VERSION contains Luacheck version as a string in MAJOR.MINOR.PATCH format. ``` -------------------------------- ### Luacheck Documentation Build Command Source: https://github.com/tradeskillmaster/luacheck/blob/master/README.md Command to build the project's documentation using Sphinx. The generated files will be placed in the 'doc/' directory. ```shell sphinx-build docsrc doc ``` -------------------------------- ### Luacheck Per-File Configuration Autovivification Source: https://github.com/tradeskillmaster/luacheck/blob/master/docsrc/config.rst Demonstrates the autovivification feature for the `files` configuration table in Luacheck. Shows that nested table assignments are equivalent to direct table assignments. ```lua files["src/dir"].enable = {"212"} -- is equivalent to: files["src/dir"] = {enable = {"212"}} ``` -------------------------------- ### luacheck Command Line Options Source: https://github.com/tradeskillmaster/luacheck/blob/master/docsrc/cli.rst Details the various command-line options available for luacheck, including short and long forms, and how to combine or use options that accept multiple arguments. ```APIDOC Command line options for luacheck: - Short options without arguments can be combined (e.g., ``-qqu`` is ``-q -q -u``). - Long options can use ``--option value`` or ``--option=value``. - Options taking multiple arguments can be used multiple times (e.g., ``--ignore foo --ignore bar`` is equivalent to ``--ignore foo bar``). - Options that may take several arguments should not be used immediately before positional arguments. Key Options: - ``-g | --no-global``: Filter out warnings related to global variables. - ``-u | --no-unused``: Filter out warnings related to unused variables and values. - ``-r | --no-redefined``: Filter out warnings related to redefined variables. - ``-a | --no-unused-args``: Filter out warnings related to unused arguments and loop variables. - ``-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. - ``--std ``: Set standard globals. Default is ``max``. Possible values: - ``max``: Union of globals for Lua 5.1, 5.2, 5.3, and LuaJIT 2.x. - ``min``: Intersection of globals for Lua 5.1, 5.2, 5.3, and LuaJIT 2.x. - ``lua51``: Globals of Lua 5.1 (excluding deprecated ones). - ``lua51c``: Globals of Lua 5.1 (including deprecated ones). - ``lua52``: Globals of Lua 5.2. ``` -------------------------------- ### Luacheck CLI Usage and Options Source: https://github.com/tradeskillmaster/luacheck/blob/master/docsrc/cli.rst Details how to invoke Luacheck from the command line, including recommended options for precise error reporting and compatibility. Covers input methods, output formatting, and the interpretation of error messages with codes and ranges. ```APIDOC Luacheck CLI Usage and Options: Invocation: luacheck [options] [file | -] General Usage Notes: - Start Luacheck from the directory containing the checked file. - Files can be passed via stdin using '-' as an argument or via a temporary file. - The real filename must be passed using the --filename option when using stdin or temporary files. - Use the plain formatter for one issue per line output. Key Options: --filename - Description: Specifies the real filename for reporting purposes, especially when reading from stdin or temporary files. - Example: luacheck --filename my_file.lua - < my_file.lua --ranges - Description: Enables precise error location reporting. Each line of output will start with the filename, followed by ::-:. - Output Format: filename::-: message - Note: Column numbering starts from 1. If not used, end column and dash are omitted. --codes - Description: Includes warning and error codes in the output. Codes are three-digit numbers prefixed with 'E' for errors or 'W' for warnings. - Output Format: filename::-: [E###|W###] message - Note: Lack of a code substring indicates a fatal error. Output Interpretation: - Each line represents one issue (warning or error). - The rest of the line after the code (if present) is the warning message. Compatibility: - For versions 0.11.0 and later, the described interface is guaranteed until 1.0.0. - For older versions, consult `luacheck --help` for specific interface details. ``` -------------------------------- ### Luacheck Formatter Options Source: https://github.com/tradeskillmaster/luacheck/blob/master/docsrc/cli.rst Allows selection of custom output formatters for Luacheck. Supported built-in formatters include TAP, JUnit, visual_studio, plain, and default. Custom formatters are Lua modules. ```APIDOC Luacheck Formatter Options: --formatter Use custom 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. Custom formatter modules receive report, file names, and options as arguments and must return a string. ``` -------------------------------- ### Luacheck Compatibility and Definition Options Source: https://github.com/tradeskillmaster/luacheck/blob/master/docsrc/cli.rst Flags that control Luacheck's compatibility settings and how it handles implicitly defined globals. These options help tailor the analysis to specific Lua versions or coding styles. ```APIDOC -c | --compat Equivalent to ``--std max``, enabling the latest Lua standard. -d | --allow-defined Allow defining globals implicitly by setting them. See :ref:`implicitlydefinedglobals`. -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. See :ref:`modules`. ``` -------------------------------- ### Luacheck Predefined Globals Source: https://github.com/tradeskillmaster/luacheck/blob/master/docsrc/cli.rst Defines standard global environments that Luacheck can use for static analysis. These environments specify the built-in globals available in different Lua versions or specific frameworks, helping Luacheck identify undefined variables. ```APIDOC --std Selects a predefined global environment. Available options include: * ``lua52`` - globals of Lua 5.2; * ``lua52c`` - globals of Lua 5.2 compiled with LUA_COMPAT_ALL; * ``lua53`` - globals of Lua 5.3; * ``lua53c`` - globals of Lua 5.3 compiled with LUA_COMPAT_5_2; * ``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`; * ``busted`` - globals added by Busted 2.0; * ``rockspec`` - globals allowed in rockspecs; * ``luacheckrc`` - globals allowed in Luacheck configs; * ``none`` - no standard globals. See :ref:`stds` for more details. ``` -------------------------------- ### Luacheck Standard Globals Sets Source: https://github.com/tradeskillmaster/luacheck/blob/master/docsrc/cli.rst Enables the use of predefined sets of standard globals, which can be combined using the '+' operator. Custom sets can also be defined in the configuration. ```APIDOC Luacheck Standard Globals Sets: --stds [,...] Combine built-in sets of standard globals. Use '+' to add sets. Example: --std max Equivalent to --std=lua51c+lua52c+lua53c+luajit. --std +love Adds LÖVE framework globals to the current set. ``` -------------------------------- ### Luacheck Inline Options: Global and Ignore Source: https://github.com/tradeskillmaster/luacheck/blob/master/docsrc/inline.rst Demonstrates using inline comments to define global variables and ignore specific warnings for Lua code. It shows how options affect code until the end of the current closure, illustrating scope. ```lua -- luacheck: globals g1 g2, ignore foo local foo = g1(g2) -- No warnings emitted. -- The following unused function is not reported. local function f() -- luacheck: ignore -- luacheck: globals g3 g3() -- No warning. end g3() -- Warning is emitted as the inline option defining g3 only affected function f. ``` -------------------------------- ### Run Luacheck on Files Source: https://github.com/tradeskillmaster/luacheck/blob/master/README.md Executes Luacheck on specified Lua files, rockspecs, or directories to perform static analysis and linting. It reports warnings and errors found. ```shell luacheck src extra_file.lua another_file.lua ``` -------------------------------- ### Luacheck Configuration File Management Source: https://github.com/tradeskillmaster/luacheck/blob/master/docsrc/cli.rst Options related to specifying and managing Luacheck configuration files. This includes setting custom config paths, disabling config file lookups, and defining default configuration locations. ```APIDOC --config Path to custom configuration file (default: ``.luacheckrc``). --no-config Do not look up custom configuration file. --default-config Default path to custom configuration file, to be used if ``--[no-]config`` is not used and ``.luacheckrc`` is not found. Default global location is: * ``%LOCALAPPDATA%\Luacheck\.luacheckrc`` on Windows; * ``~/Library/Application Support/Luacheck/.luacheckrc`` on OS X/macOS; * ``$XDG_CONFIG_HOME/luacheck/.luacheckrc`` or ``~/.config/luacheck/.luacheckrc`` on other systems. --no-default-config Do not use fallback configuration file. ``` -------------------------------- ### Luacheck Default Per-Path Standard Overrides Source: https://github.com/tradeskillmaster/luacheck/blob/master/docsrc/config.rst Lists Luacheck's default per-path overrides, which automatically apply specific standard configurations (like `+busted` or `+rockspec`) to files matching certain patterns. These can be overridden by user configurations. ```lua files["**/spec/**/*_spec.lua"].std = "+busted" files["**/test/**/*_spec.lua"].std = "+busted" files["**/tests/**/*_spec.lua"].std = "+busted" files["**/*.rockspec"].std = "+rockspec" files["**/*.luacheckrc"].std = "+luacheckrc" ``` -------------------------------- ### Luacheck Core CLI Options Source: https://github.com/tradeskillmaster/luacheck/blob/master/docsrc/cli.rst Provides essential command-line flags for controlling Luacheck's behavior, including parallel checking, output verbosity, and version information. The `--jobs` option requires LuaLanes for parallel execution. ```APIDOC Luacheck Core Options: -j | --jobs Check files in parallel. Requires LuaLanes. Default: number of available processing units. -q | --quiet Suppress report output for files without warnings. -qq: Suppress output of warnings. -qqq: Only output summary. --codes Show warning codes. --ranges Show ranges of columns related to warnings. --no-color Do not colorize output. -v | --version Show version of Luacheck and its dependencies and exit. -h | --help Show help and exit. ``` -------------------------------- ### Luacheck Custom Standard Sets and Aliases Source: https://github.com/tradeskillmaster/luacheck/blob/master/docsrc/config.rst Shows how to define custom standard sets by mutating the global `stds` variable and assigning them to the `std` configuration option in Luacheck. This allows for custom configurations to be reused. ```lua stds.some_lib = {...} std = "min+some_lib" ``` -------------------------------- ### Luacheck Complexity and Filtering Options Source: https://github.com/tradeskillmaster/luacheck/blob/master/docsrc/cli.rst Controls for setting limits on cyclomatic complexity and for filtering warnings based on patterns. These options allow fine-tuning the analysis to focus on specific code quality aspects or ignore certain types of issues. ```APIDOC --max-cyclomatic-complexity Set maximum cyclomatic complexity for functions. --no-max-cyclomatic-complexity Do not limit function cyclomatic complexity (default). --ignore | -i [] ... Filter out warnings matching patterns. --enable | -e [] ... Do not filter out warnings matching patterns. --only | -o [] ... Filter out warnings not matching patterns. ``` -------------------------------- ### Luacheck Configuration with Field Definitions Source: https://github.com/tradeskillmaster/luacheck/blob/master/docsrc/config.rst Illustrates how configuration options like `globals`, `new_globals`, `read_globals`, and `new_read_globals` can accept detailed field definitions, including `read_only` and `other_fields` properties. ```lua read_globals = { server = { fields = { -- Allow mutating `server.sessions` with any keys... sessions = {read_only = false, other_fields = true}, -- other fields... } }, --- other globals... } ``` -------------------------------- ### Luacheck API Functions Source: https://github.com/tradeskillmaster/luacheck/blob/master/docsrc/module.rst Provides an overview of the core functions available in the luacheck module for analyzing Lua code, processing reports, and retrieving messages. ```APIDOC Luacheck Module API: Import: local luacheck = require "luacheck" Functions: luacheck.get_report(source) - Given source string, returns analysis data (a table). - Parameters: - source: The Lua source code as a string. - Returns: Analysis data table. luacheck.process_reports(reports, options) - Processes an array of analysis reports and applies options. Options override each other in order: options, options[i], options[i][1], etc. - Analysis reports with a 'fatal' field are ignored. - Parameters: - reports: An array of analysis reports. - options: A table with fields similar to config options. - Returns: Final report table. luacheck.check_strings(sources, options) - Checks an array of sources using options and returns the final report. - Tables with a 'fatal' field within the 'sources' array are ignored. - Parameters: - sources: An array of Lua source code strings. - options: A table with configuration options. - Returns: Final report table. luacheck.check_files(files, options) - Checks an array of files using options and returns the final report. - Open file handles can be passed instead of filenames; they will be read till EOF and closed. - Parameters: - files: An array of filenames or file handles. - options: A table with configuration options. - Returns: Final report table. luacheck.get_message(issue) - Returns a string message for a given issue. - Parameters: - issue: An issue table (from a report). - Returns: A formatted message string. luacheck() - Equivalent to calling luacheck.check_files(). - Parameters: (same as check_files) - Returns: (same as check_files) ``` -------------------------------- ### Luacheck Inline Options: Push and Pop Directives Source: https://github.com/tradeskillmaster/luacheck/blob/master/docsrc/inline.rst Illustrates the use of 'luacheck: push' and 'luacheck: pop' directives for fine-grained control over inline option visibility in Lua. These commands temporarily apply or revert configuration changes. ```lua -- luacheck: push ignore foo foo() -- No warning. -- luacheck: pop foo() -- Warning is emitted. ``` -------------------------------- ### Luacheck Filtering and Pattern Matching Source: https://github.com/tradeskillmaster/luacheck/blob/master/docsrc/cli.rst Enables filtering of warnings using pattern matching on warning codes, variable names, or both. Patterns can be anchored or unanchored, with specific rules for matching codes versus variable names. ```APIDOC Luacheck Filtering Options: --ignore Ignore warnings matching the specified pattern. --enable Enable warnings matching the specified pattern. --only Only report warnings matching the specified pattern. Pattern Matching Rules: - If pattern contains '/', the part before '/' matches warning code, and the part after matches variable name. - If pattern contains a letter or underscore, it matches variable name. - Otherwise, it matches warning code. - Unanchored variable name patterns are anchored at both sides. - Unanchored warning code patterns are anchored at their beginnings. Example Patterns: 4.2: Matches warning code 4.2. .*_: Matches variables with '_' suffix. 4.2/.*_: Matches shadowing warnings for variables with '_' suffix. ``` -------------------------------- ### Luacheck File Filtering and Caching Source: https://github.com/tradeskillmaster/luacheck/blob/master/docsrc/cli.rst Options for controlling which files Luacheck analyzes and for managing its caching mechanism. These settings allow users to include or exclude specific files or directories and to leverage caching for faster analysis. ```APIDOC --filename Use another filename in output, for selecting configuration overrides and for file filtering. --exclude-files [] ... Do not check files matching these globbing patterns. Recursive globs such as ``**/*.lua`` are supported. --include-files [] ... Do not check files not matching these globbing patterns. --cache [] Path to cache file. (default: ``.luacheckcache``). See :ref:`cache`. --no-cache Do not use cache. ``` -------------------------------- ### Luacheck Basic Global Definition Source: https://github.com/tradeskillmaster/luacheck/blob/master/docsrc/config.rst Defines basic global variables and read-only global variables for Luacheck configuration. Specifies which globals can be set and accessed, and which can only be accessed. ```lua std = { globals = {"foo", "bar"}, -- these globals can be set and accessed. read_globals = {"baz", "quux"} -- these globals can only be accessed. } ``` -------------------------------- ### Luacheck Caching Mechanism Source: https://github.com/tradeskillmaster/luacheck/blob/master/docsrc/cli.rst Supports caching of file checking results when LuaFileSystem is available. This significantly improves runtime by rechecking only changed files. Caching is enabled via the `--cache` option. ```APIDOC Luacheck Caching Option: --cache Enable caching of checking results. If is omitted or set to 'true', '.luacheckcache' is used. Note: --cache must be used every time Luacheck is run to benefit from caching. ``` -------------------------------- ### Luacheck Per-File Configuration Overrides Source: https://github.com/tradeskillmaster/luacheck/blob/master/docsrc/config.rst Configures Luacheck to apply specific settings (like enabling/ignoring checks) to files matching certain glob patterns. This allows for fine-grained control over analysis based on file paths. ```lua std = "min" ignore = {"212"} files["src/dir"] = {enable = {"212"}} files["src/dir/**/*_special.lua"] = {ignore = {"212"}} ``` -------------------------------- ### Luacheck Global and Field Definitions Source: https://github.com/tradeskillmaster/luacheck/blob/master/docsrc/cli.rst Allows defining allowed global variables and fields, including read-only globals. Options like `--globals` and `--not-globals` manage these definitions, affecting how Luacheck analyzes variable access. ```APIDOC Luacheck Global/Field Definition Options: --globals [,...] Add new allowed globals. --new-globals [,...] Add new allowed globals that must be defined before use. --read-globals [,...] Add new allowed read-only globals. --new-read-globals [,...] Add new allowed read-only globals that must be defined before use. --not-globals [,...] Remove definitions of standard and custom globals/fields. Example: --read-globals foo --globals foo.bar Allows accessing 'foo' global and mutating its 'bar' field. ``` -------------------------------- ### Luacheck Global Variable Management Source: https://github.com/tradeskillmaster/luacheck/blob/master/docsrc/cli.rst Options for managing custom global variables and fields within Luacheck's analysis. These commands allow users to explicitly define, add, or remove globals, influencing how the linter checks for undefined variables. ```APIDOC --globals [] ... Add custom global variables or fields on top of standard ones. See :ref:`fields`. --read-globals [] ... Add read-only global variables or fields. --new-globals [] ... Set custom global variables or fields. Removes custom globals added previously. --new-read-globals [] ... Set read-only global variables or fields. Removes read-only globals added previously. --not-globals [] ... Remove custom and standard global variables or fields. ``` -------------------------------- ### Shadowing Declarations (Redefining Locals) Source: https://github.com/tradeskillmaster/luacheck/blob/master/docsrc/warnings.rst Shows how Luacheck detects local variable declarations that shadow previous declarations in the same scope, unless the variable is named '_'. It highlights the difference between redefining a local variable and reassigning it. ```lua local function f(x) local x = x or "default" -- bad end local function f(x) x = x or "default" -- good end ``` -------------------------------- ### Report Format Details Source: https://github.com/tradeskillmaster/luacheck/blob/master/docsrc/module.rst Details the structure of the final report, file reports, and individual issues, including specific fields for different error types. ```APIDOC Report Structure: Final Report: - An array of file reports. - Additional fields: 'warnings', 'errors', 'fatals' (total counts). File Report: - An array of issues (warnings or errors). - If a fatal error occurred: 'fatal' field (error type) and 'msg' field (error message). Issue (Warning/Error): - 'code': Indicates the type of issue (see :doc:`warnings`). - 'line': Line number of the issue. - 'column': Column number of the issue. - 'end_column': End column number of the issue. - 'name': (Optional) Name of the related variable. Issue-Specific Fields: - Code 011 (Syntax Error): - 'msg': Syntax error message. - 'prev_line', 'prev_column', 'prev_end_column': Location of an extra relevant part, e.g., opening bracket. - Code 111 (Non-module global assignment): - 'msg': Message indicating assignment to a non-module global variable. - Codes 122, 142, 143 (Global field accessed via alias): - 'indirect': Indicates global field accessed using a local alias. - 'field': String representation of the related global field. - Code 211 (Unused variable/function): - 'func': Indicates the unused variable is a function. - 'recursive': Indicates the unused function is recursive. - 'mutually_recursive': Set for unused mutually recursive functions. - Code 314 (Unused field/index): - 'field': String representation of the unused field or index. - Codes 4.. (Overwritten definition): - 'prev_line', 'prev_column', 'prev_end_column': Location of the overwritten definition. - Code 521 (Label): - 'label': Label name. - Code 631 (Line ending): - 'line_ending': 'comment' or 'string' if line ending is within a comment or string. - 'max_length': Maximum allowed line length. ``` -------------------------------- ### Unbalanced Assignments Source: https://github.com/tradeskillmaster/luacheck/blob/master/docsrc/warnings.rst Highlights unbalanced assignments where the number of left-hand side variables differs from the number of right-hand side values. An exception is made for initializing multiple locals to nil. ```lua local a, b, c = nil -- Effectively sets `a`, `b`, and `c` to nil, no warning. ``` -------------------------------- ### Empty Blocks and Statements Source: https://github.com/tradeskillmaster/luacheck/blob/master/docsrc/warnings.rst Luacheck warns about empty `do...end` blocks and empty branches in `if` statements. It also flags semicolons in Lua 5.2+ as empty statements. -------------------------------- ### Unused Values and Uninitialized Variables Source: https://github.com/tradeskillmaster/luacheck/blob/master/docsrc/warnings.rst Demonstrates unused local variables and uninitialized variables. Luacheck warns when a value assigned to a local variable cannot be used anywhere or when accessing uninitialized variables. ```lua local foo = expr1() local bar if condition() then foo = expr2() bar = expr3() else foo = expr4() print(bar) end return foo, bar ``` -------------------------------- ### Secondary Values and Variables Source: https://github.com/tradeskillmaster/luacheck/blob/master/docsrc/warnings.rst Illustrates secondary values and variables, where a value assigned to a local variable is secondary if its origin is the last item on the RHS of an assignment and another value from that item is used. Luacheck can be configured to ignore warnings for these. ```lua local a, b, c = f(), g() return c ``` -------------------------------- ### luacheck Exit Codes Source: https://github.com/tradeskillmaster/luacheck/blob/master/docsrc/cli.rst Explains the meaning of different exit codes returned by luacheck, indicating the success or failure status of the analysis. ```APIDOC luacheck returns specific exit codes: - ``0``: No warnings or errors occurred. - ``1``: Some warnings occurred, but no syntax errors or invalid inline options. - ``2``: Some syntax errors or invalid inline options were found. - ``3``: Some files could not be checked (e.g., incorrect file name). - ``4``: A critical error occurred (e.g., invalid CLI arguments, configuration, or cache file). ``` -------------------------------- ### MIT License Source: https://github.com/tradeskillmaster/luacheck/blob/master/README.md The software is provided under the MIT License, granting broad permissions for use, modification, and distribution. ```text The MIT License (MIT) Copyright (c) 2014 - 2018 Peter Melnichenko Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ``` -------------------------------- ### Luacheck Read-Only and Other Fields Configuration Source: https://github.com/tradeskillmaster/luacheck/blob/master/docsrc/config.rst Configures global fields with `read_only` and `other_fields` properties in Luacheck. Controls mutability and the ability to contain unspecified fields for global variables and their members. ```lua std = { read_globals = { foo = { -- `foo` and its fields are read-only by default (because they are within `read_globals` table). fields = { bar = { read_only = false, -- `foo.bar` is not read-only, can be set. other_fields = true, -- `foo.bar[anything]` is defined and can be set or mutated (inherited from `foo.bar`). fields = { baz = {read_only = true}, -- `foo.bar.baz` is read-only as an exception. } } } } } } ``` -------------------------------- ### Whitespace Issues Source: https://github.com/tradeskillmaster/luacheck/blob/master/docsrc/warnings.rst Luacheck identifies trailing whitespace and inconsistent indentation, such as spaces followed by tabs. ```lua -- Whitespace example. print("Hello") print("World") ``` -------------------------------- ### Luacheck Nested Global Field Definition Source: https://github.com/tradeskillmaster/luacheck/blob/master/docsrc/config.rst Demonstrates defining nested fields within read-only globals in Luacheck configuration. Allows specifying read-only status and nested structures for global variables. ```lua std = { read_globals = { foo = { -- Defining read-only global `foo`... fields = { field1 = { -- `foo.field1` is now defined... fields = { nested_field = {} -- `foo.field1.nested_field` is now defined... } }, field2 = {} -- `foo.field2` is defined. } } } } ``` -------------------------------- ### Reversed Numeric For Loops Source: https://github.com/tradeskillmaster/luacheck/blob/master/docsrc/warnings.rst Warns about numeric for loops iterating downwards (e.g., from #t to 1) when the step is not negative, which is a common mistake when iterating in reverse. ```lua -- Warning for this loop: -- numeric for loop goes from #(expr) down to 1 but loop step is not negative for i = #t, 1 do print(t[i]) end -- This loop is okay. for i = #t, 1, -1 do print(t[i]) end ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.