Diagnostics can report possible issues at different severities such as Information, Warning, Error, etc. Also see syntax errors.

Below is a list of all diagnostics. They are organized into groups that are used by diagnostics.groupFileStatus and diagnostics.groupSeverity. The default severity is shown, but these can be edited using diagnostics.groupSeverity and diagnostics.severity. Some also list their default value for diagnostics.neededFileStatus

ambiguity

The ambiguity diagnostic group contains diagnostics that have to do with ambiguous cases.

ambiguity-1

Triggered when there is an ambiguous statement that may need some brackets in order to correct the order of operations.

ambiguity-1

count-down-loop

Triggers when a for loop will never reach its max/limit because it is incrementing when it should be decrementing.

Lua
for i=10, 1 do end

different-requires

Triggered when a file is required under two different names. This can happen when requiring a file in two different directories:

plaintext
📦 myProject/
    ├── 📂 helpers/
    │   ├── 📜 strings.lua
    │   └── 📜 pretty.lua
    └── 📜 main.lua
Lua
-- main.lua
local strings = require("helpers.strings")
local pretty = require("helpers.pretty")
Lua
-- helpers/pretty.lua
local strings = require("strings")

newfield-call

Triggered when calling a function across two lines from within a table. This may be unwanted and you may want to separate the fields with a comma (,) or semicolon (;) - unless you want to call the first field as a function.

Lua
local myTable = {
  myFunc
  ("param")
}

newline-call

Triggered when calling a function from the next line. This may be unintended and you may want to add a semicolon ; to end the line.

Lua
print(1)
('x'):sub(1, 2)

await

The await group contains diagnostics for asynchronous code.

await-in-sync

Default File Status: "None"

Triggered when calling an asynchronous function from within a synchronous function.

not-yieldable

Default File Status: "None"

Triggered when attempting to call coroutine.yield() when it is not permitted.

codestyle

The codestyle group contains diagnostics for maintaining a good code style.

codestyle-check

Default File Status: "None"

Triggered when the opinionated style checking detects an incorrectly styled line.

name-style-check

Default File Status: "None"

Triggered when the opinionated style checking detects an incorrectly named element.

spell-check

Default File Status: "None"

Triggered when a typo is detected in a string. The dictionary can be customized using the Lua.spell.dict setting .

conventions

The conventions group contains diagnostics for maintaining potentially subjective code conventions.

global-element

Default File Status: "None"

Triggered when an element is not declared local to avoid accidentally global elements.

duplicate

The duplicate group contains diagnostics for duplicate indexes and names.

duplicate-index

Triggered when there are duplicate indices.

Lua
local t = {
    -- triggered by indexes
    [1] = "a",
    [1] = "b",

    -- triggered by keys as well
    two = "c",
    two = "d"
}

duplicate-set-field

Triggered when setting the same field in a class more than once. Check the names of your fields.

Lua
---@class myClass
local myTable = {}

function myTable:x() end

function myTable:x() end

global

The global group contains diagnostics that deal with the global scope.

global-in-nil-env

Triggered when a global variable is defined and the environment (_ENV) is nil.

Lua
_ENV = nil

myGlobalVar = true

lowercase-global

Triggered when a global variable starts with a lowercase character. This is mainly for maintaining good practice.

undefined-env-child

Triggered when the environment (_ENV) is mutated and a previously global variable is no longer usable.

Lua
local A
---@type iolib
_ENV = {}
print(A)

undefined-global

Triggered when referencing an undefined global (assumed to be global). The typical "does not exist" warning. Double check that you have spelled things correctly and that the variable exists.

luadoc

The luadoc group contains diagnostics for the annotations used to document your code.

cast-type-mismatch

Triggered when casting a variable to a type that does not match its initial type.

Lua
---@type boolean
local e = nil

---@cast e integer

circle-doc-class

Triggered when two classes inherit each other forming a never ending loop of inheritance.

Lua
---@class Car:Vehicle

---@class Vehicle:Car

doc-field-no-class

Triggered when a @field is specified for a non-existent @class.

duplicate-doc-alias

Triggered when there are two @alias annotations with matching names.

duplicate-doc-field

Triggered when there are two @field annotations with matching key values.

duplicate-doc-param

Triggered when there are two @param annotations with matching names.

incomplete-signature-doc

Default File Status: "None"

Triggered when a functions signature is partially documented with annotations, but the annotations do not cover every element of the signature. E.g. one of the parameters is not annotated, or the return value is not annotated.

missing-global-doc

Default File Status: "None"

Triggered when a global function is not documented with annotations, but has parameters (requiring @param annotations) or a return value (requiring @return annotations). This ensures that functions are annotated when they are accessible outside of the current module.

missing-local-export-doc

Default File Status: "None"

Triggered when a local function is exported by adding it to the modules' return value, but the functions signature is not documented with annotations. This ensures that functions are annotated when they are accessible outside of the current module.

undefined-doc-class

Triggered when referencing an undefined class in a @class annotation.

undefined-doc-name

Triggered when referencing an undefined type or @alias in a @type annotation.

undefined-doc-param

Triggered when referencing an undefined parameter from a function declartion.

Lua
---@param doesNotExist number
function subtract(a, b) end

unknown-cast-variable

Triggered when attempting to cast an undefined variable. Double check that you have spelled things correctly and that the variable exists. Appears when using @cast.

unknown-diag-code

Triggered when entering an invalid diagnostic code. A diagnostic code is like one of the many diagnosis codes found on this page.

Lua
---@diagnostic disable: doesNotExist

unknown-operator

Triggered when an unknown operator is found like **.

redefined

The redefined group contains diagnostics that warn when variables are being redefined.

redefined-local

Triggered when a local variable is being redefined. This will result in the redefinition being underlined. While still legal, it could cause confusion when trying to use the previously defined version of the local variable that may have since been mutated. It is good practice not to re-use local variable names for this reason.

strict

The strict group contains diagnostics considered "strict". These can help you write better code but may require more work to follow.

close-non-object

Triggered when attempting to close a variable with a non-object. The value of the variable must be an object with the __close metamethod (a Lua 5.4 feature).

Lua
local x <close> = 1

deprecated

Triggered when a variable has been marked as deprecated yet is still being used. The variable in question will also be struck through.

discard-returns

Triggered when the returns of a function are being ignored when it is not permitted. Functions can specify that their returns cannot be ignored with @nodiscard.

strong

The strong group contains diagnostics considered "strong". These can help you write better code but may require more work to follow.

no-unknown

Default File Status: "None"

Triggered when a variable has an unknown type that cannot be inferred. Useful for more strict typing.

type-check

The type-check group contains diagnostics that have to do with type checking.

assign-type-mismatch

Triggered when assigning a value, in which its type does not match the type of the variable it is being assigned to.

The below will trigger this diagnostic because we are assigning a boolean to a number:

Lua
---@type number
local isNum = false

cast-local-type

Triggered when a local variable is being cast to a different value than it was defined as.

Lua
---@type boolean
local myBool

myBool = {}

cast-type-mismatch

Triggered when casting a variable to a type that does not match its initial type.

Lua
---@type boolean
local e = nil

---@cast e integer

inject-field

Triggered when injecting an undefined field into a class instance. This can be solved by adding the @field to the class or by using @class directly on the instance.

Lua
---@class Car
---@field topSpeed number
---@field seats integer

---@type Car
local myCar = { topSpeed = 180, seats = 5 }

-- wheels was not defined in the Car class
-- because myCar was marked an instance of Car outside the definition of the Car class, its fields are strictly enforced
myCar.wheels = 6

need-check-nil

Triggered when indexing a possibly nil object. Serves as a reminder to confirm the object is not nil before indexing - which would throw an error on execution.

Lua
---@class Bicycle
---@field move function

---@type Bicycle|nil
local bicycle

-- need to make sure bicycle isn't nil first
bicycle.move()

param-type-mismatch

Triggered when the type of the provided parameter does not match the type requested by the function definition. Uses information defined with @param.

return-type-mismatch

Triggered when the provided return value is not of the same type that the function expected.

Lua
---@return number sum
function add(a, b)
    return false
end

undefined-field

Triggered when referencing an undefined field.

Lua
---@class myClass
local myClass = {}

-- undefined field "hello"
myClass.hello()

unbalanced

The unbalanced group contains diagnostics that deal with too few or too many of an item being given - like too few required parameters.

missing-fields

Triggered when an instance of a class is missing a required @field.

missing-parameter

Triggered when a required parameter is not supplied when calling a function. Uses information defined with @param.

missing-return

Triggered when a required return is not supplied from within a function. Uses information defined with @return.

missing-return-value

Triggered when a return is specified but the return value is not. Uses information defined with @return.

redundant-parameter

Triggered when providing an extra parameter that a function does not ask for. Uses information defined with @param.

redundant-return-value

Triggered when a return is returning an extra value that the function has not requested. Uses information defined with @return.

redundant-value

Triggered when providing an extra value to an assignment operation that will go unused.

Lua
local a, b = 1, 2, 3

unbalanced-assignments

Triggered when there are more variables being assigned than values to assign them.

Lua
local a, b, c = 1, 2

unused

The unused group contains diagnostics that report unused or unnecessary items.

code-after-break

Triggered when unreachable code is added after a break in a loop. This will result in the affected code becoming slightly transparent.

empty-block

Triggered when a code block is left empty. This will result in the code block becoming slightly transparent.

redundant-return

Triggered when placing a return that is not needed as the function would exit on its own.

trailing-space

Triggered when a trailing space is detected. This will result in the trailing space being underlined.

unreachable-code

Triggered when a section of code can never be reached. This will result in the affected code becoming slightly transparent.

unused-function

Triggered when a function is defined but never called. This results in the function becoming slightly transparent.

unused-label

Triggered when a label is defined but never used. This results in the label becoming slightly transparent.

unused-local

Triggered when a local variable is defined but never referenced. This results in the variable becoming slightly transparent.

unused-varag

Triggered when the variable arguments symbol (...) in a function is unused. This results in the symbol becoming slightly transparent.

Last Modified: