Skip to content

Commit 897185a

Browse files
jmherbstJake HerbstadmiralAwkbar
authored
Adding scalafmt (super-linter#2053)
* Adding scalafmt * add it Co-authored-by: Jake Herbst <[email protected]> Co-authored-by: Lukas Gravley <[email protected]>
1 parent 1d50613 commit 897185a

File tree

9 files changed

+115
-3
lines changed

9 files changed

+115
-3
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Scala Test Cases
2+
3+
This folder holds the test cases for **Scala**.
4+
5+
## Additional Docs
6+
7+
No Additional information is needed for this test case.
8+
9+
## Good Test Cases
10+
11+
The test cases denoted: `LANGUAGE_good_FILE.EXTENSION` are all valid, and should pass successfully when linted.
12+
13+
- **Note:** They are linted utilizing the default linter rules.
14+
15+
## Bad Test Cases
16+
17+
The test cases denoted: `LANGUAGE_bad_FILE.EXTENSION` are **NOT** valid, and should trigger errors when linted.
18+
19+
- **Note:** They are linted utilizing the default linter rules.
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
object a {
2+
class a[
3+
t1,
4+
t2 // comment
5+
](a1: Int,
6+
a2: Int // comment
7+
)(
8+
b1: String,
9+
b2: String // comment
10+
)(implicit
11+
c1: SomeType1,
12+
c2: SomeType2 // comment
13+
) {
14+
def this(
15+
a1: Int,
16+
a2: Int // comment
17+
)(
18+
b1: String,
19+
b2: String // comment
20+
)(implicit
21+
c1: SomeType1,
22+
c2: SomeType2 // comment
23+
) = this(
24+
a1,
25+
a2 // comment
26+
) (
27+
b1,
28+
b2 // comment
29+
)
30+
}
31+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
object a {
2+
class a[
3+
t1,
4+
t2 // comment
5+
](
6+
a1: Int,
7+
a2: Int // comment
8+
)(
9+
b1: String,
10+
b2: String // comment
11+
)(implicit
12+
c1: SomeType1,
13+
c2: SomeType2 // comment
14+
) {
15+
def this(
16+
a1: Int,
17+
a2: Int // comment
18+
)(
19+
b1: String,
20+
b2: String // comment
21+
)(implicit
22+
c1: SomeType1,
23+
c2: SomeType2 // comment
24+
) = this(
25+
a1,
26+
a2 // comment
27+
)(
28+
b1,
29+
b2 // comment
30+
)
31+
}
32+
}

Dockerfile

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ FROM zricethezav/gitleaks:v7.6.1 as gitleaks
2323
FROM garethr/kubeval:0.15.0 as kubeval
2424
FROM ghcr.io/assignuser/lintr-lib:0.3.0 as lintr-lib
2525
FROM ghcr.io/awkbar-devops/clang-format:v1.0.2 as clang-format
26+
FROM scalameta/scalafmt:v2.7.5 as scalafmt
2627

2728
##################
2829
# Get base image #
@@ -253,6 +254,11 @@ COPY --from=clang-format /usr/bin/clang-format /usr/bin/
253254
####################
254255
COPY --from=gitleaks /usr/bin/gitleaks /usr/bin/
255256

257+
####################
258+
# Install scalafmt #
259+
####################
260+
COPY --from=scalafmt /bin/scalafmt /usr/bin/
261+
256262
#################
257263
# Install Litnr #
258264
#################

Dockerfile-slim

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ FROM zricethezav/gitleaks:v7.6.1 as gitleaks
2929
FROM garethr/kubeval:0.15.0 as kubeval
3030
FROM ghcr.io/assignuser/lintr-lib:0.3.0 as lintr-lib
3131
FROM ghcr.io/awkbar-devops/clang-format:v1.0.2 as clang-format
32+
FROM scalameta/scalafmt:v2.7.5 as scalafmt
3233

3334
##################
3435
# Get base image #
@@ -191,6 +192,11 @@ COPY --from=clang-format /usr/bin/clang-format /usr/bin/
191192
####################
192193
COPY --from=gitleaks /usr/bin/gitleaks /usr/bin/
193194

195+
####################
196+
# Install scalafmt #
197+
####################
198+
COPY --from=scalafmt /bin/scalafmt /usr/bin/
199+
194200
#################
195201
# Install Litnr #
196202
#################

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ Developers on **GitHub** can call the **GitHub Action** to lint their codebase w
9191
| **Raku** | [Raku](https://raku.org) |
9292
| **Ruby** | [RuboCop](https://github.com/rubocop-hq/rubocop) |
9393
| **Rust** | [Rustfmt](https://github.com/rust-lang/rustfmt) / [Clippy](https://github.com/rust-lang/rust-clippy) |
94+
| **Scala** | [scalafmt](https://github.com/scalameta/scalafmt) |
9495
| **Secrets** | [GitLeaks](https://github.com/zricethezav/gitleaks) |
9596
| **Shell** | [Shellcheck](https://github.com/koalaman/shellcheck) / [executable bit check] / [shfmt](https://github.com/mvdan/sh) |
9697
| **Snakemake** | [snakefmt](https://github.com/snakemake/snakefmt/) / [snakemake --lint](https://snakemake.readthedocs.io/en/stable/snakefiles/writing_snakefiles.html#best-practices) |
@@ -310,6 +311,7 @@ But if you wish to select or exclude specific linters, we give you full control
310311
| **RUBY_CONFIG_FILE** | `.ruby-lint.yml` | Filename for [rubocop configuration](https://docs.rubocop.org/rubocop/configuration.html) (ex: `.ruby-lint.yml`, `.rubocop.yml`) |
311312
| **SUPPRESS_FILE_TYPE_WARN** | `false` | If set to `true`, will hide warning messages about files without their proper extensions. Default is `false` |
312313
| **SUPPRESS_POSSUM** | `false` | If set to `true`, will hide the ASCII possum at top of log output. Default is `false` |
314+
| **SCALAFMT_CONFIG_FILE** | `.scalafmt.conf` | Filename for [scalafmt configuration](https://scalameta.org/scalafmt/docs/configuration.html) (ex: `.scalafmt.conf`) |
313315
| **SNAKEMAKE_SNAKEFMT_CONFIG_FILE** | `.snakefmt.toml` | Filename for [Snakemake configuration](https://github.com/snakemake/snakefmt#configuration) (ex: `pyproject.toml`, `.snakefmt.toml`) |
314316
| **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 }}) |
315317
| **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`) |
@@ -375,6 +377,7 @@ But if you wish to select or exclude specific linters, we give you full control
375377
| **VALIDATE_RUST_2015** | `true` | Flag to enable or disable the linting process of the Rust language. (edition: 2015) |
376378
| **VALIDATE_RUST_2018** | `true` | Flag to enable or disable the linting process of Rust language. (edition: 2018) |
377379
| **VALIDATE_RUST_CLIPPY** | `true` | Flag to enable or disable the clippy linting process of Rust language. |
380+
| **VALIDATE_SCALAFMT_LINT** | `true` | Flag to enable or disable the linting process of Scala language. (Utilizing: scalafmt --test) |
378381
| **VALIDATE_SHELL_SHFMT** | `true` | Flag to enable or disable the linting process of Shell scripts. (Utilizing: shfmt) |
379382
| **VALIDATE_SNAKEMAKE_LINT** | `true` | Flag to enable or disable the linting process of Snakefiles. (Utilizing: snakemake --lint) |
380383
| **VALIDATE_SNAKEMAKE_SNAKEFMT** | `true` | Flag to enable or disable the linting process of Snakefiles. (Utilizing: snakefmt) |

lib/functions/buildFileList.sh

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -687,6 +687,15 @@ function BuildFileList() {
687687
###############################################
688688
FILE_ARRAY_RUST_CLIPPY+=("${FILE}")
689689

690+
###########################
691+
# Get the SCALA files #
692+
###########################
693+
elif [ "${FILE_TYPE}" == "scala" ] || [ "${BASE_FILE}" == "??????" ]; then
694+
################################
695+
# Append the file to the array #
696+
################################
697+
FILE_ARRAY_SCALAFMT+=("${FILE}")
698+
690699
###########################
691700
# Get the SNAKEMAKE files #
692701
###########################

lib/linter.sh

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,8 @@ R_FILE_NAME=".lintr"
162162
# shellcheck disable=SC2034 # Variable is referenced indirectly
163163
RUBY_FILE_NAME="${RUBY_CONFIG_FILE:-.ruby-lint.yml}"
164164
# shellcheck disable=SC2034 # Variable is referenced indirectly
165+
SCALAFMT_FILE_NAME="${SCALAFMT_CONFIG_FILE:-.scalafmt.conf}"
166+
# shellcheck disable=SC2034 # Variable is referenced indirectly
165167
SNAKEMAKE_SNAKEFMT_FILE_NAME="${SNAKEMAKE_SNAKEFMT_CONFIG_FILE:-.snakefmt.toml}"
166168
# shellcheck disable=SC2034 # Variable is referenced indirectly
167169
SUPPRESS_FILE_TYPE_WARN="${SUPPRESS_FILE_TYPE_WARN:-false}"
@@ -218,9 +220,9 @@ LANGUAGE_ARRAY=('ANSIBLE' 'ARM' 'BASH' 'BASH_EXEC' 'CLANG_FORMAT'
218220
'OPENAPI' 'PERL' 'PHP_BUILTIN' 'PHP_PHPCS' 'PHP_PHPSTAN' 'PHP_PSALM'
219221
'POWERSHELL' 'PROTOBUF' 'PYTHON_BLACK' 'PYTHON_PYLINT' 'PYTHON_FLAKE8'
220222
'PYTHON_ISORT' 'PYTHON_MYPY' 'R' 'RAKU' 'RUBY' 'RUST_2015' 'RUST_2018'
221-
'RUST_CLIPPY' 'SHELL_SHFMT' 'SNAKEMAKE_LINT' 'SNAKEMAKE_SNAKEFMT' 'STATES'
222-
'SQL' 'SQLFLUFF' 'TEKTON' 'TERRAFORM_TFLINT' 'TERRAFORM_TERRASCAN' 'TERRAGRUNT'
223-
'TSX' 'TYPESCRIPT_ES' 'TYPESCRIPT_STANDARD' 'XML' 'YAML')
223+
'RUST_CLIPPY' 'SCALAFMT' 'SHELL_SHFMT' 'SNAKEMAKE_LINT' 'SNAKEMAKE_SNAKEFMT'
224+
'STATES' 'SQL' 'SQLFLUFF' 'TEKTON' 'TERRAFORM_TFLINT' 'TERRAFORM_TERRASCAN'
225+
'TERRAGRUNT' 'TSX' 'TYPESCRIPT_ES' 'TYPESCRIPT_STANDARD' 'XML' 'YAML')
224226

225227
##############################
226228
# Linter command names array #
@@ -281,6 +283,7 @@ LINTER_NAMES_ARRAY['RUBY']="rubocop"
281283
LINTER_NAMES_ARRAY['RUST_2015']="rustfmt"
282284
LINTER_NAMES_ARRAY['RUST_2018']="rustfmt"
283285
LINTER_NAMES_ARRAY['RUST_CLIPPY']="clippy"
286+
LINTER_NAMES_ARRAY['SCALAFMT']="scalafmt"
284287
LINTER_NAMES_ARRAY['SHELL_SHFMT']="shfmt"
285288
LINTER_NAMES_ARRAY['SNAKEMAKE_LINT']="snakemake"
286289
LINTER_NAMES_ARRAY['SNAKEMAKE_SNAKEFMT']="snakefmt"
@@ -899,6 +902,7 @@ LINTER_COMMANDS_ARRAY['RUBY']="rubocop -c ${RUBY_LINTER_RULES} --force-exclusion
899902
LINTER_COMMANDS_ARRAY['RUST_2015']="rustfmt --check --edition 2015"
900903
LINTER_COMMANDS_ARRAY['RUST_2018']="rustfmt --check --edition 2018"
901904
LINTER_COMMANDS_ARRAY['RUST_CLIPPY']="clippy"
905+
LINTER_COMMANDS_ARRAY['SCALAFMT']="scalafmt --config ${SCALAFMT_LINTER_RULES} --test"
902906
LINTER_COMMANDS_ARRAY['SHELL_SHFMT']="shfmt -d"
903907
LINTER_COMMANDS_ARRAY['SNAKEMAKE_LINT']="snakemake --lint -s"
904908
LINTER_COMMANDS_ARRAY['SNAKEMAKE_SNAKEFMT']="snakefmt --config ${SNAKEMAKE_SNAKEFMT_LINTER_RULES} --check --compact-diff"

test/inspec/super-linter/controls/super_linter.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@
137137
{ linter_name: "raku", version_command: "raku --version | strings -n 8"},
138138
{ linter_name: "rubocop"},
139139
{ linter_name: "rustfmt"},
140+
{ linter_name: "scalafmt"},
140141
{ linter_name: "shellcheck"},
141142
{ linter_name: "shfmt"},
142143
{ linter_name: "snakefmt"},
@@ -424,6 +425,7 @@
424425
"/action/lib/.automation/.python-black",
425426
"/action/lib/.automation/.python-lint",
426427
"/action/lib/.automation/.ruby-lint.yml",
428+
"/action/lib/.automation/.scalafmt.conf",
427429
"/action/lib/.automation/.snakefmt.toml",
428430
"/action/lib/.automation/.sql-config.json",
429431
"/action/lib/.automation/.stylelintrc.json",

0 commit comments

Comments
 (0)