Skip to content

Commit

Permalink
Merge pull request #476 from github/lua
Browse files Browse the repository at this point in the history
add lua/luacheck to super-linter
  • Loading branch information
admiralAwkbar committed Jul 27, 2020
2 parents ce92354 + 5fa6aca commit 85209cf
Show file tree
Hide file tree
Showing 11 changed files with 133 additions and 2 deletions.
13 changes: 13 additions & 0 deletions .automation/test/lua/README.md
Original file line number Diff line number Diff line change
@@ -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.
9 changes: 9 additions & 0 deletions .automation/test/lua/lua_bad_1.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package.loaded[...] = {}

local function helper(...)
-- NYI
end

function embrace(opt)
local opt = opt or "default"
return hepler(opt.."?")
12 changes: 12 additions & 0 deletions .automation/test/lua/lua_good_1.lua
Original file line number Diff line number Diff line change
@@ -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 change: 1 addition & 0 deletions .github/linters/.luacheckrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
--std max
22 changes: 22 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand All @@ -66,6 +68,7 @@ RUN apk add --update --no-cache \
perl \
php7 \
py3-setuptools \
readline-dev \
ruby ruby-dev ruby-bundler ruby-rdoc

########################################
Expand Down Expand Up @@ -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 #
###########################################
Expand Down Expand Up @@ -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} \
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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) |
Expand Down Expand Up @@ -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. |
Expand Down
1 change: 1 addition & 0 deletions TEMPLATES/.luacheckrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
--std max
41 changes: 41 additions & 0 deletions docs/disabling-linters.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

<!-- toc -->

Expand Down Expand Up @@ -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)
Expand Down
9 changes: 9 additions & 0 deletions lib/buildFileList.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 #
############################
Expand Down
24 changes: 22 additions & 2 deletions lib/linter.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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')

Expand All @@ -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')
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 #
####################
Expand Down
1 change: 1 addition & 0 deletions lib/worker.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 85209cf

Please sign in to comment.