forked from TrueCloudLab/linters
Compare commits
11 commits
docs/licen
...
master
Author | SHA1 | Date | |
---|---|---|---|
0db97985fe | |||
177c8a8e7f | |||
628ee422df | |||
007db8eff4 | |||
7fbd18be41 | |||
a0d01aad6a | |||
73c7ec4274 | |||
9ea0089703 | |||
ec63f386a7 | |||
7b767571bc | |||
2c4e1d8b53 |
9 changed files with 111 additions and 57 deletions
|
@ -11,7 +11,7 @@ jobs:
|
|||
- name: Set up Go
|
||||
uses: actions/setup-go@v3
|
||||
with:
|
||||
go-version: '1.20'
|
||||
go-version: '1.23'
|
||||
cache: true
|
||||
- name: Build lib
|
||||
run: make lib
|
||||
|
@ -25,11 +25,11 @@ jobs:
|
|||
- name: Set up Go
|
||||
uses: actions/setup-go@v3
|
||||
with:
|
||||
go-version: '1.20'
|
||||
go-version: '1.23'
|
||||
cache: true
|
||||
|
||||
- name: golangci-lint
|
||||
uses: https://github.com/golangci/golangci-lint-action@v3
|
||||
uses: actions/golangci-lint@v3
|
||||
with:
|
||||
version: latest
|
||||
|
||||
|
@ -44,7 +44,7 @@ jobs:
|
|||
- name: Set up Go
|
||||
uses: actions/setup-go@v3
|
||||
with:
|
||||
go-version: '1.20'
|
||||
go-version: '1.23'
|
||||
cache: true
|
||||
|
||||
- name: Run tests
|
||||
|
@ -59,7 +59,7 @@ jobs:
|
|||
- name: Set up Go
|
||||
uses: actions/setup-go@v3
|
||||
with:
|
||||
go-version: '1.20'
|
||||
go-version: '1.23'
|
||||
cache: true
|
||||
|
||||
- name: Install staticcheck
|
||||
|
|
|
@ -12,7 +12,8 @@ run:
|
|||
# output configuration options
|
||||
output:
|
||||
# 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
|
||||
linters-settings:
|
||||
|
@ -46,7 +47,7 @@ linters:
|
|||
- bidichk
|
||||
- durationcheck
|
||||
- exhaustive
|
||||
- exportloopref
|
||||
- copyloopvar
|
||||
- gofmt
|
||||
- goimports
|
||||
- misspell
|
||||
|
|
3
CODEOWNERS
Normal file
3
CODEOWNERS
Normal file
|
@ -0,0 +1,3 @@
|
|||
.* @TrueCloudLab/storage-core-committers @TrueCloudLab/storage-core-developers
|
||||
.forgejo/.* @potyarkin
|
||||
Makefile @potyarkin
|
3
Makefile
3
Makefile
|
@ -6,7 +6,8 @@ test:
|
|||
|
||||
lib:
|
||||
@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:
|
||||
@golangci-lint run
|
||||
|
|
4
go.mod
4
go.mod
|
@ -1,8 +1,8 @@
|
|||
module git.frostfs.info/TrueCloudLab/linters
|
||||
|
||||
go 1.20
|
||||
go 1.22.0
|
||||
|
||||
require (
|
||||
github.com/mitchellh/mapstructure v1.5.0
|
||||
golang.org/x/tools v0.14.0
|
||||
golang.org/x/tools v0.27.0
|
||||
)
|
||||
|
|
8
go.sum
8
go.sum
|
@ -1,6 +1,6 @@
|
|||
github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyuac5Z2hdY=
|
||||
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.12.0/go.mod h1:Sc0INKfu04TlqNoRA1hgpFZbhYXHPr4V5DzpSBTPqQM=
|
||||
golang.org/x/tools v0.14.0 h1:jvNa2pY0M4r62jkRQ6RwEZZyPcymeL9XZMLBbV7U2nc=
|
||||
golang.org/x/tools v0.14.0/go.mod h1:uYBEerGOWcJyEORxN+Ek8+TT266gXkNlHdJBwexUsBg=
|
||||
golang.org/x/tools v0.25.0 h1:oFU9pkj/iJgs+0DT+VMHrx+oBKs/LJMV+Uvg78sl+fE=
|
||||
golang.org/x/tools v0.25.0/go.mod h1:/vtpO8WL1N9cQC3FN5zPqb//fRXskFHbLKk4OW1Q7rg=
|
||||
golang.org/x/tools v0.27.0 h1:qEKojBykQkQ4EynWy4S8Weg69NumxKdn40Fce3uc/8o=
|
||||
golang.org/x/tools v0.27.0/go.mod h1:sUi0ZgbwW9ZPAq26Ekut+weQPR5eIM6GQLQ1Yjm1H0Q=
|
||||
|
|
|
@ -2,6 +2,7 @@ package noliteral
|
|||
|
||||
import (
|
||||
"go/ast"
|
||||
"go/token"
|
||||
|
||||
astutils "git.frostfs.info/TrueCloudLab/linters/pkg/ast-utils"
|
||||
"github.com/mitchellh/mapstructure"
|
||||
|
@ -51,49 +52,66 @@ func run(pass *analysis.Pass) (interface{}, error) {
|
|||
}
|
||||
for _, file := range pass.Files {
|
||||
ast.Inspect(file, func(n ast.Node) bool {
|
||||
expr, ok := n.(*ast.CallExpr)
|
||||
if !ok {
|
||||
return true
|
||||
}
|
||||
|
||||
isLog, _ := astutils.IsTargetMethod(expr.Fun, Config.TargetMethods)
|
||||
if !isLog || len(expr.Args) == 0 || astutils.HasNoLintComment(pass, expr.Pos()) {
|
||||
return true
|
||||
}
|
||||
|
||||
if !astutils.IsStringValue(expr.Args[0]) {
|
||||
alias, _ := astutils.GetAliasByPkgName(file, Config.ConstantsPackage)
|
||||
if Config.ConstantsPackage == "" || astutils.GetPackageName(expr.Args[0]) == alias || astutils.GetPackageName(expr.Args[0]) == "" {
|
||||
return true
|
||||
switch v := n.(type) {
|
||||
// a := zap.Error()
|
||||
case *ast.AssignStmt:
|
||||
if _, ok := v.Rhs[0].(*ast.CallExpr); ok {
|
||||
return false
|
||||
}
|
||||
|
||||
for _, pkgName := range Config.DisablePackages {
|
||||
if pkgName == astutils.GetPackageName(expr.Args[0]) {
|
||||
return true
|
||||
}
|
||||
// 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)
|
||||
}
|
||||
|
||||
pass.Report(analysis.Diagnostic{
|
||||
Pos: expr.Pos(),
|
||||
End: expr.End(),
|
||||
Category: LinterName,
|
||||
Message: "Wrong package for constants",
|
||||
SuggestedFixes: nil,
|
||||
})
|
||||
return true
|
||||
}
|
||||
|
||||
pass.Report(analysis.Diagnostic{
|
||||
Pos: expr.Pos(),
|
||||
End: expr.End(),
|
||||
Category: LinterName,
|
||||
Message: "Literals are not allowed in the body of the logger",
|
||||
SuggestedFixes: nil,
|
||||
})
|
||||
|
||||
return false
|
||||
return true
|
||||
})
|
||||
}
|
||||
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func analyzeCallExpr(pass *analysis.Pass, expr *ast.CallExpr, file *ast.File) bool {
|
||||
isLog, _ := astutils.IsTargetMethod(expr.Fun, Config.TargetMethods)
|
||||
|
||||
if !isLog || len(expr.Args) == 0 || astutils.HasNoLintComment(pass, expr.Pos()) {
|
||||
return false
|
||||
}
|
||||
|
||||
if !astutils.IsStringValue(expr.Args[0]) {
|
||||
alias, _ := astutils.GetAliasByPkgName(file, Config.ConstantsPackage)
|
||||
if Config.ConstantsPackage == "" || astutils.GetPackageName(expr.Args[0]) == alias || astutils.GetPackageName(expr.Args[0]) == "" {
|
||||
return false
|
||||
}
|
||||
|
||||
for _, pkgName := range Config.DisablePackages {
|
||||
if pkgName == astutils.GetPackageName(expr.Args[0]) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
pass.Report(analysis.Diagnostic{
|
||||
Pos: expr.Pos(),
|
||||
End: expr.End(),
|
||||
Category: LinterName,
|
||||
Message: "Wrong package for constants",
|
||||
SuggestedFixes: nil,
|
||||
})
|
||||
return false
|
||||
}
|
||||
|
||||
pass.Report(analysis.Diagnostic{
|
||||
Pos: expr.Pos(),
|
||||
End: expr.End(),
|
||||
Category: LinterName,
|
||||
Message: "Literals are not allowed in the body of the logger",
|
||||
SuggestedFixes: nil,
|
||||
})
|
||||
|
||||
return false
|
||||
}
|
||||
|
|
|
@ -4,25 +4,46 @@ package logs //declaration package
|
|||
|
||||
import (
|
||||
"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() {
|
||||
c.log.Info(tochno_ne_const_dly_log.MSG)
|
||||
c.log.Info(tochno_ne_dly_const_log.MSG)
|
||||
}
|
||||
|
||||
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() {
|
||||
c.log.Error(tochno_ne_const_dly_log.MSG)
|
||||
c.log.Error(tochno_ne_dly_const_log.MSG)
|
||||
}
|
||||
|
||||
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 {
|
||||
Debug(msg string)
|
||||
|
|
|
@ -15,6 +15,16 @@ func (c *cfg) debug_ok() {
|
|||
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() {
|
||||
c.log.Error(logs.MSG) //acceptable
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue