mirror of
https://github.com/super-linter/super-linter.git
synced 2024-11-22 00:31:07 -05:00
Add kotlin support to super-linter
This commit is contained in:
parent
9537bb5051
commit
037865ec11
7 changed files with 111 additions and 5 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)
|
||||||
|
}
|
|
@ -27,7 +27,7 @@ RUN apk add --no-cache \
|
||||||
libxml2-utils perl \
|
libxml2-utils perl \
|
||||||
ruby ruby-dev ruby-bundler ruby-rdoc make \
|
ruby ruby-dev ruby-bundler ruby-rdoc make \
|
||||||
py3-setuptools ansible-lint \
|
py3-setuptools ansible-lint \
|
||||||
go
|
go openjdk8-jre
|
||||||
|
|
||||||
#####################
|
#####################
|
||||||
# Run Pip3 Installs #
|
# Run Pip3 Installs #
|
||||||
|
@ -108,6 +108,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 - \
|
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
|
&& mv "dotenv-linter" /usr/bin
|
||||||
|
|
||||||
|
##################
|
||||||
|
# Install ktlint #
|
||||||
|
##################
|
||||||
|
RUN curl -sSLO https://github.com/pinterest/ktlint/releases/download/0.37.2/ktlint && chmod a+x ktlint \
|
||||||
|
&& mv "ktlint" /usr/bin/
|
||||||
|
|
||||||
###########################################
|
###########################################
|
||||||
# Load GitHub Env Vars for GitHub Actions #
|
# Load GitHub Env Vars for GitHub Actions #
|
||||||
###########################################
|
###########################################
|
||||||
|
@ -135,6 +141,7 @@ ENV GITHUB_SHA=${GITHUB_SHA} \
|
||||||
VALIDATE_TERRAFORM=${VALIDATE_TERRAFORM} \
|
VALIDATE_TERRAFORM=${VALIDATE_TERRAFORM} \
|
||||||
VALIDATE_CSS=${VALIDATE_CSS} \
|
VALIDATE_CSS=${VALIDATE_CSS} \
|
||||||
VALIDATE_ENV=${VALIDATE_ENV} \
|
VALIDATE_ENV=${VALIDATE_ENV} \
|
||||||
|
VALIDATE_KOTLIN=${VALIDATE_KOTLIN} \
|
||||||
ANSIBLE_DIRECTORY=${ANSIBLE_DIRECTORY} \
|
ANSIBLE_DIRECTORY=${ANSIBLE_DIRECTORY} \
|
||||||
RUN_LOCAL=${RUN_LOCAL} \
|
RUN_LOCAL=${RUN_LOCAL} \
|
||||||
TEST_CASE_RUN=${TEST_CASE_RUN} \
|
TEST_CASE_RUN=${TEST_CASE_RUN} \
|
||||||
|
|
|
@ -35,6 +35,7 @@ Developers on **GitHub** can call the **GitHub Action** to lint their code base
|
||||||
| **XML** | [LibXML](http://xmlsoft.org/) |
|
| **XML** | [LibXML](http://xmlsoft.org/) |
|
||||||
| **YAML** | [YamlLint](https://github.com/adrienverge/yamllint) |
|
| **YAML** | [YamlLint](https://github.com/adrienverge/yamllint) |
|
||||||
| **ENV** | [dotenv-linter](https://github.com/dotenv-linter/dotenv-linter) |
|
| **ENV** | [dotenv-linter](https://github.com/dotenv-linter/dotenv-linter) |
|
||||||
|
| **Kotlin** | [ktlint](https://github.com/pinterest/ktlint) |
|
||||||
|
|
||||||
## How to use
|
## How to use
|
||||||
To use this **GitHub** Action you will need to complete the following:
|
To use this **GitHub** Action you will need to complete the following:
|
||||||
|
@ -137,6 +138,7 @@ and won't run anything unexpected.
|
||||||
| **VALIDATE_TERRAFORM** | `true` | Flag to enable or disable the linting process of the language. |
|
| **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_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_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). |
|
| **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. |
|
| **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. |
|
| **DISABLE_ERRORS** | `false` | Flag to have the linter complete with exit code 0 even if errors were detected. |
|
||||||
|
|
|
@ -22,6 +22,7 @@ Below is examples and documentation for each language and the various methods to
|
||||||
- [Terraform](#terraform)
|
- [Terraform](#terraform)
|
||||||
- [CSS](#stylelint)
|
- [CSS](#stylelint)
|
||||||
- [ENV](#dotenv-linter)
|
- [ENV](#dotenv-linter)
|
||||||
|
- [Kotlin](#kotlin)
|
||||||
|
|
||||||
<!-- toc -->
|
<!-- toc -->
|
||||||
|
|
||||||
|
@ -564,3 +565,27 @@ a {}
|
||||||
|
|
||||||
### dotenv-linter disable entire file
|
### dotenv-linter disable entire file
|
||||||
- There is currently **No** way to disable rules inline of the file(s)
|
- 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)
|
||||||
|
|
|
@ -59,14 +59,14 @@ CSS_LINTER_RULES="$DEFAULT_RULES_LOCATION/$CSS_FILE_NAME" # Path to th
|
||||||
LINTER_ARRAY=("jsonlint" "yamllint" "xmllint" "markdownlint" "shellcheck"
|
LINTER_ARRAY=("jsonlint" "yamllint" "xmllint" "markdownlint" "shellcheck"
|
||||||
"pylint" "perl" "rubocop" "coffeelint" "eslint" "standard"
|
"pylint" "perl" "rubocop" "coffeelint" "eslint" "standard"
|
||||||
"ansible-lint" "/dockerfilelint/bin/dockerfilelint" "golangci-lint" "tflint"
|
"ansible-lint" "/dockerfilelint/bin/dockerfilelint" "golangci-lint" "tflint"
|
||||||
"stylelint" "dotenv-linter")
|
"stylelint" "dotenv-linter" "ktlint")
|
||||||
|
|
||||||
#############################
|
#############################
|
||||||
# Language array for prints #
|
# Language array for prints #
|
||||||
#############################
|
#############################
|
||||||
LANGUAGE_ARRAY=('YML' 'JSON' 'XML' 'MARKDOWN' 'BASH' 'PERL' 'RUBY' 'PYTHON'
|
LANGUAGE_ARRAY=('YML' 'JSON' 'XML' 'MARKDOWN' 'BASH' 'PERL' 'RUBY' 'PYTHON'
|
||||||
'COFFEESCRIPT' 'ANSIBLE' 'JAVASCRIPT_STANDARD' 'JAVASCRIPT_ES'
|
'COFFEESCRIPT' 'ANSIBLE' 'JAVASCRIPT_STANDARD' 'JAVASCRIPT_ES'
|
||||||
'TYPESCRIPT_STANDARD' 'TYPESCRIPT_ES' 'DOCKER' 'GO' 'TERRAFORM' 'CSS' "ENV")
|
'TYPESCRIPT_STANDARD' 'TYPESCRIPT_ES' 'DOCKER' 'GO' 'TERRAFORM' 'CSS' 'ENV' 'KOTLIN')
|
||||||
|
|
||||||
###################
|
###################
|
||||||
# GitHub ENV Vars #
|
# GitHub ENV Vars #
|
||||||
|
@ -96,6 +96,7 @@ VALIDATE_GO="${VALIDATE_GO}" # Boolean to validate lang
|
||||||
VALIDATE_TERRAFORM="${VALIDATE_TERRAFORM}" # Boolean to validate language
|
VALIDATE_TERRAFORM="${VALIDATE_TERRAFORM}" # Boolean to validate language
|
||||||
VALIDATE_CSS="${VALIDATE_CSS}" # Boolean to validate language
|
VALIDATE_CSS="${VALIDATE_CSS}" # Boolean to validate language
|
||||||
VALIDATE_ENV="${VALIDATE_ENV}" # 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
|
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
|
DISABLE_ERRORS="${DISABLE_ERRORS}" # Boolean to enable warning-only output without throwing errors
|
||||||
|
|
||||||
|
@ -140,6 +141,7 @@ FILE_ARRAY_GO=() # Array of files to check
|
||||||
FILE_ARRAY_TERRAFORM=() # Array of files to check
|
FILE_ARRAY_TERRAFORM=() # Array of files to check
|
||||||
FILE_ARRAY_CSS=() # Array of files to check
|
FILE_ARRAY_CSS=() # Array of files to check
|
||||||
FILE_ARRAY_ENV=() # Array of files to check
|
FILE_ARRAY_ENV=() # Array of files to check
|
||||||
|
FILE_ARRAY_KOTLIN=() # Array of files to check
|
||||||
|
|
||||||
############
|
############
|
||||||
# Counters #
|
# Counters #
|
||||||
|
@ -163,6 +165,7 @@ ERRORS_FOUND_GO=0 # Count of errors found
|
||||||
ERRORS_FOUND_TERRAFORM=0 # Count of errors found
|
ERRORS_FOUND_TERRAFORM=0 # Count of errors found
|
||||||
ERRORS_FOUND_CSS=0 # Count of errors found
|
ERRORS_FOUND_CSS=0 # Count of errors found
|
||||||
ERRORS_FOUND_ENV=0 # Count of errors found
|
ERRORS_FOUND_ENV=0 # Count of errors found
|
||||||
|
ERRORS_FOUND_KOTLIN=0 # Count of errors found
|
||||||
|
|
||||||
################################################################################
|
################################################################################
|
||||||
########################## FUNCTIONS BELOW #####################################
|
########################## FUNCTIONS BELOW #####################################
|
||||||
|
@ -741,6 +744,7 @@ GetValidationInfo()
|
||||||
VALIDATE_TERRAFORM=$(echo "$VALIDATE_TERRAFORM" | awk '{print tolower($0)}')
|
VALIDATE_TERRAFORM=$(echo "$VALIDATE_TERRAFORM" | awk '{print tolower($0)}')
|
||||||
VALIDATE_CSS=$(echo "$VALIDATE_CSS" | awk '{print tolower($0)}')
|
VALIDATE_CSS=$(echo "$VALIDATE_CSS" | awk '{print tolower($0)}')
|
||||||
VALIDATE_ENV=$(echo "$VALIDATE_ENV" | 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 #
|
# Determine if any linters were explicitly set #
|
||||||
|
@ -764,7 +768,8 @@ GetValidationInfo()
|
||||||
-n "$VALIDATE_GO" || \
|
-n "$VALIDATE_GO" || \
|
||||||
-n "$VALIDATE_TERRAFORM" || \
|
-n "$VALIDATE_TERRAFORM" || \
|
||||||
-n "$VALIDATE_CSS" || \
|
-n "$VALIDATE_CSS" || \
|
||||||
-n "$VALIDATE_ENV" ]]; then
|
-n "$VALIDATE_ENV" || \
|
||||||
|
-n "$VALIDATE_KOTLIN" ]]; then
|
||||||
ANY_SET="true"
|
ANY_SET="true"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
@ -1034,6 +1039,21 @@ GetValidationInfo()
|
||||||
VALIDATE_ENV="true"
|
VALIDATE_ENV="true"
|
||||||
fi
|
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 #
|
# Print which linters we are enabling #
|
||||||
#######################################
|
#######################################
|
||||||
|
@ -1132,6 +1152,11 @@ GetValidationInfo()
|
||||||
else
|
else
|
||||||
PRINT_ARRAY+=("- Excluding [ENV] files in code base...")
|
PRINT_ARRAY+=("- Excluding [ENV] files in code base...")
|
||||||
fi
|
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 #
|
# Validate Ansible Directory #
|
||||||
|
@ -1479,6 +1504,15 @@ 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" == "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
|
elif [ "$FILE" == "Dockerfile" ]; then
|
||||||
################################
|
################################
|
||||||
# Append the file to the array #
|
# Append the file to the array #
|
||||||
|
@ -1992,7 +2026,8 @@ Footer()
|
||||||
[ "$ERRORS_FOUND_TERRAFORM" -ne 0 ] || \
|
[ "$ERRORS_FOUND_TERRAFORM" -ne 0 ] || \
|
||||||
[ "$ERRORS_FOUND_RUBY" -ne 0 ] || \
|
[ "$ERRORS_FOUND_RUBY" -ne 0 ] || \
|
||||||
[ "$ERRORS_FOUND_CSS" -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
|
# Failed exit
|
||||||
echo "Exiting with errors found!"
|
echo "Exiting with errors found!"
|
||||||
exit 1
|
exit 1
|
||||||
|
@ -2051,6 +2086,7 @@ RunTestCases()
|
||||||
TestCodebase "TERRAFORM" "tflint" "tflint -c $TERRAFORM_LINTER_RULES" ".*\.\(tf\)\$"
|
TestCodebase "TERRAFORM" "tflint" "tflint -c $TERRAFORM_LINTER_RULES" ".*\.\(tf\)\$"
|
||||||
TestCodebase "CSS" "stylelint" "stylelint --config $CSS_LINTER_RULES" ".*\.\(css\)\$"
|
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 #
|
# Footer prints #
|
||||||
|
@ -2347,6 +2383,17 @@ if [ "$VALIDATE_ENV" == "true" ]; then
|
||||||
LintCodebase "ENV" "dotenv-linter" "dotenv-linter" ".*\.\(env\)\$" "${FILE_ARRAY_ENV[@]}"
|
LintCodebase "ENV" "dotenv-linter" "dotenv-linter" ".*\.\(env\)\$" "${FILE_ARRAY_ENV[@]}"
|
||||||
fi
|
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 #
|
# DOCKER LINTING #
|
||||||
##################
|
##################
|
||||||
|
|
Loading…
Reference in a new issue