generated from TrueCloudLab/basic
noliteral: Add ignoring of nested functions #17
No reviewers
Labels
No labels
Infrastructure
blocked
bug
config
discussion
documentation
duplicate
enhancement
go
help wanted
internal
invalid
kludge
observability
perfomance
question
refactoring
wontfix
No milestone
No project
No assignees
5 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference: TrueCloudLab/linters#17
Loading…
Reference in a new issue
No description provided.
Delete branch "achuprov/linters:bugfix/noliteral_ignoring_nested_functions"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Add ignoring of nested functions.
Example: ignore
zap.Error(invalid_pkg.Error)
inClose #16
Signed-off-by: Alexander Chuprov a.chuprov@yadro.com
dea5a71c18
toe1322ab51f
@ -100,0 +91,4 @@
*endFunctionCall = expr.End()
if !astutils.IsStringValue(expr.Args[0]) {
alias, _ := astutils.GetAliasByPkgName(file, Config.ConstantsPackage)
I still do not see any check for non-package usage like
zap.Error(obj.Error)
Could this solve the problem? :)
We cannot rely on
valExp.Type
because it is only available when explicitly declared asvar name Type
. Example:dba7fe3257
@ -58,3 +59,2 @@
isLog, _ := astutils.IsTargetMethod(expr.Fun, Config.TargetMethods)
if !isLog || len(expr.Args) == 0 || astutils.HasNoLintComment(pass, expr.Pos()) {
if n.Pos() < endPosAssignment {
Using
Pos()
checks feels wrong: we are traversing ast, why do we need to compare positions of bytes in text?I looks the only thing that needed to be changed is
IsTargetMethod
:sel.X
is the part before the dot and in our case it should be some object, not the package. Or is it not enough?You are right. We can choose not to use
Pos()
.We can't exclude all functions that are not part of an object. This is because there are packages with package-level logging, like https://github.com/sirupsen/logrus. My solution has a drawback: we can't distinguish between
&zap.Error(...)
and&log.Error(...)
, but this does not seem to be a common issue.e1322ab51f
to957216b893
957216b893
to7b767571bc