summaryrefslogtreecommitdiff
path: root/script/core/diagnostics/unused-vararg.lua
blob: 2e07e1eed9db70c2b72cecebe71549446f6424fc (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
local files  = require 'files'
local guide  = require 'parser.guide'
local define = require 'proto.define'
local lang   = require 'language'

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

    guide.eachSourceType(ast.ast, 'function', function (source)
        local args = source.args
        if not args then
            return
        end

        for _, arg in ipairs(args) do
            if arg.type == '...' then
                if not arg.ref then
                    callback {
                        start   = arg.start,
                        finish  = arg.finish,
                        tags    = { define.DiagnosticTag.Unnecessary },
                        message = lang.script.DIAG_UNUSED_VARARG,
                    }
                end
            end
        end
    end)
end