File tree Expand file tree Collapse file tree 4 files changed +36
-0
lines changed Expand file tree Collapse file tree 4 files changed +36
-0
lines changed Original file line number Diff line number Diff line change @@ -42,6 +42,7 @@ DIAG_COUNT_DOWN_LOOP = 'Do you mean `{}` ?'
4242DIAG_IMPLICIT_ANY = ' Can not infer type.'
4343DIAG_DEPRECATED = ' Deprecated.'
4444DIAG_DIFFERENT_REQUIRES = ' The same file is required with different names.'
45+ DIAG_REDUNDANT_RETURN = ' Redundant return.'
4546
4647DIAG_CIRCLE_DOC_CLASS = ' Circularly inherited classes.'
4748DIAG_DOC_FIELD_NO_CLASS = ' The field must be defined after the class.'
Original file line number Diff line number Diff line change @@ -42,6 +42,7 @@ DIAG_COUNT_DOWN_LOOP = '你的意思是 `{}` 吗?'
4242DIAG_IMPLICIT_ANY = ' 无法推测出类型。'
4343DIAG_DEPRECATED = ' 已废弃。'
4444DIAG_DIFFERENT_REQUIRES = ' 使用了不同的名字 require 了同一个文件。'
45+ DIAG_REDUNDANT_RETURN = ' 冗余返回。'
4546
4647DIAG_CIRCLE_DOC_CLASS = ' 循环继承的类。'
4748DIAG_DOC_FIELD_NO_CLASS = ' 字段必须定义在类之后。'
Original file line number Diff line number Diff line change 1+ local files = require ' files'
2+ local guide = require ' parser.guide'
3+ local lang = require ' language'
4+ local define = require ' proto.define'
5+
6+ -- reports 'return' or 'return nil' at the end of functions
7+ return function (uri , callback )
8+ local ast = files .getState (uri )
9+ if not ast then
10+ return
11+ end
12+
13+ guide .eachSourceType (ast .ast , ' return' , function (source )
14+ if not source .parent or source .parent .type ~= " function" then
15+ return
16+ end
17+ for _ , node in ipairs (source ) do
18+ while node and node .type == " paren" do
19+ node = node .exp
20+ end
21+ if node and (node .type ~= " nil" or # node > 0 ) then
22+ return
23+ end
24+ end
25+ callback {
26+ start = source .start ,
27+ finish = source .finish ,
28+ tags = { define .DiagnosticTag .Unnecessary },
29+ message = lang .script .DIAG_REDUNDANT_RETURN ,
30+ }
31+ end )
32+ end
Original file line number Diff line number Diff line change @@ -29,6 +29,7 @@ m.DiagnosticDefaultSeverity = {
2929 [' newline-call' ] = ' Information' ,
3030 [' newfield-call' ] = ' Warning' ,
3131 [' redundant-parameter' ] = ' Warning' ,
32+ [' redundant-return' ] = ' Warning' ,
3233 [' ambiguity-1' ] = ' Warning' ,
3334 [' lowercase-global' ] = ' Information' ,
3435 [' undefined-env-child' ] = ' Information' ,
@@ -82,6 +83,7 @@ m.DiagnosticDefaultNeededFileStatus = {
8283 [' newline-call' ] = ' Any' ,
8384 [' newfield-call' ] = ' Any' ,
8485 [' redundant-parameter' ] = ' Opened' ,
86+ [' redundant-return' ] = ' Opened' ,
8587 [' ambiguity-1' ] = ' Any' ,
8688 [' lowercase-global' ] = ' Any' ,
8789 [' undefined-env-child' ] = ' Any' ,
You can’t perform that action at this time.
0 commit comments