Skip to content

Commit 7dc8713

Browse files
committed
feat(diagnostics): add missing local doc implementation for english
1 parent e13aa5c commit 7dc8713

File tree

7 files changed

+61
-0
lines changed

7 files changed

+61
-0
lines changed

doc/en-us/config.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,7 @@ Array<string>
314314
* ``"miss-symbol"``
315315
* ``"missing-fields"``
316316
* ``"missing-global-doc"``
317+
* ``"missing-local-doc"``
317318
* ``"missing-local-export-doc"``
318319
* ``"missing-parameter"``
319320
* ``"missing-return"``
@@ -504,6 +505,7 @@ object<string, string>
504505
* duplicate-doc-param
505506
* incomplete-signature-doc
506507
* missing-global-doc
508+
* missing-local-doc
507509
* missing-local-export-doc
508510
* undefined-doc-class
509511
* undefined-doc-name
@@ -633,6 +635,7 @@ object<string, string>
633635
* duplicate-doc-param
634636
* incomplete-signature-doc
635637
* missing-global-doc
638+
* missing-local-doc
636639
* missing-local-export-doc
637640
* undefined-doc-class
638641
* undefined-doc-name
@@ -870,6 +873,10 @@ object<string, string>
870873
*/
871874
"missing-global-doc": "None",
872875
/*
876+
Missing annotations for locals! Local functions must have a comment and annotations for all parameters and return values.
877+
*/
878+
"missing-local-export-doc": "None",
879+
/*
873880
Missing annotations for exported locals! Exported local functions must have a comment and annotations for all parameters and return values.
874881
*/
875882
"missing-local-export-doc": "None",

locale/en-us/script.lua

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,12 @@ DIAG_MISSING_GLOBAL_DOC_PARAM =
126126
'Missing @param annotation for parameter `{}` in global function `{}`.'
127127
DIAG_MISSING_GLOBAL_DOC_RETURN =
128128
'Missing @return annotation at index `{}` in global function `{}`.'
129+
DIAG_MISSING_LOCAL_DOC_COMMENT =
130+
'Missing comment for local function `{}`.'
131+
DIAG_MISSING_LOCAL_DOC_PARAM =
132+
'Missing @param annotation for parameter `{}` in local function `{}`.'
133+
DIAG_MISSING_LOCAL_DOC_RETURN =
134+
'Missing @return annotation at index `{}` in local function `{}`.'
129135
DIAG_MISSING_LOCAL_EXPORT_DOC_COMMENT =
130136
'Missing comment for exported local function `{}`.'
131137
DIAG_MISSING_LOCAL_EXPORT_DOC_PARAM =

locale/en-us/setting.lua

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -411,6 +411,8 @@ config.diagnostics['invisible'] =
411411
'Enable diagnostics for accesses to fields which are invisible.'
412412
config.diagnostics['missing-global-doc'] =
413413
'Missing annotations for globals! Global functions must have a comment and annotations for all parameters and return values.'
414+
config.diagnostics['missing-local-doc'] =
415+
'Missing annotations for locals! Local functions must have a comment and annotations for all parameters and return values.'
414416
config.diagnostics['missing-local-export-doc'] =
415417
'Missing annotations for exported locals! Exported local functions must have a comment and annotations for all parameters and return values.'
416418
config.diagnostics['missing-parameter'] =
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
local files = require 'files'
2+
local guide = require 'parser.guide'
3+
local await = require 'await'
4+
local helper = require 'core.diagnostics.helper.missing-doc-helper'
5+
6+
---@async
7+
return function (uri, callback)
8+
local state = files.getState(uri)
9+
10+
if not state then
11+
return
12+
end
13+
14+
if not state.ast then
15+
return
16+
end
17+
18+
---@async
19+
guide.eachSourceType(state.ast, 'function', function (source)
20+
await.delay()
21+
22+
if source.parent.type ~= 'local' then return end
23+
24+
helper.CheckFunction(source, callback, 'DIAG_MISSING_LOCAL_DOC_COMMENT', 'DIAG_MISSING_LOCAL_DOC_PARAM',
25+
'DIAG_MISSING_LOCAL_DOC_RETURN')
26+
end)
27+
end

script/proto/diagnostic.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ m.register {
106106
m.register {
107107
'incomplete-signature-doc',
108108
'missing-global-doc',
109+
'missing-local-doc',
109110
'missing-local-export-doc',
110111
} {
111112
group = 'luadoc',

test/diagnostics/init.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ check 'invisible'
101101
check 'lowercase-global'
102102
check 'missing-fields'
103103
check 'missing-global-doc'
104+
check 'missing-local-doc'
104105
check 'missing-local-export-doc'
105106
check 'missing-parameter'
106107
check 'missing-return-value'
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
TEST [[
2+
local <!function fl0()
3+
end!>
4+
5+
---comment
6+
local function fl1()
7+
end
8+
]]
9+
10+
TEST [[
11+
local function fl0(<!p!>)
12+
end
13+
14+
---@param p integer
15+
local function fl1(p)
16+
end
17+
]]

0 commit comments

Comments
 (0)