lunarmodules / luacheck

A tool for linting and static analysis of Lua code.

Home Page:https://luacheck.readthedocs.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Warn of mutated loop variables

Zash opened this issue · comments

Lua development version has made loop variables read-only in lua/lua@b2f7b3b so having a warning for this would be good so that those cases could be found early.

E.g. code like

for i = 1, 10 do
  i = i - 1
end
for k,v in pairs({ foo = "bar" }) do
  k = "k:"..k
end

Fails with attempt to assign to const variable 'i'

Similarly, a warning when trying to explicitly assign to a const variable in 5.4.

local foo <const> = 5
foo = 6  -- should generate warning

Contributions welcome. I don't have a lot of time to develop this myself right now but I mostly keep up with facilitating community contributions.