generated from TrueCloudLab/basic
const-check #4
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
3 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference: TrueCloudLab/linters#4
Loading…
Reference in a new issue
No description provided.
Delete branch "achuprov/linters:const-check"
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 check for source of constants
const-checkto WIP: const-check2be7deb992
tof44444299c
f44444299c
tob51088a244
b51088a244
tode6df5678a
WIP: const-checkto const-check@ -25,0 +23,4 @@
original-url: git.frostfs.info/TrueCloudLab/linters.git
settings:
target-methods : ["reportFlushError", "reportError"] #optional. Enabled by default "Debug", "Info", "Warn", "Error"
constants-repository: "git.frostfs.info/rep/logs" #if not set, then the check is disabled
Isn't it a
package
, notrepository
?@ -44,6 +47,7 @@ Add to .golangci.yml
path: <Path to the directory with libraries>
original-url: git.frostfs.info/TrueCloudLab/linters
?
@ -39,1 +46,3 @@
if len(expr.Args) == 0 || !isStringValue(expr.Args[0]) {
if !isStringValue(expr.Args[0]) {
alias, _ := getAliasByRepName(file, Config.ConstantsRepository)
if Config.ConstantsRepository == "" || isConstLogsField(expr.Args[0], alias) || getPackageName(expr.Args[0]) == "" {
It seems we use
isConstLogsFIeld
only here, and we still dogetPackageName
inside and on this line. What about removingisConstLogsField
and usingreal == alias || real == ""
?@ -40,0 +53,4 @@
Pos: expr.Pos(),
End: expr.End(),
Category: LinterName,
Message: "Source of constants cannot be resolved",
What kind of resolving problems can we have here? Isn't it just
wrong package for constants
?@ -85,0 +121,4 @@
return alias, nil
}
func getImportSpecs(file *ast.File) []*ast.ImportSpec {
What about
file.Imports
?*ast.File.Imports is a slice, it can't be used as a key. Thus, we would have to add a second argument solely to use it as a key. Should I do it this way?
No, I mean isn't is the case that
file.Imports == getImportSpecs(file)
?fixed
@ -85,0 +151,4 @@
return ""
}
split := strings.Split(importName, "/")
Have you checked what happens when the directory is
pkg/xxx
and there ispackage yyy
file inside?I tested it in the case with aliases. If I understood correctly, this is the same situation
I mean https://go.dev/ref/spec#Import_declarations
It seem you use directory name instead here.
de6df5678a
to6cff064b02
@ -85,0 +154,4 @@
split := strings.Split(importName, "/")
alias := split[len(split)-1]
if spec.Name != nil {
Looks like this condition can be checked before replace and split.
fixed
6cff064b02
to6e43f24a57
6e43f24a57
tofddd52a332
fddd52a332
to0c3e5e8d68
0c3e5e8d68
to420dd98c24
TrueCloudLab/frostfs-node#526 (comment)
6a00a875e4
to1c1b1596a8
@ -62,3 +62,3 @@
- contextcheck
disable-all: true
fast: false
fast: false
What has changed here?
@ -39,1 +47,3 @@
if len(expr.Args) == 0 || !isStringValue(expr.Args[0]) {
if !isStringValue(expr.Args[0]) {
alias, _ := getAliasByPkgName(file, Config.ConstantsPackage)
if Config.ConstantsPackage == "" || getPackageName(expr.Args[0]) == alias || getPackageName(expr.Args[0]) == "" {
It could be better to cache it, but ok.
1c1b1596a8
tobf126a4841
bf126a4841
to75a7ce14d6
75a7ce14d6
to7ceda9eddf