diff --git a/.automation/test/lua/README.md b/.automation/test/lua/README.md new file mode 100644 index 00000000..db695378 --- /dev/null +++ b/.automation/test/lua/README.md @@ -0,0 +1,13 @@ +# Lua Test Cases +This folder holds the test cases for **Lua**. + +## Additional Docs +No Additional information is needed for this test case. + +## Good Test Cases +The test cases denoted: `LANGUAGE_good_FILE.EXTENSION` are all valid, and should pass successfully when linted. +- **Note:** They are linted utilizing the default linter rules. + +## Bad Test Cases +The test cases denoted: `LANGUAGE_bad_FILE.EXTENSION` are **NOT** valid, and should trigger errors when linted. +- **Note:** They are linted utilizing the default linter rules. \ No newline at end of file diff --git a/.automation/test/lua/lua_bad_1.lua b/.automation/test/lua/lua_bad_1.lua new file mode 100644 index 00000000..2c31e39d --- /dev/null +++ b/.automation/test/lua/lua_bad_1.lua @@ -0,0 +1,9 @@ +package.loaded[...] = {} + +local function helper(...) + -- NYI +end + +function embrace(opt) + local opt = opt or "default" + return hepler(opt.."?") diff --git a/.automation/test/lua/lua_good_1.lua b/.automation/test/lua/lua_good_1.lua new file mode 100644 index 00000000..f7ade80b --- /dev/null +++ b/.automation/test/lua/lua_good_1.lua @@ -0,0 +1,12 @@ +local embracer = {} + +local function helper() + -- NYI wontfix +end + +function embracer.embrace(opt) + opt = opt or "default" + return helper(opt.."?") +end + +return embracer diff --git a/.github/linters/.luacheckrc b/.github/linters/.luacheckrc new file mode 100644 index 00000000..00aa308f --- /dev/null +++ b/.github/linters/.luacheckrc @@ -0,0 +1 @@ +--std max diff --git a/Dockerfile b/Dockerfile index 797633b4..2aa7dec9 100644 --- a/Dockerfile +++ b/Dockerfile @@ -52,12 +52,14 @@ ARG GLIBC_VERSION='2.31-r0' RUN apk add --update --no-cache \ ansible-lint \ bash \ + coreutils \ curl \ gcc \ git git-lfs\ go \ icu-libs \ jq \ + libc-dev \ libxml2-utils \ make \ musl-dev \ @@ -66,6 +68,7 @@ RUN apk add --update --no-cache \ perl \ php7 \ py3-setuptools \ + readline-dev \ ruby ruby-dev ruby-bundler ruby-rdoc ######################################## @@ -183,6 +186,24 @@ RUN wget https://storage.googleapis.com/dart-archive/channels/stable/release/${D RUN echo "http://dl-cdn.alpinelinux.org/alpine/edge/testing/" >> /etc/apk/repositories \ && apk add --update --no-cache rakudo zef +#################### +# Install luacheck # +#################### +RUN wget https://www.lua.org/ftp/lua-5.3.5.tar.gz -O - -q | tar -xzf - \ + && cd lua-5.3.5 \ + && make linux \ + && make install \ + && cd .. && rm -r lua-5.3.5/ + +RUN wget https://github.com/cvega/luarocks/archive/v3.3.1-super-linter.tar.gz -O - -q | tar -xzf - \ + && cd luarocks-3.3.1-super-linter \ + && ./configure --with-lua-include=/usr/local/include \ + && make \ + && make -b install \ + && cd .. && rm -r luarocks-3.3.1-super-linter/ + +RUN luarocks install luacheck + ########################################### # Load GitHub Env Vars for GitHub Actions # ########################################### @@ -218,6 +239,7 @@ ENV ACTIONS_RUNNER_DEBUG=${ACTIONS_RUNNER_DEBUG} \ VALIDATE_JAVASCRIPT_STANDARD=${VALIDATE_JAVASCRIPT_STANDARD} \ VALIDATE_JSON=${VALIDATE_JSON} \ VALIDATE_KOTLIN=${VALIDATE_KOTLIN} \ + VALIDATE_LUA=${VALIDATE_LUA} \ VALIDATE_MD=${VALIDATE_MD} \ VALIDATE_OPENAPI=${VALIDATE_OPENAPI} \ VALIDATE_PERL=${VALIDATE_PERL} \ diff --git a/README.md b/README.md index f9c77028..4c09d542 100644 --- a/README.md +++ b/README.md @@ -59,6 +59,7 @@ Developers on **GitHub** can call the **GitHub Action** to lint their code base | **JavaScript** | [eslint](https://eslint.org/) [standard js](https://standardjs.com/) | | **JSON** | [jsonlint](https://github.com/zaach/jsonlint) | | **Kotlin** | [ktlint](https://github.com/pinterest/ktlint) | +| **Lua** | [luacheck](https://github.com/luarocks/luacheck) | | **Markdown** | [markdownlint](https://github.com/igorshubovych/markdownlint-cli#readme) | | **OpenAPI** | [spectral](https://github.com/stoplightio/spectral) | | **Perl** | [perl](https://pkgs.alpinelinux.org/package/edge/main/x86/perl) | @@ -201,6 +202,7 @@ and won't run anything unexpected. | **VALIDATE_JSON** | `true` | Flag to enable or disable the linting process of the JSON language. | | **VALIDATE_JSX** | `true` | Flag to enable or disable the linting process for jsx files (Utilizing: eslint) | | **VALIDATE_KOTLIN** | `true` | Flag to enable or disable the linting process of the Kotlin language. | +| **VALIDATE_LUA** | `true` | Flag to enable or disable the linting process of the language. | | **VALIDATE_MD** | `true` | Flag to enable or disable the linting process of the Markdown language. | | **VALIDATE_OPENAPI** | `true` | Flag to enable or disable the linting process of the OpenAPI language. | | **VALIDATE_PERL** | `true` | Flag to enable or disable the linting process of the Perl language. | diff --git a/TEMPLATES/.luacheckrc b/TEMPLATES/.luacheckrc new file mode 100644 index 00000000..00aa308f --- /dev/null +++ b/TEMPLATES/.luacheckrc @@ -0,0 +1 @@ +--std max diff --git a/docs/disabling-linters.md b/docs/disabling-linters.md index 2d3632d4..fbdb578e 100644 --- a/docs/disabling-linters.md +++ b/docs/disabling-linters.md @@ -44,6 +44,7 @@ For some linters it is also possible to override rules on a case by case level w - [Clojure](#clojure) - [EDITORCONFIG-CHECKER](#editorconfig-checker) - [HTML](#html) +- [LUA](#lua) @@ -859,6 +860,46 @@ import package.b.* --- +## Lua +- [luarocks](https://github.com/luarocks/luacheck) + +### luacheck standard Config file +- `.github/linters/.luacheckrc` +- You can pass multiple rules and overwrite default rules +- File should be located at: `.github/linters/.luacheckrc` +- See [luacheck](https://luacheck.readthedocs.io/en/stable/config.html) docs for additional + behaviors + +### luacheck disable single line +```lua +-- luacheck: globals g1 g2, ignore foo +local foo = g1(g2) -- No warnings emitted. +``` + +### luacheck disable code block +```lua +-- The following unused function is not reported. +local function f() -- luacheck: ignore + -- luacheck: globals g3 + g3() -- No warning. +end +``` + +### luacheck include/exclude files (via .luacheckrc) +```lua +include_files = {"src", "spec/*.lua", "scripts/*.lua", "*.rockspec", "*.luacheckrc"} +exclude_files = {"src/luacheck/vendor"} +``` + +### luacheck push/pop +```lua +-- luacheck: push ignore foo +foo() -- No warning. +-- luacheck: pop +foo() -- Warning is emitted. +``` +--- + ## Dart - [dartanalyzer](https://dart.dev/tools/dartanalyzer) diff --git a/lib/buildFileList.sh b/lib/buildFileList.sh index 2efc0fb3..05cdf29f 100755 --- a/lib/buildFileList.sh +++ b/lib/buildFileList.sh @@ -393,6 +393,15 @@ function BuildFileList() { # Set the READ_ONLY_CHANGE_FLAG since this could be exec # ########################################################## READ_ONLY_CHANGE_FLAG=1 + elif [ "$FILE_TYPE" == "lua" ]; then + ################################ + # Append the file to the array # + ################################ + FILE_ARRAY_LUA+=("$FILE") + ########################################################## + # Set the READ_ONLY_CHANGE_FLAG since this could be exec # + ########################################################## + READ_ONLY_CHANGE_FLAG=1 ############################ # Get the Protocol Buffers files # ############################ diff --git a/lib/linter.sh b/lib/linter.sh index 9e51f010..5ccbafaf 100755 --- a/lib/linter.sh +++ b/lib/linter.sh @@ -62,6 +62,9 @@ JAVASCRIPT_LINTER_RULES="${DEFAULT_RULES_LOCATION}/${JAVASCRIPT_FILE_NAME}" JAVASCRIPT_STANDARD_LINTER_RULES='' # ENV string to pass when running js standard # Default linter path LINTER_RULES_PATH="${LINTER_RULES_PATH:-.github/linters}" # Linter Path Directory +# Lua Vars +LUA_FILE_NAME='.luacheckrc' # Name of the file +LUA_LINTER_RULES="${DEFAULT_RULES_LOCATION}/${LUA_FILE_NAME}" # Path to the Lua lint rules # MD Vars MARKDOWN_FILE_NAME='.markdown-lint.yml' # Name of the file MARKDOWN_LINTER_RULES="${DEFAULT_RULES_LOCATION}/${MARKDOWN_FILE_NAME}" # Path to the markdown lint rules @@ -96,7 +99,7 @@ YAML_LINTER_RULES="${DEFAULT_RULES_LOCATION}/${YAML_FILE_NAME}" ####################################### LINTER_ARRAY=('ansible-lint' 'arm-ttk' 'asl-validator' 'cfn-lint' 'clj-kondo' 'coffeelint' 'dart' 'dockerfilelint' 'dotenv-linter' 'eslint' 'golangci-lint' - 'htmlhint' 'jsonlint' 'ktlint' 'markdownlint' 'npm-groovy-lint' 'perl' + 'htmlhint' 'jsonlint' 'ktlint' 'lua' 'markdownlint' 'npm-groovy-lint' 'perl' 'protolint' 'pwsh' 'pylint' 'raku' 'rubocop' 'shellcheck' 'spectral' 'standard' 'stylelint' 'terrascan' 'tflint' 'xmllint' 'yamllint') @@ -106,7 +109,7 @@ LINTER_ARRAY=('ansible-lint' 'arm-ttk' 'asl-validator' 'cfn-lint' 'clj-kondo' ############################# LANGUAGE_ARRAY=('ANSIBLE' 'ARM' 'BASH' 'CLOUDFORMATION' 'CLOJURE' 'COFFEESCRIPT' 'CSS' 'DART' 'DOCKER' 'ENV' 'GO' 'GROOVY' 'HTML' 'JAVASCRIPT_ES' - 'JAVASCRIPT_STANDARD' 'JSON' 'JSX' 'KOTLIN' 'MARKDOWN' 'OPENAPI' + 'JAVASCRIPT_STANDARD' 'JSON' 'JSX' 'KOTLIN' 'LUA' 'MARKDOWN' 'OPENAPI' 'PERL' 'PHP' 'POWERSHELL' 'PROTOBUF' 'PYTHON' 'RAKU' 'RUBY' 'STATES' 'TERRAFORM' 'TERRAFORM_TERRASCAN' 'TSX' 'TYPESCRIPT_ES' 'TYPESCRIPT_STANDARD' 'XML' 'YAML') @@ -151,6 +154,7 @@ VALIDATE_JAVASCRIPT_STANDARD="${VALIDATE_JAVASCRIPT_STANDARD}" # Boolean to vali VALIDATE_JSON="${VALIDATE_JSON}" # Boolean to validate language VALIDATE_JSX="${VALIDATE_JSX}" # Boolean to validate language VALIDATE_KOTLIN="${VALIDATE_KOTLIN}" # Boolean to validate language +VALIDATE_LUA="${VALIDATE_LUA}" # Boolean to validate language VALIDATE_MARKDOWN="${VALIDATE_MD:-}" # Boolean to validate language VALIDATE_OPENAPI="${VALIDATE_OPENAPI}" # Boolean to validate language VALIDATE_PERL="${VALIDATE_PERL}" # Boolean to validate language @@ -227,6 +231,7 @@ FILE_ARRAY_JAVASCRIPT_STANDARD=() # Array of files to check FILE_ARRAY_JSON=() # Array of files to check FILE_ARRAY_JSX=() # Array of files to check FILE_ARRAY_KOTLIN=() # Array of files to check +FILE_ARRAY_LUA=() # Array of files to check FILE_ARRAY_MARKDOWN=() # Array of files to check FILE_ARRAY_OPENAPI=() # Array of files to check FILE_ARRAY_PERL=() # Array of files to check @@ -283,6 +288,8 @@ ERRORS_FOUND_JSX=0 # Count of errors found export ERRORS_FOUND_JSX # Workaround SC2034 ERRORS_FOUND_KOTLIN=0 # Count of errors found export ERRORS_FOUND_KOTLIN # Workaround SC2034 +ERRORS_FOUND_LUA=0 # Count of errors found +export ERRORS_FOUND_LUA=0 # Workaround SC2034 ERRORS_FOUND_MARKDOWN=0 # Count of errors found export ERRORS_FOUND_MARKDOWN # Workaround SC2034 ERRORS_FOUND_OPENAPI=0 # Count of errors found @@ -1080,6 +1087,8 @@ GetLinterRules "GROOVY" GetLinterRules "HTML" # Get JavaScript rules GetLinterRules "JAVASCRIPT" +# Get LUA rules +GetLinterRules "LUA" # Get Markdown rules GetLinterRules "MARKDOWN" # Get PowerShell rules @@ -1397,6 +1406,17 @@ if [ "${VALIDATE_KOTLIN}" == "true" ]; then LintCodebase "KOTLIN" "ktlint" "ktlint" ".*\.\(kt\|kts\)\$" "${FILE_ARRAY_KOTLIN[@]}" fi +############### +# LUA LINTING # +############### +if [ "${VALIDATE_LUA}" == "true" ]; then + ###################### + # Lint the Lua files # + ###################### + # LintCodebase "FILE_TYPE" "LINTER_NAME" "LINTER_CMD" "FILE_TYPES_REGEX" "FILE_ARRAY" + LintCodebase "LUA" "lua" "luacheck --config ${LUA_LINTER_RULES}" ".*\.\(lua\)\$" "${FILE_ARRAY_LUA[@]}" +fi + #################### # MARKDOWN LINTING # #################### diff --git a/lib/worker.sh b/lib/worker.sh index 70141d10..ab23e60f 100755 --- a/lib/worker.sh +++ b/lib/worker.sh @@ -595,6 +595,7 @@ function RunTestCases() { TestCodebase "JAVASCRIPT_STANDARD" "standard" "standard ${JAVASCRIPT_STANDARD_LINTER_RULES}" ".*\.\(js\)\$" "javascript" TestCodebase "JSON" "jsonlint" "jsonlint" ".*\.\(json\)\$" "json" TestCodebase "KOTLIN" "ktlint" "ktlint" ".*\.\(kt\|kts\)\$" "kotlin" + TestCodebase "LUA" "lua" "luacheck" ".*\.\(lua\)\$" "lua" TestCodebase "MARKDOWN" "markdownlint" "markdownlint -c ${MARKDOWN_LINTER_RULES}" ".*\.\(md\)\$" "markdown" TestCodebase "PERL" "perl" "perl -Mstrict -cw" ".*\.\(pl\)\$" "perl" TestCodebase "PHP" "php" "php -l" ".*\.\(php\)\$" "php"