mirror of
https://github.com/super-linter/super-linter.git
synced 2024-12-22 15:22:16 -05:00
Merge branch 'master' into issue/111
This commit is contained in:
commit
c1d579cf15
7 changed files with 135 additions and 6 deletions
13
.automation/test/env/README.md
vendored
Normal file
13
.automation/test/env/README.md
vendored
Normal file
|
@ -0,0 +1,13 @@
|
|||
# ENV Test Cases
|
||||
This folder holds the test cases for **ENV**.
|
||||
|
||||
## 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.
|
5
.automation/test/env/env_bad_1.env
vendored
Normal file
5
.automation/test/env/env_bad_1.env
vendored
Normal file
|
@ -0,0 +1,5 @@
|
|||
LOGGER_LEVEL=info
|
||||
MY_ENV
|
||||
DB-NAME=testing
|
||||
DEbUG_hTTP=true
|
||||
DB_NAME=development
|
4
.automation/test/env/env_good_1.env
vendored
Normal file
4
.automation/test/env/env_good_1.env
vendored
Normal file
|
@ -0,0 +1,4 @@
|
|||
DB_NAME=development
|
||||
DEBUG_HTTP=true
|
||||
LOGGER_LEVEL=info
|
||||
MY_ENV=
|
10
Dockerfile
10
Dockerfile
|
@ -102,6 +102,12 @@ RUN wget -O- -nvq https://raw.githubusercontent.com/golangci/golangci-lint/maste
|
|||
RUN curl -Ls "$(curl -Ls https://api.github.com/repos/terraform-linters/tflint/releases/latest | grep -o -E "https://.+?_linux_amd64.zip")" -o tflint.zip && unzip tflint.zip && rm tflint.zip \
|
||||
&& mv "tflint" /usr/bin/
|
||||
|
||||
##################
|
||||
# Install dotenv-linter #
|
||||
##################
|
||||
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 clj-kondo #
|
||||
#####################
|
||||
|
@ -137,11 +143,13 @@ ENV GITHUB_SHA=${GITHUB_SHA} \
|
|||
VALIDATE_GO=${VALIDATE_GO} \
|
||||
VALIDATE_TERRAFORM=${VALIDATE_TERRAFORM} \
|
||||
VALIDATE_CSS=${VALIDATE_CSS} \
|
||||
VALIDATE_ENV=${VALIDATE_ENV} \
|
||||
VALIDATE_CLOJURE=${VALIDATE_CLOJURE} \
|
||||
ANSIBLE_DIRECTORY=${ANSIBLE_DIRECTORY} \
|
||||
RUN_LOCAL=${RUN_LOCAL} \
|
||||
TEST_CASE_RUN=${TEST_CASE_RUN} \
|
||||
ACTIONS_RUNNER_DEBUG=${ACTIONS_RUNNER_DEBUG}
|
||||
ACTIONS_RUNNER_DEBUG=${ACTIONS_RUNNER_DEBUG} \
|
||||
DISABLE_ERRORS=${DISABLE_ERRORS}
|
||||
|
||||
#############################
|
||||
# Copy scripts to container #
|
||||
|
|
|
@ -35,6 +35,7 @@ Developers on **GitHub** can call the **GitHub Action** to lint their code base
|
|||
| **TypeScript** | [eslint](https://eslint.org/) [standard js](https://standardjs.com/) |
|
||||
| **XML** | [LibXML](http://xmlsoft.org/) |
|
||||
| **YAML** | [YamlLint](https://github.com/adrienverge/yamllint) |
|
||||
| **ENV** | [dotenv-linter](https://github.com/dotenv-linter/dotenv-linter) |
|
||||
|
||||
## How to use
|
||||
To use this **GitHub** Action you will need to complete the following:
|
||||
|
@ -136,9 +137,11 @@ and won't run anything unexpected.
|
|||
| **VALIDATE_GO** | `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_ENV** | `true` | Flag to enable or disable the linting process of the language. |
|
||||
| **VALIDATE_CLOJURE** | `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. |
|
||||
| **DEFAULT_WORKSPACE** | `/tmp/lint` | The location containing files to lint if you are running locally. |
|
||||
|
||||
### Template rules files
|
||||
|
|
|
@ -21,6 +21,7 @@ Below is examples and documentation for each language and the various methods to
|
|||
- [Dockerfile](#dockerfile)
|
||||
- [Terraform](#terraform)
|
||||
- [CSS](#stylelint)
|
||||
- [ENV](#dotenv-linter)
|
||||
|
||||
<!-- toc -->
|
||||
|
||||
|
@ -544,3 +545,22 @@ a {}
|
|||
]
|
||||
}
|
||||
```
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
## ENV
|
||||
- [dotenv-linter](https://github.com/dotenv-linter/dotenv-linter)
|
||||
|
||||
### dotenv-linter Config file
|
||||
- There is no top level *configuration file* available at this time
|
||||
|
||||
### dotenv-linter disable single line
|
||||
```env
|
||||
# Comment line will be ignored
|
||||
```
|
||||
|
||||
### dotenv-linter disable code block
|
||||
- There is currently **No** way to disable rules inline of the file(s)
|
||||
|
||||
### dotenv-linter disable entire file
|
||||
- There is currently **No** way to disable rules inline of the file(s)
|
||||
|
|
|
@ -62,14 +62,14 @@ CLOJURE_LINTER_RULES="$DEFAULT_RULES_LOCATION/$CLOJURE_FILE_NAME"
|
|||
LINTER_ARRAY=("jsonlint" "yamllint" "xmllint" "markdownlint" "shellcheck"
|
||||
"pylint" "perl" "rubocop" "coffeelint" "eslint" "standard"
|
||||
"ansible-lint" "/dockerfilelint/bin/dockerfilelint" "golangci-lint" "tflint"
|
||||
"stylelint" "clj-kondo")
|
||||
"stylelint" "dotenv-linter" "clj-kondo")
|
||||
|
||||
#############################
|
||||
# Language array for prints #
|
||||
#############################
|
||||
LANGUAGE_ARRAY=('YML' 'JSON' 'XML' 'MARKDOWN' 'BASH' 'PERL' 'RUBY' 'PYTHON'
|
||||
'COFFEESCRIPT' 'ANSIBLE' 'JAVASCRIPT_STANDARD' 'JAVASCRIPT_ES'
|
||||
'TYPESCRIPT_STANDARD' 'TYPESCRIPT_ES' 'DOCKER' 'GO' 'TERRAFORM' 'CSS'
|
||||
'TYPESCRIPT_STANDARD' 'TYPESCRIPT_ES' 'DOCKER' 'GO' 'TERRAFORM' 'CSS' "ENV"
|
||||
'CLOJURE')
|
||||
|
||||
###################
|
||||
|
@ -99,8 +99,10 @@ VALIDATE_DOCKER="${VALIDATE_DOCKER}" # Boolean to validate lang
|
|||
VALIDATE_GO="${VALIDATE_GO}" # Boolean to validate language
|
||||
VALIDATE_TERRAFORM="${VALIDATE_TERRAFORM}" # Boolean to validate language
|
||||
VALIDATE_CSS="${VALIDATE_CSS}" # Boolean to validate language
|
||||
VALIDATE_ENV="${VALIDATE_ENV}" # Boolean to validate language
|
||||
VALIDATE_CLOJURE="${VALIDATE_CLOJURE}" # 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
|
||||
|
||||
##############
|
||||
# Debug Vars #
|
||||
|
@ -120,6 +122,7 @@ DEFAULT_ACTIONS_RUNNER_DEBUG='false' # Default value for debugg
|
|||
RAW_FILE_ARRAY=() # Array of all files that were changed
|
||||
READ_ONLY_CHANGE_FLAG=0 # Flag set to 1 if files changed are not txt or md
|
||||
TEST_CASE_FOLDER='.automation/test' # Folder for test cases we should always ignore
|
||||
DEFAULT_DISABLE_ERRORS='false' # Default to enabling errors
|
||||
|
||||
##########################
|
||||
# Array of changed files #
|
||||
|
@ -141,7 +144,8 @@ FILE_ARRAY_DOCKER=() # Array of files to check
|
|||
FILE_ARRAY_GO=() # Array of files to check
|
||||
FILE_ARRAY_TERRAFORM=() # Array of files to check
|
||||
FILE_ARRAY_CSS=() # Array of files to check
|
||||
FILE_ARRAY_CLOJURE=() # Array of files to check
|
||||
FILE_ARRAY_ENV=() # Array of files to check
|
||||
FILE_ARRAY_CLOJURE=() # Array of files to check
|
||||
|
||||
############
|
||||
# Counters #
|
||||
|
@ -164,6 +168,7 @@ ERRORS_FOUND_DOCKER=0 # Count of errors found
|
|||
ERRORS_FOUND_GO=0 # Count of errors found
|
||||
ERRORS_FOUND_TERRAFORM=0 # Count of errors found
|
||||
ERRORS_FOUND_CSS=0 # Count of errors found
|
||||
ERRORS_FOUND_ENV=0 # Count of errors found
|
||||
ERRORS_FOUND_CLOJURE=0 # Count of errors found
|
||||
|
||||
################################################################################
|
||||
|
@ -742,6 +747,7 @@ GetValidationInfo()
|
|||
VALIDATE_GO=$(echo "$VALIDATE_GO" | awk '{print tolower($0)}')
|
||||
VALIDATE_TERRAFORM=$(echo "$VALIDATE_TERRAFORM" | awk '{print tolower($0)}')
|
||||
VALIDATE_CSS=$(echo "$VALIDATE_CSS" | awk '{print tolower($0)')
|
||||
VALIDATE_ENV=$(echo "$VALIDATE_ENV" | awk '{print tolower($0)')
|
||||
VALIDATE_CLOJURE=$(echo "$VALIDATE_CLOJURE" | awk '{print tolower($0)')
|
||||
|
||||
################################################
|
||||
|
@ -766,6 +772,7 @@ GetValidationInfo()
|
|||
-n "$VALIDATE_GO" || \
|
||||
-n "$VALIDATE_TERRAFORM" || \
|
||||
-n "$VALIDATE_CSS" || \
|
||||
-n "$VALIDATE_ENV" || \
|
||||
-n "$VALIDATE_CLOJURE" ]]; then
|
||||
ANY_SET="true"
|
||||
fi
|
||||
|
@ -1022,6 +1029,20 @@ GetValidationInfo()
|
|||
VALIDATE_CSS="true"
|
||||
fi
|
||||
|
||||
####################################
|
||||
# Validate if we should check ENV #
|
||||
####################################
|
||||
if [[ "$ANY_SET" == "true" ]]; then
|
||||
# Some linter flags were set - only run those set to true
|
||||
if [[ -z "$VALIDATE_ENV" ]]; then
|
||||
# ENV flag was not set - default to false
|
||||
VALIDATE_ENV="false"
|
||||
fi
|
||||
else
|
||||
# No linter flags were set - default all to true
|
||||
VALIDATE_ENV="true"
|
||||
fi
|
||||
|
||||
#######################################
|
||||
# Validate if we should check Clojure #
|
||||
#######################################
|
||||
|
@ -1134,6 +1155,11 @@ GetValidationInfo()
|
|||
else
|
||||
PRINT_ARRAY+=("- Excluding [CLOJURE] files in code base...")
|
||||
fi
|
||||
if [[ "$VALIDATE_ENV" == "true" ]]; then
|
||||
PRINT_ARRAY+=("- Validating [ENV] files in code base...")
|
||||
else
|
||||
PRINT_ARRAY+=("- Excluding [ENV] files in code base...")
|
||||
fi
|
||||
|
||||
##############################
|
||||
# Validate Ansible Directory #
|
||||
|
@ -1153,6 +1179,28 @@ GetValidationInfo()
|
|||
ANSIBLE_DIRECTORY="$TEMP_ANSIBLE_DIRECTORY"
|
||||
fi
|
||||
|
||||
###############################
|
||||
# Get the disable errors flag #
|
||||
###############################
|
||||
if [ -z "$DISABLE_ERRORS" ]; then
|
||||
##################################
|
||||
# No flag passed, set to default #
|
||||
##################################
|
||||
DISABLE_ERRORS="$DEFAULT_DISABLE_ERRORS"
|
||||
fi
|
||||
|
||||
###############################
|
||||
# Convert string to lowercase #
|
||||
###############################
|
||||
DISABLE_ERRORS=$(echo "$DISABLE_ERRORS" | awk '{print tolower($0)}')
|
||||
|
||||
############################
|
||||
# Set to false if not true #
|
||||
############################
|
||||
if [ "$DISABLE_ERRORS" != "true" ]; then
|
||||
DISABLE_ERRORS="false"
|
||||
fi
|
||||
|
||||
############################
|
||||
# Get the run verbose flag #
|
||||
############################
|
||||
|
@ -1450,6 +1498,15 @@ BuildFileList()
|
|||
# Set the READ_ONLY_CHANGE_FLAG since this could be exec #
|
||||
##########################################################
|
||||
READ_ONLY_CHANGE_FLAG=1
|
||||
elif [ "$FILE_TYPE" == "env" ]; then
|
||||
################################
|
||||
# Append the file to the array #
|
||||
################################
|
||||
FILE_ARRAY_ENV+=("$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 #
|
||||
|
@ -1945,10 +2002,16 @@ Footer()
|
|||
fi
|
||||
done
|
||||
|
||||
##################################
|
||||
# Exit with 0 if errors disabled #
|
||||
##################################
|
||||
if [ "$DISABLE_ERRORS" == "true" ]; then
|
||||
echo "WARN! Exiting with exit code:[0] as:[DISABLE_ERRORS] was set to:[$DISABLE_ERRORS]"
|
||||
exit 0
|
||||
###############################
|
||||
# Exit with 1 if errors found #
|
||||
###############################
|
||||
if [ "$ERRORS_FOUND_YML" -ne 0 ] || \
|
||||
elif [ "$ERRORS_FOUND_YML" -ne 0 ] || \
|
||||
[ "$ERRORS_FOUND_JSON" -ne 0 ] || \
|
||||
[ "$ERRORS_FOUND_XML" -ne 0 ] || \
|
||||
[ "$ERRORS_FOUND_MARKDOWN" -ne 0 ] || \
|
||||
|
@ -1965,7 +2028,8 @@ Footer()
|
|||
[ "$ERRORS_FOUND_GO" -ne 0 ] || \
|
||||
[ "$ERRORS_FOUND_TERRAFORM" -ne 0 ] || \
|
||||
[ "$ERRORS_FOUND_RUBY" -ne 0 ] || \
|
||||
[ "$ERRORS_FOUND_CSS" -ne 0 ]; then
|
||||
[ "$ERRORS_FOUND_CSS" -ne 0 ] || \
|
||||
[ "$ERRORS_FOUND_ENV" -ne 0 ]; then
|
||||
# Failed exit
|
||||
echo "Exiting with errors found!"
|
||||
exit 1
|
||||
|
@ -2023,6 +2087,7 @@ RunTestCases()
|
|||
TestCodebase "ANSIBLE" "ansible-lint" "ansible-lint -v -c $ANSIBLE_LINTER_RULES" "ansible-lint"
|
||||
TestCodebase "TERRAFORM" "tflint" "tflint -c $TERRAFORM_LINTER_RULES" ".*\.\(tf\)\$"
|
||||
TestCodebase "CSS" "stylelint" "stylelint --config $CSS_LINTER_RULES" ".*\.\(css\)\$"
|
||||
TestCodebase "ENV" "dotenv-linter" "dotenv-linter" ".*\.\(env\)\$"
|
||||
TestCodebase "CLOJURE" "clj-kondo" "clj-kondo --config $CLOJURE_LINTER_RULES" ".*\.\(clj\)\$"
|
||||
|
||||
#################
|
||||
|
@ -2309,6 +2374,17 @@ if [ "$VALIDATE_CSS" == "true" ]; then
|
|||
LintCodebase "CSS" "stylelint" "stylelint --config $CSS_LINTER_RULES" ".*\.\(css\)\$" "${FILE_ARRAY_CSS[@]}"
|
||||
fi
|
||||
|
||||
################
|
||||
# ENV LINTING #
|
||||
################
|
||||
if [ "$VALIDATE_ENV" == "true" ]; then
|
||||
#######################
|
||||
# Lint the env files #
|
||||
#######################
|
||||
# LintCodebase "FILE_TYPE" "LINTER_NAME" "LINTER_CMD" "FILE_TYPES_REGEX" "FILE_ARRAY"
|
||||
LintCodebase "ENV" "dotenv-linter" "dotenv-linter" ".*\.\(env\)\$" "${FILE_ARRAY_ENV[@]}"
|
||||
fi
|
||||
|
||||
##################
|
||||
# DOCKER LINTING #
|
||||
##################
|
||||
|
|
Loading…
Reference in a new issue