Skip to content

Commit

Permalink
build: use embedded checkstyle configuration files (#5089)
Browse files Browse the repository at this point in the history
checkstyle embeds sun_checks.xml and google_checks.xml so we can use
them instead of shipping our own.
  • Loading branch information
ferrarimarco committed Jan 2, 2024
1 parent 901a901 commit 9257ba8
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 206 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ You can configure super-linter using the following environment variables:
| **GITLEAKS_CONFIG_FILE** | `.gitleaks.toml` | Filename for [GitLeaks configuration](https://github.com/zricethezav/gitleaks#configuration) (ex: `.gitleaks.toml`) |
| **IGNORE_GENERATED_FILES** | `false` | If set to `true`, super-linter will ignore all the files with `@generated` marker but without `@not-generated` marker. |
| **IGNORE_GITIGNORED_FILES** | `false` | If set to `true`, super-linter will ignore all the files that are ignored by Git. |
| **JAVA_FILE_NAME** | `sun_checks.xml` | Filename for [Checkstyle configuration](https://checkstyle.sourceforge.io/config.html) (ex: `checkstyle.xml`) |
| **JAVA_FILE_NAME** | `sun_checks.xml` | Filename for [Checkstyle configuration](https://checkstyle.sourceforge.io/config.html). Checkstyle embeds several configuration files, such as `sun_checks.xml`, `google_checks.xml` that you can use without providing your own configuration file. |
| **JAVASCRIPT_DEFAULT_STYLE** | `standard` | Flag to set the default style of JavaScript. Available options: **standard**/**prettier** |
| **JAVASCRIPT_ES_CONFIG_FILE** | `.eslintrc.yml` | Filename for [ESLint configuration](https://eslint.org/docs/user-guide/configuring#configuration-file-formats) (ex: `.eslintrc.yml`, `.eslintrc.json`) |
| **JSCPD_CONFIG_FILE** | `.jscpd.json` | Filename for JSCPD configuration |
Expand Down
201 changes: 0 additions & 201 deletions TEMPLATES/sun_checks.xml

This file was deleted.

16 changes: 14 additions & 2 deletions lib/functions/linterRules.sh
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,20 @@ GetLinterRules() {
# Found the rules file
debug " -> ${LANGUAGE_LINTER_RULES} rules file (${!LANGUAGE_LINTER_RULES}) exists."
else
# Here we expect a rules file, so fail if not available.
fatal " -> ${LANGUAGE_LINTER_RULES} rules file (${!LANGUAGE_LINTER_RULES}) doesn't exist. Terminating..."
local LANGUAGE_LINTER_RULES_BASENAME
LANGUAGE_LINTER_RULES_BASENAME="$(basename "${!LANGUAGE_LINTER_RULES}")"
debug "LANGUAGE_LINTER_RULES_BASENAME: ${LANGUAGE_LINTER_RULES_BASENAME}"
# checkstyle embeds some configuration files, such as google_checks.xml and sun_checks.xml.
# If we or the user specified one of those files and the file is missing, fall back to
# the embedded one.
if [[ "${LANGUAGE_NAME}" == "JAVA" && ("${LANGUAGE_LINTER_RULES_BASENAME}" == "google_checks.xml" || "${LANGUAGE_LINTER_RULES_BASENAME}" == "sun_checks.xml") ]]; then
debug "${!LANGUAGE_LINTER_RULES} for ${LANGUAGE_NAME} doesn't exist. Falling back to ${LANGUAGE_LINTER_RULES_BASENAME} that the linter ships."
eval "${LANGUAGE_LINTER_RULES}=/${LANGUAGE_LINTER_RULES_BASENAME}"
debug "Updated ${LANGUAGE_LINTER_RULES}: ${!LANGUAGE_LINTER_RULES}"
else
# Here we expect a rules file, so fail if not available.
fatal " -> ${LANGUAGE_LINTER_RULES} rules file (${!LANGUAGE_LINTER_RULES}) doesn't exist. Terminating..."
fi
fi

######################
Expand Down
3 changes: 1 addition & 2 deletions test/inspec/super-linter/controls/super_linter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -484,8 +484,7 @@
"/action/lib/.automation/.yaml-lint.yml",
"/action/lib/.automation/phpcs.xml",
"/action/lib/.automation/phpstan.neon",
"/action/lib/.automation/psalm.xml",
"/action/lib/.automation/sun_checks.xml"
"/action/lib/.automation/psalm.xml"
]

files.each do |item|
Expand Down
5 changes: 5 additions & 0 deletions test/linters/java/java_good_2.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
@SuppressWarnings("checkstyle:hideutilityclassconstructor")
public class Application {

protected StringUtils() {
// prevents calls from subclass
throw new UnsupportedOperationException();
}

/**
* main.
*
Expand Down

0 comments on commit 9257ba8

Please sign in to comment.