Skip to content

Commit 7fcadf6

Browse files
committed
add linters
1 parent f972e52 commit 7fcadf6

File tree

15 files changed

+139
-55
lines changed

15 files changed

+139
-55
lines changed

.github/super-linter.env

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# disable kubernetes linter - complains about resource limits, etc
2+
VALIDATE_CHECKOV=false
3+
# we have many duplicate code in our codebase for demo purposes
4+
VALIDATE_JSCPD=false
5+
VALIDATE_GIT_COMMITLINT=false
6+
IGNORE_GITIGNORED_FILES=true
7+
FILTER_REGEX_EXCLUDE=mvnw
8+
JAVA_FILE_NAME=google_checks.xml
9+
10+
FIX_SHELL_SHFMT=true
11+
FIX_JSON=true
12+
FIX_JSON_PRETTIER=true
13+
FIX_GOOGLE_JAVA_FORMAT=true
14+
FIX_GO=true
15+
FIX_GO_MODULES=true
16+
FIX_ENV=true
17+
FIX_PYTHON_BLACK=true
18+
FIX_PYTHON_ISORT=true
19+
FIX_PYTHON_PYINK=true
20+
FIX_MARKDOWN=true
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
---
2+
name: Fix Lint Issues
3+
4+
on:
5+
pull_request:
6+
7+
permissions:
8+
contents: read
9+
10+
jobs:
11+
fix-lint-issues:
12+
runs-on: ubuntu-24.04
13+
14+
permissions:
15+
# To write linting fixes
16+
contents: write
17+
# To write Super-linter status checks
18+
statuses: write
19+
20+
steps:
21+
- name: Checkout code
22+
uses: actions/checkout@v4
23+
with:
24+
fetch-depth: 0
25+
26+
- name: Load super-linter configuration
27+
run: grep -v '^#' .github/super-linter.env >> "$GITHUB_ENV"
28+
29+
- name: Super-linter
30+
uses: super-linter/[email protected]
31+
env:
32+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
33+
- name: Commit and push linting fixes
34+
uses: stefanzweifel/git-auto-commit-action@v5
35+
with:
36+
branch: ${{ github.event.pull_request.head.ref || github.head_ref || github.ref }}
37+
commit_message: "chore: fix linting issues"
38+
commit_user_name: super-linter
39+
commit_user_email: [email protected]

.github/workflows/super-linter.yml

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@ on:
44
pull_request:
55

66
jobs:
7-
build:
8-
name: Lint
7+
lint:
98
runs-on: ubuntu-24.04
109

1110
permissions:
@@ -18,13 +17,13 @@ jobs:
1817
- name: Checkout code
1918
uses: actions/checkout@v4
2019
with:
21-
# super-linter needs the full git history to get the
22-
# list of files that changed across commits
2320
fetch-depth: 0
2421

22+
- name: Load super-linter configuration
23+
run: grep -v '^#' .github/super-linter.env | grep -v 'FIX_' >> "$GITHUB_ENV"
24+
2525
- name: Super-linter
2626
uses: super-linter/[email protected]
2727
env:
2828
# To report GitHub Actions status checks
2929
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
30-
VALIDATE_CHECKOV: false

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
.idea
1+
.idea/
22
venv/
33
.venv
44
/container/grafana/*

checkstyle-suppressions.xml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?xml version="1.0"?>
2+
3+
<!DOCTYPE suppressions PUBLIC
4+
"-//Checkstyle//DTD SuppressionFilter Configuration 1.2//EN"
5+
"https://checkstyle.org/dtds/suppressions_1_2.dtd">
6+
7+
<suppressions>
8+
<suppress checks="Javadoc" files="."/>
9+
</suppressions>

docker/Dockerfile

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
FROM redhat/ubi9
1+
# hadolint global ignore=DL3059
2+
FROM redhat/ubi9:9.5
23

34
# renovate: datasource=github-releases depName=grafana packageName=grafana/grafana
45
ENV GRAFANA_VERSION=v11.4.0
@@ -20,7 +21,8 @@ ENV TARGETARCH=${TARGETARCH}
2021
RUN mkdir /otel-lgtm
2122
WORKDIR /otel-lgtm
2223

23-
RUN yum install -y unzip jq procps dos2unix
24+
# hadolint ignore=DL3033
25+
RUN yum install -y unzip jq procps dos2unix && yum clean all
2426

2527
RUN bash -c 'ARCHIVE=grafana-"${GRAFANA_VERSION:1}".linux-"${TARGETARCH}".tar.gz && \
2628
curl -sOL https://dl.grafana.com/oss/release/"${ARCHIVE}" && \
@@ -68,6 +70,7 @@ COPY run-tempo.sh .
6870
COPY otelcol-config.yaml .
6971
COPY run-otelcol.sh .
7072
COPY run-all.sh .
73+
# hadolint ignore=SC2038,DL4006
7174
RUN find . -maxdepth 1 -type f | xargs dos2unix
7275

73-
CMD /otel-lgtm/run-all.sh
76+
CMD ["/otel-lgtm/run-all.sh"]

examples/go/go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module dice
22

3-
go 1.21.1
3+
go 1.23
44

55
require (
66
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.53.0

examples/go/otel.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package main
33
import (
44
"context"
55
"errors"
6+
"log/slog"
67
"time"
78

89
"go.opentelemetry.io/contrib/bridges/otelslog"
@@ -95,7 +96,7 @@ func setupOTelSDK(ctx context.Context) (shutdown func(context.Context) error, er
9596

9697
err = runtime.Start(runtime.WithMinimumReadMemStatsInterval(time.Second))
9798
if err != nil {
98-
logger.ErrorContext(ctx, "otel runtime instrumentation failed:", err)
99+
logger.ErrorContext(ctx, "otel runtime instrumentation failed:", slog.Any("error", err))
99100
}
100101

101102
return

examples/go/rolldice.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,14 @@ func rolldice(w http.ResponseWriter, r *http.Request) {
1313
ctx, span := tracer.Start(r.Context(), "roll")
1414
defer span.End()
1515

16+
//nolint:gosec
1617
roll := 1 + rand.Intn(6)
1718

1819
msg := fmt.Sprintf("Rolled a dice: %d\n", roll)
1920
logger.InfoContext(ctx, msg, slog.Int("result", roll))
2021

2122
resp := strconv.Itoa(roll) + "\n"
2223
if _, err := io.WriteString(w, resp); err != nil {
23-
logger.ErrorContext(ctx, "Write failed: %v\n", err)
24+
logger.ErrorContext(ctx, "Write failed: %v\n", slog.Any("error", err))
2425
}
2526
}

examples/java/src/main/java/com/grafana/example/RollController.java

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -11,25 +11,25 @@
1111
@RestController
1212
public class RollController {
1313

14-
private static final Logger logger = LoggerFactory.getLogger(RollController.class);
15-
private final Random random = new Random(0);
14+
private static final Logger logger = LoggerFactory.getLogger(RollController.class);
15+
private final Random random = new Random(0);
1616

17-
@GetMapping("/rolldice")
18-
public String index(@RequestParam("player") Optional<String> player) throws InterruptedException {
19-
Thread.sleep((long) (Math.abs((random.nextGaussian() + 1.0) * 200.0)));
20-
if (random.nextInt(10) < 3) {
21-
throw new RuntimeException("simulating an error");
22-
}
23-
int result = this.getRandomNumber(1, 6);
24-
if (player.isPresent()) {
25-
logger.info("{} is rolling the dice: {}", player.get(), result);
26-
} else {
27-
logger.info("Anonymous player is rolling the dice: {}", result);
28-
}
29-
return Integer.toString(result);
17+
@GetMapping("/rolldice")
18+
public String index(@RequestParam("player") Optional<String> player) throws InterruptedException {
19+
Thread.sleep((long) (Math.abs((random.nextGaussian() + 1.0) * 200.0)));
20+
if (random.nextInt(10) < 3) {
21+
throw new RuntimeException("simulating an error");
3022
}
31-
32-
public int getRandomNumber(int min, int max) {
33-
return random.nextInt(min, max + 1);
23+
int result = this.getRandomNumber(1, 6);
24+
if (player.isPresent()) {
25+
logger.info("{} is rolling the dice: {}", player.get(), result);
26+
} else {
27+
logger.info("Anonymous player is rolling the dice: {}", result);
3428
}
29+
return Integer.toString(result);
30+
}
31+
32+
public int getRandomNumber(int min, int max) {
33+
return random.nextInt(min, max + 1);
34+
}
3535
}

0 commit comments

Comments
 (0)