mirror of
https://github.com/leafo/moonscript.git
synced 2024-11-22 02:44:23 +00:00
make lint use ref, whitelist nil, true, false
This commit is contained in:
parent
887745491d
commit
da0109bd14
@ -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
|
||||
|
@ -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: (...) =>
|
||||
|
Loading…
Reference in New Issue
Block a user