From 43794193ef981ffecb477bfce444428ded852aa0 Mon Sep 17 00:00:00 2001 From: AndreaWalchshoferSCCH <122894794+AndreaWalchshoferSCCH@users.noreply.github.com> Date: Thu, 30 Mar 2023 14:49:30 +0200 Subject: Add diagnostic to enforce lowercase local element names (#2) --- test/diagnostics/init.lua | 3 +- test/diagnostics/uppercase-local.lua | 66 ++++++++++++++++++++++++++++++++++++ 2 files changed, 68 insertions(+), 1 deletion(-) create mode 100644 test/diagnostics/uppercase-local.lua (limited to 'test/diagnostics') diff --git a/test/diagnostics/init.lua b/test/diagnostics/init.lua index 4025dd8c..a18e5cea 100644 --- a/test/diagnostics/init.lua +++ b/test/diagnostics/init.lua @@ -86,4 +86,5 @@ end require 'diagnostics.common' require 'diagnostics.type-check' -require 'diagnostics.global-element' \ No newline at end of file +require 'diagnostics.global-element' +require 'diagnostics.uppercase-local' \ No newline at end of file diff --git a/test/diagnostics/uppercase-local.lua b/test/diagnostics/uppercase-local.lua new file mode 100644 index 00000000..fb8b726d --- /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', + ['strict-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', +{}) \ No newline at end of file -- cgit v1.2.3