diff --git a/.automation/test/java/README.md b/.automation/test/java/README.md new file mode 100644 index 00000000..c51155cc --- /dev/null +++ b/.automation/test/java/README.md @@ -0,0 +1,19 @@ +# Java Test Cases + +This folder holds the test cases for **Java**. + +## 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. diff --git a/.automation/test/java/java_bad_1.java b/.automation/test/java/java_bad_1.java new file mode 100644 index 00000000..1d4127e9 --- /dev/null +++ b/.automation/test/java/java_bad_1.java @@ -0,0 +1,8 @@ +class java_bad_1 // first letter of classname is not capitalized +{ + + public static void main(String args[]) + { + System.out.println("Hello, World"); + } +} diff --git a/.automation/test/java/java_good_1.java b/.automation/test/java/java_good_1.java new file mode 100644 index 00000000..70f50e7c --- /dev/null +++ b/.automation/test/java/java_good_1.java @@ -0,0 +1,9 @@ +/** + * Represents a good Java file. +*/ +public static class JavaGood { + // Prints "Hello, World" to the terminal window. + private void helloWorld() { + System.out.println("Hello, World"); + } +} diff --git a/.github/linters/sun_checks.xml b/.github/linters/sun_checks.xml new file mode 100644 index 00000000..8bff099a --- /dev/null +++ b/.github/linters/sun_checks.xml @@ -0,0 +1,198 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Dockerfile b/Dockerfile index 96eee394..5adfa969 100644 --- a/Dockerfile +++ b/Dockerfile @@ -206,6 +206,17 @@ RUN wget https://storage.googleapis.com/dart-archive/channels/stable/release/${D RUN echo "http://dl-cdn.alpinelinux.org/alpine/edge/testing/" >> /etc/apk/repositories \ && apk add --update --no-cache rakudo zef +###################### +# Install CheckStyle # +###################### + +RUN CHECKSTYLE_LATEST=$(curl -s https://api.github.com/repos/checkstyle/checkstyle/releases/latest \ + | grep browser_download_url \ + | grep ".jar" \ + | cut -d '"' -f 4) \ + && curl -sSL $CHECKSTYLE_LATEST \ + --output /usr/bin/checkstyle + #################### # Install luacheck # #################### @@ -258,6 +269,7 @@ ENV ACTIONS_RUNNER_DEBUG=${ACTIONS_RUNNER_DEBUG} \ VALIDATE_ENV=${VALIDATE_ENV} \ VALIDATE_GO=${VALIDATE_GO} \ VALIDATE_HTML=${VALIDATE_HTML} \ + VALIDATE_JAVA=${VALIDATE_JAVA} \ VALIDATE_JAVASCRIPT_ES=${VALIDATE_JAVASCRIPT_ES} \ VALIDATE_JAVASCRIPT_STANDARD=${VALIDATE_JAVASCRIPT_STANDARD} \ VALIDATE_JSON=${VALIDATE_JSON} \ diff --git a/README.md b/README.md index 1fefdd9a..66fffc84 100644 --- a/README.md +++ b/README.md @@ -50,12 +50,13 @@ 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/) | | **Dart** | [dartanalyzer](https://dart.dev/guides/language/analysis-options) | -| **Dockerfile** | [dockerfilelint](https://github.com/replicatedhq/dockerfilelint.git) https://github.com/hadolint/hadolint | +| **Dockerfile** | [dockerfilelint](https://github.com/replicatedhq/dockerfilelint.git) [hadolint](https://github.com/hadolint/hadolint) | | **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) | | **Groovy** | [npm-groovy-lint](https://github.com/nvuillam/npm-groovy-lint) | | **HTMLHint** | [HTMLHint](https://github.com/htmlhint/HTMLHint) | +| **Java** | [checkstyle](https://checkstyle.org) | | **JavaScript** | [eslint](https://eslint.org/) [standard js](https://standardjs.com/) | | **JSON** | [jsonlint](https://github.com/zaach/jsonlint) | | **Kotlin** | [ktlint](https://github.com/pinterest/ktlint) | @@ -202,6 +203,7 @@ and won't run anything unexpected. | **VALIDATE_GO** | `true` | Flag to enable or disable the linting process of the Golang language. | | **VALIDATE_GROOVY** | `true` | Flag to enable or disable the linting process of the language. | | **VALIDATE_HTML** | `true` | Flag to enable or disable the linting process of the HTML language. | +| **VALIDATE_JAVA** | `true` | Flag to enable or disable the linting process of the language. | | **VALIDATE_JAVASCRIPT_ES** | `true` | Flag to enable or disable the linting process of the Javascript language. (Utilizing: eslint) | | **VALIDATE_JAVASCRIPT_STANDARD** | `true` | Flag to enable or disable the linting process of the Javascript language. (Utilizing: standard) | | **VALIDATE_JSON** | `true` | Flag to enable or disable the linting process of the JSON language. | @@ -233,6 +235,7 @@ and won't run anything unexpected. | **VALIDATE_YAML** | `true` | Flag to enable or disable the linting process of the YAML language. | | **YAML_CONFIG_FILE** | `.yaml-lint.yml` | Filename for [Yamllint configuration](https://yamllint.readthedocs.io/en/stable/configuration.html) (ex: `.yaml-lint.yml`, `.yamllint.yml`) | + ### Template rules files You can use the **GitHub** **Super-Linter** _with_ or _without_ your own personal rules sets. This allows for greater flexibility for each individual code base. The Template rules all try to follow the standards we believe should be enabled at the basic level. diff --git a/TEMPLATES/sun_checks.xml b/TEMPLATES/sun_checks.xml new file mode 100644 index 00000000..adfd1b1c --- /dev/null +++ b/TEMPLATES/sun_checks.xml @@ -0,0 +1,198 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/docs/disabling-linters.md b/docs/disabling-linters.md index 00b246a2..455f37f2 100644 --- a/docs/disabling-linters.md +++ b/docs/disabling-linters.md @@ -29,6 +29,7 @@ For some linters it is also possible to override rules on a case by case level w - [Golang](#golang) - [Groovy](#groovy) - [HTML](#html) + - [Java](#java) - [Javascript eslint](#javascript-eslint) - [Javascript standard](#javascript-standard) - [JSON](#json) @@ -461,6 +462,27 @@ def variable = 1; --- +## Java + +- [checkstyle](https://github.com/checkstyle/checkstyle) + +### Java Config file + +- `.github/linters/sun_checks.xml` +- You can pass multiple rules and overwrite default rules +- File should be located at: `.github/linters/sun_checks.xml` + +### Java disable single line +- There is currently **No** way to disable rules inline of the file(s) + +### Java disable code block +- There is currently **No** way to disable rules inline of the file(s) + +### Java disable entire file +- There is currently **No** way to disable rules inline of the file(s) + +--- + ## Javascript eslint - [eslint](https://eslint.org/) diff --git a/lib/buildFileList.sh b/lib/buildFileList.sh index d98e7e6f..c878a3be 100755 --- a/lib/buildFileList.sh +++ b/lib/buildFileList.sh @@ -275,6 +275,18 @@ function BuildFileList() { # Set the READ_ONLY_CHANGE_FLAG since this could be exec # ########################################################## READ_ONLY_CHANGE_FLAG=1 + ###################### + # Get the Java files # + ###################### + elif [ "${FILE_TYPE}" == "java" ]; then + ################################ + # Append the file to the array # + ################################ + FILE_ARRAY_JAVA+=("${FILE}") + ########################################################## + # Set the READ_ONLY_CHANGE_FLAG since this could be exec # + ########################################################## + READ_ONLY_CHANGE_FLAG=1 ############################ # Get the JavaScript files # ############################ diff --git a/lib/linter.sh b/lib/linter.sh index 6c1fda1f..b3c15c91 100755 --- a/lib/linter.sh +++ b/lib/linter.sh @@ -60,6 +60,9 @@ GROOVY_LINTER_RULES="${DEFAULT_RULES_LOCATION}/${GROOVY_FILE_NAME}" # Path to th # HTML Vars HTML_FILE_NAME='.htmlhintrc' # Name of the file HTML_LINTER_RULES="${DEFAULT_RULES_LOCATION}/${HTML_FILE_NAME}" # Path to the CSS lint rules +# Java Vars +JAVA_FILE_NAME="sun_checks.xml" # Name of the Java config file +JAVA_LINTER_RULES="${DEFAULT_RULES_LOCATION}/${JAVA_FILE_NAME}" # Path to the Java lint rules # Javascript Vars JAVASCRIPT_FILE_NAME="${JAVASCRIPT_ES_CONFIG_FILE:-.eslintrc.yml}" # Name of the file JAVASCRIPT_LINTER_RULES="${DEFAULT_RULES_LOCATION}/${JAVASCRIPT_FILE_NAME}" # Path to the Javascript lint rules @@ -121,7 +124,7 @@ YAML_LINTER_RULES="${DEFAULT_RULES_LOCATION}/${YAML_FILE_NAME}" # Path to the ya ####################################### # Linter array for information prints # ####################################### -LINTER_ARRAY=('ansible-lint' 'arm-ttk' 'asl-validator' 'cfn-lint' 'clj-kondo' 'coffeelint' +LINTER_ARRAY=('ansible-lint' 'arm-ttk' 'asl-validator' 'cfn-lint' 'checkstyle' 'clj-kondo' 'coffeelint' 'dart' 'dockerfilelint' 'dotenv-linter' 'eslint' 'flake8' 'golangci-lint' 'hadolint' 'htmlhint' 'jsonlint' 'ktlint' 'lua' 'markdownlint' 'npm-groovy-lint' 'perl' 'protolint' 'pwsh' 'pylint' 'raku' 'rubocop' 'shellcheck' 'spectral' 'standard' 'stylelint' 'terrascan' @@ -131,7 +134,7 @@ LINTER_ARRAY=('ansible-lint' 'arm-ttk' 'asl-validator' 'cfn-lint' 'clj-kondo' 'c # Language array for prints # ############################# LANGUAGE_ARRAY=('ANSIBLE' 'ARM' 'BASH' 'CLOUDFORMATION' 'CLOJURE' 'COFFEESCRIPT' 'CSS' - 'DART' 'DOCKERFILE' 'DOCKERFILE_HADOLINT' 'ENV' 'GO' 'GROOVY' 'HTML' 'JAVASCRIPT_ES' 'JAVASCRIPT_STANDARD' + 'DART' 'DOCKERFILE' 'DOCKERFILE_HADOLINT' 'ENV' 'GO' 'GROOVY' 'HTML' 'JAVA' 'JAVASCRIPT_ES' 'JAVASCRIPT_STANDARD' 'JSON' 'JSX' 'KOTLIN' 'LUA' 'MARKDOWN' 'OPENAPI' 'PERL' 'PHP_BUILTIN' 'PHP_PHPCS' 'PHP_PHPSTAN' 'PHP_PSALM' 'POWERSHELL' 'PROTOBUF' 'PYTHON_PYLINT' 'PYTHON_FLAKE8' 'RAKU' 'RUBY' 'STATES' 'TERRAFORM' 'TERRAFORM_TERRASCAN' 'TSX' 'TYPESCRIPT_ES' @@ -174,6 +177,7 @@ VALIDATE_ENV="${VALIDATE_ENV}" # Boolean t VALIDATE_GO="${VALIDATE_GO}" # Boolean to validate language VALIDATE_GROOVY="${VALIDATE_GROOVY}" # Boolean to validate language VALIDATE_HTML="${VALIDATE_HTML}" # Boolean to validate language +VALIDATE_JAVA="${VALIDATE_JAVA}" # 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_JSON="${VALIDATE_JSON}" # Boolean to validate language @@ -269,6 +273,7 @@ FILE_ARRAY_ENV=() # Array of files to check FILE_ARRAY_GO=() # Array of files to check FILE_ARRAY_GROOVY=() # Array of files to check FILE_ARRAY_HTML=() # Array of files to check +FILE_ARRAY_JAVA=() # 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_JSON=() # Array of files to check @@ -327,6 +332,8 @@ ERRORS_FOUND_GROOVY=0 # Count of errors found export ERRORS_FOUND_GROOVY # Workaround SC2034 ERRORS_FOUND_HTML=0 # Count of errors found export ERRORS_FOUND_HTML # Workaround SC2034 +ERRORS_FOUND_JAVA=0 +export ERRORS_FOUND_JAVA ERRORS_FOUND_JAVASCRIPT_STANDARD=0 # Count of errors found export ERRORS_FOUND_JAVASCRIPT_STANDARD # Workaround SC2034 ERRORS_FOUND_JAVASCRIPT_ES=0 # Count of errors found @@ -1128,6 +1135,8 @@ GetLinterRules "GO" GetLinterRules "GROOVY" # Get HTML rules GetLinterRules "HTML" +# get Java rules +GetLinterRules "JAVA" # Get JavaScript rules GetLinterRules "JAVASCRIPT" # Get LUA rules @@ -1398,6 +1407,17 @@ if [ "${VALIDATE_HTML}" == "true" ]; then LintCodebase "HTML" "htmlhint" "htmlhint --config ${HTML_LINTER_RULES}" ".*\.\(html\)\$" "${FILE_ARRAY_HTML[@]}" fi +################ +# JAVA LINTING # +################ +if [ "$VALIDATE_JAVA" == "true" ]; then + ####################### + # Lint the JAVA files # + ####################### + # LintCodebase "FILE_TYPE" "LINTER_NAME" "LINTER_CMD" "FILE_TYPES_REGEX" "FILE_ARRAY" + LintCodebase "JAVA" "checkstyle" "java -jar /usr/bin/checkstyle -c ${JAVA_LINTER_RULES}" ".*\.\(java\)\$" "${FILE_ARRAY_JAVA[@]}" +fi + ###################### # JAVASCRIPT LINTING # ###################### diff --git a/lib/worker.sh b/lib/worker.sh index 8caefd05..b5bf969e 100755 --- a/lib/worker.sh +++ b/lib/worker.sh @@ -583,6 +583,7 @@ function RunTestCases() { TestCodebase "GO" "golangci-lint" "golangci-lint run -c ${GO_LINTER_RULES}" ".*\.\(go\)\$" "golang" TestCodebase "GROOVY" "npm-groovy-lint" "npm-groovy-lint -c $GROOVY_LINTER_RULES --failon error" ".*\.\(groovy\|jenkinsfile\|gradle\)\$" "groovy" TestCodebase "HTML" "htmlhint" "htmlhint --config ${HTML_LINTER_RULES}" ".*\.\(html\)\$" "html" + TestCodebase "JAVA" "checkstyle" "java -jar /usr/bin/checkstyle -c ${JAVA_LINTER_RULES}" ".*\.\(java\)\$" "java" TestCodebase "JAVASCRIPT_ES" "eslint" "eslint --no-eslintrc -c ${JAVASCRIPT_LINTER_RULES}" ".*\.\(js\)\$" "javascript" TestCodebase "JAVASCRIPT_STANDARD" "standard" "standard ${JAVASCRIPT_STANDARD_LINTER_RULES}" ".*\.\(js\)\$" "javascript" TestCodebase "JSON" "jsonlint" "jsonlint" ".*\.\(json\)\$" "json"