forked from TrueCloudLab/linters
[#16] noliteral: Refactor
Signed-off-by: Alexander Chuprov <a.chuprov@yadro.com>
This commit is contained in:
parent
1b23dd3733
commit
2c4e1d8b53
2 changed files with 51 additions and 44 deletions
|
@ -51,12 +51,23 @@ 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 {
|
||||
switch n.(type) {
|
||||
// log.Error()
|
||||
case *ast.CallExpr:
|
||||
if expr, ok := n.(*ast.CallExpr); ok {
|
||||
return analyzeCallExpr(pass, expr, file)
|
||||
}
|
||||
}
|
||||
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 true
|
||||
}
|
||||
|
@ -92,8 +103,4 @@ func run(pass *analysis.Pass) (interface{}, error) {
|
|||
})
|
||||
|
||||
return false
|
||||
})
|
||||
}
|
||||
|
||||
return nil, nil
|
||||
}
|
||||
|
|
|
@ -4,23 +4,23 @@ 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)
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue