Skip to main content

Overview

Diagnostics appear as squiggly underlines in the editor and in the Problems panel (Ctrl+Shift+M). Each diagnostic has a severity level and a code identifier you can use for configuration.

Severity levels

SeverityAppearanceWhen to use
errorRed underlineHard errors that will likely break your code
warningYellow underlineProbable bugs or type mismatches
informationBlue underlineStylistic or best-practice suggestions
hintSubtle underlineMinor suggestions, safe to ignore

Configuring diagnostic severity

Change the severity of any diagnostic code, or disable it:
Use the settings menu instead of editing the JSON file directly. This helps you avoid config mistakes.
.gluarc.json
{
  "diagnostics": {
    "severity": {
      "unused": "hint",
      "undefined-field": "information",
      "param-type-mismatch": "warning"
    },
    "disable": ["redundant-return-value"],
    "enables": ["missing-return", "return-type-mismatch"]
  }
}
Use the interactive settings panel to toggle diagnostics and change severity with checkboxes and dropdowns. You do not need to edit JSON.

Diagnostic reference

Type checking

CodeDefaultDescription
param-type-mismatchWarningArgument type doesn’t match the expected parameter type
missing-parameterWarningRequired parameter not provided
redundant-parameterInformationExtra argument passed beyond what the function accepts
assign-type-mismatchWarningAssigned value type doesn’t match the variable type
return-type-mismatchOffReturn type doesn’t match the declared return type
missing-return-valueWarningFunction declared to return a value but doesn’t in all paths
redundant-return-valueOffExtra return value beyond what the function declares
missing-returnOffFunction should return a value but doesn’t
cast-type-mismatchWarningCast type is incompatible with the actual type
need-check-nilHintValue may be nil; you should check before using it
unchecked-nil-accessWarningChained access or call through an opaque table member that may be nil
undefined-fieldWarningField doesn’t exist on the type
missing-fieldsWarningTable literal is missing required fields
undefined-globalErrorReferenced variable is not defined globally or locally
undefined-global-assignmentWarningUndefined global used as a function argument or assigned to a variable / table field (alias: undefined-global-argument)
type-not-foundWarningA referenced type name doesn’t exist
generic-constraint-mismatchInformationGeneric type argument violates a constraint
enum-value-mismatchWarningValue doesn’t match a known enum entry

Code quality

CodeDefaultDescription
unusedHintLocal variable or function is never used
unused-selfOffself parameter is never used in a method
unreachable-codeHintCode after a return or error() cannot execute
deprecatedHintUsing a deprecated function or field
duplicate-requireHintModule is require()d more than once in the same scope
redefined-localHintLocal variable shadows an outer local with the same name
redefined-labelWarningCode defines the same goto label more than once
duplicate-indexWarningTable literal has the same key more than once
duplicate-set-fieldOffCode assigns a field more than once
duplicate-typeOffCode declares the same type name in multiple places
unbalanced-assignmentsWarningLeft-hand and right-hand sides of an assignment have different counts
local-const-reassignErrorCode reassigns a <const> local
read-onlyWarningCode writes to a value declared as read-only

Documentation

CodeDefaultDescription
annotation-usage-errorErrorAnnotation has wrong syntax or appears in the wrong context
doc-syntax-errorErrorAnnotation comment has a syntax error
undefined-doc-paramWarningDocumentation names a parameter that the function does not have
duplicate-doc-fieldWarning@class documents the same field more than once
incomplete-signature-docOffFunction lacks parameter or return documentation
missing-global-docOffGlobal function or variable lacks documentation
unknown-doc-tagOffUnknown @tag in an annotation comment
inject-fieldOffCode adds a field to a type outside its class definition

Access control

CodeDefaultDescription
access-invisibleWarningAccessing a private or protected member outside its class
discard-returnsWarningCode ignores the return value from a @nodiscard function

GMod-specific

CodeDefaultDescription
gmod-realm-mismatchErrorCalling a realm-specific function from the wrong realm
gmod-realm-mismatch-heuristicErrorLikely realm mismatch based on inferred evidence
gmod-unknown-realmHintRealm could not be resolved for a realm-aware call
gmod-invalid-hook-nameWarningHook name does not match a recognized GMod hook
gmod-unknown-net-messageWarningnet.Start(name) uses an unregistered message name
gmod-net-missing-network-counterpartWarningnet.Start lacks a matching net.Receive in the expected opposite realm
gmod-net-read-write-order-mismatchWarningnet.Read* calls don’t match the order of net.Write* calls
gmod-net-read-write-type-mismatchWarningnet.Read* type doesn’t match the corresponding net.Write*
gmod-net-read-write-bits-mismatchWarningLiteral bit-width differs between a matched write/read pair
gmod-duplicate-system-registrationHintDuplicate registration (concommand, net, timer, etc.)

Suppressing individual diagnostics

Use ---@diagnostic annotations to suppress warnings for specific lines or blocks:
-- Suppress for the next line only
---@diagnostic disable-next-line: undefined-global
print(someExternalGlobal)

-- Suppress for the current line
print(x) ---@diagnostic disable-line: undefined-global

-- Suppress for an entire block
---@diagnostic disable: undefined-global
SOME_GLOBAL = "value"
ANOTHER_GLOBAL = 42
---@diagnostic enable: undefined-global
See the @diagnostic annotation reference for full details.

Global whitelist

Add globals that your code uses but GLuaLS does not know about, such as globals from a module loaded by another file:
Use the settings menu instead of editing the JSON file directly. This helps you avoid config mistakes.
.gluarc.json
{
  "diagnostics": {
    "globals": ["MyFramework", "PLUGIN_REGISTRY"],
    "globalsRegex": ["^LIB_.*"]
  }
}