summaryrefslogtreecommitdiff
path: root/script-beta/core/diagnostics
diff options
context:
space:
mode:
Diffstat (limited to 'script-beta/core/diagnostics')
-rw-r--r--script-beta/core/diagnostics/ambiguity-1.lua69
-rw-r--r--script-beta/core/diagnostics/circle-doc-class.lua54
-rw-r--r--script-beta/core/diagnostics/code-after-break.lua34
-rw-r--r--script-beta/core/diagnostics/doc-field-no-class.lua41
-rw-r--r--script-beta/core/diagnostics/duplicate-doc-class.lua46
-rw-r--r--script-beta/core/diagnostics/duplicate-doc-field.lua34
-rw-r--r--script-beta/core/diagnostics/duplicate-doc-param.lua37
-rw-r--r--script-beta/core/diagnostics/duplicate-index.lua63
-rw-r--r--script-beta/core/diagnostics/empty-block.lua49
-rw-r--r--script-beta/core/diagnostics/global-in-nil-env.lua66
-rw-r--r--script-beta/core/diagnostics/init.lua56
-rw-r--r--script-beta/core/diagnostics/lowercase-global.lua56
-rw-r--r--script-beta/core/diagnostics/newfield-call.lua37
-rw-r--r--script-beta/core/diagnostics/newline-call.lua38
-rw-r--r--script-beta/core/diagnostics/redefined-local.lua32
-rw-r--r--script-beta/core/diagnostics/redundant-parameter.lua82
-rw-r--r--script-beta/core/diagnostics/redundant-value.lua24
-rw-r--r--script-beta/core/diagnostics/trailing-space.lua55
-rw-r--r--script-beta/core/diagnostics/undefined-doc-class.lua46
-rw-r--r--script-beta/core/diagnostics/undefined-doc-name.lua60
-rw-r--r--script-beta/core/diagnostics/undefined-doc-param.lua52
-rw-r--r--script-beta/core/diagnostics/undefined-env-child.lua27
-rw-r--r--script-beta/core/diagnostics/undefined-global.lua40
-rw-r--r--script-beta/core/diagnostics/unused-function.lua40
-rw-r--r--script-beta/core/diagnostics/unused-label.lua22
-rw-r--r--script-beta/core/diagnostics/unused-local.lua93
-rw-r--r--script-beta/core/diagnostics/unused-vararg.lua31
27 files changed, 0 insertions, 1284 deletions
diff --git a/script-beta/core/diagnostics/ambiguity-1.lua b/script-beta/core/diagnostics/ambiguity-1.lua
deleted file mode 100644
index 37815fb5..00000000
--- a/script-beta/core/diagnostics/ambiguity-1.lua
+++ /dev/null
@@ -1,69 +0,0 @@
-local files = require 'files'
-local guide = require 'parser.guide'
-local lang = require 'language'
-
-local opMap = {
- ['+'] = true,
- ['-'] = true,
- ['*'] = true,
- ['/'] = true,
- ['//'] = true,
- ['^'] = true,
- ['<<'] = true,
- ['>>'] = true,
- ['&'] = true,
- ['|'] = true,
- ['~'] = true,
- ['..'] = true,
-}
-
-local literalMap = {
- ['number'] = true,
- ['boolean'] = true,
- ['string'] = true,
- ['table'] = true,
-}
-
-return function (uri, callback)
- local ast = files.getAst(uri)
- if not ast then
- return
- end
- local text = files.getText(uri)
- guide.eachSourceType(ast.ast, 'binary', function (source)
- if source.op.type ~= 'or' then
- return
- end
- local first = source[1]
- local second = source[2]
- -- a + (b or 0) --> (a + b) or 0
- do
- if opMap[first.op and first.op.type]
- and first.type ~= 'unary'
- and not second.op
- and literalMap[second.type]
- and not literalMap[first[2].type]
- then
- callback {
- start = source.start,
- finish = source.finish,
- message = lang.script('DIAG_AMBIGUITY_1', text:sub(first.start, first.finish))
- }
- end
- end
- -- (a or 0) + c --> a or (0 + c)
- do
- if opMap[second.op and second.op.type]
- and second.type ~= 'unary'
- and not first.op
- and literalMap[second[1].type]
- then
- callback {
- start = source.start,
- finish = source.finish,
- message = lang.script('DIAG_AMBIGUITY_1', text:sub(second.start, second.finish))
- }
- end
- end
- end)
-end
diff --git a/script-beta/core/diagnostics/circle-doc-class.lua b/script-beta/core/diagnostics/circle-doc-class.lua
deleted file mode 100644
index 55179447..00000000
--- a/script-beta/core/diagnostics/circle-doc-class.lua
+++ /dev/null
@@ -1,54 +0,0 @@
-local files = require 'files'
-local guide = require 'parser.guide'
-local lang = require 'language'
-local define = require 'proto.define'
-local vm = require 'vm'
-
-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.class' then
- if not doc.extends then
- goto CONTINUE
- end
- local myName = guide.getName(doc)
- local list = { doc }
- local mark = {}
- for i = 1, 999 do
- local current = list[i]
- if not current then
- goto CONTINUE
- end
- if current.extends then
- local newName = current.extends[1]
- if newName == myName then
- callback {
- start = doc.start,
- finish = doc.finish,
- message = lang.script('DIAG_CIRCLE_DOC_CLASS', myName)
- }
- goto CONTINUE
- end
- if not mark[newName] then
- mark[newName] = true
- local docs = vm.getDocTypes(newName)
- for _, otherDoc in ipairs(docs) do
- if otherDoc.type == 'doc.class.name' then
- list[#list+1] = otherDoc.parent
- end
- end
- end
- end
- end
- ::CONTINUE::
- end
- end
-end
diff --git a/script-beta/core/diagnostics/code-after-break.lua b/script-beta/core/diagnostics/code-after-break.lua
deleted file mode 100644
index a2bac8a4..00000000
--- a/script-beta/core/diagnostics/code-after-break.lua
+++ /dev/null
@@ -1,34 +0,0 @@
-local files = require 'files'
-local guide = require 'parser.guide'
-local lang = require 'language'
-local define = require 'proto.define'
-
-return function (uri, callback)
- local state = files.getAst(uri)
- if not state then
- return
- end
-
- local mark = {}
- guide.eachSourceType(state.ast, 'break', function (source)
- local list = source.parent
- if mark[list] then
- return
- end
- mark[list] = true
- for i = #list, 1, -1 do
- local src = list[i]
- if src == source then
- if i == #list then
- return
- end
- callback {
- start = list[i+1].start,
- finish = list[#list].range or list[#list].finish,
- tags = { define.DiagnosticTag.Unnecessary },
- message = lang.script.DIAG_CODE_AFTER_BREAK,
- }
- end
- end
- end)
-end
diff --git a/script-beta/core/diagnostics/doc-field-no-class.lua b/script-beta/core/diagnostics/doc-field-no-class.lua
deleted file mode 100644
index f27bbb32..00000000
--- a/script-beta/core/diagnostics/doc-field-no-class.lua
+++ /dev/null
@@ -1,41 +0,0 @@
-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
- break
- end
- if other == doc then
- break
- end
- end
- if not ok then
- callback {
- start = doc.start,
- finish = doc.finish,
- message = lang.script('DIAG_DOC_FIELD_NO_CLASS'),
- }
- end
- ::CONTINUE::
- end
-end
diff --git a/script-beta/core/diagnostics/duplicate-doc-class.lua b/script-beta/core/diagnostics/duplicate-doc-class.lua
deleted file mode 100644
index 259c048b..00000000
--- a/script-beta/core/diagnostics/duplicate-doc-class.lua
+++ /dev/null
@@ -1,46 +0,0 @@
-local files = require 'files'
-local guide = require 'parser.guide'
-local lang = require 'language'
-local define = require 'proto.define'
-local vm = require 'vm'
-
-return function (uri, callback)
- local state = files.getAst(uri)
- if not state then
- return
- end
-
- if not state.ast.docs then
- return
- end
-
- local cache = {}
- for _, doc in ipairs(state.ast.docs) do
- if doc.type == 'doc.class'
- or doc.type == 'doc.alias' then
- local name = guide.getName(doc)
- if not cache[name] then
- local docs = vm.getDocTypes(name)
- cache[name] = {}
- for _, otherDoc in ipairs(docs) do
- if otherDoc.type == 'doc.class.name'
- or otherDoc.type == 'doc.alias.name' then
- cache[name][#cache[name]+1] = {
- start = otherDoc.start,
- finish = otherDoc.finish,
- uri = guide.getUri(otherDoc),
- }
- end
- end
- end
- if #cache[name] > 1 then
- callback {
- start = doc.start,
- finish = doc.finish,
- related = cache,
- message = lang.script('DIAG_DUPLICATE_DOC_CLASS', name)
- }
- end
- end
- end
-end
diff --git a/script-beta/core/diagnostics/duplicate-doc-field.lua b/script-beta/core/diagnostics/duplicate-doc-field.lua
deleted file mode 100644
index b621fd9e..00000000
--- a/script-beta/core/diagnostics/duplicate-doc-field.lua
+++ /dev/null
@@ -1,34 +0,0 @@
-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
-
- local mark
- for _, group in ipairs(state.ast.docs.groups) do
- for _, doc in ipairs(group) do
- if doc.type == 'doc.class' then
- mark = {}
- elseif doc.type == 'doc.field' then
- if mark then
- local name = doc.field[1]
- if mark[name] then
- callback {
- start = doc.field.start,
- finish = doc.field.finish,
- message = lang.script('DIAG_DUPLICATE_DOC_FIELD', name),
- }
- end
- mark[name] = true
- end
- end
- end
- end
-end
diff --git a/script-beta/core/diagnostics/duplicate-doc-param.lua b/script-beta/core/diagnostics/duplicate-doc-param.lua
deleted file mode 100644
index 676a6fb4..00000000
--- a/script-beta/core/diagnostics/duplicate-doc-param.lua
+++ /dev/null
@@ -1,37 +0,0 @@
-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.param' then
- goto CONTINUE
- end
- local name = doc.param[1]
- local bindGroup = doc.bindGroup
- if not bindGroup then
- goto CONTINUE
- end
- for _, other in ipairs(bindGroup) do
- if other ~= doc
- and other.type == 'doc.param'
- and other.param[1] == name then
- callback {
- start = doc.param.start,
- finish = doc.param.finish,
- message = lang.script('DIAG_DUPLICATE_DOC_PARAM', name)
- }
- goto CONTINUE
- end
- end
- ::CONTINUE::
- end
-end
diff --git a/script-beta/core/diagnostics/duplicate-index.lua b/script-beta/core/diagnostics/duplicate-index.lua
deleted file mode 100644
index dabe1b3c..00000000
--- a/script-beta/core/diagnostics/duplicate-index.lua
+++ /dev/null
@@ -1,63 +0,0 @@
-local files = require 'files'
-local guide = require 'parser.guide'
-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
-
- guide.eachSourceType(ast.ast, 'table', function (source)
- local mark = {}
- for _, obj in ipairs(source) do
- if obj.type == 'tablefield'
- or obj.type == 'tableindex' then
- local name = vm.getKeyName(obj)
- if name then
- if not mark[name] then
- mark[name] = {}
- end
- mark[name][#mark[name]+1] = obj.field or obj.index
- end
- end
- end
-
- for name, defs in pairs(mark) do
- local sname = name:match '^.|(.+)$'
- if #defs > 1 and sname then
- local related = {}
- for i = 1, #defs do
- local def = defs[i]
- related[i] = {
- start = def.start,
- finish = def.finish,
- uri = uri,
- }
- end
- for i = 1, #defs - 1 do
- local def = defs[i]
- callback {
- start = def.start,
- finish = def.finish,
- related = related,
- message = lang.script('DIAG_DUPLICATE_INDEX', sname),
- level = define.DiagnosticSeverity.Hint,
- tags = { define.DiagnosticTag.Unnecessary },
- }
- end
- for i = #defs, #defs do
- local def = defs[i]
- callback {
- start = def.start,
- finish = def.finish,
- related = related,
- message = lang.script('DIAG_DUPLICATE_INDEX', sname),
- }
- end
- end
- end
- end)
-end
diff --git a/script-beta/core/diagnostics/empty-block.lua b/script-beta/core/diagnostics/empty-block.lua
deleted file mode 100644
index 2024f4e3..00000000
--- a/script-beta/core/diagnostics/empty-block.lua
+++ /dev/null
@@ -1,49 +0,0 @@
-local files = require 'files'
-local guide = require 'parser.guide'
-local lang = require 'language'
-local define = require 'proto.define'
-
--- 检查空代码块
--- 但是排除忙等待(repeat/while)
-return function (uri, callback)
- local ast = files.getAst(uri)
- if not ast then
- return
- end
-
- guide.eachSourceType(ast.ast, 'if', function (source)
- for _, block in ipairs(source) do
- if #block > 0 then
- return
- end
- end
- callback {
- start = source.start,
- finish = source.finish,
- tags = { define.DiagnosticTag.Unnecessary },
- message = lang.script.DIAG_EMPTY_BLOCK,
- }
- end)
- guide.eachSourceType(ast.ast, 'loop', function (source)
- if #source > 0 then
- return
- end
- callback {
- start = source.start,
- finish = source.finish,
- tags = { define.DiagnosticTag.Unnecessary },
- message = lang.script.DIAG_EMPTY_BLOCK,
- }
- end)
- guide.eachSourceType(ast.ast, 'in', function (source)
- if #source > 0 then
- return
- end
- callback {
- start = source.start,
- finish = source.finish,
- tags = { define.DiagnosticTag.Unnecessary },
- message = lang.script.DIAG_EMPTY_BLOCK,
- }
- end)
-end
diff --git a/script-beta/core/diagnostics/global-in-nil-env.lua b/script-beta/core/diagnostics/global-in-nil-env.lua
deleted file mode 100644
index 9a0d4f35..00000000
--- a/script-beta/core/diagnostics/global-in-nil-env.lua
+++ /dev/null
@@ -1,66 +0,0 @@
-local files = require 'files'
-local guide = require 'parser.guide'
-local lang = require 'language'
-
--- TODO: 检查路径是否可达
-local function mayRun(path)
- return true
-end
-
-return function (uri, callback)
- local ast = files.getAst(uri)
- if not ast then
- return
- end
- local root = guide.getRoot(ast.ast)
- local env = guide.getENV(root)
-
- local nilDefs = {}
- if not env.ref then
- return
- end
- for _, ref in ipairs(env.ref) do
- if ref.type == 'setlocal' then
- if ref.value and ref.value.type == 'nil' then
- nilDefs[#nilDefs+1] = ref
- end
- end
- end
-
- if #nilDefs == 0 then
- return
- end
-
- local function check(source)
- local node = source.node
- if node.tag == '_ENV' then
- local ok
- for _, nilDef in ipairs(nilDefs) do
- local mode, pathA = guide.getPath(nilDef, source)
- if mode == 'before'
- and mayRun(pathA) then
- ok = nilDef
- break
- end
- end
- if ok then
- callback {
- start = source.start,
- finish = source.finish,
- uri = uri,
- message = lang.script.DIAG_GLOBAL_IN_NIL_ENV,
- related = {
- {
- start = ok.start,
- finish = ok.finish,
- uri = uri,
- }
- }
- }
- end
- end
- end
-
- guide.eachSourceType(ast.ast, 'getglobal', check)
- guide.eachSourceType(ast.ast, 'setglobal', check)
-end
diff --git a/script-beta/core/diagnostics/init.lua b/script-beta/core/diagnostics/init.lua
deleted file mode 100644
index a6b61e12..00000000
--- a/script-beta/core/diagnostics/init.lua
+++ /dev/null
@@ -1,56 +0,0 @@
-local files = require 'files'
-local define = require 'proto.define'
-local config = require 'config'
-local await = require 'await'
-
--- 把耗时最长的诊断放到最后面
-local diagLevel = {
- ['redundant-parameter'] = 100,
-}
-
-local diagList = {}
-for k in pairs(define.DiagnosticDefaultSeverity) do
- diagList[#diagList+1] = k
-end
-table.sort(diagList, function (a, b)
- return (diagLevel[a] or 0) < (diagLevel[b] or 0)
-end)
-
-local function check(uri, name, results)
- if config.config.diagnostics.disable[name] then
- return
- end
- local level = config.config.diagnostics.severity[name]
- or define.DiagnosticDefaultSeverity[name]
- if level == 'Hint' and not files.isOpen(uri) then
- return
- end
- local severity = define.DiagnosticSeverity[level]
- local clock = os.clock()
- require('core.diagnostics.' .. name)(uri, function (result)
- result.level = severity or result.level
- result.code = name
- results[#results+1] = result
- end, name)
- local passed = os.clock() - clock
- if passed >= 0.5 then
- log.warn(('Diagnostics [%s] @ [%s] takes [%.3f] sec!'):format(name, uri, passed))
- end
-end
-
-return function (uri, response)
- local vm = require 'vm'
- local ast = files.getAst(uri)
- if not ast then
- return nil
- end
-
- local isOpen = files.isOpen(uri)
-
- for _, name in ipairs(diagList) do
- await.delay()
- local results = {}
- check(uri, name, results)
- response(results)
- end
-end
diff --git a/script-beta/core/diagnostics/lowercase-global.lua b/script-beta/core/diagnostics/lowercase-global.lua
deleted file mode 100644
index fe5d1eca..00000000
--- a/script-beta/core/diagnostics/lowercase-global.lua
+++ /dev/null
@@ -1,56 +0,0 @@
-local files = require 'files'
-local guide = require 'parser.guide'
-local lang = require 'language'
-local config = require 'config'
-local vm = require 'vm'
-
-local function isDocClass(source)
- if not source.bindDocs then
- return false
- end
- for _, doc in ipairs(source.bindDocs) do
- if doc.type == 'doc.class' then
- return true
- end
- end
- return false
-end
-
--- 不允许定义首字母小写的全局变量(很可能是拼错或者漏删)
-return function (uri, callback)
- local ast = files.getAst(uri)
- if not ast then
- return
- end
-
- local definedGlobal = {}
- for name in pairs(config.config.diagnostics.globals) do
- definedGlobal[name] = true
- end
-
- guide.eachSourceType(ast.ast, 'setglobal', function (source)
- local name = guide.getName(source)
- if definedGlobal[name] then
- return
- end
- local first = name:match '%w'
- if not first then
- return
- end
- if not first:match '%l' then
- return
- end
- -- 如果赋值被标记为 doc.class ,则认为是允许的
- if isDocClass(source) then
- return
- end
- if vm.isGlobalLibraryName(name) then
- return
- end
- callback {
- start = source.start,
- finish = source.finish,
- message = lang.script.DIAG_LOWERCASE_GLOBAL,
- }
- end)
-end
diff --git a/script-beta/core/diagnostics/newfield-call.lua b/script-beta/core/diagnostics/newfield-call.lua
deleted file mode 100644
index 75681cbc..00000000
--- a/script-beta/core/diagnostics/newfield-call.lua
+++ /dev/null
@@ -1,37 +0,0 @@
-local files = require 'files'
-local guide = require 'parser.guide'
-local lang = require 'language'
-
-return function (uri, callback)
- local ast = files.getAst(uri)
- if not ast then
- return
- end
-
- local lines = files.getLines(uri)
- local text = files.getText(uri)
-
- guide.eachSourceType(ast.ast, 'table', function (source)
- for i = 1, #source do
- local field = source[i]
- if field.type == 'call' then
- local func = field.node
- local args = field.args
- if args then
- local funcLine = guide.positionOf(lines, func.finish)
- local argsLine = guide.positionOf(lines, args.start)
- if argsLine > funcLine then
- callback {
- start = field.start,
- finish = field.finish,
- message = lang.script('DIAG_PREFIELD_CALL'
- , text:sub(func.start, func.finish)
- , text:sub(args.start, args.finish)
- )
- }
- end
- end
- end
- end
- end)
-end
diff --git a/script-beta/core/diagnostics/newline-call.lua b/script-beta/core/diagnostics/newline-call.lua
deleted file mode 100644
index cb318380..00000000
--- a/script-beta/core/diagnostics/newline-call.lua
+++ /dev/null
@@ -1,38 +0,0 @@
-local files = require 'files'
-local guide = require 'parser.guide'
-local lang = require 'language'
-
-return function (uri, callback)
- local ast = files.getAst(uri)
- if not ast then
- return
- end
- local lines = files.getLines(uri)
-
- guide.eachSourceType(ast.ast, 'call', function (source)
- local node = source.node
- local args = source.args
- if not args then
- return
- end
-
- -- 必须有其他人在继续使用当前对象
- if not source.next then
- return
- end
-
- local nodeRow = guide.positionOf(lines, node.finish)
- local argRow = guide.positionOf(lines, args.start)
- if nodeRow == argRow then
- return
- end
-
- if #args == 1 then
- callback {
- start = args.start,
- finish = args.finish,
- message = lang.script.DIAG_PREVIOUS_CALL,
- }
- end
- end)
-end
diff --git a/script-beta/core/diagnostics/redefined-local.lua b/script-beta/core/diagnostics/redefined-local.lua
deleted file mode 100644
index 5e53d837..00000000
--- a/script-beta/core/diagnostics/redefined-local.lua
+++ /dev/null
@@ -1,32 +0,0 @@
-local files = require 'files'
-local guide = require 'parser.guide'
-local lang = require 'language'
-
-return function (uri, callback)
- local ast = files.getAst(uri)
- if not ast then
- return
- end
- guide.eachSourceType(ast.ast, 'local', function (source)
- local name = source[1]
- if name == '_'
- or name == ast.ENVMode then
- return
- end
- local exist = guide.getLocal(source, name, source.start-1)
- if exist then
- callback {
- start = source.start,
- finish = source.finish,
- message = lang.script('DIAG_REDEFINED_LOCAL', name),
- related = {
- {
- start = exist.start,
- finish = exist.finish,
- uri = uri,
- }
- },
- }
- end
- end)
-end
diff --git a/script-beta/core/diagnostics/redundant-parameter.lua b/script-beta/core/diagnostics/redundant-parameter.lua
deleted file mode 100644
index 2fae20e8..00000000
--- a/script-beta/core/diagnostics/redundant-parameter.lua
+++ /dev/null
@@ -1,82 +0,0 @@
-local files = require 'files'
-local guide = require 'parser.guide'
-local vm = require 'vm'
-local lang = require 'language'
-local define = require 'proto.define'
-local await = require 'await'
-
-local function countCallArgs(source)
- local result = 0
- if not source.args then
- return 0
- end
- if source.node and source.node.type == 'getmethod' then
- result = result + 1
- end
- result = result + #source.args
- return result
-end
-
-local function countFuncArgs(source)
- local result = 0
- if source.parent and source.parent.type == 'setmethod' then
- result = result + 1
- end
- if not source.args then
- return result
- end
- if source.args[#source.args].type == '...' then
- return math.maxinteger
- end
- result = result + #source.args
- return result
-end
-
-return function (uri, callback)
- local ast = files.getAst(uri)
- if not ast then
- return
- end
-
- guide.eachSourceType(ast.ast, 'call', function (source)
- local callArgs = countCallArgs(source)
- if callArgs == 0 then
- return
- end
-
- local func = source.node
- local funcArgs
- local defs = vm.getDefs(func)
- for _, def in ipairs(defs) do
- if def.value then
- def = def.value
- end
- if def.type == 'function' then
- local args = countFuncArgs(def)
- if not funcArgs or args > funcArgs then
- funcArgs = args
- end
- end
- end
-
- if not funcArgs then
- return
- end
-
- local delta = callArgs - funcArgs
- if delta <= 0 then
- return
- end
- for i = #source.args - delta + 1, #source.args do
- local arg = source.args[i]
- if arg then
- callback {
- start = arg.start,
- finish = arg.finish,
- tags = { define.DiagnosticTag.Unnecessary },
- message = lang.script('DIAG_OVER_MAX_ARGS', funcArgs, callArgs)
- }
- end
- end
- end)
-end
diff --git a/script-beta/core/diagnostics/redundant-value.lua b/script-beta/core/diagnostics/redundant-value.lua
deleted file mode 100644
index be483448..00000000
--- a/script-beta/core/diagnostics/redundant-value.lua
+++ /dev/null
@@ -1,24 +0,0 @@
-local files = require 'files'
-local define = require 'proto.define'
-local lang = require 'language'
-
-return function (uri, callback, code)
- local ast = files.getAst(uri)
- if not ast then
- return
- end
-
- local diags = ast.diags[code]
- if not diags then
- return
- end
-
- for _, info in ipairs(diags) do
- callback {
- start = info.start,
- finish = info.finish,
- tags = { define.DiagnosticTag.Unnecessary },
- message = lang.script('DIAG_OVER_MAX_VALUES', info.max, info.passed)
- }
- end
-end
diff --git a/script-beta/core/diagnostics/trailing-space.lua b/script-beta/core/diagnostics/trailing-space.lua
deleted file mode 100644
index e54a6e60..00000000
--- a/script-beta/core/diagnostics/trailing-space.lua
+++ /dev/null
@@ -1,55 +0,0 @@
-local files = require 'files'
-local lang = require 'language'
-local guide = require 'parser.guide'
-
-local function isInString(ast, offset)
- local result = false
- guide.eachSourceType(ast, 'string', function (source)
- if offset >= source.start and offset <= source.finish then
- result = true
- end
- end)
- return result
-end
-
-return function (uri, callback)
- local ast = files.getAst(uri)
- if not ast then
- return
- end
- local text = files.getText(uri)
- local lines = files.getLines(uri)
- for i = 1, #lines do
- local start = lines[i].start
- local range = lines[i].range
- local lastChar = text:sub(range, range)
- if lastChar ~= ' ' and lastChar ~= '\t' then
- goto NEXT_LINE
- end
- if isInString(ast.ast, range) then
- goto NEXT_LINE
- end
- local first = start
- for n = range - 1, start, -1 do
- local char = text:sub(n, n)
- if char ~= ' ' and char ~= '\t' then
- first = n + 1
- break
- end
- end
- if first == start then
- callback {
- start = first,
- finish = range,
- message = lang.script.DIAG_LINE_ONLY_SPACE,
- }
- else
- callback {
- start = first,
- finish = range,
- message = lang.script.DIAG_LINE_POST_SPACE,
- }
- end
- ::NEXT_LINE::
- end
-end
diff --git a/script-beta/core/diagnostics/undefined-doc-class.lua b/script-beta/core/diagnostics/undefined-doc-class.lua
deleted file mode 100644
index bbfdceec..00000000
--- a/script-beta/core/diagnostics/undefined-doc-class.lua
+++ /dev/null
@@ -1,46 +0,0 @@
-local files = require 'files'
-local guide = require 'parser.guide'
-local lang = require 'language'
-local define = require 'proto.define'
-local vm = require 'vm'
-
-return function (uri, callback)
- local state = files.getAst(uri)
- if not state then
- return
- end
-
- if not state.ast.docs then
- return
- end
-
- local cache = {}
- for _, doc in ipairs(state.ast.docs) do
- if doc.type == 'doc.class' then
- local ext = doc.extends
- if not ext then
- goto CONTINUE
- end
- local name = ext[1]
- local docs = vm.getDocTypes(name)
- if cache[name] == nil then
- cache[name] = false
- for _, otherDoc in ipairs(docs) do
- if otherDoc.type == 'doc.class.name' then
- cache[name] = true
- break
- end
- end
- end
- if not cache[name] then
- callback {
- start = ext.start,
- finish = ext.finish,
- related = cache,
- message = lang.script('DIAG_UNDEFINED_DOC_CLASS', name)
- }
- end
- end
- ::CONTINUE::
- end
-end
diff --git a/script-beta/core/diagnostics/undefined-doc-name.lua b/script-beta/core/diagnostics/undefined-doc-name.lua
deleted file mode 100644
index 5c1e8fbf..00000000
--- a/script-beta/core/diagnostics/undefined-doc-name.lua
+++ /dev/null
@@ -1,60 +0,0 @@
-local files = require 'files'
-local guide = require 'parser.guide'
-local lang = require 'language'
-local define = require 'proto.define'
-local vm = require 'vm'
-
-local function hasNameOfClassOrAlias(name)
- local docs = vm.getDocTypes(name)
- for _, otherDoc in ipairs(docs) do
- if otherDoc.type == 'doc.class.name'
- or otherDoc.type == 'doc.alias.name' then
- return true
- end
- end
- return false
-end
-
-local function hasNameOfGeneric(name, source)
- if not source.typeGeneric then
- return false
- end
- if not source.typeGeneric[name] then
- return false
- end
- return true
-end
-
-return function (uri, callback)
- local state = files.getAst(uri)
- if not state then
- return
- end
-
- if not state.ast.docs then
- return
- end
-
- guide.eachSource(state.ast.docs, function (source)
- if source.type ~= 'doc.extends.name'
- and source.type ~= 'doc.type.name' then
- return
- end
- if source.parent.type == 'doc.class' then
- return
- end
- local name = source[1]
- if name == '...' then
- return
- end
- if hasNameOfClassOrAlias(name)
- or hasNameOfGeneric(name, source) then
- return
- end
- callback {
- start = source.start,
- finish = source.finish,
- message = lang.script('DIAG_UNDEFINED_DOC_NAME', name)
- }
- end)
-end
diff --git a/script-beta/core/diagnostics/undefined-doc-param.lua b/script-beta/core/diagnostics/undefined-doc-param.lua
deleted file mode 100644
index af3e07bc..00000000
--- a/script-beta/core/diagnostics/undefined-doc-param.lua
+++ /dev/null
@@ -1,52 +0,0 @@
-local files = require 'files'
-local guide = require 'parser.guide'
-local lang = require 'language'
-local define = require 'proto.define'
-local vm = require 'vm'
-
-local function hasParamName(func, name)
- if not func.args then
- return false
- end
- for _, arg in ipairs(func.args) do
- if arg[1] == name then
- return true
- end
- end
- return false
-end
-
-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.param' then
- goto CONTINUE
- end
- local binds = doc.bindSources
- if not binds then
- goto CONTINUE
- end
- local param = doc.param
- local name = param[1]
- for _, source in ipairs(binds) do
- if source.type == 'function' then
- if not hasParamName(source, name) then
- callback {
- start = param.start,
- finish = param.finish,
- message = lang.script('DIAG_UNDEFINED_DOC_PARAM', name)
- }
- end
- end
- end
- ::CONTINUE::
- end
-end
diff --git a/script-beta/core/diagnostics/undefined-env-child.lua b/script-beta/core/diagnostics/undefined-env-child.lua
deleted file mode 100644
index 6b8c62f0..00000000
--- a/script-beta/core/diagnostics/undefined-env-child.lua
+++ /dev/null
@@ -1,27 +0,0 @@
-local files = require 'files'
-local guide = require 'parser.guide'
-local vm = require 'vm'
-local lang = require 'language'
-
-return function (uri, callback)
- local ast = files.getAst(uri)
- if not ast then
- return
- end
- guide.eachSourceType(ast.ast, 'getglobal', function (source)
- -- 单独验证自己是否在重载过的 _ENV 中有定义
- if source.node.tag == '_ENV' then
- return
- end
- local defs = guide.requestDefinition(source)
- if #defs > 0 then
- return
- end
- local key = source[1]
- callback {
- start = source.start,
- finish = source.finish,
- message = lang.script('DIAG_UNDEF_ENV_CHILD', key),
- }
- end)
-end
diff --git a/script-beta/core/diagnostics/undefined-global.lua b/script-beta/core/diagnostics/undefined-global.lua
deleted file mode 100644
index 778fc1f1..00000000
--- a/script-beta/core/diagnostics/undefined-global.lua
+++ /dev/null
@@ -1,40 +0,0 @@
-local files = require 'files'
-local vm = require 'vm'
-local lang = require 'language'
-local config = require 'config'
-local guide = require 'parser.guide'
-
-return function (uri, callback)
- local ast = files.getAst(uri)
- if not ast then
- return
- end
-
- -- 遍历全局变量,检查所有没有 set 模式的全局变量
- guide.eachSourceType(ast.ast, 'getglobal', function (src)
- local key = guide.getName(src)
- if not key then
- return
- end
- if config.config.diagnostics.globals[key] then
- return
- end
- if #vm.getGlobalSets(guide.getKeyName(src)) > 0 then
- return
- end
- local message = lang.script('DIAG_UNDEF_GLOBAL', key)
- -- TODO check other version
- local otherVersion
- local customVersion
- if otherVersion then
- message = ('%s(%s)'):format(message, lang.script('DIAG_DEFINED_VERSION', table.concat(otherVersion, '/'), config.config.runtime.version))
- elseif customVersion then
- message = ('%s(%s)'):format(message, lang.script('DIAG_DEFINED_CUSTOM', table.concat(customVersion, '/')))
- end
- callback {
- start = src.start,
- finish = src.finish,
- message = message,
- }
- end)
-end
diff --git a/script-beta/core/diagnostics/unused-function.lua b/script-beta/core/diagnostics/unused-function.lua
deleted file mode 100644
index f0bca613..00000000
--- a/script-beta/core/diagnostics/unused-function.lua
+++ /dev/null
@@ -1,40 +0,0 @@
-local files = require 'files'
-local guide = require 'parser.guide'
-local vm = require 'vm'
-local define = require 'proto.define'
-local lang = require 'language'
-local await = require 'await'
-
-return function (uri, callback)
- local ast = files.getAst(uri)
- if not ast then
- return
- end
- -- 只检查局部函数
- guide.eachSourceType(ast.ast, 'function', function (source)
- local parent = source.parent
- if not parent then
- return
- end
- if parent.type ~= 'local'
- and parent.type ~= 'setlocal' then
- return
- end
- local hasGet
- local refs = vm.getRefs(source)
- for _, src in ipairs(refs) do
- if vm.isGet(src) then
- hasGet = true
- break
- end
- end
- if not hasGet then
- callback {
- start = source.start,
- finish = source.finish,
- tags = { define.DiagnosticTag.Unnecessary },
- message = lang.script.DIAG_UNUSED_FUNCTION,
- }
- end
- end)
-end
diff --git a/script-beta/core/diagnostics/unused-label.lua b/script-beta/core/diagnostics/unused-label.lua
deleted file mode 100644
index e6d998ba..00000000
--- a/script-beta/core/diagnostics/unused-label.lua
+++ /dev/null
@@ -1,22 +0,0 @@
-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.getAst(uri)
- if not ast then
- return
- end
-
- guide.eachSourceType(ast.ast, 'label', function (source)
- if not source.ref then
- callback {
- start = source.start,
- finish = source.finish,
- tags = { define.DiagnosticTag.Unnecessary },
- message = lang.script('DIAG_UNUSED_LABEL', source[1]),
- }
- end
- end)
-end
diff --git a/script-beta/core/diagnostics/unused-local.lua b/script-beta/core/diagnostics/unused-local.lua
deleted file mode 100644
index 873a70f2..00000000
--- a/script-beta/core/diagnostics/unused-local.lua
+++ /dev/null
@@ -1,93 +0,0 @@
-local files = require 'files'
-local guide = require 'parser.guide'
-local define = require 'proto.define'
-local lang = require 'language'
-
-local function hasGet(loc)
- if not loc.ref then
- return false
- end
- local weak
- for _, ref in ipairs(loc.ref) do
- if ref.type == 'getlocal' then
- if not ref.next then
- return 'strong'
- end
- local nextType = ref.next.type
- if nextType ~= 'setmethod'
- and nextType ~= 'setfield'
- and nextType ~= 'setindex' then
- return 'strong'
- else
- weak = true
- end
- end
- end
- if weak then
- return 'weak'
- else
- return nil
- end
-end
-
-local function isMyTable(loc)
- local value = loc.value
- if value and value.type == 'table' then
- return true
- end
- return false
-end
-
-local function isClose(source)
- if not source.attrs then
- return false
- end
- for _, attr in ipairs(source.attrs) do
- if attr[1] == 'close' then
- return true
- end
- end
- return false
-end
-
-return function (uri, callback)
- local ast = files.getAst(uri)
- if not ast then
- return
- end
- guide.eachSourceType(ast.ast, 'local', function (source)
- local name = source[1]
- if name == '_'
- or name == ast.ENVMode then
- return
- end
- if isClose(source) then
- return
- end
- local data = hasGet(source)
- if data == 'strong' then
- return
- end
- if data == 'weak' then
- if not isMyTable(source) then
- return
- end
- end
- callback {
- start = source.start,
- finish = source.finish,
- tags = { define.DiagnosticTag.Unnecessary },
- message = lang.script('DIAG_UNUSED_LOCAL', name),
- }
- if source.ref then
- for _, ref in ipairs(source.ref) do
- callback {
- start = ref.start,
- finish = ref.finish,
- tags = { define.DiagnosticTag.Unnecessary },
- message = lang.script('DIAG_UNUSED_LOCAL', name),
- }
- end
- end
- end)
-end
diff --git a/script-beta/core/diagnostics/unused-vararg.lua b/script-beta/core/diagnostics/unused-vararg.lua
deleted file mode 100644
index 74cc08e7..00000000
--- a/script-beta/core/diagnostics/unused-vararg.lua
+++ /dev/null
@@ -1,31 +0,0 @@
-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.getAst(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