From 27cfa2e23648b015a94fab6e0938ec42a5a040e5 Mon Sep 17 00:00:00 2001 From: AndreaWalchshoferSCCH <122894794+AndreaWalchshoferSCCH@users.noreply.github.com> Date: Tue, 4 Apr 2023 11:02:59 +0200 Subject: Add diagnostic to enforce lowercase local element names (#6) - diagnostic `uppercase-local` in group `conventions`, disabled by default - isolated unit tests for diagnostic --- doc/en-us/config.md | 15 ++++++- doc/pt-br/config.md | 15 ++++++- doc/zh-cn/config.md | 15 ++++++- doc/zh-tw/config.md | 15 ++++++- locale/en-us/script.lua | 5 ++- locale/en-us/setting.lua | 6 ++- locale/pt-br/script.lua | 4 +- locale/pt-br/setting.lua | 6 ++- locale/zh-cn/script.lua | 4 +- locale/zh-cn/setting.lua | 6 ++- locale/zh-tw/script.lua | 4 +- locale/zh-tw/setting.lua | 6 ++- script/core/diagnostics/uppercase-local.lua | 47 ++++++++++++++++++++ script/proto/diagnostic.lua | 1 + test/diagnostics/init.lua | 1 + test/diagnostics/uppercase-local.lua | 66 +++++++++++++++++++++++++++++ 16 files changed, 196 insertions(+), 20 deletions(-) create mode 100644 script/core/diagnostics/uppercase-local.lua create mode 100644 test/diagnostics/uppercase-local.lua diff --git a/doc/en-us/config.md b/doc/en-us/config.md index b180c25d..9e6fa64c 100644 --- a/doc/en-us/config.md +++ b/doc/en-us/config.md @@ -329,6 +329,7 @@ Array * ``"unused-label"`` * ``"unused-local"`` * ``"unused-vararg"`` +* ``"uppercase-local"`` ## default @@ -470,6 +471,7 @@ object "strict": "Fallback", /* * global-element + * uppercase-local */ "conventions": "None", /* @@ -593,6 +595,7 @@ object "strict": "Fallback", /* * global-element + * uppercase-local */ "conventions": "Fallback", /* @@ -926,7 +929,11 @@ object /* Enable unused vararg diagnostics. */ - "unused-vararg": "Opened" + "unused-vararg": "Opened", + /* + Enable diagnostics to warn about local element names starting with an uppercase letter. + */ + "uppercase-local": "None" } ``` @@ -1178,7 +1185,11 @@ object /* Enable unused vararg diagnostics. */ - "unused-vararg": "Hint" + "unused-vararg": "Hint", + /* + Enable diagnostics to warn about local element names starting with an uppercase letter. + */ + "uppercase-local": "Warning" } ``` diff --git a/doc/pt-br/config.md b/doc/pt-br/config.md index a0054531..6e2f58a0 100644 --- a/doc/pt-br/config.md +++ b/doc/pt-br/config.md @@ -329,6 +329,7 @@ Array * ``"unused-label"`` * ``"unused-local"`` * ``"unused-vararg"`` +* ``"uppercase-local"`` ## default @@ -470,6 +471,7 @@ object "strict": "Fallback", /* * global-element + * uppercase-local */ "conventionss": "None", /* @@ -593,6 +595,7 @@ object "strict": "Fallback", /* * global-element + * uppercase-local */ "conventionss": "Fallback", /* @@ -926,7 +929,11 @@ object /* 未使用的不定参数 */ - "unused-vararg": "Opened" + "unused-vararg": "Opened", + /* + Enable diagnostics to warn about local element names starting with an uppercase letter. + */ + "uppercase-local": "None" } ``` @@ -1178,7 +1185,11 @@ object /* 未使用的不定参数 */ - "unused-vararg": "Hint" + "unused-vararg": "Hint", + /* + Enable diagnostics to warn about local element names starting with an uppercase letter. + */ + "uppercase-local": "Warning" } ``` diff --git a/doc/zh-cn/config.md b/doc/zh-cn/config.md index 7698ac42..1cacfed3 100644 --- a/doc/zh-cn/config.md +++ b/doc/zh-cn/config.md @@ -329,6 +329,7 @@ Array * ``"unused-label"`` * ``"unused-local"`` * ``"unused-vararg"`` +* ``"uppercase-local"`` ## default @@ -470,6 +471,7 @@ object "strict": "Fallback", /* * global-element + * uppercase-local */ "conventions": "None", /* @@ -593,6 +595,7 @@ object "strict": "Fallback", /* * global-element + * uppercase-local */ "conventions": "Fallback", /* @@ -926,7 +929,11 @@ object /* 未使用的不定参数 */ - "unused-vararg": "Opened" + "unused-vararg": "Opened", + /* + Enable diagnostics to warn about local element names starting with an uppercase letter. + */ + "uppercase-local": "None" } ``` @@ -1177,7 +1184,11 @@ object /* 未使用的不定参数 */ - "unused-vararg": "Hint" + "unused-vararg": "Hint", + /* + Enable diagnostics to warn about local element names starting with an uppercase letter. + */ + "uppercase-local": "Warning" } ``` diff --git a/doc/zh-tw/config.md b/doc/zh-tw/config.md index 30e6b20b..78e565f2 100644 --- a/doc/zh-tw/config.md +++ b/doc/zh-tw/config.md @@ -329,6 +329,7 @@ Array * ``"unused-label"`` * ``"unused-local"`` * ``"unused-vararg"`` +* ``"uppercase-local"`` ## default @@ -470,6 +471,7 @@ object "strict": "Fallback", /* * global-element + * uppercase-local */ "convention": "None", /* @@ -593,6 +595,7 @@ object "strict": "Fallback", /* * global-element + * uppercase-local */ "convention": "Fallback", /* @@ -926,7 +929,11 @@ object /* 未使用的不定引數 */ - "unused-vararg": "Opened" + "unused-vararg": "Opened", + /* + Enable diagnostics to warn about local element names starting with an uppercase letter. + */ + "uppercase-local": "None" } ``` @@ -1177,7 +1184,11 @@ object /* 未使用的不定引數 */ - "unused-vararg": "Hint" + "unused-vararg": "Hint", + /* + Enable diagnostics to warn about local element names starting with an uppercase letter. + */ + "uppercase-local": "Warning" } ``` diff --git a/locale/en-us/script.lua b/locale/en-us/script.lua index 2a13214f..e7f4b98b 100644 --- a/locale/en-us/script.lua +++ b/locale/en-us/script.lua @@ -150,8 +150,11 @@ DIAG_INVISIBLE_PROTECTED = 'Field `{field}` is protected, it can only be accessed in class `{class}` and its subclasses.' DIAG_INVISIBLE_PACKAGE = 'Field `{field}` can only be accessed in same file `{uri}`.' -DIAG_GLOBAL_ELEMENT = +DIAG_GLOBAL_ELEMENT = 'Element is global.' +DIAG_UPPERCASE_LOCAL = +'Local element `{}` must start with lowercase letter' + MWS_NOT_SUPPORT = '{} does not support multi workspace for now, I may need to restart to support the new workspace ...' diff --git a/locale/en-us/setting.lua b/locale/en-us/setting.lua index 9f606cd7..b03e3e43 100644 --- a/locale/en-us/setting.lua +++ b/locale/en-us/setting.lua @@ -415,8 +415,10 @@ config.diagnostics['unknown-operator'] = 'Enable diagnostics for unknown operators.' config.diagnostics['unreachable-code'] = 'Enable diagnostics for unreachable code.' -config.diagnostics['global-element'] = -'Enable diagnostics to warn about global elements.' +config.diagnostics['global-element'] = +'Enable diagnostics to warn about global variables.' +config.diagnostics['uppercase-local'] = +'Enable diagnostics to warn about local element names starting with an uppercase letter.' config.typeFormat.config = 'Configures the formatting behavior while typing Lua code.' config.typeFormat.config.auto_complete_end = diff --git a/locale/pt-br/script.lua b/locale/pt-br/script.lua index affcd893..6497c520 100644 --- a/locale/pt-br/script.lua +++ b/locale/pt-br/script.lua @@ -150,8 +150,10 @@ DIAG_INVISIBLE_PROTECTED = -- TODO: need translate! 'Field `{field}` is protected, it can only be accessed in class `{class}` and its subclasses.' DIAG_INVISIBLE_PACKAGE = -- TODO: need translate! 'Field `{field}` can only be accessed in same file `{uri}`.' -DIAG_GLOBAL_ELEMENT = -- TODO: need translate! +DIAG_GLOBAL_ELEMENT = -- TODO: need translate! 'Element is global.' +DIAG_UPPERCASE_LOCAL = -- TODO: need translate! +'Local element `{}` must start with lowercase letter' MWS_NOT_SUPPORT = '{} não é suportado múltiplos espaços de trabalho por enquanto, posso precisar reiniciar para estabelecer um novo espaço de trabalho ...' diff --git a/locale/pt-br/setting.lua b/locale/pt-br/setting.lua index 95f26b76..ec94f575 100644 --- a/locale/pt-br/setting.lua +++ b/locale/pt-br/setting.lua @@ -415,8 +415,10 @@ config.diagnostics['unknown-operator'] = -- TODO: need translate! 'Enable diagnostics for unknown operators.' config.diagnostics['unreachable-code'] = -- TODO: need translate! 'Enable diagnostics for unreachable code.' -config.diagnostics['global-element'] = -- TODO: need translate! -'Enable diagnostics to warn about global elements.' +config.diagnostics['global-element'] = -- TODO: need translate! +'Enable diagnostics to warn about global variables.' +config.diagnostics['uppercase-local'] = -- TODO: need translate! +'Enable diagnostics to warn about local element names starting with an uppercase letter.' config.typeFormat.config = -- TODO: need translate! 'Configures the formatting behavior while typing Lua code.' config.typeFormat.config.auto_complete_end = -- TODO: need translate! diff --git a/locale/zh-cn/script.lua b/locale/zh-cn/script.lua index f6f639ea..da817698 100644 --- a/locale/zh-cn/script.lua +++ b/locale/zh-cn/script.lua @@ -150,8 +150,10 @@ DIAG_INVISIBLE_PROTECTED = '字段 `{field}` 受到保护,只能在 `{class}` 类极其子类中才能访问。' DIAG_INVISIBLE_PACKAGE = '字段 `{field}` 只能在相同的文件 `{uri}` 中才能访问。' -DIAG_GLOBAL_ELEMENT = -- TODO: need translate! +DIAG_GLOBAL_ELEMENT = -- TODO: need translate! 'Element is global.' +DIAG_UPPERCASE_LOCAL = -- TODO: need translate! +'Local element `{}` must start with lowercase letter' MWS_NOT_SUPPORT = '{} 目前还不支持多工作目录,我可能需要重启才能支持新的工作目录...' diff --git a/locale/zh-cn/setting.lua b/locale/zh-cn/setting.lua index 731190e2..e1eb7de9 100644 --- a/locale/zh-cn/setting.lua +++ b/locale/zh-cn/setting.lua @@ -414,8 +414,10 @@ config.diagnostics['unknown-operator'] = -- TODO: need translate! 'Enable diagnostics for unknown operators.' config.diagnostics['unreachable-code'] = -- TODO: need translate! 'Enable diagnostics for unreachable code.' -config.diagnostics['global-element'] = -- TODO: need translate! -'Enable diagnostics to warn about global elements.' +config.diagnostics['global-element'] = -- TODO: need translate! +'Enable diagnostics to warn about global variables.' +config.diagnostics['uppercase-local'] = -- TODO: need translate! +'Enable diagnostics to warn about local element names starting with an uppercase letter.' config.typeFormat.config = -- TODO: need translate! 'Configures the formatting behavior while typing Lua code.' config.typeFormat.config.auto_complete_end = -- TODO: need translate! diff --git a/locale/zh-tw/script.lua b/locale/zh-tw/script.lua index 4d9a89ad..77ff6fea 100644 --- a/locale/zh-tw/script.lua +++ b/locale/zh-tw/script.lua @@ -150,8 +150,10 @@ DIAG_INVISIBLE_PROTECTED = -- TODO: need translate! 'Field `{field}` is protected, it can only be accessed in class `{class}` and its subclasses.' DIAG_INVISIBLE_PACKAGE = -- TODO: need translate! 'Field `{field}` can only be accessed in same file `{uri}`.' -DIAG_GLOBAL_ELEMENT = -- TODO: need translate! +DIAG_GLOBAL_ELEMENT = -- TODO: need translate! 'Element is global.' +DIAG_UPPERCASE_LOCAL = -- TODO: need translate! +'Local element `{}` must start with lowercase letter' MWS_NOT_SUPPORT = '{} 目前還不支援多工作目錄,我可能需要重新啟動才能支援新的工作目錄...' diff --git a/locale/zh-tw/setting.lua b/locale/zh-tw/setting.lua index fd363d3f..ebf615ac 100644 --- a/locale/zh-tw/setting.lua +++ b/locale/zh-tw/setting.lua @@ -414,8 +414,10 @@ config.diagnostics['unknown-operator'] = -- TODO: need translate! 'Enable diagnostics for unknown operators.' config.diagnostics['unreachable-code'] = -- TODO: need translate! 'Enable diagnostics for unreachable code.' -config.diagnostics['global-element'] = -- TODO: need translate! -'Enable diagnostics to warn about global elements.' +config.diagnostics['global-element'] = -- TODO: need translate! +'Enable diagnostics to warn about global variables.' +config.diagnostics['uppercase-local'] = -- TODO: need translate! +'Enable diagnostics to warn about local element names starting with an uppercase letter.' config.typeFormat.config = -- TODO: need translate! 'Configures the formatting behavior while typing Lua code.' config.typeFormat.config.auto_complete_end = -- TODO: need translate! diff --git a/script/core/diagnostics/uppercase-local.lua b/script/core/diagnostics/uppercase-local.lua new file mode 100644 index 00000000..cc377dd2 --- /dev/null +++ b/script/core/diagnostics/uppercase-local.lua @@ -0,0 +1,47 @@ +local files = require 'files' +local guide = require 'parser.guide' +local lang = require 'language' + +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 + +-- If local elements must be named lowercase by coding convention, this diagnostic helps with reminding about that +return function (uri, callback) + local ast = files.getState(uri) + if not ast then + return + end + + guide.eachSourceType(ast.ast, 'local', function (source) + local name = guide.getKeyName(source) + if not name then + return + end + local first = name:match '%w' -- alphanumeric character + if not first then + return + end + if not first:match '%u' then -- uppercase + return + end + -- If the assignment is marked as doc.class, then it is considered allowed + if isDocClass(source) then + return + end + + callback { + start = source.start, + finish = source.finish, + message = lang.script('DIAG_UPPERCASE_LOCAL', name), + } + end) +end diff --git a/script/proto/diagnostic.lua b/script/proto/diagnostic.lua index 24ab0814..48a9094c 100644 --- a/script/proto/diagnostic.lua +++ b/script/proto/diagnostic.lua @@ -173,6 +173,7 @@ m.register { m.register { 'global-element', + 'uppercase-local', } { group = 'conventions', severity = 'Warning', diff --git a/test/diagnostics/init.lua b/test/diagnostics/init.lua index c12bfca6..5e8abf7d 100644 --- a/test/diagnostics/init.lua +++ b/test/diagnostics/init.lua @@ -87,3 +87,4 @@ end require 'diagnostics.common' require 'diagnostics.type-check' require 'diagnostics.global-element' +require 'diagnostics.uppercase-local' diff --git a/test/diagnostics/uppercase-local.lua b/test/diagnostics/uppercase-local.lua new file mode 100644 index 00000000..fc0b95d1 --- /dev/null +++ b/test/diagnostics/uppercase-local.lua @@ -0,0 +1,66 @@ +local config = require 'config' +local util = require 'utility' + +-- disable all default groups to make isolated tests +config.set(nil, 'Lua.diagnostics.groupFileStatus', +{ + ['ambiguity'] = 'None', + ['await'] = 'None', + ['codestyle'] = 'None', + ['conventions'] = 'None', + ['duplicate'] = 'None', + ['global'] = 'None', + ['luadoc'] = 'None', + ['redefined'] = 'None', + ['strict'] = 'None', + ['strong'] = 'None', + ['type-check'] = 'None', + ['unbalanced'] = 'None', + ['unused'] = 'None' +}) + +-- enable single diagnostic that is to be tested +config.set(nil, 'Lua.diagnostics.neededFileStatus', +{ + ['uppercase-local'] = 'Any!' -- override groupFileStatus +}) + +-- check that global elements are not warned about +TEST [[ +Var1 = "global" +VAR2 = "global" + +local x = true +local = false +local = false +]] + +TEST [[ +local function test1() + print() +end + +local function () + print() +end +]] + +TEST [[ +local function closure1() + local elem1 = 1 + local = 2 +end + +local function () + local elem1 = 1 + local = 2 +end +]] + +-- reset configurations +config.set(nil, 'Lua.diagnostics.groupFileStatus', +{}) +config.set(nil, 'Lua.diagnostics.neededFileStatus', +{}) +config.set(nil, 'Lua.diagnostics.globals', +{}) -- cgit v1.2.3 From be232fcf95aab66d751b5dbaff9ccaf06299cc8e Mon Sep 17 00:00:00 2001 From: Thomas Wetzlmaier Date: Wed, 19 Apr 2023 16:49:35 +0200 Subject: Warn about missing '---comment', '@return' and '@param' annotations (#3) All functions that have at least one such annotation should be fully annotated in that respect, because we find that partially annotating something leads to confusion. However, all global functions must always be fully annotated, because they should be avoided in the first place, but if necessary then only with the maximum amount of documentation/support for those who use them! We provide the following keys for the `diagnostics.disable` setting to specifically deactive these checks: _missing-global-doc_: global function definitions which are not fully annotated. _incomplete-signature-doc_: function definitions that have some annotations but are not fully annotated --- doc/en-us/config.md | 22 ++ doc/pt-br/config.md | 21 ++ doc/zh-cn/config.md | 22 ++ doc/zh-tw/config.md | 22 ++ locale/en-us/script.lua | 10 + locale/en-us/setting.lua | 4 + locale/pt-br/script.lua | 12 +- locale/pt-br/setting.lua | 4 + locale/zh-cn/script.lua | 10 + locale/zh-cn/setting.lua | 4 + locale/zh-tw/script.lua | 10 + locale/zh-tw/setting.lua | 4 + .../core/diagnostics/incomplete-signature-doc.lua | 91 ++++++ script/core/diagnostics/missing-global-doc.lua | 98 ++++++ script/proto/diagnostic.lua | 9 + test/diagnostics/incomplete-signature-doc.lua | 331 ++++++++++++++++++++ test/diagnostics/init.lua | 3 + test/diagnostics/missing-global-doc.lua | 333 +++++++++++++++++++++ 18 files changed, 1009 insertions(+), 1 deletion(-) create mode 100644 script/core/diagnostics/incomplete-signature-doc.lua create mode 100644 script/core/diagnostics/missing-global-doc.lua create mode 100644 test/diagnostics/incomplete-signature-doc.lua create mode 100644 test/diagnostics/missing-global-doc.lua diff --git a/doc/en-us/config.md b/doc/en-us/config.md index 9e6fa64c..4319901c 100644 --- a/doc/en-us/config.md +++ b/doc/en-us/config.md @@ -240,6 +240,7 @@ Array * ``"exp-in-action"`` * ``"global-element"`` * ``"global-in-nil-env"`` +* ``"incomplete-signature-doc"`` * ``"index-in-func-name"`` * ``"invisible"`` * ``"jump-local-scope"`` @@ -284,6 +285,7 @@ Array * ``"miss-sep-in-table"`` * ``"miss-space-between"`` * ``"miss-symbol"`` +* ``"missing-global-doc"`` * ``"missing-parameter"`` * ``"missing-return"`` * ``"missing-return-value"`` @@ -450,6 +452,8 @@ object * duplicate-doc-alias * duplicate-doc-field * duplicate-doc-param + * incomplete-signature-doc + * missing-global-doc * undefined-doc-class * undefined-doc-name * undefined-doc-param @@ -574,6 +578,8 @@ object * duplicate-doc-alias * duplicate-doc-field * duplicate-doc-param + * incomplete-signature-doc + * missing-global-doc * undefined-doc-class * undefined-doc-name * undefined-doc-param @@ -795,6 +801,10 @@ object */ "global-in-nil-env": "Any", /* + Enable diagnostics for function definitions which are not fully annotated. + */ + "incomplete-signature-doc": "None", + /* Enable diagnostics for accesses to fields which are invisible. */ "invisible": "Any", @@ -803,6 +813,10 @@ object */ "lowercase-global": "Any", /* + Enable diagnostics for global function definitions which are not fully annotated. + */ + "missing-global-doc": "None", + /* Enable diagnostics for function calls where the number of arguments is less than the number of annotated function parameters. */ "missing-parameter": "Any", @@ -1051,6 +1065,10 @@ object */ "global-in-nil-env": "Warning", /* + Enable diagnostics for function definitions which are not fully annotated. + */ + "incomplete-signature-doc": "Warning", + /* Enable diagnostics for accesses to fields which are invisible. */ "invisible": "Warning", @@ -1059,6 +1077,10 @@ object */ "lowercase-global": "Information", /* + Enable diagnostics for global function definitions which are not annotated. + */ + "missing-global-doc": "Warning", + /* Enable diagnostics for function calls where the number of arguments is less than the number of annotated function parameters. */ "missing-parameter": "Warning", diff --git a/doc/pt-br/config.md b/doc/pt-br/config.md index 6e2f58a0..c3ab1107 100644 --- a/doc/pt-br/config.md +++ b/doc/pt-br/config.md @@ -240,6 +240,7 @@ Array * ``"exp-in-action"`` * ``"global-element"`` * ``"global-in-nil-env"`` +* ``"incomplete-signature-doc"`` * ``"index-in-func-name"`` * ``"invisible"`` * ``"jump-local-scope"`` @@ -284,6 +285,7 @@ Array * ``"miss-sep-in-table"`` * ``"miss-space-between"`` * ``"miss-symbol"`` +* ``"missing-global-doc"`` * ``"missing-parameter"`` * ``"missing-return"`` * ``"missing-return-value"`` @@ -450,6 +452,8 @@ object * duplicate-doc-alias * duplicate-doc-field * duplicate-doc-param + * incomplete-signature-doc + * missing-global-doc * undefined-doc-class * undefined-doc-name * undefined-doc-param @@ -574,6 +578,7 @@ object * duplicate-doc-alias * duplicate-doc-field * duplicate-doc-param + * incomplete-signature-doc * undefined-doc-class * undefined-doc-name * undefined-doc-param @@ -795,6 +800,10 @@ object */ "global-in-nil-env": "Any", /* + Enable diagnostics for function definitions which are not fully annotated. + */ + "incomplete-signature-doc": "None", + /* Enable diagnostics for accesses to fields which are invisible. */ "invisible": "Any", @@ -803,6 +812,10 @@ object */ "lowercase-global": "Any", /* + Enable diagnostics for global function definitions which are not fully annotated. + */ + "missing-global-doc": "None", + /* Enable diagnostics for function calls where the number of arguments is less than the number of annotated function parameters. */ "missing-parameter": "Any", @@ -1051,6 +1064,10 @@ object */ "global-in-nil-env": "Warning", /* + Enable diagnostics for function definitions which are not fully annotated. + */ + "incomplete-signature-doc": "Warning", + /* Enable diagnostics for accesses to fields which are invisible. */ "invisible": "Warning", @@ -1059,6 +1076,10 @@ object */ "lowercase-global": "Information", /* + Enable diagnostics for global function definitions which are not annotated. + */ + "missing-global-doc": "Warning", + /* Enable diagnostics for function calls where the number of arguments is less than the number of annotated function parameters. */ "missing-parameter": "Warning", diff --git a/doc/zh-cn/config.md b/doc/zh-cn/config.md index 1cacfed3..32a6db68 100644 --- a/doc/zh-cn/config.md +++ b/doc/zh-cn/config.md @@ -240,6 +240,7 @@ Array * ``"exp-in-action"`` * ``"global-element"`` * ``"global-in-nil-env"`` +* ``"incomplete-signature-doc"`` * ``"index-in-func-name"`` * ``"invisible"`` * ``"jump-local-scope"`` @@ -284,6 +285,7 @@ Array * ``"miss-sep-in-table"`` * ``"miss-space-between"`` * ``"miss-symbol"`` +* ``"missing-global-doc"`` * ``"missing-parameter"`` * ``"missing-return"`` * ``"missing-return-value"`` @@ -450,6 +452,8 @@ object * duplicate-doc-alias * duplicate-doc-field * duplicate-doc-param + * incomplete-signature-doc + * missing-global-doc * undefined-doc-class * undefined-doc-name * undefined-doc-param @@ -574,6 +578,8 @@ object * duplicate-doc-alias * duplicate-doc-field * duplicate-doc-param + * incomplete-signature-doc + * missing-global-doc * undefined-doc-class * undefined-doc-name * undefined-doc-param @@ -795,6 +801,10 @@ object */ "global-in-nil-env": "Any", /* + Enable diagnostics for function definitions which are not fully annotated. + */ + "incomplete-signature-doc": "None", + /* Enable diagnostics for accesses to fields which are invisible. */ "invisible": "Any", @@ -803,6 +813,10 @@ object */ "lowercase-global": "Any", /* + Enable diagnostics for global function definitions which are not fully annotated. + */ + "missing-global-doc": "None", + /* Enable diagnostics for function calls where the number of arguments is less than the number of annotated function parameters. */ "missing-parameter": "Any", @@ -1050,6 +1064,10 @@ object */ "global-in-nil-env": "Warning", /* + Enable diagnostics for function definitions which are not fully annotated. + */ + "incomplete-signature-doc": "Warning", + /* Enable diagnostics for accesses to fields which are invisible. */ "invisible": "Warning", @@ -1058,6 +1076,10 @@ object */ "lowercase-global": "Information", /* + Enable diagnostics for global function definitions which are not annotated. + */ + "missing-global-doc": "Warning", + /* Enable diagnostics for function calls where the number of arguments is less than the number of annotated function parameters. */ "missing-parameter": "Warning", diff --git a/doc/zh-tw/config.md b/doc/zh-tw/config.md index 78e565f2..bc9dae01 100644 --- a/doc/zh-tw/config.md +++ b/doc/zh-tw/config.md @@ -240,6 +240,7 @@ Array * ``"exp-in-action"`` * ``"global-element"`` * ``"global-in-nil-env"`` +* ``"incomplete-signature-doc"`` * ``"index-in-func-name"`` * ``"invisible"`` * ``"jump-local-scope"`` @@ -284,6 +285,7 @@ Array * ``"miss-sep-in-table"`` * ``"miss-space-between"`` * ``"miss-symbol"`` +* ``"missing-global-doc"`` * ``"missing-parameter"`` * ``"missing-return"`` * ``"missing-return-value"`` @@ -450,6 +452,8 @@ object * duplicate-doc-alias * duplicate-doc-field * duplicate-doc-param + * incomplete-signature-doc + * missing-global-doc * undefined-doc-class * undefined-doc-name * undefined-doc-param @@ -574,6 +578,8 @@ object * duplicate-doc-alias * duplicate-doc-field * duplicate-doc-param + * incomplete-signature-doc + * missing-global-doc * undefined-doc-class * undefined-doc-name * undefined-doc-param @@ -795,6 +801,10 @@ object */ "global-in-nil-env": "Any", /* + Enable diagnostics for function definitions which are not fully annotated. + */ + "incomplete-signature-doc": "None", + /* Enable diagnostics for accesses to fields which are invisible. */ "invisible": "Any", @@ -803,6 +813,10 @@ object */ "lowercase-global": "Any", /* + Enable diagnostics for global function definitions which are not fully annotated. + */ + "missing-global-doc": "None", + /* Enable diagnostics for function calls where the number of arguments is less than the number of annotated function parameters. */ "missing-parameter": "Any", @@ -1050,6 +1064,10 @@ object */ "global-in-nil-env": "Warning", /* + Enable diagnostics for function definitions which are not fully annotated. + */ + "incomplete-signature-doc": "Warning", + /* Enable diagnostics for accesses to fields which are invisible. */ "invisible": "Warning", @@ -1058,6 +1076,10 @@ object */ "lowercase-global": "Information", /* + Enable diagnostics for global function definitions which are not annotated. + */ + "missing-global-doc": "Warning", + /* Enable diagnostics for function calls where the number of arguments is less than the number of annotated function parameters. */ "missing-parameter": "Warning", diff --git a/locale/en-us/script.lua b/locale/en-us/script.lua index e7f4b98b..6742b784 100644 --- a/locale/en-us/script.lua +++ b/locale/en-us/script.lua @@ -114,6 +114,16 @@ DIAG_UNDEFINED_DOC_NAME = 'Undefined type or alias `{}`.' DIAG_UNDEFINED_DOC_PARAM = 'Undefined param `{}`.' +DIAG_MISSING_GLOBAL_DOC_COMMENT = +'Missing comment for global function `{}`.' +DIAG_MISSING_GLOBAL_DOC_PARAM = +'Missing @param annotation for parameter `{}` in global function `{}`.' +DIAG_MISSING_GLOBAL_DOC_RETURN = +'Missing @return annotation at index `{}` in global function `{}`.' +DIAG_INCOMPLETE_SIGNATURE_DOC_PARAM = +'Incomplete signature. Missing @param annotation for parameter `{}` in function `{}`.' +DIAG_INCOMPLETE_SIGNATURE_DOC_RETURN = +'Incomplete signature. Missing @return annotation at index `{}` in function `{}`.' DIAG_UNKNOWN_DIAG_CODE = 'Unknown diagnostic code `{}`.' DIAG_CAST_LOCAL_TYPE = diff --git a/locale/en-us/setting.lua b/locale/en-us/setting.lua index b03e3e43..4b34042f 100644 --- a/locale/en-us/setting.lua +++ b/locale/en-us/setting.lua @@ -373,8 +373,12 @@ config.diagnostics['duplicate-doc-param'] = 'Enable diagnostics for a duplicated param annotation name.' config.diagnostics['duplicate-set-field'] = 'Enable diagnostics for setting the same field in a class more than once.' +config.diagnostics['incomplete-signature-doc'] = +'Incomplete @param or @return annotations for functions.' config.diagnostics['invisible'] = 'Enable diagnostics for accesses to fields which are invisible.' +config.diagnostics['missing-global-doc'] = +'Missing annotations for globals! Global functions must have a comment and annotations for all parameters and return values.' config.diagnostics['missing-parameter'] = 'Enable diagnostics for function calls where the number of arguments is less than the number of annotated function parameters.' config.diagnostics['missing-return'] = diff --git a/locale/pt-br/script.lua b/locale/pt-br/script.lua index 6497c520..be6de9b2 100644 --- a/locale/pt-br/script.lua +++ b/locale/pt-br/script.lua @@ -114,7 +114,17 @@ DIAG_UNDEFINED_DOC_NAME = 'Tipo ou alias indefinido `{}`.' DIAG_UNDEFINED_DOC_PARAM = 'Parâmetro indefinido `{}`.' -DIAG_UNKNOWN_DIAG_CODE = +DIAG_MISSING_GLOBAL_DOC_COMMENT = -- TODO: need translate! +'Missing comment for global function `{}`.' +DIAG_MISSING_GLOBAL_DOC_PARAM = -- TODO: need translate! +'Missing @param annotation for parameter `{}` in global function `{}`.' +DIAG_MISSING_GLOBAL_DOC_RETURN = -- TODO: need translate! +'Missing @return annotation at index `{}` in global function `{}`.' +DIAG_INCOMPLETE_SIGNATURE_DOC_PARAM = -- TODO: need translate! +'Incomplete signature. Missing @param annotation for parameter `{}` in function `{}`.' +DIAG_INCOMPLETE_SIGNATURE_DOC_RETURN = -- TODO: need translate! +'Incomplete signature. Missing @return annotation at index `{}` in function `{}`.' +DIAG_UNKNOWN_DIAG_CODE = -- TODO: need translate! 'Código de diagnóstico desconhecido `{}`.' DIAG_CAST_LOCAL_TYPE = -- TODO: need translate! 'This variable is defined as type `{def}`. Cannot convert its type to `{ref}`.' diff --git a/locale/pt-br/setting.lua b/locale/pt-br/setting.lua index ec94f575..5038a5da 100644 --- a/locale/pt-br/setting.lua +++ b/locale/pt-br/setting.lua @@ -373,8 +373,12 @@ config.diagnostics['duplicate-doc-param'] = -- TODO: need translate! 'Enable diagnostics for a duplicated param annotation name.' config.diagnostics['duplicate-set-field'] = -- TODO: need translate! 'Enable diagnostics for setting the same field in a class more than once.' +config.diagnostics['incomplete-signature-doc'] = -- TODO: need translate! +'Incomplete @param or @return annotations for functions.' config.diagnostics['invisible'] = -- TODO: need translate! 'Enable diagnostics for accesses to fields which are invisible.' +config.diagnostics['missing-global-doc'] = -- TODO: need translate! +'Missing annotations for globals! Global functions must have a comment and annotations for all parameters and return values.' config.diagnostics['missing-parameter'] = -- TODO: need translate! 'Enable diagnostics for function calls where the number of arguments is less than the number of annotated function parameters.' config.diagnostics['missing-return'] = -- TODO: need translate! diff --git a/locale/zh-cn/script.lua b/locale/zh-cn/script.lua index da817698..40a8d35d 100644 --- a/locale/zh-cn/script.lua +++ b/locale/zh-cn/script.lua @@ -114,6 +114,16 @@ DIAG_UNDEFINED_DOC_NAME = '未定义的类型或别名 `{}`。' DIAG_UNDEFINED_DOC_PARAM = '指向了未定义的参数 `{}`。' +DIAG_MISSING_GLOBAL_DOC_COMMENT = -- TODO: need translate! +'Missing comment for global function `{}`.' +DIAG_MISSING_GLOBAL_DOC_PARAM = -- TODO: need translate! +'Missing @param annotation for parameter `{}` in global function `{}`.' +DIAG_MISSING_GLOBAL_DOC_RETURN = -- TODO: need translate! +'Missing @return annotation at index `{}` in global function `{}`.' +DIAG_INCOMPLETE_SIGNATURE_DOC_PARAM = -- TODO: need translate! +'Incomplete signature. Missing @param annotation for parameter `{}` in function `{}`.' +DIAG_INCOMPLETE_SIGNATURE_DOC_RETURN = -- TODO: need translate! +'Incomplete signature. Missing @return annotation at index `{}` in function `{}`.' DIAG_UNKNOWN_DIAG_CODE = '未知的诊断代号 `{}`。' DIAG_CAST_LOCAL_TYPE = diff --git a/locale/zh-cn/setting.lua b/locale/zh-cn/setting.lua index e1eb7de9..bece9a80 100644 --- a/locale/zh-cn/setting.lua +++ b/locale/zh-cn/setting.lua @@ -372,8 +372,12 @@ config.diagnostics['duplicate-doc-param'] = -- TODO: need translate! 'Enable diagnostics for a duplicated param annotation name.' config.diagnostics['duplicate-set-field'] = -- TODO: need translate! 'Enable diagnostics for setting the same field in a class more than once.' +config.diagnostics['incomplete-signature-doc'] = -- TODO: need translate! +'Incomplete @param or @return annotations for functions.' config.diagnostics['invisible'] = -- TODO: need translate! 'Enable diagnostics for accesses to fields which are invisible.' +config.diagnostics['missing-global-doc'] = -- TODO: need translate! +'Missing annotations for globals! Global functions must have a comment and annotations for all parameters and return values.' config.diagnostics['missing-parameter'] = -- TODO: need translate! 'Enable diagnostics for function calls where the number of arguments is less than the number of annotated function parameters.' config.diagnostics['missing-return'] = -- TODO: need translate! diff --git a/locale/zh-tw/script.lua b/locale/zh-tw/script.lua index 77ff6fea..7bc9e8a4 100644 --- a/locale/zh-tw/script.lua +++ b/locale/zh-tw/script.lua @@ -114,6 +114,16 @@ DIAG_UNDEFINED_DOC_NAME = '未定義的類型或別名 `{}`。' DIAG_UNDEFINED_DOC_PARAM = '指向了未定義的參數 `{}`。' +DIAG_MISSING_GLOBAL_DOC_COMMENT = -- TODO: need translate! +'Missing comment for global function `{}`.' +DIAG_MISSING_GLOBAL_DOC_PARAM = -- TODO: need translate! +'Missing @param annotation for parameter `{}` in global function `{}`.' +DIAG_MISSING_GLOBAL_DOC_RETURN = -- TODO: need translate! +'Missing @return annotation at index `{}` in global function `{}`.' +DIAG_INCOMPLETE_SIGNATURE_DOC_PARAM = -- TODO: need translate! +'Incomplete signature. Missing @param annotation for parameter `{}` in function `{}`.' +DIAG_INCOMPLETE_SIGNATURE_DOC_RETURN = -- TODO: need translate! +'Incomplete signature. Missing @return annotation at index `{}` in function `{}`.' DIAG_UNKNOWN_DIAG_CODE = '未知的診斷代碼 `{}`。' DIAG_CAST_LOCAL_TYPE = diff --git a/locale/zh-tw/setting.lua b/locale/zh-tw/setting.lua index ebf615ac..26ddc932 100644 --- a/locale/zh-tw/setting.lua +++ b/locale/zh-tw/setting.lua @@ -372,8 +372,12 @@ config.diagnostics['duplicate-doc-param'] = -- TODO: need translate! 'Enable diagnostics for a duplicated param annotation name.' config.diagnostics['duplicate-set-field'] = -- TODO: need translate! 'Enable diagnostics for setting the same field in a class more than once.' +config.diagnostics['incomplete-signature-doc'] = -- TODO: need translate! +'Incomplete @param or @return annotations for functions.' config.diagnostics['invisible'] = -- TODO: need translate! 'Enable diagnostics for accesses to fields which are invisible.' +config.diagnostics['missing-global-doc'] = -- TODO: need translate! +'Missing annotations for globals! Global functions must have a comment and annotations for all parameters and return values.' config.diagnostics['missing-parameter'] = -- TODO: need translate! 'Enable diagnostics for function calls where the number of arguments is less than the number of annotated function parameters.' config.diagnostics['missing-return'] = -- TODO: need translate! diff --git a/script/core/diagnostics/incomplete-signature-doc.lua b/script/core/diagnostics/incomplete-signature-doc.lua new file mode 100644 index 00000000..91f2db74 --- /dev/null +++ b/script/core/diagnostics/incomplete-signature-doc.lua @@ -0,0 +1,91 @@ +-- incomplete-signature-doc +local files = require 'files' +local lang = require 'language' +local guide = require "parser.guide" +local await = require 'await' + +local function findParam(docs, param) + if not docs then + return false + end + + for _, doc in ipairs(docs) do + if doc.type == 'doc.param' then + if doc.param[1] == param then + return true + end + end + end + + return false +end + +local function findReturn(docs, index) + if not docs then + return false + end + + for _, doc in ipairs(docs) do + if doc.type == 'doc.return' then + for _, ret in ipairs(doc.returns) do + if ret.returnIndex == index then + return true + end + end + end + end + + return false +end + +---@async +return function (uri, callback) + local state = files.getState(uri) + if not state then + return + end + + if not state.ast then + return + end + + ---@async + guide.eachSourceType(state.ast, 'function', function (source) + await.delay() + + if not source.bindDocs then + return + end + + local functionName = source.parent[1] + + if #source.args > 0 then + for _, arg in ipairs(source.args) do + local argName = arg[1] + if argName ~= 'self' then + if not findParam(source.bindDocs, argName) then + callback { + start = arg.start, + finish = arg.finish, + message = lang.script('DIAG_INCOMPLETE_SIGNATURE_DOC_PARAM', argName, functionName), + } + end + end + end + end + + if source.returns then + for _, ret in ipairs(source.returns) do + for index, expr in ipairs(ret) do + if not findReturn(source.bindDocs, index) then + callback { + start = expr.start, + finish = expr.finish, + message = lang.script('DIAG_INCOMPLETE_SIGNATURE_DOC_RETURN', index, functionName), + } + end + end + end + end + end) +end diff --git a/script/core/diagnostics/missing-global-doc.lua b/script/core/diagnostics/missing-global-doc.lua new file mode 100644 index 00000000..adcdf404 --- /dev/null +++ b/script/core/diagnostics/missing-global-doc.lua @@ -0,0 +1,98 @@ +local files = require 'files' +local lang = require 'language' +local guide = require "parser.guide" +local await = require 'await' + +local function findParam(docs, param) + if not docs then + return false + end + + for _, doc in ipairs(docs) do + if doc.type == 'doc.param' then + if doc.param[1] == param then + return true + end + end + end + + return false +end + +local function findReturn(docs, index) + if not docs then + return false + end + + for _, doc in ipairs(docs) do + if doc.type == 'doc.return' then + for _, ret in ipairs(doc.returns) do + if ret.returnIndex == index then + return true + end + end + end + end + + return false +end + +---@async +return function (uri, callback) + local state = files.getState(uri) + if not state then + return + end + + if not state.ast then + return + end + + ---@async + guide.eachSourceType(state.ast, 'function', function (source) + await.delay() + + if source.parent.type ~= 'setglobal' then + return + end + + local functionName = source.parent[1] + + if #source.args == 0 and not source.returns and not source.bindDocs then + callback { + start = source.start, + finish = source.finish, + message = lang.script('DIAG_MISSING_GLOBAL_DOC_COMMENT', functionName), + } + end + + if #source.args > 0 then + for _, arg in ipairs(source.args) do + local argName = arg[1] + if argName ~= 'self' then + if not findParam(source.bindDocs, argName) then + callback { + start = arg.start, + finish = arg.finish, + message = lang.script('DIAG_MISSING_GLOBAL_DOC_PARAM', argName, functionName), + } + end + end + end + end + + if source.returns then + for _, ret in ipairs(source.returns) do + for index, expr in ipairs(ret) do + if not findReturn(source.bindDocs, index) then + callback { + start = expr.start, + finish = expr.finish, + message = lang.script('DIAG_MISSING_GLOBAL_DOC_RETURN', index, functionName), + } + end + end + end + end + end) +end diff --git a/script/proto/diagnostic.lua b/script/proto/diagnostic.lua index 48a9094c..7f76c435 100644 --- a/script/proto/diagnostic.lua +++ b/script/proto/diagnostic.lua @@ -100,6 +100,15 @@ m.register { status = 'Any', } +m.register { + 'incomplete-signature-doc', + 'missing-global-doc', +} { + group = 'luadoc', + severity = 'Warning', + status = 'None', +} + m.register { 'codestyle-check' } { diff --git a/test/diagnostics/incomplete-signature-doc.lua b/test/diagnostics/incomplete-signature-doc.lua new file mode 100644 index 00000000..c3099cd2 --- /dev/null +++ b/test/diagnostics/incomplete-signature-doc.lua @@ -0,0 +1,331 @@ +local config = require 'config' +local util = require 'utility' + +-- disable all default groups to make isolated tests +config.set(nil, 'Lua.diagnostics.groupFileStatus', +{ + ['ambiguity'] = 'None', + ['await'] = 'None', + ['codestyle'] = 'None', + ['conventions'] = 'None', + ['duplicate'] = 'None', + ['global'] = 'None', + ['luadoc'] = 'None', + ['redefined'] = 'None', + ['strict'] = 'None', + ['strong'] = 'None', + ['type-check'] = 'None', + ['unbalanced'] = 'None', + ['unused'] = 'None' +}) + +-- enable single diagnostic that is to be tested +config.set(nil, 'Lua.diagnostics.neededFileStatus', +{ + ['incomplete-signature-doc'] = 'Any!' -- override groupFileStatus +}) + +-- check global functions +TEST [[ +function FG0() +end + +---comment +function FG1() +end +]] + +TEST [[ +function FGP0(p) + print(p) +end + +---comment +function FGP1() + print(p) +end + +---comment +---@param p any +function FGP2(p) + print(p) +end +]] + +TEST [[ +function FGPP0(p0, p1) + print(p0, p1) +end + +---comment +function FGPP1(, ) + print(p0, p1) +end + +---comment +---@param p0 any +function FGPP2(p0, ) + print(p0, p1) +end + +---comment +---@param p0 any +---@param p1 any +function FGPP3(p0, p1) + print(p0, p1) +end +]] + +TEST [[ +function FGR0() + return 0 +end + +---comment +function FGR1() + return +end + +---comment +---@return integer +function FGR2() + return 0 +end +]] + +TEST [[ +function FGRR0() + return 0, 1 +end + +---comment +function FGRR1() + return , +end + +---comment +---@return integer +function FGRR2() + return 0, +end + +---comment +---@return integer +---@return integer +function FGRR3() + return 0, 1 +end +]] + +TEST [[ +function FGPR0(p) + print(p) + return 0 +end + +---comment +function FGPR1() + print(p) + return +end + +---comment +---@param p any +function FGPR2(p) + print(p) + return +end + +---comment +---@return integer +function FGPR3() + print(p) + return 0 +end + +---comment +---@param p any +---@return integer +function FGPR4(p) + print(p) + return 0 +end +]] + +-- check local functions + +TEST [[ +local function FL0() +end + +FL0() + +---comment +local function FL1() +end + +FL1() +]] + +TEST [[ +local function FLP0(p) + print(p) +end + +FLP0(0) + +---comment +local function FLP1() + print(p) +end + +FLP1(0) + +---comment +---@param p any +local function FLP2(p) + print(p) +end + +FLP2(0) +]] + +TEST [[ +local function FLPP0(p0, p1) + print(p0, p1) +end + +FLPP0(0, 1) + +---comment +local function FLPP1(, ) + print(p0, p1) +end + +FLPP1(0, 1) + +---comment +---@param p0 any +local function FLPP2(p0, ) + print(p0, p1) +end + +FLPP2(0, 1) + +---comment +---@param p0 any +---@param p1 any +local function FLPP3(p0, p1) + print(p0, p1) +end + +FLPP3(0, 1) +]] + +TEST [[ +local function FLR0() + return 0 +end + +local vr0 = FLR0() + +---comment +local function FLR1() + return +end + +local vr1 = FLR1() + +---comment +---@return integer +local function FLR2() + return 0 +end + +local vr2 = FLR2() +]] + +TEST [[ +local function FLRR0() + return 0, 1 +end + +local vrr0, _ = FLRR0() + +---comment +local function FLRR1() + return , +end + +local vrr1, _ = FLRR1() + +---comment +---@return integer +local function FLRR2() + return 0, +end + +local vrr2, _ = FLRR2() + +---comment +---@return integer +---@return integer +local function FLRR3() + return 0, 1 +end + +local vrr3, _ = FLRR3() +]] + +TEST [[ +local function FLPR0(p) + print(p) + return 0 +end + +local vpr0 = FLPR0(0) + +---comment +local function FLPR1() + print(p) + return +end + +local vpr1 = FLPR1(0) + +---comment +---@param p any +local function FLPR2(p) + print(p) + return +end + +local vpr2 = FLPR2(0) + +---comment +---@return integer +local function FLPR3() + print(p) + return 0 +end + +local vpr3 = FLPR3(0) + +---comment +---@param p any +---@return integer +local function FLPR4(p) + print(p) + return 0 +end + +local vpr4 = FLPR4(0) +]] + +-- reset configurations +config.set(nil, 'Lua.diagnostics.groupFileStatus', +{}) +config.set(nil, 'Lua.diagnostics.neededFileStatus', +{}) +config.set(nil, 'Lua.diagnostics.globals', +{}) \ No newline at end of file diff --git a/test/diagnostics/init.lua b/test/diagnostics/init.lua index 5e8abf7d..821685f0 100644 --- a/test/diagnostics/init.lua +++ b/test/diagnostics/init.lua @@ -86,5 +86,8 @@ end require 'diagnostics.common' require 'diagnostics.type-check' +require 'diagnostics.incomplete-signature-doc' +require 'diagnostics.missing-global-doc' require 'diagnostics.global-element' require 'diagnostics.uppercase-local' + diff --git a/test/diagnostics/missing-global-doc.lua b/test/diagnostics/missing-global-doc.lua new file mode 100644 index 00000000..2ebc237a --- /dev/null +++ b/test/diagnostics/missing-global-doc.lua @@ -0,0 +1,333 @@ +local config = require 'config' +local util = require 'utility' + +-- disable all default groups to make isolated tests +config.set(nil, 'Lua.diagnostics.groupFileStatus', +{ + ['ambiguity'] = 'None', + ['await'] = 'None', + ['codestyle'] = 'None', + ['conventions'] = 'None', + ['duplicate'] = 'None', + ['global'] = 'None', + ['luadoc'] = 'None', + ['redefined'] = 'None', + ['strict'] = 'None', + ['strong'] = 'None', + ['type-check'] = 'None', + ['unbalanced'] = 'None', + ['unused'] = 'None' +}) + +-- enable single diagnostic that is to be tested +config.set(nil, 'Lua.diagnostics.neededFileStatus', +{ + ['missing-global-doc'] = 'Any!' -- override groupFileStatus +}) + + +-- check global functions +TEST [[ + + +---comment +function FG1() +end +]] + +TEST [[ +function FGP0() + print(p) +end + +---comment +function FGP1() + print(p) +end + +---comment +---@param p any +function FGP2(p) + print(p) +end +]] + +TEST [[ +function FGPP0(, ) + print(p0, p1) +end + +---comment +function FGPP1(, ) + print(p0, p1) +end + +---comment +---@param p0 any +function FGPP2(p0, ) + print(p0, p1) +end + +---comment +---@param p0 any +---@param p1 any +function FGPP3(p0, p1) + print(p0, p1) +end +]] + +TEST [[ +function FGR0() + return +end + +---comment +function FGR1() + return +end + +---comment +---@return integer +function FGR2() + return 0 +end +]] + +TEST [[ +function FGRR0() + return , +end + +---comment +function FGRR1() + return , +end + +---comment +---@return integer +function FGRR2() + return 0, +end + +---comment +---@return integer +---@return integer +function FGRR3() + return 0, 1 +end +]] + + +TEST [[ +function FGPR0() + print(p) + return +end + +---comment +function FGPR1() + print(p) + return +end + +---comment +---@param p any +function FGPR2(p) + print(p) + return +end + +---comment +---@return integer +function FGPR3() + print(p) + return 0 +end + +---comment +---@param p any +---@return integer +function FGPR4(p) + print(p) + return 0 +end +]] + +-- check local functions + +TEST [[ +local function FL0() +end + +FL0() + +---comment +local function FL1() +end + +FL1() +]] + +TEST [[ +local function FLP0(p) + print(p) +end + +FLP0(0) + +---comment +local function FLP1(p) + print(p) +end + +FLP1(0) + +---comment +---@param p any +local function FLP2(p) + print(p) +end + +FLP2(0) +]] + +TEST [[ +local function FLPP0(p0, p1) + print(p0, p1) +end + +FLPP0(0, 1) + +---comment +local function FLPP1(p0, p1) + print(p0, p1) +end + +FLPP1(0, 1) + +---comment +---@param p0 any +local function FLPP2(p0, p1) + print(p0, p1) +end + +FLPP2(0, 1) + +---comment +---@param p0 any +---@param p1 any +local function FLPP3(p0, p1) + print(p0, p1) +end + +FLPP3(0, 1) +]] + +TEST [[ +local function FLR0() + return 0 +end + +local vr0 = FLR0() + +---comment +local function FLR1() + return 0 +end + +local vr1 = FLR1() + +---comment +---@return integer +local function FLR2() + return 0 +end + +local vr2 = FLR2() +]] + +TEST [[ +local function FLRR0() + return 0, 1 +end + +local vrr0, _ = FLRR0() + +---comment +local function FLRR1() + return 0, 1 +end + +local vrr1, _ = FLRR1() + +---comment +---@return integer +local function FLRR2() + return 0, 1 +end + +local vrr2, _ = FLRR2() + +---comment +---@return integer +---@return integer +local function FLRR3() + return 0, 1 +end + +local vrr3, _ = FLRR3() +]] + +TEST [[ +local function FLPR0(p) + print(p) + return 0 +end + +local vpr0 = FLPR0(0) + +---comment +local function FLPR1(p) + print(p) + return 0 +end + +local vpr1 = FLPR1(0) + +---comment +---@param p any +local function FLPR2(p) + print(p) + return 0 +end + +local vpr2 = FLPR2(0) + +---comment +---@return integer +local function FLPR3(p) + print(p) + return 0 +end + +local vpr3 = FLPR3(0) + +---comment +---@param p any +---@return integer +local function FLPR4(p) + print(p) + return 0 +end + +local vpr4 = FLPR4(0) +]] + +-- reset configurations +config.set(nil, 'Lua.diagnostics.groupFileStatus', +{}) +config.set(nil, 'Lua.diagnostics.neededFileStatus', +{}) +config.set(nil, 'Lua.diagnostics.globals', +{}) \ No newline at end of file -- cgit v1.2.3 From 171703c12f571d15550aacc40a45cc6a312d8b1d Mon Sep 17 00:00:00 2001 From: AndreaWalchshoferSCCH Date: Mon, 24 Apr 2023 11:03:18 +0200 Subject: Cleanup PR Revert Changes made from unrelated PR --- doc/en-us/config.md | 15 +------ doc/pt-br/config.md | 15 +------ doc/zh-cn/config.md | 15 +------ doc/zh-tw/config.md | 15 +------ locale/en-us/script.lua | 5 +-- locale/en-us/setting.lua | 6 +-- locale/pt-br/script.lua | 4 +- locale/pt-br/setting.lua | 6 +-- locale/zh-cn/script.lua | 4 +- locale/zh-cn/setting.lua | 6 +-- locale/zh-tw/script.lua | 4 +- locale/zh-tw/setting.lua | 6 +-- script/core/diagnostics/uppercase-local.lua | 47 -------------------- script/proto/diagnostic.lua | 1 - test/diagnostics/init.lua | 2 - test/diagnostics/uppercase-local.lua | 66 ----------------------------- 16 files changed, 20 insertions(+), 197 deletions(-) delete mode 100644 script/core/diagnostics/uppercase-local.lua delete mode 100644 test/diagnostics/uppercase-local.lua diff --git a/doc/en-us/config.md b/doc/en-us/config.md index 4319901c..76ae7124 100644 --- a/doc/en-us/config.md +++ b/doc/en-us/config.md @@ -331,7 +331,6 @@ Array * ``"unused-label"`` * ``"unused-local"`` * ``"unused-vararg"`` -* ``"uppercase-local"`` ## default @@ -475,7 +474,6 @@ object "strict": "Fallback", /* * global-element - * uppercase-local */ "conventions": "None", /* @@ -601,7 +599,6 @@ object "strict": "Fallback", /* * global-element - * uppercase-local */ "conventions": "Fallback", /* @@ -943,11 +940,7 @@ object /* Enable unused vararg diagnostics. */ - "unused-vararg": "Opened", - /* - Enable diagnostics to warn about local element names starting with an uppercase letter. - */ - "uppercase-local": "None" + "unused-vararg": "Opened" } ``` @@ -1207,11 +1200,7 @@ object /* Enable unused vararg diagnostics. */ - "unused-vararg": "Hint", - /* - Enable diagnostics to warn about local element names starting with an uppercase letter. - */ - "uppercase-local": "Warning" + "unused-vararg": "Hint" } ``` diff --git a/doc/pt-br/config.md b/doc/pt-br/config.md index c3ab1107..0d912b0f 100644 --- a/doc/pt-br/config.md +++ b/doc/pt-br/config.md @@ -331,7 +331,6 @@ Array * ``"unused-label"`` * ``"unused-local"`` * ``"unused-vararg"`` -* ``"uppercase-local"`` ## default @@ -475,7 +474,6 @@ object "strict": "Fallback", /* * global-element - * uppercase-local */ "conventionss": "None", /* @@ -600,7 +598,6 @@ object "strict": "Fallback", /* * global-element - * uppercase-local */ "conventionss": "Fallback", /* @@ -942,11 +939,7 @@ object /* 未使用的不定参数 */ - "unused-vararg": "Opened", - /* - Enable diagnostics to warn about local element names starting with an uppercase letter. - */ - "uppercase-local": "None" + "unused-vararg": "Opened" } ``` @@ -1206,11 +1199,7 @@ object /* 未使用的不定参数 */ - "unused-vararg": "Hint", - /* - Enable diagnostics to warn about local element names starting with an uppercase letter. - */ - "uppercase-local": "Warning" + "unused-vararg": "Hint" } ``` diff --git a/doc/zh-cn/config.md b/doc/zh-cn/config.md index 32a6db68..9ddffb9e 100644 --- a/doc/zh-cn/config.md +++ b/doc/zh-cn/config.md @@ -331,7 +331,6 @@ Array * ``"unused-label"`` * ``"unused-local"`` * ``"unused-vararg"`` -* ``"uppercase-local"`` ## default @@ -475,7 +474,6 @@ object "strict": "Fallback", /* * global-element - * uppercase-local */ "conventions": "None", /* @@ -601,7 +599,6 @@ object "strict": "Fallback", /* * global-element - * uppercase-local */ "conventions": "Fallback", /* @@ -943,11 +940,7 @@ object /* 未使用的不定参数 */ - "unused-vararg": "Opened", - /* - Enable diagnostics to warn about local element names starting with an uppercase letter. - */ - "uppercase-local": "None" + "unused-vararg": "Opened" } ``` @@ -1206,11 +1199,7 @@ object /* 未使用的不定参数 */ - "unused-vararg": "Hint", - /* - Enable diagnostics to warn about local element names starting with an uppercase letter. - */ - "uppercase-local": "Warning" + "unused-vararg": "Hint" } ``` diff --git a/doc/zh-tw/config.md b/doc/zh-tw/config.md index bc9dae01..bb7169d4 100644 --- a/doc/zh-tw/config.md +++ b/doc/zh-tw/config.md @@ -331,7 +331,6 @@ Array * ``"unused-label"`` * ``"unused-local"`` * ``"unused-vararg"`` -* ``"uppercase-local"`` ## default @@ -475,7 +474,6 @@ object "strict": "Fallback", /* * global-element - * uppercase-local */ "convention": "None", /* @@ -601,7 +599,6 @@ object "strict": "Fallback", /* * global-element - * uppercase-local */ "convention": "Fallback", /* @@ -943,11 +940,7 @@ object /* 未使用的不定引數 */ - "unused-vararg": "Opened", - /* - Enable diagnostics to warn about local element names starting with an uppercase letter. - */ - "uppercase-local": "None" + "unused-vararg": "Opened" } ``` @@ -1206,11 +1199,7 @@ object /* 未使用的不定引數 */ - "unused-vararg": "Hint", - /* - Enable diagnostics to warn about local element names starting with an uppercase letter. - */ - "uppercase-local": "Warning" + "unused-vararg": "Hint" } ``` diff --git a/locale/en-us/script.lua b/locale/en-us/script.lua index 6742b784..c42731b6 100644 --- a/locale/en-us/script.lua +++ b/locale/en-us/script.lua @@ -160,11 +160,8 @@ DIAG_INVISIBLE_PROTECTED = 'Field `{field}` is protected, it can only be accessed in class `{class}` and its subclasses.' DIAG_INVISIBLE_PACKAGE = 'Field `{field}` can only be accessed in same file `{uri}`.' -DIAG_GLOBAL_ELEMENT = +DIAG_GLOBAL_ELEMENT = 'Element is global.' -DIAG_UPPERCASE_LOCAL = -'Local element `{}` must start with lowercase letter' - MWS_NOT_SUPPORT = '{} does not support multi workspace for now, I may need to restart to support the new workspace ...' diff --git a/locale/en-us/setting.lua b/locale/en-us/setting.lua index 4b34042f..a354ff0b 100644 --- a/locale/en-us/setting.lua +++ b/locale/en-us/setting.lua @@ -419,10 +419,8 @@ config.diagnostics['unknown-operator'] = 'Enable diagnostics for unknown operators.' config.diagnostics['unreachable-code'] = 'Enable diagnostics for unreachable code.' -config.diagnostics['global-element'] = -'Enable diagnostics to warn about global variables.' -config.diagnostics['uppercase-local'] = -'Enable diagnostics to warn about local element names starting with an uppercase letter.' +config.diagnostics['global-element'] = +'Enable diagnostics to warn about global elements.' config.typeFormat.config = 'Configures the formatting behavior while typing Lua code.' config.typeFormat.config.auto_complete_end = diff --git a/locale/pt-br/script.lua b/locale/pt-br/script.lua index be6de9b2..5d4d70b5 100644 --- a/locale/pt-br/script.lua +++ b/locale/pt-br/script.lua @@ -160,10 +160,8 @@ DIAG_INVISIBLE_PROTECTED = -- TODO: need translate! 'Field `{field}` is protected, it can only be accessed in class `{class}` and its subclasses.' DIAG_INVISIBLE_PACKAGE = -- TODO: need translate! 'Field `{field}` can only be accessed in same file `{uri}`.' -DIAG_GLOBAL_ELEMENT = -- TODO: need translate! +DIAG_GLOBAL_ELEMENT = -- TODO: need translate! 'Element is global.' -DIAG_UPPERCASE_LOCAL = -- TODO: need translate! -'Local element `{}` must start with lowercase letter' MWS_NOT_SUPPORT = '{} não é suportado múltiplos espaços de trabalho por enquanto, posso precisar reiniciar para estabelecer um novo espaço de trabalho ...' diff --git a/locale/pt-br/setting.lua b/locale/pt-br/setting.lua index 5038a5da..c38f0ff0 100644 --- a/locale/pt-br/setting.lua +++ b/locale/pt-br/setting.lua @@ -419,10 +419,8 @@ config.diagnostics['unknown-operator'] = -- TODO: need translate! 'Enable diagnostics for unknown operators.' config.diagnostics['unreachable-code'] = -- TODO: need translate! 'Enable diagnostics for unreachable code.' -config.diagnostics['global-element'] = -- TODO: need translate! -'Enable diagnostics to warn about global variables.' -config.diagnostics['uppercase-local'] = -- TODO: need translate! -'Enable diagnostics to warn about local element names starting with an uppercase letter.' +config.diagnostics['global-element'] = -- TODO: need translate! +'Enable diagnostics to warn about global elements.' config.typeFormat.config = -- TODO: need translate! 'Configures the formatting behavior while typing Lua code.' config.typeFormat.config.auto_complete_end = -- TODO: need translate! diff --git a/locale/zh-cn/script.lua b/locale/zh-cn/script.lua index 40a8d35d..2944686d 100644 --- a/locale/zh-cn/script.lua +++ b/locale/zh-cn/script.lua @@ -160,10 +160,8 @@ DIAG_INVISIBLE_PROTECTED = '字段 `{field}` 受到保护,只能在 `{class}` 类极其子类中才能访问。' DIAG_INVISIBLE_PACKAGE = '字段 `{field}` 只能在相同的文件 `{uri}` 中才能访问。' -DIAG_GLOBAL_ELEMENT = -- TODO: need translate! +DIAG_GLOBAL_ELEMENT = -- TODO: need translate! 'Element is global.' -DIAG_UPPERCASE_LOCAL = -- TODO: need translate! -'Local element `{}` must start with lowercase letter' MWS_NOT_SUPPORT = '{} 目前还不支持多工作目录,我可能需要重启才能支持新的工作目录...' diff --git a/locale/zh-cn/setting.lua b/locale/zh-cn/setting.lua index bece9a80..9dbd961d 100644 --- a/locale/zh-cn/setting.lua +++ b/locale/zh-cn/setting.lua @@ -418,10 +418,8 @@ config.diagnostics['unknown-operator'] = -- TODO: need translate! 'Enable diagnostics for unknown operators.' config.diagnostics['unreachable-code'] = -- TODO: need translate! 'Enable diagnostics for unreachable code.' -config.diagnostics['global-element'] = -- TODO: need translate! -'Enable diagnostics to warn about global variables.' -config.diagnostics['uppercase-local'] = -- TODO: need translate! -'Enable diagnostics to warn about local element names starting with an uppercase letter.' +config.diagnostics['global-element'] = -- TODO: need translate! +'Enable diagnostics to warn about global elements.' config.typeFormat.config = -- TODO: need translate! 'Configures the formatting behavior while typing Lua code.' config.typeFormat.config.auto_complete_end = -- TODO: need translate! diff --git a/locale/zh-tw/script.lua b/locale/zh-tw/script.lua index 7bc9e8a4..e8f17703 100644 --- a/locale/zh-tw/script.lua +++ b/locale/zh-tw/script.lua @@ -160,10 +160,8 @@ DIAG_INVISIBLE_PROTECTED = -- TODO: need translate! 'Field `{field}` is protected, it can only be accessed in class `{class}` and its subclasses.' DIAG_INVISIBLE_PACKAGE = -- TODO: need translate! 'Field `{field}` can only be accessed in same file `{uri}`.' -DIAG_GLOBAL_ELEMENT = -- TODO: need translate! +DIAG_GLOBAL_ELEMENT = -- TODO: need translate! 'Element is global.' -DIAG_UPPERCASE_LOCAL = -- TODO: need translate! -'Local element `{}` must start with lowercase letter' MWS_NOT_SUPPORT = '{} 目前還不支援多工作目錄,我可能需要重新啟動才能支援新的工作目錄...' diff --git a/locale/zh-tw/setting.lua b/locale/zh-tw/setting.lua index 26ddc932..7cf93297 100644 --- a/locale/zh-tw/setting.lua +++ b/locale/zh-tw/setting.lua @@ -418,10 +418,8 @@ config.diagnostics['unknown-operator'] = -- TODO: need translate! 'Enable diagnostics for unknown operators.' config.diagnostics['unreachable-code'] = -- TODO: need translate! 'Enable diagnostics for unreachable code.' -config.diagnostics['global-element'] = -- TODO: need translate! -'Enable diagnostics to warn about global variables.' -config.diagnostics['uppercase-local'] = -- TODO: need translate! -'Enable diagnostics to warn about local element names starting with an uppercase letter.' +config.diagnostics['global-element'] = -- TODO: need translate! +'Enable diagnostics to warn about global elements.' config.typeFormat.config = -- TODO: need translate! 'Configures the formatting behavior while typing Lua code.' config.typeFormat.config.auto_complete_end = -- TODO: need translate! diff --git a/script/core/diagnostics/uppercase-local.lua b/script/core/diagnostics/uppercase-local.lua deleted file mode 100644 index cc377dd2..00000000 --- a/script/core/diagnostics/uppercase-local.lua +++ /dev/null @@ -1,47 +0,0 @@ -local files = require 'files' -local guide = require 'parser.guide' -local lang = require 'language' - -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 - --- If local elements must be named lowercase by coding convention, this diagnostic helps with reminding about that -return function (uri, callback) - local ast = files.getState(uri) - if not ast then - return - end - - guide.eachSourceType(ast.ast, 'local', function (source) - local name = guide.getKeyName(source) - if not name then - return - end - local first = name:match '%w' -- alphanumeric character - if not first then - return - end - if not first:match '%u' then -- uppercase - return - end - -- If the assignment is marked as doc.class, then it is considered allowed - if isDocClass(source) then - return - end - - callback { - start = source.start, - finish = source.finish, - message = lang.script('DIAG_UPPERCASE_LOCAL', name), - } - end) -end diff --git a/script/proto/diagnostic.lua b/script/proto/diagnostic.lua index 7f76c435..a8303417 100644 --- a/script/proto/diagnostic.lua +++ b/script/proto/diagnostic.lua @@ -182,7 +182,6 @@ m.register { m.register { 'global-element', - 'uppercase-local', } { group = 'conventions', severity = 'Warning', diff --git a/test/diagnostics/init.lua b/test/diagnostics/init.lua index 821685f0..fbea6680 100644 --- a/test/diagnostics/init.lua +++ b/test/diagnostics/init.lua @@ -89,5 +89,3 @@ require 'diagnostics.type-check' require 'diagnostics.incomplete-signature-doc' require 'diagnostics.missing-global-doc' require 'diagnostics.global-element' -require 'diagnostics.uppercase-local' - diff --git a/test/diagnostics/uppercase-local.lua b/test/diagnostics/uppercase-local.lua deleted file mode 100644 index fc0b95d1..00000000 --- a/test/diagnostics/uppercase-local.lua +++ /dev/null @@ -1,66 +0,0 @@ -local config = require 'config' -local util = require 'utility' - --- disable all default groups to make isolated tests -config.set(nil, 'Lua.diagnostics.groupFileStatus', -{ - ['ambiguity'] = 'None', - ['await'] = 'None', - ['codestyle'] = 'None', - ['conventions'] = 'None', - ['duplicate'] = 'None', - ['global'] = 'None', - ['luadoc'] = 'None', - ['redefined'] = 'None', - ['strict'] = 'None', - ['strong'] = 'None', - ['type-check'] = 'None', - ['unbalanced'] = 'None', - ['unused'] = 'None' -}) - --- enable single diagnostic that is to be tested -config.set(nil, 'Lua.diagnostics.neededFileStatus', -{ - ['uppercase-local'] = 'Any!' -- override groupFileStatus -}) - --- check that global elements are not warned about -TEST [[ -Var1 = "global" -VAR2 = "global" - -local x = true -local = false -local = false -]] - -TEST [[ -local function test1() - print() -end - -local function () - print() -end -]] - -TEST [[ -local function closure1() - local elem1 = 1 - local = 2 -end - -local function () - local elem1 = 1 - local = 2 -end -]] - --- reset configurations -config.set(nil, 'Lua.diagnostics.groupFileStatus', -{}) -config.set(nil, 'Lua.diagnostics.neededFileStatus', -{}) -config.set(nil, 'Lua.diagnostics.globals', -{}) -- cgit v1.2.3