summaryrefslogtreecommitdiff
path: root/script/core/diagnostics/close-non-object.lua
blob: afd259d0db1b92de45748d33023fdfb51543983c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
local files    = require 'files'
local guide    = require 'parser.guide'
local lang     = require 'language'

return function (uri, callback)
    local state = files.getState(uri)
    if not state then
        return
    end

    guide.eachSourceType(state.ast, 'local', function (source)
        if not source.attrs then
            return
        end
        if source.attrs[1][1] ~= 'close' then
            return
        end
        if not source.value then
            callback {
                start   = source.start,
                finish  = source.finish,
                message = lang.script.DIAG_COSE_NON_OBJECT,
            }
            return
        end
        if source.value.type == 'nil'
        or source.value.type == 'number'
        or source.value.type == 'boolean'
        or source.value.type == 'table'
        or source.value.type == 'function' then
            callback {
                start   = source.value.start,
                finish  = source.value.finish,
                message = lang.script.DIAG_COSE_NON_OBJECT,
            }
            return
        end
    end)
end