Skip to content

Commit b8e741b

Browse files
marcmosameer6989
andauthored
add score_linter module (#57)
Co-authored-by: Sameer Srivastava <sameer.g.srivastava@accenture.com>
1 parent 2c786fe commit b8e741b

8 files changed

Lines changed: 277 additions & 0 deletions

File tree

tools/BUILD

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# *******************************************************************************
2+
# Copyright (c) 2025 Contributors to the Eclipse Foundation
3+
#
4+
# See the NOTICE file(s) distributed with this work for additional
5+
# information regarding copyright ownership.
6+
#
7+
# This program and the accompanying materials are made available under the
8+
# terms of the Apache License Version 2.0 which is available at
9+
# https://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# SPDX-License-Identifier: Apache-2.0
12+
# *******************************************************************************
13+
14+
package(default_visibility = ["//visibility:public"])
15+
16+
exports_files([
17+
"ruff.lock.json",
18+
"actionlint.lock.json",
19+
"shellcheck.lock.json",
20+
"yamlfmt.lock.json",
21+
])
22+
23+
sh_binary(
24+
name = "ruff",
25+
srcs = ["@ruff_hub//tools/ruff:cwd"],
26+
visibility = ["//visibility:public"],
27+
)
28+
29+
sh_binary(
30+
name = "actionlint",
31+
srcs = ["@actionlint_hub//tools/actionlint:cwd"],
32+
visibility = ["//visibility:public"],
33+
)
34+
35+
sh_binary(
36+
name = "shellcheck",
37+
srcs = ["@shellcheck_hub//tools/shellcheck:cwd"],
38+
visibility = ["//visibility:public"],
39+
)
40+
41+
sh_binary(
42+
name = "yamlfmt",
43+
srcs = ["@yamlfmt_hub//tools/yamlfmt:cwd"],
44+
visibility = ["//visibility:public"],
45+
)

tools/MODULE.bazel

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# *******************************************************************************
2+
# Copyright (c) 2025 Contributors to the Eclipse Foundation
3+
#
4+
# See the NOTICE file(s) distributed with this work for additional
5+
# information regarding copyright ownership.
6+
#
7+
# This program and the accompanying materials are made available under the
8+
# terms of the Apache License Version 2.0 which is available at
9+
# https://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# SPDX-License-Identifier: Apache-2.0
12+
# *******************************************************************************
13+
14+
module(
15+
name = "score_linter",
16+
version = "0.1.0",
17+
compatibility_level = 0,
18+
)
19+
20+
bazel_dep(name = "bazel_skylib", version = "1.5.0")
21+
bazel_dep(name = "rules_multitool", version = "1.2.0")
22+
23+
multitool = use_extension("@rules_multitool//multitool:extension.bzl", "multitool")
24+
25+
# Ruff Hub
26+
multitool.hub(
27+
hub_name = "ruff_hub",
28+
lockfile = "//:ruff.lock.json",
29+
)
30+
use_repo(multitool, "ruff_hub")
31+
32+
# Actionlint Hub
33+
multitool.hub(
34+
hub_name = "actionlint_hub",
35+
lockfile = "//:actionlint.lock.json",
36+
)
37+
use_repo(multitool, "actionlint_hub")
38+
39+
# Shellcheck Hub
40+
multitool.hub(
41+
hub_name = "shellcheck_hub",
42+
lockfile = "//:shellcheck.lock.json",
43+
)
44+
use_repo(multitool, "shellcheck_hub")
45+
46+
# YAMLfmt Hub
47+
multitool.hub(
48+
hub_name = "yamlfmt_hub",
49+
lockfile = "//:yamlfmt.lock.json",
50+
)
51+
use_repo(multitool, "yamlfmt_hub")

tools/README.md

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# S-CORE linter
2+
3+
This bazel module provides centrally managed binaries for linter and static analysis tools used in S-CORE.
4+
5+
It provides a template script `sample.sh` that can be adapted to run the tools you need.
6+
7+
## Current tools:
8+
Currently binaries / executables for the following tools are provided
9+
- **Ruff**: A super-fast Python linter.
10+
- **basedpyright**: A type checker for Python.
11+
- **Actionlint**: A linter for your GitHub Actions workflows.
12+
- **Shellcheck**: A static analysis tool for shell scripts.
13+
- **Yamlfmt**: A handy formatter for YAML files.
14+
15+
## How to use the Module
16+
Add the import of `multitool` as well as `score_linter` to your `MODULE.bazel` file.
17+
Adapt the `use_repo` and `register_toolchains` calls to only import/use the tools you need.
18+
```
19+
bazel_dep(name = "rules_multitool", version = "1.2.0")
20+
bazel_dep(
21+
name = "score_linter",
22+
version = "0.1.0",
23+
)
24+
25+
multitool_root = use_extension("@rules_multitool//multitool:extension.bzl", "multitool")
26+
27+
use_repo(multitool_root, "multitool", "actionlint_hub", "ruff_hub", "shellcheck_hub", "yamlfmt_hub")
28+
29+
register_toolchains(
30+
"@ruff_hub//toolchains:all",
31+
"@actionlint_hub//toolchains:all",
32+
"@shellcheck_hub//toolchains:all",
33+
"@yamlfmt_hub//toolchains:all",
34+
)
35+
```
36+
37+
### Run the Lint Script (sample.sh)
38+
39+
Copy the [sample.sh script](https://github.com/eclipse-score/tooling/tools/sample.sh).
40+
41+
Adapt it to only run the tools you need, by deleting or commenting out the lines not necessary. The script will run all the configured linters and report any issues it finds.
42+
43+
Ensure the script is executable `chmod u+x <script name>`.
44+
45+
You now can simply run it via `./<script name>` and should see all the output for your project.

tools/actionlint.lock.json

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
{
2+
"$schema": "https://raw.githubusercontent.com/theoremlp/rules_multitool/main/lockfile.schema.json",
3+
"actionlint": {
4+
"binaries": [
5+
{
6+
"kind": "archive",
7+
"file": "actionlint",
8+
"url": "https://github.com/rhysd/actionlint/releases/download/v1.7.7/actionlint_1.7.7_darwin_arm64.tar.gz",
9+
"sha256": "2693315b9093aeacb4ebd91a993fea54fc215057bf0da2659056b4bc033873db",
10+
"type": "tar.gz",
11+
"os": "macos",
12+
"cpu": "arm64"
13+
},
14+
{
15+
"kind": "archive",
16+
"file": "actionlint",
17+
"url": "https://github.com/rhysd/actionlint/releases/download/v1.7.7/actionlint_1.7.7_linux_amd64.tar.gz",
18+
"sha256": "023070a287cd8cccd71515fedc843f1985bf96c436b7effaecce67290e7e0757",
19+
"type": "tar.gz",
20+
"os": "linux",
21+
"cpu": "x86_64"
22+
}
23+
]
24+
}
25+
}

tools/ruff.lock.json

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
{
2+
"$schema": "https://raw.githubusercontent.com/theoremlp/rules_multitool/main/lockfile.schema.json",
3+
"ruff": {
4+
"binaries": [
5+
{
6+
"kind": "archive",
7+
"file": "ruff-aarch64-apple-darwin/ruff",
8+
"url": "https://github.com/astral-sh/ruff/releases/download/0.11.13/ruff-aarch64-apple-darwin.tar.gz",
9+
"sha256": "7d5e8feea7ee5c3962807996cad557e8a0c4d676c1cba6223bfb0e8b2ca07723",
10+
"type": "tar.gz",
11+
"os": "macos",
12+
"cpu": "arm64"
13+
},
14+
{
15+
"kind": "archive",
16+
"file": "ruff-x86_64-unknown-linux-gnu/ruff",
17+
"url": "https://github.com/astral-sh/ruff/releases/download/0.11.13/ruff-x86_64-unknown-linux-gnu.tar.gz",
18+
"sha256": "01aa32d29d00876b8d1429c617ed63a00b1fc81abfa4183bb05c9cb647fbc3d0",
19+
"type": "tar.gz",
20+
"os": "linux",
21+
"cpu": "x86_64"
22+
}
23+
]
24+
}
25+
}

tools/sample.sh

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# *******************************************************************************
2+
# Copyright (c) 2025 Contributors to the Eclipse Foundation
3+
#
4+
# See the NOTICE file(s) distributed with this work for additional
5+
# information regarding copyright ownership.
6+
#
7+
# This program and the accompanying materials are made available under the
8+
# terms of the Apache License Version 2.0 which is available at
9+
# https://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# SPDX-License-Identifier: Apache-2.0
12+
# *******************************************************************************
13+
#!/usr/bin/env bash
14+
set -euo pipefail
15+
16+
bazel run //src:ide_support
17+
18+
echo "Running Ruff linter..."
19+
bazel run @score_linter//:ruff check
20+
21+
echo "Running basedpyright..."
22+
.venv/bin/python3 -m basedpyright
23+
24+
echo "Running Actionlint..."
25+
bazel run @score_linter//:actionlint
26+
27+
echo "Running Shellcheck..."
28+
find . \
29+
-type d \( -name .git -o -name .venv -o -name bazel-out -o -name node_modules \) -prune -false \
30+
-o -type f -exec grep -Il '^#!.*sh' {} \; | \
31+
xargs bazel run @score_linter//:shellcheck --
32+
33+
echo "Running Yamlfmt..."
34+
bazel run @score_linter//:yamlfmt -- $(find . \
35+
-type d \( -name .git -o -name .venv -o -name bazel-out -o -name node_modules \) -prune -false \
36+
-o -type f \( -name "*.yaml" -o -name "*.yml" \) | tr '\n' '\0' | xargs -0)

tools/shellcheck.lock.json

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
{
2+
"$schema": "https://raw.githubusercontent.com/theoremlp/rules_multitool/main/lockfile.schema.json",
3+
"shellcheck": {
4+
"binaries": [
5+
{
6+
"kind": "archive",
7+
"file": "shellcheck-v0.10.0/shellcheck",
8+
"url": "https://github.com/koalaman/shellcheck/releases/download/v0.10.0/shellcheck-v0.10.0.darwin.aarch64.tar.xz",
9+
"sha256": "bbd2f14826328eee7679da7221f2bc3afb011f6a928b848c80c321f6046ddf81",
10+
"type": "tar.xz",
11+
"os": "macos",
12+
"cpu": "arm64"
13+
},
14+
{
15+
"kind": "archive",
16+
"file": "shellcheck-v0.10.0/shellcheck",
17+
"url": "https://github.com/koalaman/shellcheck/releases/download/v0.10.0/shellcheck-v0.10.0.linux.x86_64.tar.xz",
18+
"sha256": "6c881ab0698e4e6ea235245f22832860544f17ba386442fe7e9d629f8cbedf87",
19+
"type": "tar.xz",
20+
"os": "linux",
21+
"cpu": "x86_64"
22+
}
23+
]
24+
}
25+
}

tools/yamlfmt.lock.json

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
{
2+
"$schema": "https://raw.githubusercontent.com/theoremlp/rules_multitool/main/lockfile.schema.json",
3+
"yamlfmt": {
4+
"binaries": [
5+
{
6+
"kind": "archive",
7+
"file": "yamlfmt",
8+
"url": "https://github.com/google/yamlfmt/releases/download/v0.17.0/yamlfmt_0.17.0_Darwin_arm64.tar.gz",
9+
"sha256": "1be37d76a79caa5073ce342de24f7b8b2509c2a482178286f44b72835469052b",
10+
"type": "tar.gz",
11+
"os": "macos",
12+
"cpu": "arm64"
13+
},
14+
{
15+
"kind": "archive",
16+
"file": "yamlfmt",
17+
"url": "https://github.com/google/yamlfmt/releases/download/v0.17.0/yamlfmt_0.17.0_Linux_x86_64.tar.gz",
18+
"sha256": "e91dd8722001596b8e4777a29d4a526a10ff276c4ff8a5ae39ff59be5a033054",
19+
"type": "tar.gz",
20+
"os": "linux",
21+
"cpu": "x86_64"
22+
}
23+
]
24+
}
25+
}

0 commit comments

Comments
 (0)