From 07d99d97c0612608829d001b80773b1619de9a90 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=80=E8=90=8C=E5=B0=8F=E6=B1=90?= Date: Thu, 3 Dec 2020 16:49:43 +0800 Subject: unbalanced-assignments --- script/core/diagnostics/unbalanced-assignments.lua | 43 ++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 script/core/diagnostics/unbalanced-assignments.lua (limited to 'script/core/diagnostics') diff --git a/script/core/diagnostics/unbalanced-assignments.lua b/script/core/diagnostics/unbalanced-assignments.lua new file mode 100644 index 00000000..35aebb45 --- /dev/null +++ b/script/core/diagnostics/unbalanced-assignments.lua @@ -0,0 +1,43 @@ +local files = require 'files' +local define = require 'proto.define' +local lang = require 'language' +local guide = require 'parser.guide' + +return function (uri, callback, code) + local ast = files.getAst(uri) + if not ast then + return + end + + local last + + local function checkSet(source) + if source.value then + last = source + else + if not last then + return + end + if last.start <= source.start + and last.value.start >= source.finish then + callback { + start = source.start, + finish = source.finish, + message = lang.script('DIAG_UNBALANCED_ASSIGNMENTS') + } + else + last = nil + end + end + end + + guide.eachSource(ast.ast, function (source) + if source.type == 'local' + or source.type == 'setlocal' + or source.type == 'setglobal' + or source.type == 'setfield' + or source.type == 'setindex' then + checkSet(source) + end + end) +end -- cgit v1.2.3