make lint use ref, whitelist nil, true, false

This commit is contained in:
leaf corcoran 2013-12-27 04:00:46 -08:00
parent 887745491d
commit da0109bd14
2 changed files with 16 additions and 8 deletions

View File

@ -50,7 +50,10 @@ local whitelist_globals = Set({
'setmetatable',
'tonumber',
'collectgarbage',
'coroutine'
'coroutine',
"nil",
"true",
"false"
})
local LinterBlock
do
@ -75,15 +78,16 @@ do
_parent_0.__init(self, ...)
local vc = self.value_compilers
self.value_compilers = setmetatable({
raw_value = function(block, name)
if name:match("^[%w_]+$") and not block:has_name(name) and not whitelist_globals[name] then
ref = function(block, val)
local name = val[2]
if not (block:has_name(name) or whitelist_globals[name]) then
local stm = block.current_stms[block.current_stm_i]
insert(self.lint_errors, {
"accessing global " .. tostring(name),
stm[-1]
})
end
return vc.raw_value(block, name)
return vc.raw_value(block, val)
end
}, {
__index = vc

View File

@ -42,6 +42,10 @@ whitelist_globals = Set {
'tonumber'
'collectgarbage'
'coroutine'
"nil"
"true"
"false"
}
class LinterBlock extends Block
@ -50,16 +54,16 @@ class LinterBlock extends Block
vc = @value_compilers
@value_compilers = setmetatable {
raw_value: (block, name) ->
if name\match("^[%w_]+$") and not block\has_name(name) and not whitelist_globals[name]
ref: (block, val) ->
name = val[2]
unless block\has_name(name) or whitelist_globals[name]
stm = block.current_stms[block.current_stm_i]
insert @lint_errors, {
"accessing global #{name}"
stm[-1]
}
vc.raw_value block, name
vc.raw_value block, val
}, __index: vc
block: (...) =>