MyNixOS website logo
Description

Attempts to fix your syntax erroring Lua files.

Linter for Lua, specifically the variant used in Garry's mod.

glualint

glualint - Linter and pretty printer for Garry's Mod's variant of Lua.

Installing

  1. Download the latest version of glualint from the releases page OR compile it yourself. If you download for Linux, make sure to run the right version. Most computers will need the x86_64 version. Embedded systems like a Raspberry pi will need the aarch64-linux version.
  2. Place the glualint executable inside some folder.
  3. Add the folder you put glualint in to your PATH. How this is done differs per operating system. If you're not sure how to do this, please Google "Add to path <YOUR OS>".
  4. Make sure you restart any terminals or text editors you currently have open.

After performing these steps, you can run glualint from the terminal or let your text editor use it as your linter. Failing to specifically perform the third step will make glualint very unlikely to work.

Command line parameters

ParameterDescription
--versionReturns the version of glualint.
--configSet to a glualint.json file for glualint configuration. See "Configuring glualint".
--pretty-printWill pretty-print (re-structure/re-indent) all code given in stdin. When entering code in terminal, press Ctrl+D to finish the input.
--pretty-print-filesAs above but pretty-prints the specified file or directory instead of stdin.
--indentation='something'For pretty-print: indents all pretty-printed code with the given string. Four spaces by default, should probably some amount of tabs or spaces.
--stdinProcess stdin instead of specified file or directory when linting.
--analyse-globalsShow global variables/functions that this file defines.
--testFor debugging: test whether glualint works correctly on the given files and/or folders. Tries to parse with the two available parsers, then pretty prints and tries to parse the pretty printed result. It will show errors when it fails.

Configuring glualint

glualint Allows some configuration. This is done through a file called glualint.json or .glualint.json. glualint looks for this file in three places (in order of priority)

  • The file you give to the --config parameter (when using the terminal)
  • Any folder above the file you're working in (e.g. the root of your project)
  • Your home folder, which is C:\users\yourusername\.glualint.json on Windows or /home/yourusername/.glualint.json on Unix.

Note: The file must either be called glualint.json or .glualint.json.

Example glualint.json with the default options:

{
    "lint_maxScopeDepth": 7,
    "lint_syntaxErrors": true,
    "lint_syntaxInconsistencies": true,
    "lint_deprecated": true,
    "lint_trailingWhitespace": true,
    "lint_whitespaceStyle": true,
    "lint_beginnerMistakes": true,
    "lint_emptyBlocks": true,
    "lint_shadowing": true,
    "lint_gotos": true,
    "lint_goto_identifier": true,
    "lint_doubleNegations": true,
    "lint_redundantIfStatements": true,
    "lint_redundantParentheses": true,
    "lint_duplicateTableKeys": true,
    "lint_profanity": true,
    "lint_unusedVars": true,
    "lint_unusedParameters": false,
    "lint_unusedLoopVars": false,
    "lint_inconsistentVariableStyle": false,
    "lint_spaceBetweenParens": false,
    "lint_spaceBetweenBrackets": false,
    "lint_spaceBetweenBraces": false,
    "lint_ignoreFiles": [],
    "lint_spaceBeforeComma": false,
    "lint_spaceAfterComma": false,
    "lint_maxLineLength": 0,

    "prettyprint_spaceBetweenParens": false,
    "prettyprint_spaceBetweenBrackets": false,
    "prettyprint_spaceBetweenBraces": false,
    "prettyprint_spaceEmptyParens": false,
    "prettyprint_spaceEmptyBraces": false,
    "prettyprint_spaceAfterLabel": false,
    "prettyprint_spaceBeforeComma": false,
    "prettyprint_spaceAfterComma": true,
    "prettyprint_semicolons": false,
    "prettyprint_cStyle": false,
    "prettyprint_removeRedundantParens": true,
    "prettyprint_minimizeParens": false,
    "prettyprint_assumeOperatorAssociativity": true,
    "prettyprint_indentation": "    ",

    "log_format": "auto"
}

All options explained

Linter options

OptionDescription
lint_maxScopeDepthMaximum depth of scopes in your code. Any terrible scripter can build the most atrocious sideways code pyramids, usually without knowing. The number here is at which step the linter will start calling you out on it. Set to 0 if you're king Tut and want to disable it.
lint_syntaxErrorsWhether syntax errors should be reported. This is off by default because gluac shows nicer syntax errors.
lint_syntaxInconsistenciesWarn for syntax inconsistencies (using both && and and, that kind of stuff)
lint_deprecatedWarn for deprecated functions. These functions are taken from the GMod wiki, don't blame me for the things that are on there.
lint_trailingWhitespaceWarn for whitespace at the end of a line. Your editor should have an option to automatically trim trailing whitespace.
lint_whitespaceStyleWarn for bad whitespace behaviour (e.g. lack of spaces around operators and keywords)
lint_beginnerMistakesWarn for typical beginner mistakes (using self in non-metafunction, net.WriteEntity(LocalPlayer()) in a net message, using self.Weapon in a SWEP etc.)
lint_emptyBlocksWarn for empty blocks
lint_shadowingWarn for variable shadowing
lint_gotosWarn for inappropriate gotos (i.e. the ones not used to jump out of a double loop)
lint_goto_identifierWarn when goto is used as an identifier (e.g. a = {goto = 1}). This warning exists because goto being allowed as identifier is actually a bug. You should not be able to use goto like that for the same reason you're not allowed to use any other keyword as identifier.
lint_doubleNegationsWarn for double negations (things like not (a == b))
lint_redundantIfStatementsWarn for nested if-statements that can be combined with and
lint_redundantParenthesesWarn for unneeded parentheses around expressions.
lint_duplicateTableKeysWarn for duplicate table keys (e.g. {a = 1, a = 2})
lint_profanityWarn for profanity (bitch, cock, cocks, cunt, dick, dicks, fuck, fucking, goddamnit, knob, knobs, motherfucker, nipple, shit)
lint_unusedVarsWarn for variables that are never used
lint_unusedParametersWarn for function parameters that are never used. NOTE: Only has effect when lint_unusedVars is enabled!
lint_unusedLoopVarsWarn for loop variables that are never used (for k,v in ...). NOTE: Only has effect when lint_unusedVars is enabled!
lint_ignoreFilesFiles to ignore when linting. You can use glob patterns (e.g. "**.lua", "*.lua" or libraries/*.lua)
lint_inconsistentVariableStyleWhether to warn about inconsistent styles in naming local variables (e.g. lowercase and uppercase variables)
lint_spaceBetweenParensWhether to warn about there being spaces between parentheses. This option used to be named lint_spaceAfterParens. For backwards compatibility that option still works.
lint_spaceBetweenBracketsWhether to warn about there being spaces between brackets. This option used to be named lint_spaceAfterBrackets. For backwards compatibility that option still works.
lint_spaceBetweenBracesWhether to warn about there being spaces between braces. This option used to be named lint_spaceAfterBraces. For backwards compatibility that option still works.
lint_spaceBeforeCommaWhether to warn about spaces before the comma. This option depends on prettyprint_spaceBeforeComma on whether the space is wanted.
lint_spaceAfterCommaWhether to warn about spaces after the comma. This option depends on prettyprint_spaceAfterComma on whether the space is wanted.
lint_maxLineLengthWarn for lines longer than the given number. Set to 0 to disable.

Pretty print options

These options affect the pretty printing functionality of glualint.

OptionDescription
prettyprint_spaceBetweenParensPut a space between all parentheses
prettyprint_spaceBetweenBracketsPut a space between all brackets
prettyprint_spaceBetweenBracesPut a space between all curly braces
prettyprint_spaceEmptyParensPut a space between empty parentheses (e.g. ( )). Only applies when prettyprint_spaceBetweenParens is set
prettyprint_spaceEmptyBracesPut a space between empty braces (e.g. { }). Only applies when prettyprint_spaceBetweenBraces is set
prettyprint_spaceAfterLabelPut a space after a ::label:: statement
prettyprint_semicolonsClutter the script with semicolons after every damn statement
prettyprint_cStyleUse C style operators and comments everywhere
prettyprint_indentationWhat to use for indentation. Any string is valid, but some amount of spaces or "\t" is recommended
prettyprint_spaceBeforeCommaWhether to place a space before every comma
prettyprint_spaceAfterCommaWhether to place a space after every comma
prettyprint_removeRedundantParensWhether to remove unnecessary parentheses (e.g. x = (1 + 2), if ((1) + (2) == 3) then)
prettyprint_minimizeParensRemoves parentheses which are unnecessary due to operator precedence (e.g. (1 * 2) + 3). This option also removes redundant parameters, regardless of whether prettyprint_removeRedundantParens is enabled.
prettyprint_assumeOperatorAssociativityOnly takes effect when prettyprint_minimizeParens is true. It decides whether parameters can be removed when the involved operators are assumed associative. Examples: a * (b * c), a and (b and c). This assumption is generally true, except for floating point numbers, where removing parentheses can actually change the outcome of the calculation. See Stack Overflow. This option is set to true by default, because the expectation is that this will not be problematic even if it affects your code. In a very rare case, this might cause trouble, though. You might want to consider turning this off if you have floating point code that heavily relies on evaluation order. You may also choose to leave this option on and ensure evaluation order by explicitly setting variables.

Other options

  • log_format: Decides how to format linter warnings and error messages. Possible values are "auto", "standard" and "github". The "github" output format is specifically designed for usage with GitHub actions. The default value is "auto", With "auto", the log format will be "github" when the environment variables GITHUB_ACTIONS and GITHUB_WORKFLOW are both present, and "standard" otherwise.

In-code directives

If you add a comment containing the text format: multiline, the next statement will be forced to be pretty printed as multiline. Example:

-- format: multiline
a = {1, 2, 3}

Will be turned into:

-- format: multiline
a = {
  1,
  2,
  3
}

Editor Plugins

Through community support, GLuaFixer is supported across a wide variety of popular editors.

Here's a list of plugins we recommend (PRs for more tools welcome!):

Sublime

Atom

VS Code

Vim

Reusable Workflow

You can easily run GLuaFixer in your own Workflows using the included Reusable Workflow.

Setup

To run GLuaFixer on all of your PRs, create a new file in your repository: .github/workflows/glualint.yml with the following contents:

name: GLuaFixer

on:
  pull_request:

jobs:
  Lint:
    uses: FPtje/GLuaFixer/.github/workflows/glualint.yml@master

Now, every time you make or update a PR, GLuaFixer will run and report any linting violations right on your PR!

Configuration

The GLuaFixer Workflow can be configured, too.

You have two options for configuration:

  • Include a file in your repository containing the GLuaFixer config
  • Upload your GLuaFixer config somewhere (gist.github.com, pastebin/hastebin, etc.)

Then, modify your Workflow like so:

name: GLuaLint

on:
  pull_request:

jobs:
  Lint:
    uses: FPtje/GLuaFixer/.github/workflows/glualint.yml@master
    with:
      config: "<link or relative path to config file>"
Metadata

Version

1.29.0

Platforms (75)

    Darwin
    FreeBSD
    Genode
    GHCJS
    Linux
    MMIXware
    NetBSD
    none
    OpenBSD
    Redox
    Solaris
    WASI
    Windows
Show all
  • aarch64-darwin
  • aarch64-genode
  • aarch64-linux
  • aarch64-netbsd
  • aarch64-none
  • aarch64_be-none
  • arm-none
  • armv5tel-linux
  • armv6l-linux
  • armv6l-netbsd
  • armv6l-none
  • armv7a-darwin
  • armv7a-linux
  • armv7a-netbsd
  • armv7l-linux
  • armv7l-netbsd
  • avr-none
  • i686-cygwin
  • i686-darwin
  • i686-freebsd
  • i686-genode
  • i686-linux
  • i686-netbsd
  • i686-none
  • i686-openbsd
  • i686-windows
  • javascript-ghcjs
  • loongarch64-linux
  • m68k-linux
  • m68k-netbsd
  • m68k-none
  • microblaze-linux
  • microblaze-none
  • microblazeel-linux
  • microblazeel-none
  • mips-linux
  • mips-none
  • mips64-linux
  • mips64-none
  • mips64el-linux
  • mipsel-linux
  • mipsel-netbsd
  • mmix-mmixware
  • msp430-none
  • or1k-none
  • powerpc-netbsd
  • powerpc-none
  • powerpc64-linux
  • powerpc64le-linux
  • powerpcle-none
  • riscv32-linux
  • riscv32-netbsd
  • riscv32-none
  • riscv64-linux
  • riscv64-netbsd
  • riscv64-none
  • rx-none
  • s390-linux
  • s390-none
  • s390x-linux
  • s390x-none
  • vc4-none
  • wasm32-wasi
  • wasm64-wasi
  • x86_64-cygwin
  • x86_64-darwin
  • x86_64-freebsd
  • x86_64-genode
  • x86_64-linux
  • x86_64-netbsd
  • x86_64-none
  • x86_64-openbsd
  • x86_64-redox
  • x86_64-solaris
  • x86_64-windows