-
-
Couldn't load subscription status.
- Fork 384
Diagnostics
⚠️ WarningThis wiki has been replaced by the wiki on our website. This wiki will be removed in the future.
There are many different diagnostics that can be used to report information 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 ambiguity diagnostic group contains diagnostics that have to do with ambiguous cases.
Default Severity: Warning
Triggered when there is an ambiguous statement that may need some brackets in order to correct the order of operations.
ambiguity-1
Default Severity: Warning
Triggers when a for loop will never reach its max/limit because it is incrementing when it should be decrementing.
for i=10, 1 do end
Default Severity: Warning
Triggered when a file is required under two different names. This can happen when requiring a file in two different directories:
📦 myProject/ ├── 📂 helpers/ │ ├── 📜 strings.lua │ └── 📜 pretty.lua └── 📜 main.lua
-- main.lua local strings = require("helpers.strings") local pretty = require("helpers.pretty")
-- helpers/pretty.lua local strings = require("strings")
Default Severity: Warning
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.
local myTable = { myFunc ("param") }
Default Severity: Warning
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.
print(1) ('x'):sub(1, 2)
The await group contains diagnostics for asynchronous code.
Default Severity: Warning
Default File Status: "None"
Triggered when calling an asynchronous function from within a synchronous function.
Default Severity: Warning
Default File Status: "None"
Triggered when attempting to call coroutine.yield() when it is not permitted.
The codestyle group contains diagnostics for maintaining a good code style.
Default Severity: Warning
Default File Status: "None"
Triggered when the opinionated style checking detects an incorrectly styled line.
Default Severity: Information
Default File Status: "None"
Triggered when a typo is detected in a string. The dictionary can be customized using the Lua.spell.dict setting.
The duplicate group contains diagnostics for duplicate indexes and names.
Default Severity: Warning
Triggered when there are duplicate indexes.
local t = { -- triggered by indexes [1] = "a", [1] = "b", -- triggered by keys as well two = "c", two = "d" }
Default Severity: Warning
Triggered when setting the same field in a class more than once. Check the names of your fields.
---@class myClass local myTable = {} function myTable:x() end function myTable:x() end
The global group contains diagnostics that deal with the global scope.
Default Severity: Warning
Triggered when a global variable is defined and the environment (_ENV) is nil.
_ENV = nil myGlobalVar = true
Default Severity: Information
Triggered when a global variable starts with a lowercase character. This is mainly for maintaining good practice.
Default Severity: Information
Triggered when the environment (_ENV) is mutated and a previously global variable is no longer usable.
local A ---@type iolib _ENV = {} print(A)
Default Severity: Warning
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.
The luadoc group contains diagnostics for the annotations used to document your code.
Default Severity: Warning
Triggered when casting a variable to a type that does not match its initial type.
---@type boolean local e = nil ---@cast e integer
Default Severity: Warning
Triggered when two classes inherit each other forming a never ending loop of inheritance.
---@class Car:Vehicle ---@class Vehicle:Car
Default Severity: Warning
Triggered when a @field is specified for a non-existent @class.
Default Severity: Warning
Triggered when there are two @alias annotations with matching names.
Default Severity: Warning
Triggered when there are two @field annotations with matching key values.
Default Severity: Warning
Triggered when there are two @param annotations with matching names.
Default Severity: Warning
Triggered when referencing an undefined class in a @class annotation.
Default Severity: Warning
Triggered when referencing an undefined type or @alias in a @type annotation.
Default Severity: Warning
Triggered when referencing an undefined parameter from a function declartion.
---@param doesNotExist number function subtract(a, b) end
Default Severity: Warning
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.
Default Severity: Warning
Triggered when entering an invalid diagnostic code. A diagnostic code is like one of the many diagnosis codes found on this page.
---@diagnostic disable: doesNotExistDefault Severity: Warning
Triggered when an unknown operator is found like **.
The redefined group contains diagnostics that warn when variables are being redefined.
Default Severity: Hint
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.
The strict group contains diagnostics considered "strict". These can help you write better code but may require more work to follow.
Default Severity: Warning
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).
local x <close> = 1
Default Severity: Warning
Triggered when a variable has been marked as deprecated yet is still being used. The variable in question will also be (削除) struck through (削除ここまで).
Default Severity: Warning
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.
The strong group contains diagnostics considered "strong". These can help you write better code but may require more work to follow.
Default Severity: Warning
Default File Status: "None"
Triggered when a variable has an unknown type that cannot be inferred. Useful for more strict typing.
The type-check group contains diagnostics that have to do with type checking.
Default Severity: Warning
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:
---@type number local isNum = false
Default Severity: Warning
Triggered when a local variable is being cast to a different value than it was defined as.
---@type boolean local myBool myBool = {}
Default Severity: Warning
Triggered when casting a variable to a type that does not match its initial type.
---@type boolean local e = nil ---@cast e integer
Default Severity: Warning
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.
---@class Bicycle ---@field move function ---@type Bicycle|nil local bicycle -- need to make sure bicycle isn't nil first bicycle.move()
Default Severity: Warning
Triggered when the type of the provided parameter does not match the type requested by the function definition. Uses information defined with @param.
Default Severity: Warning
Triggered when the provided return value is not of the same type that the function expected.
---@return number sum function add(a, b) return false end
Default Severity: Warning
Triggered when referencing an undefined field.
---@class myClass local myClass = {} -- undefined field "hello" myClass.hello()
The unbalanced group contains diagnostics that deal with too few or too many of an item being given - like too few required parameters.
Default Severity: Warning
Triggered when a required parameter is not supplied when calling a function. Uses information defined with @param.
Default Severity: Warning
Triggered when a required return is not supplied from within a function. Uses information defined with @return.
Default Severity: Warning
Triggered when a return is specified but the return value is not. Uses information defined with @return.
Default Severity: Warning
Triggered when providing an extra parameter that a function does not ask for. Uses information defined with @param.
Default Severity: Warning
Triggered when a return is returning an extra value that the function has not requested. Uses information defined with @return.
Default Severity: Warning
Triggered when providing an extra value to an assignment operation that will go unused.
local a, b = 1, 2, 3
Default Severity: Warning
Triggered when there are more variables being assigned than values to assign them.
local a, b, c = 1, 2
The unused group contains diagnostics that report unused or unnecessary items.
Default Severity: Hint
Triggered when unreachable code is added after a break in a loop. This will result in the affected code becoming slightly transparent.
Default Severity: Hint
Triggered when a code block is left empty. This will result in the code block becoming slightly transparent.
Default Severity: Hint
Triggered when placing a return that is not needed as the function would exit on its own.
Default Severity: Hint
Triggered when a trailing space is detected. This will result in the trailing space being underlined.
Default Severity: Hint
Triggered when a section of code can never be reached. This will result in the affected code becoming slightly transparent.
Default Severity: Hint
Triggered when a function is defined but never called. This results in the function becoming slightly transparent.
Default Severity: Hint
Triggered when a label is defined but never used. This results in the label becoming slightly transparent.
Default Severity: Hint
Triggered when a local variable is defined but never referenced. This results in the variable becoming slightly transparent.
Default Severity: Hint
Triggered when the variable arguments symbol (...) in a function is unused. This results in the symbol becoming slightly transparent.