mirror of
https://github.com/super-linter/super-linter.git
synced 2024-11-25 07:31:05 -05:00
Adding groovy
This commit is contained in:
parent
885ba1a0ab
commit
afe4f087cb
10 changed files with 123 additions and 5 deletions
13
.automation/test/groovy/README.md
Normal file
13
.automation/test/groovy/README.md
Normal file
|
@ -0,0 +1,13 @@
|
|||
# Groovy Test Cases
|
||||
This folder holds the test cases for **Groovy**.
|
||||
|
||||
## 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/groovy/groovy_bad_01.groovy
Normal file
6
.automation/test/groovy/groovy_bad_01.groovy
Normal file
|
@ -0,0 +1,6 @@
|
|||
class Example {
|
||||
static void main(String[] args)
|
||||
File file = new File("E:/Example.txt")
|
||||
The file ${file.absolutePath} has ${file.length()} bytes"
|
||||
}
|
||||
}
|
6
.automation/test/groovy/groovy_good_01.groovy
Normal file
6
.automation/test/groovy/groovy_good_01.groovy
Normal file
|
@ -0,0 +1,6 @@
|
|||
class Example {
|
||||
static void main(String[] args) {
|
||||
File file = new File("E:/Example.txt")
|
||||
println "The file ${file.absolutePath} has ${file.length()} bytes"
|
||||
}
|
||||
}
|
|
@ -40,10 +40,11 @@ Developers on **GitHub** can call the **GitHub Action** to lint their code base
|
|||
| **Clojure** | [clj-kondo](https://github.com/borkdude/clj-kondo) |
|
||||
| **CoffeeScript** | [coffeelint](https://coffeelint.github.io/) |
|
||||
| **Dockerfile** | [dockerfilelint](https://github.com/replicatedhq/dockerfilelint.git) |
|
||||
| **EDITORCONFIG** | [editorconfig-checker](https://github.com/editorconfig-checker/editorconfig-checker) |
|
||||
| **EDITORCONFIG** | [editorconfig-checker](https://github.com/editorconfig-checker/editorconfig-checker) |
|
||||
| **ENV** | [dotenv-linter](https://github.com/dotenv-linter/dotenv-linter) |
|
||||
| **Golang** | [golangci-lint](https://github.com/golangci/golangci-lint) |
|
||||
| **HTMLHint** | [HTMLHint](https://github.com/htmlhint/HTMLHint) |
|
||||
| **Groovy** | [npm-groovy-lint](https://github.com/nvuillam/npm-groovy-lint) |
|
||||
| **HTML** | [HTMLHint](https://github.com/htmlhint/HTMLHint) |
|
||||
| **JavaScript** | [eslint](https://eslint.org/) [standard js](https://standardjs.com/) |
|
||||
| **JSON** | [jsonlint](https://github.com/zaach/jsonlint) |
|
||||
| **Kotlin** | [ktlint](https://github.com/pinterest/ktlint) |
|
||||
|
@ -177,6 +178,7 @@ and won't run anything unexpected.
|
|||
| **VALIDATE_TYPESCRIPT_STANDARD** | `true` | Flag to enable or disable the linting process of the language. (Utilizing: standard) |
|
||||
| **VALIDATE_DOCKER** | `true` | Flag to enable or disable the linting process of the language. |
|
||||
| **VALIDATE_GO** | `true` | Flag to enable or disable the linting process of the language. |
|
||||
| **VALIDATE_GROOVY** | `true` | Flag to enable or disable the linting process of the language. |
|
||||
| **VALIDATE_POWERSHELL** | `true` | Flag to enable or disable the linting process of the language. |
|
||||
| **VALIDATE_ARM** | `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. |
|
||||
|
|
3
dependencies/package.json
vendored
3
dependencies/package.json
vendored
|
@ -18,6 +18,7 @@
|
|||
"standard": "^14.3.4",
|
||||
"stylelint": "^13.6.1",
|
||||
"stylelint-config-standard": "^20.0.0",
|
||||
"typescript": "^3.9.6"
|
||||
"typescript": "^3.9.6",
|
||||
"npm-groovy-lint": "^5.5.0"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -30,6 +30,7 @@ For some linters it is also possible to override rules on a case by case level w
|
|||
- [Typescript Eslint](#typescript-eslint)
|
||||
- [Typescript Standard](#typescript-standard)
|
||||
- [Golang](#golang)
|
||||
- [Groovy](#groovy)
|
||||
- [Dockerfile](#dockerfile)
|
||||
- [Terraform](#terraform)
|
||||
- [CSS](#css)
|
||||
|
@ -563,6 +564,44 @@ alert('foo')
|
|||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
## Groovy
|
||||
- [npm-groovy-lint](https://github.com/nvuillam/npm-groovy-lint)
|
||||
|
||||
### groovy-lint standard Config file
|
||||
- `.github/linters/.groovylintrc.json`
|
||||
- You can pass multiple rules and overwrite default rules
|
||||
- File should be located at: `.github/linters/.groovylintrc.json`
|
||||
|
||||
### groovy-lint disable single line
|
||||
```groovy
|
||||
def variable = 1; // groovylint-disable-line
|
||||
|
||||
// groovylint-disable-next-line
|
||||
def variable = 1;
|
||||
|
||||
/* groovylint-disable-next-line */
|
||||
def variable = 1;
|
||||
|
||||
def variable = 1; /* groovylint-disable-line */
|
||||
```
|
||||
|
||||
### groovy-lint disable code block
|
||||
```groovy
|
||||
/* groovylint-disable */
|
||||
|
||||
def variable = 1;
|
||||
|
||||
/* groovylint-enable */
|
||||
```
|
||||
|
||||
### groovy-lint disable entire file
|
||||
- At the top line of the file add the line:
|
||||
```groovy
|
||||
/* groovylint-disable */
|
||||
```
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
## Dockerfile
|
||||
- [dockerfilelint](https://github.com/replicatedhq/dockerfilelint.git)
|
||||
|
||||
|
|
|
@ -421,6 +421,15 @@ function BuildFileList() {
|
|||
# Set the READ_ONLY_CHANGE_FLAG since this could be exec #
|
||||
##########################################################
|
||||
READ_ONLY_CHANGE_FLAG=1
|
||||
elif [ "$FILE_TYPE" == "groovy" ] || [ "$FILE_TYPE" == "jenkinsfile" ]; then
|
||||
################################
|
||||
# Append the file to the array #
|
||||
################################
|
||||
FILE_ARRAY_GROOVY+=("$FILE")
|
||||
##########################################################
|
||||
# Set the READ_ONLY_CHANGE_FLAG since this could be exec #
|
||||
##########################################################
|
||||
READ_ONLY_CHANGE_FLAG=1
|
||||
else
|
||||
##############################################
|
||||
# Use file to see if we can parse what it is #
|
||||
|
|
|
@ -59,6 +59,9 @@ DOCKER_LINTER_RULES="$DEFAULT_RULES_LOCATION/$DOCKER_FILE_NAME" # Path t
|
|||
# Golang Vars
|
||||
GO_FILE_NAME='.golangci.yml' # Name of the file
|
||||
GO_LINTER_RULES="$DEFAULT_RULES_LOCATION/$GO_FILE_NAME" # Path to the Go lint rules
|
||||
# Groovy Vars
|
||||
GROOVY_FILE_NAME='.groovylintrc.json' # Name of the file
|
||||
GROOVY_LINTER_RULES="$DEFAULT_RULES_LOCATION/$GROOVY_FILE_NAME" # Path to the Go lint rules
|
||||
# Terraform Vars
|
||||
TERRAFORM_FILE_NAME='.tflint.hcl' # Name of the file
|
||||
TERRAFORM_LINTER_RULES="$DEFAULT_RULES_LOCATION/$TERRAFORM_FILE_NAME" # Path to the Terraform lint rules
|
||||
|
@ -91,7 +94,7 @@ LINTER_ARRAY=("jsonlint" "yamllint" "xmllint" "markdownlint" "shellcheck"
|
|||
"pylint" "perl" "raku" "rubocop" "coffeelint" "eslint" "standard"
|
||||
"ansible-lint" "dockerfilelint" "golangci-lint" "tflint"
|
||||
"stylelint" "dotenv-linter" "pwsh" "arm-ttk" "ktlint" "protolint" "clj-kondo"
|
||||
"spectral" "cfn-lint" "htmlhint")
|
||||
"spectral" "cfn-lint" "htmlhint" "npm-groovy-lint")
|
||||
|
||||
#############################
|
||||
# Language array for prints #
|
||||
|
@ -100,7 +103,7 @@ LANGUAGE_ARRAY=('YML' 'JSON' 'XML' 'MARKDOWN' 'BASH' 'PERL' 'RAKU' 'PHP' 'RUBY'
|
|||
'COFFEESCRIPT' 'ANSIBLE' 'JAVASCRIPT_STANDARD' 'JAVASCRIPT_ES' 'JSX' 'TSX'
|
||||
'TYPESCRIPT_STANDARD' 'TYPESCRIPT_ES' 'DOCKER' 'GO' 'TERRAFORM'
|
||||
'CSS' 'ENV' 'POWERSHELL' 'ARM' 'KOTLIN' 'PROTOBUF' 'CLOJURE' 'OPENAPI'
|
||||
'CFN' 'HTML')
|
||||
'CFN' 'HTML' 'GROOVY')
|
||||
|
||||
###################
|
||||
# GitHub ENV Vars #
|
||||
|
@ -144,6 +147,7 @@ VALIDATE_EDITORCONFIG="${VALIDATE_EDITORCONFIG}" # Boolean to vali
|
|||
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
|
||||
VALIDATE_HTML="${VALIDATE_HTML}" # Boolean to validate language
|
||||
VALIDATE_GROOVY="${VALIDATE_GROOVY}" # Boolean to validate language
|
||||
|
||||
##############
|
||||
# Debug Vars #
|
||||
|
@ -207,6 +211,7 @@ FILE_ARRAY_KOTLIN=() # Array of files to check
|
|||
FILE_ARRAY_PROTOBUF=() # Array of files to check
|
||||
FILE_ARRAY_OPENAPI=() # Array of files to check
|
||||
FILE_ARRAY_HTML=() # Array of files to check
|
||||
FILE_ARRAY_GROOVY=() # Array of files to check
|
||||
|
||||
############
|
||||
# Counters #
|
||||
|
@ -242,6 +247,7 @@ ERRORS_FOUND_KOTLIN=0 # Count of errors found
|
|||
ERRORS_FOUND_PROTOBUF=0 # Count of errors found
|
||||
ERRORS_FOUND_OPENAPI=0 # Count of errors found
|
||||
ERRORS_FOUND_HTML=0 # Count of errors found
|
||||
ERRORS_FOUND_GROOVY=0 # Count of errors found
|
||||
|
||||
################################################################################
|
||||
########################## FUNCTIONS BELOW #####################################
|
||||
|
@ -802,6 +808,7 @@ Footer() {
|
|||
[ "$ERRORS_FOUND_PROTOBUF" -ne 0 ] ||
|
||||
[ "$ERRORS_FOUND_CLOJURE" -ne 0 ] ||
|
||||
[ "$ERRORS_FOUND_KOTLIN" -ne 0 ] ||
|
||||
[ "$ERRORS_FOUND_GROOVY" -ne 0 ] ||
|
||||
[ "$ERRORS_FOUND_HTML" -ne 0 ]; then
|
||||
# Failed exit
|
||||
echo -e "${NC}${F[R]}Exiting with errors found!${NC}"
|
||||
|
@ -861,6 +868,8 @@ GetLinterRules "JAVASCRIPT"
|
|||
GetLinterRules "TYPESCRIPT"
|
||||
# Get Golang rules
|
||||
GetLinterRules "GO"
|
||||
# Get Groovy rules
|
||||
GetLinterRules "GROOVY"
|
||||
# Get Docker rules
|
||||
GetLinterRules "DOCKER"
|
||||
# Get Terraform rules
|
||||
|
@ -1054,6 +1063,17 @@ if [ "$VALIDATE_GO" == "true" ]; then
|
|||
LintCodebase "GO" "golangci-lint" "golangci-lint run -c $GO_LINTER_RULES" ".*\.\(go\)\$" "${FILE_ARRAY_GO[@]}"
|
||||
fi
|
||||
|
||||
##################
|
||||
# GROOVY LINTING #
|
||||
##################
|
||||
if [ "$VALIDATE_GROOVY" == "true" ]; then
|
||||
#########################
|
||||
# Lint the groovy files #
|
||||
#########################
|
||||
# LintCodebase "FILE_TYPE" "LINTER_NAME" "LINTER_CMD" "FILE_TYPES_REGEX" "FILE_ARRAY"
|
||||
LintCodebase "GROOVY" "npm-groovy-lint" "npm-groovy-lint -c $GROOVY_LINTER_RULES -f" ".*\.\(groovy\|jenkinsfile\|gradle\)\$" "${FILE_ARRAY_GROOVY[@]}"
|
||||
fi
|
||||
|
||||
#####################
|
||||
# TERRAFORM LINTING #
|
||||
#####################
|
||||
|
|
|
@ -77,6 +77,7 @@ function GetValidationInfo() {
|
|||
VALIDATE_OPENAPI=$(echo "$VALIDATE_OPENAPI" | awk '{print tolower($0)}')
|
||||
VALIDATE_EDITORCONFIG=$(echo "$VALIDATE_EDITORCONFIG" | awk '{print tolower($0)}')
|
||||
VALIDATE_HTML=$(echo "$VALIDATE_HTML" | awk '{print tolower($0)}')
|
||||
VALIDATE_GROOVY=$(echo "$VALIDATE_GROOVY" | awk '{print tolower($0)}')
|
||||
|
||||
################################################
|
||||
# Determine if any linters were explicitly set #
|
||||
|
@ -100,6 +101,7 @@ function GetValidationInfo() {
|
|||
$VALIDATE_TYPESCRIPT_STANDARD || -n \
|
||||
$VALIDATE_DOCKER || -n \
|
||||
$VALIDATE_GO || -n \
|
||||
$VALIDATE_GROOVY || -n \
|
||||
$VALIDATE_TERRAFORM || -n \
|
||||
$VALIDATE_POWERSHELL || -n \
|
||||
$VALIDATE_ARM || -n \
|
||||
|
@ -551,6 +553,20 @@ function GetValidationInfo() {
|
|||
VALIDATE_HTML="true"
|
||||
fi
|
||||
|
||||
######################################
|
||||
# Validate if we should check GROOVY #
|
||||
######################################
|
||||
if [[ $ANY_SET == "true" ]]; then
|
||||
# Some linter flags were set - only run those set to true
|
||||
if [[ -z $VALIDATE_GROOVY ]]; then
|
||||
# GROOVY flag was not set - default to false
|
||||
VALIDATE_GROOVY="false"
|
||||
fi
|
||||
else
|
||||
# No linter flags were set - default all to true
|
||||
VALIDATE_GROOVY="true"
|
||||
fi
|
||||
|
||||
#######################################
|
||||
# Print which linters we are enabling #
|
||||
#######################################
|
||||
|
@ -699,6 +715,11 @@ function GetValidationInfo() {
|
|||
else
|
||||
PRINT_ARRAY+=("- Excluding [HTML] files in code base...")
|
||||
fi
|
||||
if [[ $VALIDATE_GROOVY == "true" ]]; then
|
||||
PRINT_ARRAY+=("- Validating [GROOVY] files in code base...")
|
||||
else
|
||||
PRINT_ARRAY+=("- Excluding [GROOVY] files in code base...")
|
||||
fi
|
||||
|
||||
##############################
|
||||
# Validate Ansible Directory #
|
||||
|
|
|
@ -483,6 +483,7 @@ function RunTestCases() {
|
|||
TestCodebase "PROTOBUF" "protolint" "protolint lint --config_path $PROTOBUF_LINTER_RULES" ".*\.\(proto\)\$" "protobuf"
|
||||
TestCodebase "OPENAPI" "spectral" "spectral lint -r $OPENAPI_LINTER_RULES" ".*\.\(ymlopenapi\|jsonopenapi\)\$" "openapi"
|
||||
TestCodebase "HTML" "htmlhint" "htmlhint --config $HTML_LINTER_RULES" ".*\.\(html\)\$" "html"
|
||||
TestCodebase "GROOVY" "npm-groovy-lint" "npm-groovy-lint -c $GROOVY_LINTER_RULES -f" ".*\.\(groovy\|jenkinsfile\|gradle\)\$" "groovy"
|
||||
|
||||
#################
|
||||
# Footer prints #
|
||||
|
|
Loading…
Reference in a new issue