我正在使用 GitHub 操作https://github.com/golangci/golangci-lint-action
我收到错误:
Installed golangci-lint into /home/runner/golangci-lint-1.43.0-linux-amd64/golangci-lint in 458ms
Prepared env in 606ms
run golangci-lint
Running [/home/runner/golangci-lint-1.43.0-linux-amd64/golangci-lint run --out-format=github-actions] in [] ...
panic: load embedded ruleguard rules: rules/rules.go:13: can't load fmt
goroutine 1 [running]:
github.com/go-critic/go-critic/checkers.init.9()
github.com/go-critic/go-critic@v0.6.1/checkers/checkers.go:58 +0x4b4
Error: golangci-lint exit with code 2
Ran golangci-lint in 13383ms
Run Code Online (Sandbox Code Playgroud)
golangci-lint这是golang v1.18.0的一个已知问题https://github.com/golangci/golangci-lint/issues/2374
我的 GitHub 操作文件是:
name: golangci-lint
on:
push:
tags:
- v*
branches:
- master
- main
pull_request:
permissions:
contents: read
jobs:
golangci:
name: lint
runs-on: ubuntu-latest
steps:
- …Run Code Online (Sandbox Code Playgroud) 我有这样的代码:
if cfg.GetRedisTLS() {
clientOpts.TLSConfig = &tls.Config{
MinVersion: tls.VersionTLS12,
//nolint:gosec // need insecure TLS option for testing and development
InsecureSkipVerify: cfg.GetRedisInsecure(),
}
}
Run Code Online (Sandbox Code Playgroud)
当我运行时,golangci-lint run它会识别该nolint指令并忽略该错误,但是当 Sonarqube 运行时,它会不断失败并显示消息“TLS InsecureSkipVerify 可能为真”
此问题https://github.com/securego/gosec/issues/278讨论了#nosec在评论中使用来禁用该错误。这里讨论了在声明的特定部分中使用它https://github.com/securego/gosec/issues/278#issuecomment-745209803
所以我尝试过:
if cfg.GetRedisTLS() {
clientOpts.TLSConfig = &tls.Config{
MinVersion: tls.VersionTLS12,
//nolint:gosec // need insecure TLS option for testing and development
// NOSONAR #nosec
InsecureSkipVerify: cfg.GetRedisInsecure(),
}
}
Run Code Online (Sandbox Code Playgroud)
和
if cfg.GetRedisTLS() {
clientOpts.TLSConfig = &tls.Config{
MinVersion: tls.VersionTLS12,
//nolint:gosec // need insecure TLS option …Run Code Online (Sandbox Code Playgroud)