summaryrefslogtreecommitdiff
path: root/script-beta/core/diagnostics/doc-field-no-class.lua
blob: 88c61824426720ba0bdd8cb9ecded0f5630a9878 (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
40
41
42
local files   = require 'files'
local lang    = require 'language'

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

    if not state.ast.docs then
        return
    end

    for _, doc in ipairs(state.ast.docs) do
        if doc.type ~= 'doc.field' then
            goto CONTINUE
        end
        local bindGroup = doc.bindGroup
        if not bindGroup then
            goto CONTINUE
        end
        local ok
        for _, other in ipairs(bindGroup) do
            if other.type == 'doc.class' then
                ok = true
            elseif other == doc then
                if not ok then
                    callback {
                        start   = doc.start,
                        finish  = doc.finish,
                        message = lang.script('DIAG_DOC_FIELD_NO_CLASS'),
                    }
                end
                goto CONTINUE
            elseif other.type == 'doc.field' then
            else
                ok = false
            end
        end
        ::CONTINUE::
    end
end