A syntax error will appear when the Lua syntax has been violated, which will result in a error at runtime.
These work similar to diagnostics.
Below is a list of all of the possible syntax errors that can be reported by the language server:
Triggered when there is unreachable code after a return
.
Triggered when there is a parameter defined after a variable arguments symbol (...
).
Triggered when there is an else
or elseif
after a terminating else
in an if
statement.
if myVar then
print("Truthy")
else
print("Falsy")
elseif nil then --Error!
end
Triggered when a break
is placed outside of a break
-able loop.
Triggered when using the equality symbol (==
) to assign a variable. You should instead use the assignment symbol =
.
Triggered when using /** */
for multi-line comments instead of --[[ ]]
, as required by Lua's syntax. You should instead use --[[ ]]
for your multi-line comments.
Triggered when using //
for comments instead of --
, as required by Lua's syntax. You should instead use --
for your comments and ---
for your annotations.
Triggered when using then
instead of do
for a while
loop.
Triggered when using the assignment symbol (=
) to test equality. You should instead use the equality symbol ==
.
Triggered when an unknown escape sequence is found, such as "\c"
.
Triggered when using a non-Lua symbol like &&
instead of and
or ||
instead of or
.
Triggered when using do
instead of then
in an if
statement.
Triggered when there is an unexpected expression like in local 3 + 2 = 10
- there is an unexpected expression during an assignment action.
Triggered when there is an indexing operation taking place in a function's name e.g. function myTable[1]() end
.
Triggered when a local variable is "jumped" over using goto
and labels. "jumping" the variable means it is never defined and will cause errors when it is referenced. This diagnostic serves to protect against such errors.
goto jump
local a = 10
::jump::
-- a is jumped over by this label,
-- meaning it is never defined
print(a)
Triggered when using a reserved keyword as a name e.g. local true = "hello"
.
Triggered when the limit for local
variables has been reached in this scope. Lua has a limit of 200 local variables in each scope.
Triggered when a malformed number is found like 0y16
instead of 0x16
or 0.0.4
.
Triggered when an end
is missing from an if
, for
, while
, or function
. This is usually due to nesting and a matching end
is missing from an outer if
, for
, etc.
Triggered when the hexadecimal digits are missing from an \x
hexadecimal escape.
Triggered when an expression is missing from your code. For example, forgetting the expression to an if statement, i.e. if then end
.
Triggered when the exponent has been left out when representing a number in exponent form.
local incorrect = 1e
local correct = 1e10
Triggered when a field reference is underway but no field name has been given e.g. print(myTable.)
.
Triggered when the maximum (limit) to a for
loop is not provided.
Triggered when the minimum (start) to a for
loop is not provided.
Triggered when a method (:
) is being called but the method name is not provided e.g. Class:
.
Triggered when the name is missing to a function/method.
Triggered when a separator (,
or ;
) is missing from a table.
Triggered when using the variable arguments symbol (...
) outside of a function that has variable arguments.
Triggered when a function is being assigned to a variable and is also given a name.
local x = function x() end
Triggered when a function is marked as local. The method either belongs to a table or is a local function, not both.
local function x:t() end
Triggered when a variable name contains unicode characters. Unicode characters can be allowed by disabling this diagnostic or by enabling runtime.unicodeName
.
Triggered when an unknown symbols is found like in local a = &
. A simple syntax error, most likely a typo.