Merge pull request #476 from github/lua

add lua/luacheck to super-linter
This commit is contained in:
Lukas Gravley 2020-07-27 12:13:39 -05:00 committed by GitHub
commit 85209cfb5d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 133 additions and 2 deletions

View file

@ -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.

View file

@ -0,0 +1,9 @@
package.loaded[...] = {}
local function helper(...)
-- NYI
end
function embrace(opt)
local opt = opt or "default"
return hepler(opt.."?")

View file

@ -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

1
.github/linters/.luacheckrc vendored Normal file
View file

@ -0,0 +1 @@
--std max

View file

@ -52,12 +52,14 @@ ARG GLIBC_VERSION='2.31-r0'
RUN apk add --update --no-cache \ RUN apk add --update --no-cache \
ansible-lint \ ansible-lint \
bash \ bash \
coreutils \
curl \ curl \
gcc \ gcc \
git git-lfs\ git git-lfs\
go \ go \
icu-libs \ icu-libs \
jq \ jq \
libc-dev \
libxml2-utils \ libxml2-utils \
make \ make \
musl-dev \ musl-dev \
@ -66,6 +68,7 @@ RUN apk add --update --no-cache \
perl \ perl \
php7 \ php7 \
py3-setuptools \ py3-setuptools \
readline-dev \
ruby ruby-dev ruby-bundler ruby-rdoc 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 \ RUN echo "http://dl-cdn.alpinelinux.org/alpine/edge/testing/" >> /etc/apk/repositories \
&& apk add --update --no-cache rakudo zef && 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 # # 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_JAVASCRIPT_STANDARD=${VALIDATE_JAVASCRIPT_STANDARD} \
VALIDATE_JSON=${VALIDATE_JSON} \ VALIDATE_JSON=${VALIDATE_JSON} \
VALIDATE_KOTLIN=${VALIDATE_KOTLIN} \ VALIDATE_KOTLIN=${VALIDATE_KOTLIN} \
VALIDATE_LUA=${VALIDATE_LUA} \
VALIDATE_MD=${VALIDATE_MD} \ VALIDATE_MD=${VALIDATE_MD} \
VALIDATE_OPENAPI=${VALIDATE_OPENAPI} \ VALIDATE_OPENAPI=${VALIDATE_OPENAPI} \
VALIDATE_PERL=${VALIDATE_PERL} \ VALIDATE_PERL=${VALIDATE_PERL} \

View file

@ -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/) | | **JavaScript** | [eslint](https://eslint.org/) [standard js](https://standardjs.com/) |
| **JSON** | [jsonlint](https://github.com/zaach/jsonlint) | | **JSON** | [jsonlint](https://github.com/zaach/jsonlint) |
| **Kotlin** | [ktlint](https://github.com/pinterest/ktlint) | | **Kotlin** | [ktlint](https://github.com/pinterest/ktlint) |
| **Lua** | [luacheck](https://github.com/luarocks/luacheck) |
| **Markdown** | [markdownlint](https://github.com/igorshubovych/markdownlint-cli#readme) | | **Markdown** | [markdownlint](https://github.com/igorshubovych/markdownlint-cli#readme) |
| **OpenAPI** | [spectral](https://github.com/stoplightio/spectral) | | **OpenAPI** | [spectral](https://github.com/stoplightio/spectral) |
| **Perl** | [perl](https://pkgs.alpinelinux.org/package/edge/main/x86/perl) | | **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_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_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_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_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_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. | | **VALIDATE_PERL** | `true` | Flag to enable or disable the linting process of the Perl language. |

1
TEMPLATES/.luacheckrc Normal file
View file

@ -0,0 +1 @@
--std max

View file

@ -44,6 +44,7 @@ For some linters it is also possible to override rules on a case by case level w
- [Clojure](#clojure) - [Clojure](#clojure)
- [EDITORCONFIG-CHECKER](#editorconfig-checker) - [EDITORCONFIG-CHECKER](#editorconfig-checker)
- [HTML](#html) - [HTML](#html)
- [LUA](#lua)
<!-- toc --> <!-- toc -->
@ -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 ## Dart
- [dartanalyzer](https://dart.dev/tools/dartanalyzer) - [dartanalyzer](https://dart.dev/tools/dartanalyzer)

View file

@ -393,6 +393,15 @@ function BuildFileList() {
# Set the READ_ONLY_CHANGE_FLAG since this could be exec # # Set the READ_ONLY_CHANGE_FLAG since this could be exec #
########################################################## ##########################################################
READ_ONLY_CHANGE_FLAG=1 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 # # Get the Protocol Buffers files #
############################ ############################

View file

@ -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 JAVASCRIPT_STANDARD_LINTER_RULES='' # ENV string to pass when running js standard
# Default linter path # Default linter path
LINTER_RULES_PATH="${LINTER_RULES_PATH:-.github/linters}" # Linter Path Directory 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 # MD Vars
MARKDOWN_FILE_NAME='.markdown-lint.yml' # Name of the file 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 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' LINTER_ARRAY=('ansible-lint' 'arm-ttk' 'asl-validator' 'cfn-lint' 'clj-kondo'
'coffeelint' 'dart' 'dockerfilelint' 'dotenv-linter' 'eslint' 'golangci-lint' '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' 'protolint' 'pwsh' 'pylint' 'raku' 'rubocop' 'shellcheck' 'spectral'
'standard' 'stylelint' 'terrascan' 'tflint' 'xmllint' 'yamllint') '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' LANGUAGE_ARRAY=('ANSIBLE' 'ARM' 'BASH' 'CLOUDFORMATION' 'CLOJURE' 'COFFEESCRIPT'
'CSS' 'DART' 'DOCKER' 'ENV' 'GO' 'GROOVY' 'HTML' 'JAVASCRIPT_ES' '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' 'PERL' 'PHP' 'POWERSHELL' 'PROTOBUF' 'PYTHON'
'RAKU' 'RUBY' 'STATES' 'TERRAFORM' 'TERRAFORM_TERRASCAN' 'TSX' 'TYPESCRIPT_ES' 'RAKU' 'RUBY' 'STATES' 'TERRAFORM' 'TERRAFORM_TERRASCAN' 'TSX' 'TYPESCRIPT_ES'
'TYPESCRIPT_STANDARD' 'XML' 'YAML') '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_JSON="${VALIDATE_JSON}" # Boolean to validate language
VALIDATE_JSX="${VALIDATE_JSX}" # Boolean to validate language VALIDATE_JSX="${VALIDATE_JSX}" # Boolean to validate language
VALIDATE_KOTLIN="${VALIDATE_KOTLIN}" # 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_MARKDOWN="${VALIDATE_MD:-}" # Boolean to validate language
VALIDATE_OPENAPI="${VALIDATE_OPENAPI}" # Boolean to validate language VALIDATE_OPENAPI="${VALIDATE_OPENAPI}" # Boolean to validate language
VALIDATE_PERL="${VALIDATE_PERL}" # 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_JSON=() # Array of files to check
FILE_ARRAY_JSX=() # Array of files to check FILE_ARRAY_JSX=() # Array of files to check
FILE_ARRAY_KOTLIN=() # 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_MARKDOWN=() # Array of files to check
FILE_ARRAY_OPENAPI=() # Array of files to check FILE_ARRAY_OPENAPI=() # Array of files to check
FILE_ARRAY_PERL=() # 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 export ERRORS_FOUND_JSX # Workaround SC2034
ERRORS_FOUND_KOTLIN=0 # Count of errors found ERRORS_FOUND_KOTLIN=0 # Count of errors found
export ERRORS_FOUND_KOTLIN # Workaround SC2034 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 ERRORS_FOUND_MARKDOWN=0 # Count of errors found
export ERRORS_FOUND_MARKDOWN # Workaround SC2034 export ERRORS_FOUND_MARKDOWN # Workaround SC2034
ERRORS_FOUND_OPENAPI=0 # Count of errors found ERRORS_FOUND_OPENAPI=0 # Count of errors found
@ -1080,6 +1087,8 @@ GetLinterRules "GROOVY"
GetLinterRules "HTML" GetLinterRules "HTML"
# Get JavaScript rules # Get JavaScript rules
GetLinterRules "JAVASCRIPT" GetLinterRules "JAVASCRIPT"
# Get LUA rules
GetLinterRules "LUA"
# Get Markdown rules # Get Markdown rules
GetLinterRules "MARKDOWN" GetLinterRules "MARKDOWN"
# Get PowerShell rules # Get PowerShell rules
@ -1397,6 +1406,17 @@ if [ "${VALIDATE_KOTLIN}" == "true" ]; then
LintCodebase "KOTLIN" "ktlint" "ktlint" ".*\.\(kt\|kts\)\$" "${FILE_ARRAY_KOTLIN[@]}" LintCodebase "KOTLIN" "ktlint" "ktlint" ".*\.\(kt\|kts\)\$" "${FILE_ARRAY_KOTLIN[@]}"
fi 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 # # MARKDOWN LINTING #
#################### ####################

View file

@ -595,6 +595,7 @@ function RunTestCases() {
TestCodebase "JAVASCRIPT_STANDARD" "standard" "standard ${JAVASCRIPT_STANDARD_LINTER_RULES}" ".*\.\(js\)\$" "javascript" TestCodebase "JAVASCRIPT_STANDARD" "standard" "standard ${JAVASCRIPT_STANDARD_LINTER_RULES}" ".*\.\(js\)\$" "javascript"
TestCodebase "JSON" "jsonlint" "jsonlint" ".*\.\(json\)\$" "json" TestCodebase "JSON" "jsonlint" "jsonlint" ".*\.\(json\)\$" "json"
TestCodebase "KOTLIN" "ktlint" "ktlint" ".*\.\(kt\|kts\)\$" "kotlin" TestCodebase "KOTLIN" "ktlint" "ktlint" ".*\.\(kt\|kts\)\$" "kotlin"
TestCodebase "LUA" "lua" "luacheck" ".*\.\(lua\)\$" "lua"
TestCodebase "MARKDOWN" "markdownlint" "markdownlint -c ${MARKDOWN_LINTER_RULES}" ".*\.\(md\)\$" "markdown" TestCodebase "MARKDOWN" "markdownlint" "markdownlint -c ${MARKDOWN_LINTER_RULES}" ".*\.\(md\)\$" "markdown"
TestCodebase "PERL" "perl" "perl -Mstrict -cw" ".*\.\(pl\)\$" "perl" TestCodebase "PERL" "perl" "perl -Mstrict -cw" ".*\.\(pl\)\$" "perl"
TestCodebase "PHP" "php" "php -l" ".*\.\(php\)\$" "php" TestCodebase "PHP" "php" "php -l" ".*\.\(php\)\$" "php"