Super Strict

Super Strict is a pure Lua library that finds undeclared variables and other minor mistakes in your source code through static analysis. You do not need to execute any code to find your mistakes because Super Strict will check the code during loading. Just require the "sstrict.lua" file and any subsequent calls to "require","dofile","loadfile" or "loadstring" will be checked through Super Strict.
require('sstrict.lua')
To exclude a specific Lua file from the being checked place the "--!strict" line at the top of your source code.
The source code is available on GitHub and the official documentation is on 2dengine.com

Examples

Undefined and unused variables

function foo()
  a = 5 -- undefined variable 'a'
end
function bar(a, b)
  local c = a + b -- unused variable 'c'
  return a + b
end

Redefinition of variable names

for i = 1, 10 do
  for i = 1, 10 do
    -- variable name 'i' redefinition
  end
end

Empty and unnecessary code blocks

for i = 1, 3 do
  -- empty code block error
end
function baz()
  local n = 5
  n = n - 1 -- unnecessary code block error
end

Constant conditions

if 5+5 > 11 then
  -- constant condition error in if/else statement
end

Too many values in assignment

a = 1, 2 -- too many values on the right-hand side in assignment

Duplicate variables, arguments and table fields

t =
{ 
  ['a'] = 100,
  a = 100 -- duplicate field 'a' in table constructor
}
for b, b in pairs(t) do
  -- duplicate lvariable 'b'
end
c, c = 1, 2 -- duplicate variable 'c'
function foo(d, d)
  -- duplicate argument 'd'
end

Credits

grump, pgimeno, MrFariator and the rest of the Love2D community
sstrict.lua is not related in any way to the strict.lua library
Please support our work so we can release more free software in the future.

Super Strict > sstrict

sstrict


api.dofile(path, ...)
api.error(what, line)
api.loadfile(path, ...)
api.loadstring(source, ...)
api.parse(source, where)
api.parseFile(path)
api.require(rpath, ...)
lex.pmatch(source, patterns, offset)
lex.tokenize(source, patterns)
par.access(k)
par.check(a)
par.checklist(t)
par.define(s, k, l)
par.done()
par.expect(a)
par.lookahead(a)
par.mark()
par.nextsym()
par.pop()
par.push()
par.reset(stream)
par.rewind()
par.runbinop(t, a, b)
stx.addsubexp()
stx.args()
stx.assignorcall()
stx.block()
stx.call(scope)
stx.chunk()
stx.concatexp()
stx.doblock()
stx.explist()
stx.expoexp()
stx.expression()
stx.forloop()
stx.funcbody()
stx.functioncall()
stx.functiondef()
stx.ifcondition()
stx.ifstatement()
stx.localdef()
stx.logical()
stx.muldivexp()
stx.namelist(kind)
stx.neblock()
stx.prefixexp()
stx.relational()
stx.repeatloop()
stx.stat()
stx.tableconstructor()
stx.term()
stx.unaryexp()
stx.varaccess(scope)
stx.varlist()
stx.whileloop()

api.dofile(path, ...)

Arguments
valuepath
value...

api.error(what, line)

Arguments
valuewhat
valueline

api.loadfile(path, ...)

Arguments
valuepath
value...

api.loadstring(source, ...)

Arguments
valuesource
value...

api.parse(source, where)

Arguments
valuesource
valuewhere

api.parseFile(path)

Arguments
valuepath

api.require(rpath, ...)

Arguments
valuerpath
value...

lex.pmatch(source, patterns, offset)

Arguments
valuesource
valuepatterns
valueoffset

lex.tokenize(source, patterns)

Arguments
valuesource
valuepatterns

par.access(k)

Arguments
valuek

par.check(a)

Arguments
valuea

par.checklist(t)

Arguments
valuet

par.define(s, k, l)

Arguments
values
valuek
valuel

par.done()

par.expect(a)

Arguments
valuea

par.lookahead(a)

Arguments
valuea

par.mark()

par.nextsym()

par.pop()

par.push()

par.reset(stream)

Arguments
valuestream

par.rewind()

par.runbinop(t, a, b)

Arguments
valuet
valuea
valueb

stx.addsubexp()

stx.args()

stx.assignorcall()

stx.block()

stx.call(scope)

Arguments
valuescope

stx.chunk()

stx.concatexp()

stx.doblock()

stx.explist()

stx.expoexp()

stx.expression()

stx.forloop()

stx.funcbody()

stx.functioncall()

stx.functiondef()

stx.ifcondition()

stx.ifstatement()

stx.localdef()

stx.logical()

stx.muldivexp()

stx.namelist(kind)

Arguments
valuekind

stx.neblock()

stx.prefixexp()

stx.relational()

stx.repeatloop()

stx.stat()

stx.tableconstructor()

stx.term()

stx.unaryexp()

stx.varaccess(scope)

Arguments
valuescope

stx.varlist()

stx.whileloop()


This document was last updated on October 09, 2024, by 2dengine LLC. © All rights reserved.