adding it up

This commit is contained in:
Lucas Gravley 2020-04-02 12:42:07 -05:00
parent 81ac401fc5
commit 015adc6c97
7 changed files with 256 additions and 78 deletions

View file

@ -0,0 +1,13 @@
# Typescript Test Cases
This folder holds the test cases for **Typescript**.
## 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,6 @@
const spiderman = (person: String) => {
return 'Hello, ' + person;
}
let user = 1;
console.log(spiderman(user));

View file

@ -0,0 +1,6 @@
const spiderman = (person) => {
return 'Hello, ' + person;
}
const user = 'Peter Parker';
console.log(spiderman(user));

View file

@ -62,10 +62,22 @@ Once the container has been downloaded to your local environment, you can then b
- `-e VALIDATE_ANSIBLE=<true|false>`
- Default: `true`
- Flag to enable or disable the linting process of the language
- **VALIDATE_JAVASCRIPT**
- `-e VALIDATE_JAVASCRIPT=<true|false>`
- **VALIDATE_JAVASCRIPT_ES**
- `-e VALIDATE_JAVASCRIPT_ES=<true|false>`
- Default: `true`
- Flag to enable or disable the linting process of the language
- Flag to enable or disable the linting process of the language (Utilizing: eslint)
- **VALIDATE_JAVASCRIPT_STANDARD**
- `-e VALIDATE_JAVASCRIPT_STANDARD=<true|false>`
- Default: `true`
- Flag to enable or disable the linting process of the language (Utilizing: standard)
- **VALIDATE_TYPESCRIPT_ES**
- `-e VALIDATE_TYPESCRIPT_ES=<true|false>`
- Default: `true`
- Flag to enable or disable the linting process of the language (Utilizing: eslint)
- **VALIDATE_TYPESCRIPT_STANDARD**
- `-e VALIDATE_TYPESCRIPT_STANDARD=<true|false>`
- Default: `true`
- Flag to enable or disable the linting process of the language (Utilizing: standard)
- **VALIDATE_DOCKER**
- `-e VALIDATE_DOCKER=<true|false>`
- Default: `true`

View file

@ -110,7 +110,10 @@ ENV GITHUB_SHA=${GITHUB_SHA} \
VALIDATE_COFFEE=${VALIDATE_COFFEE} \
VALIDATE_ANSIBLE=${VALIDATE_ANSIBLE} \
VALIDATE_DOCKER=${VALIDATE_DOCKER} \
VALIDATE_JAVASCRIPT=${VALIDATE_JAVASCRIPT} \
VALIDATE_JAVASCRIPT_ES=${VALIDATE_JAVASCRIPT_ES} \
VALIDATE_JAVASCRIPT_STANDARD=${VALIDATE_JAVASCRIPT_STANDARD} \
VALIDATE_TYPESCRIPT_ES=${VALIDATE_TYPESCRIPT_ES} \
VALIDATE_TYPESCRIPT_STANDARD=${VALIDATE_TYPESCRIPT_STANDARD} \
VALIDATE_GO=${VALIDATE_GO} \
VALIDATE_TERRAFORM=${VALIDATE_TERRAFORM} \
ANSIBLE_DIRECTORY=${ANSIBLE_DIRECTORY} \

View file

@ -13,6 +13,7 @@ Developers on **GitHub** can call this Action to lint their code base with the f
- **XML** (LibXML)
- **Coffeescript** (coffeelint)
- **Javascript** (eslint)(standard)
- **Typescript** (eslint)(standard)
- **Golang** (golangci-lint)
- **Dockerfile** (dockerfilelint)
- **Terraform** (tflint)
@ -118,9 +119,18 @@ The super-linter allows you to pass the following `ENV` variables to be able to
- **VALIDATE_ANSIBLE**
- Default: `true`
- Flag to enable or disable the linting process of the language
- **VALIDATE_JAVASCRIPT**
- **VALIDATE_JAVASCRIPT_ES**
- Default: `true`
- Flag to enable or disable the linting process of the language
- Flag to enable or disable the linting process of the language (Utilizing: eslint)
- **VALIDATE_JAVASCRIPT_STANDARD**
- Default: `true`
- Flag to enable or disable the linting process of the language (Utilizing: standard)
- **VALIDATE_TYPESCRIPT_ES**
- Default: `true`
- Flag to enable or disable the linting process of the language (Utilizing: eslint)
- **VALIDATE_TYPESCRIPT_STANDARD**
- Default: `true`
- Flag to enable or disable the linting process of the language (Utilizing: standard)
- **ANSIBLE_DIRECTORY**
- Default: `/ansible`
- Flag to set the root directory for Ansible file location(s)

View file

@ -29,7 +29,11 @@ COFFEESCRIPT_LINTER_RULES="$DEFAULT_RULES_LOCATION/$COFFEE_FILE_NAME" # Path to
# Javascript Vars
JAVASCRIPT_FILE_NAME='.eslintrc.yml' # Name of the file
JAVASCRIPT_LINTER_RULES="$DEFAULT_RULES_LOCATION/$JAVASCRIPT_FILE_NAME" # Path to the Javascript lint rules
STANDARD_LINTER_RULES='' # ENV string to pass when running js standard
JAVASCRIPT_STANDARD_LINTER_RULES='' # ENV string to pass when running js standard
# Typecript Vars
TYPESCRIPT_FILE_NAME='.eslintrc.yml' # Name of the file
TYPESCRIPT_LINTER_RULES="$DEFAULT_RULES_LOCATION/$TYPESCRIPT_FILE_NAME" # Path to the Typescript lint rules
TYPESCRIPT_STANDARD_LINTER_RULES='' # ENV string to pass when running js standard
# Ansible Vars
ANSIBLE_FILE_NAME='.ansible-lint.yml' # Name of the file
ANSIBLE_LINTER_RULES="$DEFAULT_RULES_LOCATION/$ANSIBLE_FILE_NAME" # Path to the Ansible lint rules
@ -68,7 +72,10 @@ VALIDATE_PYTHON="${VALIDATE_PYTHON}" # Boolean to validate language
VALIDATE_RUBY="${VALIDATE_RUBY}" # Boolean to validate language
VALIDATE_COFFEE="${VALIDATE_COFFEE}" # Boolean to validate language
VALIDATE_ANSIBLE="${VALIDATE_ANSIBLE}" # Boolean to validate language
VALIDATE_JAVASCRIPT="${VALIDATE_JAVASCRIPT}" # Boolean to validate language
VALIDATE_JAVASCRIPT_ES="${VALIDATE_JAVASCRIPT_ES}" # Boolean to validate language
VALIDATE_JAVASCRIPT_STANDARD="${VALIDATE_JAVASCRIPT_STANDARD}" # Boolean to validate language
VALIDATE_TYPESCRIPT_ES="${VALIDATE_TYPESCRIPT_ES}" # Boolean to validate language
VALIDATE_TYPESCRIPT_STANDARD="${VALIDATE_TYPESCRIPT_STANDARD}" # Boolean to validate language
VALIDATE_DOCKER="${VALIDATE_DOCKER}" # Boolean to validate language
VALIDATE_GO="${VALIDATE_GO}" # Boolean to validate language
VALIDATE_TERRAFORM="${VALIDATE_TERRAFORM}" # Boolean to validate language
@ -107,8 +114,10 @@ FILE_ARRAY_PERL=() # Array of files to check
FILE_ARRAY_RUBY=() # Array of files to check
FILE_ARRAY_PYTHON=() # Array of files to check
FILE_ARRAY_COFFEESCRIPT=() # Array of files to check
FILE_ARRAY_ESLINT=() # Array of files to check
FILE_ARRAY_STANDARD=() # Array of files to check
FILE_ARRAY_JAVASCRIPT_ES=() # Array of files to check
FILE_ARRAY_JAVASCRIPT_STANDARD=() # Array of files to check
FILE_ARRAY_TYPESCRIPT_ES=() # Array of files to check
FILE_ARRAY_TYPESCRIPT_STANDARD=() # Array of files to check
FILE_ARRAY_DOCKER=() # Array of files to check
FILE_ARRAY_GO=() # Array of files to check
FILE_ARRAY_TERRAFORM=() # Array of files to check
@ -126,8 +135,10 @@ ERRORS_FOUND_RUBY=0 # Count of errors found
ERRORS_FOUND_PYTHON=0 # Count of errors found
ERRORS_FOUND_COFFEESCRIPT=0 # Count of errors found
ERRORS_FOUND_ANSIBLE=0 # Count of errors found
ERRORS_FOUND_STANDARD=0 # Count of errors found
ERRORS_FOUND_ESLINT=0 # Count of errors found
ERRORS_FOUND_JAVASCRIPT_STANDARD=0 # Count of errors found
ERRORS_FOUND_JAVASCRIPT_ES=0 # Count of errors found
ERRORS_FOUND_TYPESCRIPT_STANDARD=0 # Count of errors found
ERRORS_FOUND_TYPESCRIPT_ES=0 # Count of errors found
ERRORS_FOUND_DOCKER=0 # Count of errors found
ERRORS_FOUND_GO=0 # Count of errors found
ERRORS_FOUND_TERRAFORM=0 # Count of errors found
@ -250,6 +261,11 @@ GetLinterRules()
#### Function GetStandardRules #################################################
GetStandardRules()
{
################
# Pull In Vars #
################
LINTER="$1" # Type: javascript | typescript
#########################################################################
# Need to get the ENV vars from the linter rules to run in command line #
#########################################################################
@ -262,8 +278,14 @@ GetStandardRules()
# Get list of all environment variables #
#########################################
# Only env vars that are marked as true
GET_ENV_ARRAY=()
if [[ "$LINTER" == "javascript" ]]; then
# shellcheck disable=SC2207
GET_ENV_ARRAY=($(yq .env "$JAVASCRIPT_LINTER_RULES" |grep true))
elif [[ "$LINTER" == "typescript" ]]; then
# shellcheck disable=SC2207
GET_ENV_ARRAY=($(yq .env "$TYPESCRIPT_LINTER_RULES" |grep true))
fi
#######################
# Load the error code #
@ -311,7 +333,11 @@ GetStandardRules()
########################################
# Remove trailing and ending witespace #
########################################
STANDARD_LINTER_RULES="$(echo -e "${ENV_STRING}" | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')"
if [[ "$LINTER" == "javascript" ]]; then
JAVASCRIPT_STANDARD_LINTER_RULES="$(echo -e "${ENV_STRING}" | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')"
elif [[ "$LINTER" == "typescript" ]]; then
TYPESCRIPT_STANDARD_LINTER_RULES="$(echo -e "${ENV_STRING}" | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')"
fi
}
################################################################################
#### Function LintAnsibleFiles #################################################
@ -789,17 +815,65 @@ GetGitHubVars()
###############################
# Convert string to lowercase #
###############################
VALIDATE_JAVASCRIPT=$(echo "$VALIDATE_JAVASCRIPT" | awk '{print tolower($0)}')
VALIDATE_JAVASCRIPT_ES=$(echo "$VALIDATE_JAVASCRIPT_ES" | awk '{print tolower($0)}')
######################################
# Validate we should check all files #
######################################
if [[ "$VALIDATE_JAVASCRIPT" != "false" ]]; then
if [[ "$VALIDATE_JAVASCRIPT_ES" != "false" ]]; then
# Set to true
VALIDATE_JAVASCRIPT="$DEFAULT_VALIDATE_LANGUAGE"
echo "- Validating [JAVASCRIPT] files in code base..."
VALIDATE_JAVASCRIPT_ES="$DEFAULT_VALIDATE_LANGUAGE"
echo "- Validating [JAVASCRIPT(eslint)] files in code base..."
else
# Its false
echo "- Excluding [JAVASCRIPT] files in code base..."
echo "- Excluding [JAVASCRIPT(eslint)] files in code base..."
fi
###############################
# Convert string to lowercase #
###############################
VALIDATE_JAVASCRIPT_STANDARD=$(echo "$VALIDATE_JAVASCRIPT_STANDARD" | awk '{print tolower($0)}')
######################################
# Validate we should check all files #
######################################
if [[ "$VALIDATE_JAVASCRIPT_STANDARD" != "false" ]]; then
# Set to true
VALIDATE_JAVASCRIPT_STANDARD="$DEFAULT_VALIDATE_LANGUAGE"
echo "- Validating [JAVASCRIPT(standard)] files in code base..."
else
# Its false
echo "- Excluding [JAVASCRIPT(standard)] files in code base..."
fi
###############################
# Convert string to lowercase #
###############################
VALIDATE_TYPESCRIPT_ES=$(echo "$VALIDATE_TYPESCRIPT_ES" | awk '{print tolower($0)}')
######################################
# Validate we should check all files #
######################################
if [[ "$VALIDATE_TYPESCRIPT_ES" != "false" ]]; then
# Set to true
VALIDATE_TYPESCRIPT_ES="$DEFAULT_VALIDATE_LANGUAGE"
echo "- Validating [TYPESCRIPT(eslint)] files in code base..."
else
# Its false
echo "- Excluding [TYPESCRIPT(eslint)] files in code base..."
fi
###############################
# Convert string to lowercase #
###############################
VALIDATE_TYPESCRIPT_STANDARD=$(echo "$VALIDATE_TYPESCRIPT_STANDARD" | awk '{print tolower($0)}')
######################################
# Validate we should check all files #
######################################
if [[ "$VALIDATE_TYPESCRIPT_STANDARD" != "false" ]]; then
# Set to true
VALIDATE_TYPESCRIPT_STANDARD="$DEFAULT_VALIDATE_LANGUAGE"
echo "- Validating [TYPESCRIPT(standard)] files in code base..."
else
# Its false
echo "- Excluding [TYPESCRIPT(standard)] files in code base..."
fi
###############################
@ -1094,7 +1168,21 @@ BuildFileList()
################################
# Append the file to the array #
################################
FILE_ARRAY_JAVASCRIPT+=("$FILE")
FILE_ARRAY_JAVASCRIPT_ES+=("$FILE")
FILE_ARRAY_JAVASCRIPT_STANDARD+=("$FILE")
##########################################################
# Set the READ_ONLY_CHANGE_FLAG since this could be exec #
##########################################################
READ_ONLY_CHANGE_FLAG=1
############################
# Get the TypeScript files #
############################
elif [ "$FILE_TYPE" == "ts" ]; then
################################
# Append the file to the array #
################################
FILE_ARRAY_TYPESCRIPT_ES+=("$FILE")
FILE_ARRAY_TYPESCRIPT_STANDARD+=("$FILE")
##########################################################
# Set the READ_ONLY_CHANGE_FLAG since this could be exec #
##########################################################
@ -1516,8 +1604,10 @@ Footer()
echo "ERRORS FOUND in COFFEESCRIPT:[$ERRORS_FOUND_COFFEESCRIPT]"
echo "ERRORS FOUND in RUBY:[$ERRORS_FOUND_RUBY]"
echo "ERRORS FOUND in ANSIBLE:[$ERRORS_FOUND_ANSIBLE]"
echo "ERRORS FOUND in JAVASCRIPT(eslint):[$ERRORS_FOUND_ESLINT]"
echo "ERRORS FOUND in JAVASCRIPT(Standard):[$ERRORS_FOUND_STANDARD]"
echo "ERRORS FOUND in JAVASCRIPT(eslint):[$ERRORS_FOUND_JAVASCRIPT_ES]"
echo "ERRORS FOUND in JAVASCRIPT(Standard):[$ERRORS_FOUND_JAVASCRIPT_STANDARD]"
echo "ERRORS FOUND in TYPESCRIPT(eslint):[$ERRORS_FOUND_TYPESCRIPT_ES]"
echo "ERRORS FOUND in TYPESCRIPT(Standard):[$ERRORS_FOUND_TYPESCRIPT_STANDARD]"
echo "ERRORS FOUND in DOCKER:[$ERRORS_FOUND_DOCKER]"
echo "ERRORS FOUND in GO:[$ERRORS_FOUND_GO]"
echo "ERRORS FOUND in TERRAFORM:[$ERRORS_FOUND_TERRAFORM]"
@ -1536,8 +1626,10 @@ Footer()
[ "$ERRORS_FOUND_PYTHON" -ne 0 ] || \
[ "$ERRORS_FOUND_COFFEESCRIPT" -ne 0 ] || \
[ "$ERRORS_FOUND_ANSIBLE" -ne 0 ] || \
[ "$ERRORS_FOUND_ESLINT" -ne 0 ] || \
[ "$ERRORS_FOUND_STANDARD" -ne 0 ] || \
[ "$ERRORS_FOUND_JAVASCRIPT_ES" -ne 0 ] || \
[ "$ERRORS_FOUND_JAVASCRIPT_STANDARD" -ne 0 ] || \
[ "$ERRORS_FOUND_TYPESCRIPT_ES" -ne 0 ] || \
[ "$ERRORS_FOUND_TYPESCRIPT_STANDARD" -ne 0 ] || \
[ "$ERRORS_FOUND_DOCKER" -ne 0 ] || \
[ "$ERRORS_FOUND_GO" -ne 0 ] || \
[ "$ERRORS_FOUND_TERRAFORM" -ne 0 ] || \
@ -1585,7 +1677,9 @@ RunTestCases()
TestCodebase "GO" "golangci-lint" "golangci-lint run -c $GO_LINTER_RULES" ".*\.\(go\)\$"
TestCodebase "COFFEESCRIPT" "coffeelint" "coffeelint -f $COFFEESCRIPT_LINTER_RULES" ".*\.\(coffee\)\$"
TestCodebase "ESLINT" "eslint" "eslint --no-eslintrc -c $JAVASCRIPT_LINTER_RULES" ".*\.\(js\)\$"
TestCodebase "STANDARD" "standard" "standard $STANDARD_LINTER_RULES" ".*\.\(js\)\$"
TestCodebase "STANDARD" "standard" "standard $JAVASCRIPT_STANDARD_LINTER_RULES" ".*\.\(js\)\$"
TestCodebase "ESLINT" "eslint" "eslint --no-eslintrc -c $TYPESCRIPT_LINTER_RULES" ".*\.\(ts\)\$"
TestCodebase "STANDARD" "standard" "standard --parser @typescript-eslint/parser --plugin @typescript-eslint/eslint-plugin $TYPESCRIPT_STANDARD_LINTER_RULES" ".*\.\(ts\)\$"
TestCodebase "DOCKER" "/dockerfilelint/bin/dockerfilelint" "/dockerfilelint/bin/dockerfilelint" ".*\(Dockerfile\)\$"
TestCodebase "ANSIBLE" "ansible-lint" "ansible-lint -v -c $ANSIBLE_LINTER_RULES" "ansible-lint"
TestCodebase "TERRAFORM" "tflint" "tflint -c $TERRAFORM_LINTER_RULES" ".*\.\(tf\)\$"
@ -1630,6 +1724,8 @@ GetLinterRules "$COFFEE_FILE_NAME" "$COFFEESCRIPT_LINTER_RULES"
GetLinterRules "$ANSIBLE_FILE_NAME" "$ANSIBLE_LINTER_RULES"
# Get JavaScript rules
GetLinterRules "$JAVASCRIPT_FILE_NAME" "$JAVASCRIPT_LINTER_RULES"
# Get TypeScript rules
GetLinterRules "$TYPESCRIPT_FILE_NAME" "$TYPESCRIPT_LINTER_RULES"
# Get Golang rules
GetLinterRules "$GO_FILE_NAME" "$GO_LINTER_RULES"
# Get Docker rules
@ -1805,18 +1901,50 @@ fi
######################
# JAVASCRIPT LINTING #
######################
if [ "$VALIDATE_JAVASCRIPT" == "true" ]; then
#################################
# Get Javascript standard rules #
#################################
GetStandardRules
if [ "$VALIDATE_JAVASCRIPT_ES" == "true" ]; then
#############################
# Lint the Javascript files #
#############################
# LintCodebase "FILE_TYPE" "LINTER_NAME" "LINTER_CMD" "FILE_TYPES_REGEX" "FILE_ARRAY"
LintCodebase "ESLINT" "eslint" "eslint --no-eslintrc -c $JAVASCRIPT_LINTER_RULES" ".*\.\(js\)\$" "${FILE_ARRAY_ESLINT[@]}"
LintCodebase "STANDARD" "standard" "standard $STANDARD_LINTER_RULES" ".*\.\(js\)\$" "${FILE_ARRAY_STANDARD[@]}"
LintCodebase "JAVASCRIPT_ES" "eslint" "eslint --no-eslintrc -c $JAVASCRIPT_LINTER_RULES" ".*\.\(js\)\$" "${FILE_ARRAY_JAVASCRIPT_ES[@]}"
fi
######################
# JAVASCRIPT LINTING #
######################
if [ "$VALIDATE_JAVASCRIPT_STANDARD" == "true" ]; then
#################################
# Get Javascript standard rules #
#################################
GetStandardRules
#############################
# Lint the Javascript files #
#############################
# LintCodebase "FILE_TYPE" "LINTER_NAME" "LINTER_CMD" "FILE_TYPES_REGEX" "FILE_ARRAY"
LintCodebase "JAVASCRIPT_STANDARD" "standard" "standard $JAVASCRIPT_STANDARD_LINTER_RULES" ".*\.\(js\)\$" "${FILE_ARRAY_JAVASCRIPT_STANDARD[@]}"
fi
######################
# TYPESCRIPT LINTING #
######################
if [ "$VALIDATE_TYPESCRIPT_ES" == "true" ]; then
#############################
# Lint the Typescript files #
#############################
LintCodebase "TYPESCRIPT_ES" "eslint" "eslint --no-eslintrc -c $TYPESCRIPT_LINTER_RULES" ".*\.\(ts\)\$" "${FILE_ARRAY_TYPESCRIPT_ES[@]}"
fi
######################
# TYPESCRIPT LINTING #
######################
if [ "$VALIDATE_TYPESCRIPT_STANDARD" == "true" ]; then
#################################
# Get Typescript standard rules #
#################################
GetStandardRules
#############################
# Lint the Typescript files #
#############################
LintCodebase "TYPESCRIPT_STANDARD" "standard" "standard --parser @typescript-eslint/parser --plugin @typescript-eslint/eslint-plugin $TYPESCRIPT_STANDARD_LINTER_RULES" ".*\.\(ts\)\$" "${FILE_ARRAY_TYPESCRIPT_STANDARD[@]}"
fi
##################