Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding scalafmt #2053

Merged
merged 3 commits into from
Nov 10, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions .automation/test/scalafmt/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Scala Test Cases

This folder holds the test cases for **Scala**.

## 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.
31 changes: 31 additions & 0 deletions .automation/test/scalafmt/scalafmt_bad_1.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
object a {
class a[
t1,
t2 // comment
](a1: Int,
a2: Int // comment
)(
b1: String,
b2: String // comment
)(implicit
c1: SomeType1,
c2: SomeType2 // comment
) {
def this(
a1: Int,
a2: Int // comment
)(
b1: String,
b2: String // comment
)(implicit
c1: SomeType1,
c2: SomeType2 // comment
) = this(
a1,
a2 // comment
) (
b1,
b2 // comment
)
}
}
32 changes: 32 additions & 0 deletions .automation/test/scalafmt/scalafmt_good_1.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
object a {
class a[
t1,
t2 // comment
](
a1: Int,
a2: Int // comment
)(
b1: String,
b2: String // comment
)(implicit
c1: SomeType1,
c2: SomeType2 // comment
) {
def this(
a1: Int,
a2: Int // comment
)(
b1: String,
b2: String // comment
)(implicit
c1: SomeType1,
c2: SomeType2 // comment
) = this(
a1,
a2 // comment
)(
b1,
b2 // comment
)
}
}
6 changes: 6 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ FROM zricethezav/gitleaks:v7.6.1 as gitleaks
FROM garethr/kubeval:0.15.0 as kubeval
FROM ghcr.io/assignuser/lintr-lib:0.3.0 as lintr-lib
FROM ghcr.io/awkbar-devops/clang-format:v1.0.2 as clang-format
FROM scalameta/scalafmt:v2.7.5 as scalafmt

##################
# Get base image #
Expand Down Expand Up @@ -253,6 +254,11 @@ COPY --from=clang-format /usr/bin/clang-format /usr/bin/
####################
COPY --from=gitleaks /usr/bin/gitleaks /usr/bin/

####################
# Install scalafmt #
####################
COPY --from=scalafmt /bin/scalafmt /usr/bin/

#################
# Install Litnr #
#################
Expand Down
6 changes: 6 additions & 0 deletions Dockerfile-slim
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ FROM zricethezav/gitleaks:v7.6.1 as gitleaks
FROM garethr/kubeval:0.15.0 as kubeval
FROM ghcr.io/assignuser/lintr-lib:0.3.0 as lintr-lib
FROM ghcr.io/awkbar-devops/clang-format:v1.0.2 as clang-format
FROM scalameta/scalafmt:v2.7.5 as scalafmt

##################
# Get base image #
Expand Down Expand Up @@ -191,6 +192,11 @@ COPY --from=clang-format /usr/bin/clang-format /usr/bin/
####################
COPY --from=gitleaks /usr/bin/gitleaks /usr/bin/

####################
# Install scalafmt #
####################
COPY --from=scalafmt /bin/scalafmt /usr/bin/

#################
# Install Litnr #
#################
Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ Developers on **GitHub** can call the **GitHub Action** to lint their codebase w
| **Raku** | [Raku](https://raku.org) |
| **Ruby** | [RuboCop](https://github.com/rubocop-hq/rubocop) |
| **Rust** | [Rustfmt](https://github.com/rust-lang/rustfmt) / [Clippy](https://github.com/rust-lang/rust-clippy) |
| **Scala** | [scalafmt](https://github.com/scalameta/scalafmt) |
| **Secrets** | [GitLeaks](https://github.com/zricethezav/gitleaks) |
| **Shell** | [Shellcheck](https://github.com/koalaman/shellcheck) / [executable bit check] / [shfmt](https://github.com/mvdan/sh) |
| **Snakemake** | [snakefmt](https://github.com/snakemake/snakefmt/) / [snakemake --lint](https://snakemake.readthedocs.io/en/stable/snakefiles/writing_snakefiles.html#best-practices) |
Expand Down Expand Up @@ -310,6 +311,7 @@ But if you wish to select or exclude specific linters, we give you full control
| **RUBY_CONFIG_FILE** | `.ruby-lint.yml` | Filename for [rubocop configuration](https://docs.rubocop.org/rubocop/configuration.html) (ex: `.ruby-lint.yml`, `.rubocop.yml`) |
| **SUPPRESS_FILE_TYPE_WARN** | `false` | If set to `true`, will hide warning messages about files without their proper extensions. Default is `false` |
| **SUPPRESS_POSSUM** | `false` | If set to `true`, will hide the ASCII possum at top of log output. Default is `false` |
| **SCALAFMT_CONFIG_FILE** | `.scalafmt.conf` | Filename for [scalafmt configuration](https://scalameta.org/scalafmt/docs/configuration.html) (ex: `.scalafmt.conf`) |
| **SNAKEMAKE_SNAKEFMT_CONFIG_FILE** | `.snakefmt.toml` | Filename for [Snakemake configuration](https://github.com/snakemake/snakefmt#configuration) (ex: `pyproject.toml`, `.snakefmt.toml`) |
| **SSL_CERT_SECRET** | `none` | SSL cert to add to the **Super-Linter** trust store. This is needed for users on `self-hosted` runners or need to inject the cert for security standards (ex. ${{ secrets.SSL_CERT }}) |
| **SQL_CONFIG_FILE** | `.sql-config.json` | Filename for [SQL-Lint configuration](https://sql-lint.readthedocs.io/en/latest/files/configuration.html) (ex: `sql-config.json` , `.config.json`) |
Expand Down Expand Up @@ -375,6 +377,7 @@ But if you wish to select or exclude specific linters, we give you full control
| **VALIDATE_RUST_2015** | `true` | Flag to enable or disable the linting process of the Rust language. (edition: 2015) |
| **VALIDATE_RUST_2018** | `true` | Flag to enable or disable the linting process of Rust language. (edition: 2018) |
| **VALIDATE_RUST_CLIPPY** | `true` | Flag to enable or disable the clippy linting process of Rust language. |
| **VALIDATE_SCALAFMT_LINT** | `true` | Flag to enable or disable the linting process of Scala language. (Utilizing: scalafmt --test) |
| **VALIDATE_SHELL_SHFMT** | `true` | Flag to enable or disable the linting process of Shell scripts. (Utilizing: shfmt) |
| **VALIDATE_SNAKEMAKE_LINT** | `true` | Flag to enable or disable the linting process of Snakefiles. (Utilizing: snakemake --lint) |
| **VALIDATE_SNAKEMAKE_SNAKEFMT** | `true` | Flag to enable or disable the linting process of Snakefiles. (Utilizing: snakefmt) |
Expand Down
9 changes: 9 additions & 0 deletions lib/functions/buildFileList.sh
Original file line number Diff line number Diff line change
Expand Up @@ -687,6 +687,15 @@ function BuildFileList() {
###############################################
FILE_ARRAY_RUST_CLIPPY+=("${FILE}")

###########################
# Get the SCALA files #
###########################
elif [ "${FILE_TYPE}" == "scala" ] || [ "${BASE_FILE}" == "??????" ]; then
################################
# Append the file to the array #
################################
FILE_ARRAY_SCALAFMT+=("${FILE}")

###########################
# Get the SNAKEMAKE files #
###########################
Expand Down
10 changes: 7 additions & 3 deletions lib/linter.sh
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,8 @@ R_FILE_NAME=".lintr"
# shellcheck disable=SC2034 # Variable is referenced indirectly
RUBY_FILE_NAME="${RUBY_CONFIG_FILE:-.ruby-lint.yml}"
# shellcheck disable=SC2034 # Variable is referenced indirectly
SCALAFMT_FILE_NAME="${SCALAFMT_CONFIG_FILE:-.scalafmt.conf}"
# shellcheck disable=SC2034 # Variable is referenced indirectly
SNAKEMAKE_SNAKEFMT_FILE_NAME="${SNAKEMAKE_SNAKEFMT_CONFIG_FILE:-.snakefmt.toml}"
# shellcheck disable=SC2034 # Variable is referenced indirectly
SUPPRESS_FILE_TYPE_WARN="${SUPPRESS_FILE_TYPE_WARN:-false}"
Expand Down Expand Up @@ -218,9 +220,9 @@ LANGUAGE_ARRAY=('ANSIBLE' 'ARM' 'BASH' 'BASH_EXEC' 'CLANG_FORMAT'
'OPENAPI' 'PERL' 'PHP_BUILTIN' 'PHP_PHPCS' 'PHP_PHPSTAN' 'PHP_PSALM'
'POWERSHELL' 'PROTOBUF' 'PYTHON_BLACK' 'PYTHON_PYLINT' 'PYTHON_FLAKE8'
'PYTHON_ISORT' 'PYTHON_MYPY' 'R' 'RAKU' 'RUBY' 'RUST_2015' 'RUST_2018'
'RUST_CLIPPY' 'SHELL_SHFMT' 'SNAKEMAKE_LINT' 'SNAKEMAKE_SNAKEFMT' 'STATES'
'SQL' 'SQLFLUFF' 'TEKTON' 'TERRAFORM_TFLINT' 'TERRAFORM_TERRASCAN' 'TERRAGRUNT'
'TSX' 'TYPESCRIPT_ES' 'TYPESCRIPT_STANDARD' 'XML' 'YAML')
'RUST_CLIPPY' 'SCALAFMT' 'SHELL_SHFMT' 'SNAKEMAKE_LINT' 'SNAKEMAKE_SNAKEFMT'
'STATES' 'SQL' 'SQLFLUFF' 'TEKTON' 'TERRAFORM_TFLINT' 'TERRAFORM_TERRASCAN'
'TERRAGRUNT' 'TSX' 'TYPESCRIPT_ES' 'TYPESCRIPT_STANDARD' 'XML' 'YAML')

##############################
# Linter command names array #
Expand Down Expand Up @@ -281,6 +283,7 @@ LINTER_NAMES_ARRAY['RUBY']="rubocop"
LINTER_NAMES_ARRAY['RUST_2015']="rustfmt"
LINTER_NAMES_ARRAY['RUST_2018']="rustfmt"
LINTER_NAMES_ARRAY['RUST_CLIPPY']="clippy"
LINTER_NAMES_ARRAY['SCALAFMT']="scalafmt"
LINTER_NAMES_ARRAY['SHELL_SHFMT']="shfmt"
LINTER_NAMES_ARRAY['SNAKEMAKE_LINT']="snakemake"
LINTER_NAMES_ARRAY['SNAKEMAKE_SNAKEFMT']="snakefmt"
Expand Down Expand Up @@ -899,6 +902,7 @@ LINTER_COMMANDS_ARRAY['RUBY']="rubocop -c ${RUBY_LINTER_RULES} --force-exclusion
LINTER_COMMANDS_ARRAY['RUST_2015']="rustfmt --check --edition 2015"
LINTER_COMMANDS_ARRAY['RUST_2018']="rustfmt --check --edition 2018"
LINTER_COMMANDS_ARRAY['RUST_CLIPPY']="clippy"
LINTER_COMMANDS_ARRAY['SCALAFMT']="scalafmt --config ${SCALAFMT_LINTER_RULES} --test"
LINTER_COMMANDS_ARRAY['SHELL_SHFMT']="shfmt -d"
LINTER_COMMANDS_ARRAY['SNAKEMAKE_LINT']="snakemake --lint -s"
LINTER_COMMANDS_ARRAY['SNAKEMAKE_SNAKEFMT']="snakefmt --config ${SNAKEMAKE_SNAKEFMT_LINTER_RULES} --check --compact-diff"
Expand Down
2 changes: 2 additions & 0 deletions test/inspec/super-linter/controls/super_linter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@
{ linter_name: "raku", version_command: "raku --version | strings -n 8"},
{ linter_name: "rubocop"},
{ linter_name: "rustfmt"},
{ linter_name: "scalafmt"},
{ linter_name: "shellcheck"},
{ linter_name: "shfmt"},
{ linter_name: "snakefmt"},
Expand Down Expand Up @@ -424,6 +425,7 @@
"/action/lib/.automation/.python-black",
"/action/lib/.automation/.python-lint",
"/action/lib/.automation/.ruby-lint.yml",
"/action/lib/.automation/.scalafmt.conf",
"/action/lib/.automation/.snakefmt.toml",
"/action/lib/.automation/.sql-config.json",
"/action/lib/.automation/.stylelintrc.json",
Expand Down