summaryrefslogtreecommitdiff
path: root/script/core/diagnostics/no-implicit-any.lua
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2021-02-23 19:31:48 +0800
committer最萌小汐 <sumneko@hotmail.com>2021-02-23 19:31:48 +0800
commit63396ada5c7d2037ec19ed45e99e1a56f23c590b (patch)
tree9a1beb761861b8628cd86715aee4a5040f6f3b3b /script/core/diagnostics/no-implicit-any.lua
parent54876cb601466c409eb0be1af489c7ceca7f22cf (diff)
downloadlua-language-server-63396ada5c7d2037ec19ed45e99e1a56f23c590b.zip
close #328 new diagnostic: `no-implicit-any`
Diffstat (limited to 'script/core/diagnostics/no-implicit-any.lua')
-rw-r--r--script/core/diagnostics/no-implicit-any.lua32
1 files changed, 32 insertions, 0 deletions
diff --git a/script/core/diagnostics/no-implicit-any.lua b/script/core/diagnostics/no-implicit-any.lua
new file mode 100644
index 00000000..a2062b37
--- /dev/null
+++ b/script/core/diagnostics/no-implicit-any.lua
@@ -0,0 +1,32 @@
+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.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