Compare commits

..

11 commits

Author SHA1 Message Date
0db97985fe [#27] Add CODEOWNERS
Signed-off-by: Vitaliy Potyarkin <v.potyarkin@yadro.com>
2025-02-17 10:18:36 +03:00
177c8a8e7f [#28] Use selfhosted actions mirror
TrueCloudLab/frostfs-infra#152

Signed-off-by: Vitaliy Potyarkin <v.potyarkin@yadro.com>
2024-12-12 11:53:59 +03:00
628ee422df
[#26] go.mod: Update version
Signed-off-by: Alexander Chuprov <a.chuprov@yadro.com>
2024-11-11 21:12:04 +03:00
007db8eff4 [#25] .golangci.yml: Replace exportloopref with copyloopvar
Fix the warning:
```
WARN The linter 'exportloopref' is deprecated (since v1.60.2) due to: Since Go1.22 (loopvar) this linter is no longer relevant. Replaced by copyloopvar.
```

Signed-off-by: Evgenii Stratonikov <e.stratonikov@yadro.com>
2024-08-28 14:23:46 +03:00
7fbd18be41 [#25] Makefile: Use -trimpath while building
Signed-off-by: Evgenii Stratonikov <e.stratonikov@yadro.com>
2024-08-28 14:23:46 +03:00
a0d01aad6a [#1316] lint: Fix golangci-lint config
Signed-off-by: Ekaterina Lebedeva <ekaterina.lebedeva@yadro.com>
2024-08-21 14:22:21 +03:00
73c7ec4274 [#1316] go.mod: Upgrade go version to 1.22
Signed-off-by: Ekaterina Lebedeva <ekaterina.lebedeva@yadro.com>
2024-08-21 14:22:21 +03:00
9ea0089703 [#23] go.mod: Update version
Signed-off-by: Alexander Chuprov <a.chuprov@yadro.com>
2024-07-29 17:43:07 +03:00
ec63f386a7 [#18] go.mod: Update version
Signed-off-by: Alexander Chuprov <a.chuprov@yadro.com>
2024-02-15 17:02:14 +03:00
7b767571bc [#16] noliteral: Fix nested functions
Signed-off-by: Alexander Chuprov <a.chuprov@yadro.com>
2024-02-13 19:45:34 +03:00
2c4e1d8b53 [#16] noliteral: Refactor
Signed-off-by: Alexander Chuprov <a.chuprov@yadro.com>
2024-02-13 19:45:34 +03:00
9 changed files with 111 additions and 57 deletions

View file

@ -11,7 +11,7 @@ jobs:
- name: Set up Go - name: Set up Go
uses: actions/setup-go@v3 uses: actions/setup-go@v3
with: with:
go-version: '1.20' go-version: '1.23'
cache: true cache: true
- name: Build lib - name: Build lib
run: make lib run: make lib
@ -25,11 +25,11 @@ jobs:
- name: Set up Go - name: Set up Go
uses: actions/setup-go@v3 uses: actions/setup-go@v3
with: with:
go-version: '1.20' go-version: '1.23'
cache: true cache: true
- name: golangci-lint - name: golangci-lint
uses: https://github.com/golangci/golangci-lint-action@v3 uses: actions/golangci-lint@v3
with: with:
version: latest version: latest
@ -44,7 +44,7 @@ jobs:
- name: Set up Go - name: Set up Go
uses: actions/setup-go@v3 uses: actions/setup-go@v3
with: with:
go-version: '1.20' go-version: '1.23'
cache: true cache: true
- name: Run tests - name: Run tests
@ -59,7 +59,7 @@ jobs:
- name: Set up Go - name: Set up Go
uses: actions/setup-go@v3 uses: actions/setup-go@v3
with: with:
go-version: '1.20' go-version: '1.23'
cache: true cache: true
- name: Install staticcheck - name: Install staticcheck

View file

@ -12,7 +12,8 @@ run:
# output configuration options # output configuration options
output: output:
# colored-line-number|line-number|json|tab|checkstyle|code-climate, default is "colored-line-number" # colored-line-number|line-number|json|tab|checkstyle|code-climate, default is "colored-line-number"
format: tab formats:
- format: tab
# all available settings of specific linters # all available settings of specific linters
linters-settings: linters-settings:
@ -46,7 +47,7 @@ linters:
- bidichk - bidichk
- durationcheck - durationcheck
- exhaustive - exhaustive
- exportloopref - copyloopvar
- gofmt - gofmt
- goimports - goimports
- misspell - misspell

3
CODEOWNERS Normal file
View file

@ -0,0 +1,3 @@
.* @TrueCloudLab/storage-core-committers @TrueCloudLab/storage-core-developers
.forgejo/.* @potyarkin
Makefile @potyarkin

View file

@ -6,7 +6,8 @@ test:
lib: lib:
@mkdir -pv $(OUT_DIR) @mkdir -pv $(OUT_DIR)
@go build -buildmode=plugin -o $(OUT_DIR)/external_linters.so $(PLUGIN_SOURCE) @go build -buildmode=plugin -trimpath \
-o $(OUT_DIR)/external_linters.so $(PLUGIN_SOURCE)
lint: lint:
@golangci-lint run @golangci-lint run

4
go.mod
View file

@ -1,8 +1,8 @@
module git.frostfs.info/TrueCloudLab/linters module git.frostfs.info/TrueCloudLab/linters
go 1.20 go 1.22.0
require ( require (
github.com/mitchellh/mapstructure v1.5.0 github.com/mitchellh/mapstructure v1.5.0
golang.org/x/tools v0.14.0 golang.org/x/tools v0.27.0
) )

8
go.sum
View file

@ -1,6 +1,6 @@
github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyuac5Z2hdY= github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyuac5Z2hdY=
github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo= github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo=
golang.org/x/tools v0.12.0 h1:YW6HUoUmYBpwSgyaGaZq1fHjrBjX1rlpZ54T6mu2kss= golang.org/x/tools v0.25.0 h1:oFU9pkj/iJgs+0DT+VMHrx+oBKs/LJMV+Uvg78sl+fE=
golang.org/x/tools v0.12.0/go.mod h1:Sc0INKfu04TlqNoRA1hgpFZbhYXHPr4V5DzpSBTPqQM= golang.org/x/tools v0.25.0/go.mod h1:/vtpO8WL1N9cQC3FN5zPqb//fRXskFHbLKk4OW1Q7rg=
golang.org/x/tools v0.14.0 h1:jvNa2pY0M4r62jkRQ6RwEZZyPcymeL9XZMLBbV7U2nc= golang.org/x/tools v0.27.0 h1:qEKojBykQkQ4EynWy4S8Weg69NumxKdn40Fce3uc/8o=
golang.org/x/tools v0.14.0/go.mod h1:uYBEerGOWcJyEORxN+Ek8+TT266gXkNlHdJBwexUsBg= golang.org/x/tools v0.27.0/go.mod h1:sUi0ZgbwW9ZPAq26Ekut+weQPR5eIM6GQLQ1Yjm1H0Q=

View file

@ -2,6 +2,7 @@ package noliteral
import ( import (
"go/ast" "go/ast"
"go/token"
astutils "git.frostfs.info/TrueCloudLab/linters/pkg/ast-utils" astutils "git.frostfs.info/TrueCloudLab/linters/pkg/ast-utils"
"github.com/mitchellh/mapstructure" "github.com/mitchellh/mapstructure"
@ -51,25 +52,46 @@ func run(pass *analysis.Pass) (interface{}, error) {
} }
for _, file := range pass.Files { for _, file := range pass.Files {
ast.Inspect(file, func(n ast.Node) bool { ast.Inspect(file, func(n ast.Node) bool {
expr, ok := n.(*ast.CallExpr) switch v := n.(type) {
if !ok { // a := zap.Error()
case *ast.AssignStmt:
if _, ok := v.Rhs[0].(*ast.CallExpr); ok {
return false
}
// a := &log.Error()
case *ast.UnaryExpr:
if _, ok := v.X.(*ast.CallExpr); ok && v.Op == token.AND {
return false
}
// log.Error()
case *ast.CallExpr:
if expr, ok := n.(*ast.CallExpr); ok {
return analyzeCallExpr(pass, expr, file)
}
}
return true return true
})
} }
return nil, nil
}
func analyzeCallExpr(pass *analysis.Pass, expr *ast.CallExpr, file *ast.File) bool {
isLog, _ := astutils.IsTargetMethod(expr.Fun, Config.TargetMethods) isLog, _ := astutils.IsTargetMethod(expr.Fun, Config.TargetMethods)
if !isLog || len(expr.Args) == 0 || astutils.HasNoLintComment(pass, expr.Pos()) { if !isLog || len(expr.Args) == 0 || astutils.HasNoLintComment(pass, expr.Pos()) {
return true return false
} }
if !astutils.IsStringValue(expr.Args[0]) { if !astutils.IsStringValue(expr.Args[0]) {
alias, _ := astutils.GetAliasByPkgName(file, Config.ConstantsPackage) alias, _ := astutils.GetAliasByPkgName(file, Config.ConstantsPackage)
if Config.ConstantsPackage == "" || astutils.GetPackageName(expr.Args[0]) == alias || astutils.GetPackageName(expr.Args[0]) == "" { if Config.ConstantsPackage == "" || astutils.GetPackageName(expr.Args[0]) == alias || astutils.GetPackageName(expr.Args[0]) == "" {
return true return false
} }
for _, pkgName := range Config.DisablePackages { for _, pkgName := range Config.DisablePackages {
if pkgName == astutils.GetPackageName(expr.Args[0]) { if pkgName == astutils.GetPackageName(expr.Args[0]) {
return true return false
} }
} }
@ -80,7 +102,7 @@ func run(pass *analysis.Pass) (interface{}, error) {
Message: "Wrong package for constants", Message: "Wrong package for constants",
SuggestedFixes: nil, SuggestedFixes: nil,
}) })
return true return false
} }
pass.Report(analysis.Diagnostic{ pass.Report(analysis.Diagnostic{
@ -92,8 +114,4 @@ func run(pass *analysis.Pass) (interface{}, error) {
}) })
return false return false
})
}
return nil, nil
} }

View file

@ -4,25 +4,46 @@ package logs //declaration package
import ( import (
"fmt" "fmt"
tochno_ne_const_dly_log "git.frostfs.info/TrueCloudLab/frostfs-node/internal/logs"// The alias of the package with constants differs from the one used tochno_ne_dly_const_log "git.frostfs.info/TrueCloudLab/frostfs-node/internal/logs"// The alias of the package with constants differs from the one used
) )
func (c *cfg) info_ok() { func (c *cfg) info_ok() {
c.log.Info(tochno_ne_const_dly_log.MSG) c.log.Info(tochno_ne_dly_const_log.MSG)
} }
func (c *cfg) debug_ok() { func (c *cfg) debug_ok() {
c.log.Debug(tochno_ne_const_dly_log.MSG) c.log.Debug(tochno_ne_dly_const_log.MSG)
} }
func (c *cfg) error_ok() { func (c *cfg) error_ok() {
c.log.Error(tochno_ne_const_dly_log.MSG) c.log.Error(tochno_ne_dly_const_log.MSG)
} }
func (c *cfg) custom_ok_const() { func (c *cfg) custom_ok_const() {
c.log.Abyr(tochno_ne_const_dly_log.MSG) c.log.Abyr(tochno_ne_dly_const_log.MSG)
} }
// issue: https://git.frostfs.info/TrueCloudLab/linters/issues/16.
// Check that the check does not trigger a false positive for "zap.Error(invalid_pkg.Error)" passed as an argument.
func (c *cfg) debug1_ok() {
c.log.Debug(tochno_ne_dly_const_log.MSG, zap.Stringer("cid", bkt.CID), zap.String("oid", obj.VersionID), zap.Error(invalid_pkg.Error))
}
func (c *cfg) error_ok() {
field:=zap.Error(invalid_pkg.Error)
}
func (c *cfg) error_ok() {
callBack:=&zap.Error(invalid_pkg.Error)
}
func (c *cfg) error_ok() {
field=zap.Error(invalid_pkg.Error)
}
func (c *cfg) error_ok() {
callBack=&zap.Error(invalid_pkg.Error)
}
type Logger interface { type Logger interface {
Debug(msg string) Debug(msg string)

View file

@ -15,6 +15,16 @@ func (c *cfg) debug_ok() {
c.log.Debug(logs.MSG) //acceptable c.log.Debug(logs.MSG) //acceptable
} }
// issue: https://git.frostfs.info/TrueCloudLab/linters/issues/16.
// Check that the check does not trigger a false positive for "zap.Error("literal")" passed as an argument.
func (c *cfg) debug1_ok() {
c.log.Debug(logs.MSG, zap.Stringer("cid", bkt.CID), zap.String("oid", obj.VersionID), zap.Error("literal"))
}
func (c *cfg) debug1_ok() {
f(zap.Error("logs.MSG"))
}
func (c *cfg) error_ok() { func (c *cfg) error_ok() {
c.log.Error(logs.MSG) //acceptable c.log.Error(logs.MSG) //acceptable
} }