summaryrefslogtreecommitdiff
path: root/script/core/diagnostics/no-implicit-any.lua
blob: 23af570ad0cb9ca93710c9ba913c3cd078c8f152 (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
local files   = require 'files'
local searcher   = require 'core.searcher'
local lang    = require 'language'
local define  = require 'proto.define'
local vm      = require 'vm'

return function (uri, callback)
    local ast = files.getAst(uri)
    if not ast then
        return
    end

    searcher.eachSource(ast.ast, function (source)
        if  source.type ~= 'local'
        and source.type ~= 'setlocal'
        and source.type ~= 'setglobal'
        and source.type ~= 'getglobal'
        and source.type ~= 'setfield'
        and source.type ~= 'setindex'
        and source.type ~= 'tablefield'
        and source.type ~= 'tableindex' then
            return
        end
        if vm.getInferType(source, 0) == 'any' then
            callback {
                start   = source.start,
                finish  = source.finish,
                message = lang.script('DIAG_IMPLICIT_ANY'),
            }
        end
    end)
end