mirror of
https://github.com/super-linter/super-linter.git
synced 2024-11-22 00:31:07 -05:00
commit
6452f93b32
7 changed files with 116 additions and 9 deletions
13
.automation/test/kotlin/README.md
Normal file
13
.automation/test/kotlin/README.md
Normal file
|
@ -0,0 +1,13 @@
|
|||
# Kotlin Test Cases
|
||||
This folder holds the test cases for **Kotlin**.
|
||||
|
||||
## 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.
|
6
.automation/test/kotlin/kotlin_bad_1.kt
Normal file
6
.automation/test/kotlin/kotlin_bad_1.kt
Normal file
|
@ -0,0 +1,6 @@
|
|||
fun main() {
|
||||
val n = "World";
|
||||
val v = "Hello, ${n}!";
|
||||
|
||||
println(v);
|
||||
}
|
6
.automation/test/kotlin/kotlint_good_1.kt
Normal file
6
.automation/test/kotlin/kotlint_good_1.kt
Normal file
|
@ -0,0 +1,6 @@
|
|||
fun main() {
|
||||
val n = "World"
|
||||
val v = "Hello, $n!"
|
||||
|
||||
println(v)
|
||||
}
|
|
@ -28,6 +28,7 @@ RUN apk add --no-cache \
|
|||
ruby ruby-dev ruby-bundler ruby-rdoc make \
|
||||
py3-setuptools ansible-lint \
|
||||
go \
|
||||
openjdk8-jre \
|
||||
php7 \
|
||||
ca-certificates less ncurses-terminfo-base \
|
||||
krb5-libs libgcc libintl libssl1.1 libstdc++ \
|
||||
|
@ -130,6 +131,12 @@ RUN curl -Ls "$(curl -Ls https://api.github.com/repos/terraform-linters/tflint/r
|
|||
RUN wget "https://github.com/dotenv-linter/dotenv-linter/releases/latest/download/dotenv-linter-alpine-x86_64.tar.gz" -O - -q | tar -xzf - \
|
||||
&& mv "dotenv-linter" /usr/bin
|
||||
|
||||
##################
|
||||
# Install ktlint #
|
||||
##################
|
||||
RUN curl -sSLO https://github.com/pinterest/ktlint/releases/latest/download/ktlint && chmod a+x ktlint \
|
||||
&& mv "ktlint" /usr/bin/
|
||||
|
||||
###########################################
|
||||
# Load GitHub Env Vars for GitHub Actions #
|
||||
###########################################
|
||||
|
@ -158,6 +165,7 @@ ENV GITHUB_SHA=${GITHUB_SHA} \
|
|||
VALIDATE_TERRAFORM=${VALIDATE_TERRAFORM} \
|
||||
VALIDATE_CSS=${VALIDATE_CSS} \
|
||||
VALIDATE_ENV=${VALIDATE_ENV} \
|
||||
VALIDATE_KOTLIN=${VALIDATE_KOTLIN} \
|
||||
VALIDATE_POWERSHELL=${VALIDATE_POWERSHELL} \
|
||||
ANSIBLE_DIRECTORY=${ANSIBLE_DIRECTORY} \
|
||||
RUN_LOCAL=${RUN_LOCAL} \
|
||||
|
|
|
@ -37,6 +37,7 @@ Developers on **GitHub** can call the **GitHub Action** to lint their code base
|
|||
| **YAML** | [YamlLint](https://github.com/adrienverge/yamllint) |
|
||||
| **PowerShell** | [PSScriptAnalyzer](https://github.com/PowerShell/Psscriptanalyzer) |
|
||||
| **ENV** | [dotenv-linter](https://github.com/dotenv-linter/dotenv-linter) |
|
||||
| **Kotlin** | [ktlint](https://github.com/pinterest/ktlint) |
|
||||
|
||||
## How to use
|
||||
To use this **GitHub** Action you will need to complete the following:
|
||||
|
@ -141,6 +142,7 @@ and won't run anything unexpected.
|
|||
| **VALIDATE_TERRAFORM** | `true` | Flag to enable or disable the linting process of the language. |
|
||||
| **VALIDATE_CSS** | `true` | Flag to enable or disable the linting process of the language. |
|
||||
| **VALIDATE_ENV** | `true` | Flag to enable or disable the linting process of the language. |
|
||||
| **VALIDATE_KOTLIN** | `true` | Flag to enable or disable the linting process of the language. |
|
||||
| **ANSIBLE_DIRECTORY** | `/ansible` | Flag to set the root directory for Ansible file location(s). |
|
||||
| **ACTIONS_RUNNER_DEBUG** | `false` | Flag to enable additional information about the linter, versions, and additional output. |
|
||||
| **DISABLE_ERRORS** | `false` | Flag to have the linter complete with exit code 0 even if errors were detected. |
|
||||
|
|
|
@ -21,8 +21,9 @@ Below is examples and documentation for each language and the various methods to
|
|||
- [Golang](#golang)
|
||||
- [Dockerfile](#dockerfile)
|
||||
- [Terraform](#terraform)
|
||||
- [CSS](#css)
|
||||
- [ENV](#env)
|
||||
- [CSS](#stylelint)
|
||||
- [ENV](#dotenv-linter)
|
||||
- [Kotlin](#kotlin)
|
||||
|
||||
<!-- toc -->
|
||||
|
||||
|
@ -582,3 +583,27 @@ a {}
|
|||
|
||||
### dotenv-linter disable entire file
|
||||
- There is currently **No** way to disable rules inline of the file(s)
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
## Kotlin
|
||||
- [ktlint](https://github.com/pinterest/ktlint)
|
||||
|
||||
### ktlint Config file
|
||||
- There is no top level *configuration file* available at this time
|
||||
|
||||
### ktlint disable single line
|
||||
```kotlin
|
||||
import package.* // ktlint-disable no-wildcard-imports
|
||||
```
|
||||
|
||||
### ktlint disable code block
|
||||
```kotlin
|
||||
/* ktlint-disable no-wildcard-imports */
|
||||
import package.a.*
|
||||
import package.b.*
|
||||
/* ktlint-enable no-wildcard-imports */
|
||||
```
|
||||
|
||||
### ktlint disable entire file
|
||||
- There is currently **No** way to disable rules inline of the file(s)
|
||||
|
|
|
@ -61,15 +61,15 @@ CSS_LINTER_RULES="$DEFAULT_RULES_LOCATION/$CSS_FILE_NAME" # Path to th
|
|||
LINTER_ARRAY=("jsonlint" "yamllint" "xmllint" "markdownlint" "shellcheck"
|
||||
"pylint" "perl" "rubocop" "coffeelint" "eslint" "standard"
|
||||
"ansible-lint" "/dockerfilelint/bin/dockerfilelint" "golangci-lint" "tflint"
|
||||
"stylelint" "dotenv-linter" "powershell")
|
||||
"stylelint" "dotenv-linter" "powershell" "ktlint")
|
||||
|
||||
#############################
|
||||
# Language array for prints #
|
||||
#############################
|
||||
LANGUAGE_ARRAY=('YML' 'JSON' 'XML' 'MARKDOWN' 'BASH' 'PERL' 'PHP' 'RUBY' 'PYTHON'
|
||||
'COFFEESCRIPT' 'ANSIBLE' 'JAVASCRIPT_STANDARD' 'JAVASCRIPT_ES'
|
||||
'TYPESCRIPT_STANDARD' 'TYPESCRIPT_ES' 'DOCKER' 'GO' 'TERRAFORM' 'CSS'
|
||||
'ENV' 'POWERSHELL')
|
||||
'TYPESCRIPT_STANDARD' 'TYPESCRIPT_ES' 'DOCKER' 'GO' 'TERRAFORM'
|
||||
'ENV' 'POWERSHELL' 'KOTLIN')
|
||||
|
||||
###################
|
||||
# GitHub ENV Vars #
|
||||
|
@ -101,6 +101,7 @@ VALIDATE_TERRAFORM="${VALIDATE_TERRAFORM}" # Boolean to validate lang
|
|||
VALIDATE_POWERSHELL="${VALIDATE_POWERSHELL}" # Boolean to validate language
|
||||
VALIDATE_CSS="${VALIDATE_CSS}" # Boolean to validate language
|
||||
VALIDATE_ENV="${VALIDATE_ENV}" # Boolean to validate language
|
||||
VALIDATE_KOTLIN="${VALIDATE_KOTLIN}" # Boolean to validate language
|
||||
TEST_CASE_RUN="${TEST_CASE_RUN}" # Boolean to validate only test cases
|
||||
DISABLE_ERRORS="${DISABLE_ERRORS}" # Boolean to enable warning-only output without throwing errors
|
||||
|
||||
|
@ -147,6 +148,7 @@ FILE_ARRAY_TERRAFORM=() # Array of files to check
|
|||
FILE_ARRAY_POWERSHELL=() # Array of files to check
|
||||
FILE_ARRAY_CSS=() # Array of files to check
|
||||
FILE_ARRAY_ENV=() # Array of files to check
|
||||
FILE_ARRAY_KOTLIN=() # Array of files to check
|
||||
|
||||
############
|
||||
# Counters #
|
||||
|
@ -172,6 +174,7 @@ ERRORS_FOUND_TERRAFORM=0 # Count of errors found
|
|||
ERRORS_FOUND_POWERSHELL=0 # Count of errors found
|
||||
ERRORS_FOUND_CSS=0 # Count of errors found
|
||||
ERRORS_FOUND_ENV=0 # Count of errors found
|
||||
ERRORS_FOUND_KOTLIN=0 # Count of errors found
|
||||
|
||||
################################################################################
|
||||
########################## FUNCTIONS BELOW #####################################
|
||||
|
@ -752,6 +755,7 @@ GetValidationInfo()
|
|||
VALIDATE_POWERSHELL=$(echo "$VALIDATE_POWERSHELL" | awk '{print tolower($0)}')
|
||||
VALIDATE_CSS=$(echo "$VALIDATE_CSS" | awk '{print tolower($0)}')
|
||||
VALIDATE_ENV=$(echo "$VALIDATE_ENV" | awk '{print tolower($0)}')
|
||||
VALIDATE_KOTLIN=$(echo "$VALIDATE_KOTLIN" | awk '{print tolower($0)}')
|
||||
|
||||
################################################
|
||||
# Determine if any linters were explicitly set #
|
||||
|
@ -777,7 +781,8 @@ GetValidationInfo()
|
|||
-n "$VALIDATE_TERRAFORM" || \
|
||||
-n "$VALIDATE_POWERSHELL" || \
|
||||
-n "$VALIDATE_CSS" || \
|
||||
-n "$VALIDATE_ENV" ]]; then
|
||||
-n "$VALIDATE_ENV" || \
|
||||
-n "$VALIDATE_KOTLIN" ]]; then
|
||||
ANY_SET="true"
|
||||
fi
|
||||
|
||||
|
@ -1075,6 +1080,21 @@ GetValidationInfo()
|
|||
VALIDATE_ENV="true"
|
||||
fi
|
||||
|
||||
######################################
|
||||
# Validate if we should check KOTLIN #
|
||||
######################################
|
||||
if [[ "$ANY_SET" == "true" ]]; then
|
||||
# Some linter flags were set - only run those set to true
|
||||
if [[ -z "$VALIDATE_KOTLIN" ]]; then
|
||||
# ENV flag was not set - default to false
|
||||
VALIDATE_KOTLIN="false"
|
||||
fi
|
||||
else
|
||||
# No linter flags were set - default all to true
|
||||
VALIDATE_KOTLIN="true"
|
||||
fi
|
||||
|
||||
|
||||
#######################################
|
||||
# Print which linters we are enabling #
|
||||
#######################################
|
||||
|
@ -1183,6 +1203,11 @@ GetValidationInfo()
|
|||
else
|
||||
PRINT_ARRAY+=("- Excluding [ENV] files in code base...")
|
||||
fi
|
||||
if [[ "$VALIDATE_KOTLIN" == "true" ]]; then
|
||||
PRINT_ARRAY+=("- Validating [KOTLIN] files in code base...")
|
||||
else
|
||||
PRINT_ARRAY+=("- Excluding [KOTLIN] files in code base...")
|
||||
fi
|
||||
|
||||
##############################
|
||||
# Validate Ansible Directory #
|
||||
|
@ -1550,6 +1575,15 @@ BuildFileList()
|
|||
# Set the READ_ONLY_CHANGE_FLAG since this could be exec #
|
||||
##########################################################
|
||||
READ_ONLY_CHANGE_FLAG=1
|
||||
elif [ "$FILE_TYPE" == "kt" ] || [ "$FILE_TYPE" == "kts" ]; then
|
||||
################################
|
||||
# Append the file to the array #
|
||||
################################
|
||||
FILE_ARRAY_KOTLIN+=("$FILE")
|
||||
##########################################################
|
||||
# Set the READ_ONLY_CHANGE_FLAG since this could be exec #
|
||||
##########################################################
|
||||
READ_ONLY_CHANGE_FLAG=1
|
||||
elif [ "$FILE" == "Dockerfile" ]; then
|
||||
################################
|
||||
# Append the file to the array #
|
||||
|
@ -2087,7 +2121,8 @@ Footer()
|
|||
[ "$ERRORS_FOUND_POWERSHELL" -ne 0 ] || \
|
||||
[ "$ERRORS_FOUND_RUBY" -ne 0 ] || \
|
||||
[ "$ERRORS_FOUND_CSS" -ne 0 ] || \
|
||||
[ "$ERRORS_FOUND_ENV" -ne 0 ]; then
|
||||
[ "$ERRORS_FOUND_ENV" -ne 0 ] || \
|
||||
[ "$ERRORS_FOUND_KOTLIN" -ne 0 ]; then
|
||||
# Failed exit
|
||||
echo "Exiting with errors found!"
|
||||
exit 1
|
||||
|
@ -2147,7 +2182,8 @@ RunTestCases()
|
|||
TestCodebase "TERRAFORM" "tflint" "tflint -c $TERRAFORM_LINTER_RULES" ".*\.\(tf\)\$"
|
||||
TestCodebase "POWERSHELL" "pwsh" "pwsh -c Invoke-ScriptAnalyzer -EnableExit -Settings $POWERSHELL_LINTER_RULES -Path" ".*\.\(ps1\|psm1\|psd1\|ps1xml\|pssc\|psrc\|cdxml\)\$"
|
||||
TestCodebase "CSS" "stylelint" "stylelint --config $CSS_LINTER_RULES" ".*\.\(css\)\$"
|
||||
TestCodebase "ENV" "dotenv-linter" "dotenv-linter" ".*\.\(env\).*\$"
|
||||
TestCodebase "ENV" "dotenv-linter" "dotenv-linter" ".*\.\(env\)\$"
|
||||
TestCodebase "KOTLIN" "ktlint" "ktlint" ".*\.\(kt\|kts\)\$"
|
||||
|
||||
#################
|
||||
# Footer prints #
|
||||
|
@ -2457,6 +2493,17 @@ if [ "$VALIDATE_ENV" == "true" ]; then
|
|||
LintCodebase "ENV" "dotenv-linter" "dotenv-linter" ".*\.\(env\).*\$" "${FILE_ARRAY_ENV[@]}"
|
||||
fi
|
||||
|
||||
##################
|
||||
# KOTLIN LINTING #
|
||||
##################
|
||||
if [ "$VALIDATE_KOTLIN" == "true" ]; then
|
||||
#######################
|
||||
# Lint the Kotlin files #
|
||||
#######################
|
||||
# LintCodebase "FILE_TYPE" "LINTER_NAME" "LINTER_CMD" "FILE_TYPES_REGEX" "FILE_ARRAY"
|
||||
LintCodebase "KOTLIN" "ktlint" "ktlint" ".*\.\(kt\|kts\)\$" "${FILE_ARRAY_ENV[@]}"
|
||||
fi
|
||||
|
||||
##################
|
||||
# DOCKER LINTING #
|
||||
##################
|
||||
|
|
Loading…
Reference in a new issue