-
Hello! I use go 1.22.2, golangci-lint has version v1.54.2. package main
import (
"fmt"
)
func main() {
fmt.Println("Hello, let's use some functions")
fmt.Println("========================")
fmt.Println("1:", UsedFunc1())
}
func UsedFunc1() string {
return "I'm used func 1."
}
func UnusedFunc1() string {
return "I'm UNused func 1."
}
func unusedFunc2() string {
return "I'm UNused func 2."
} And this is the golangci.yml: run:
issues-exit-code: 1
output:
format: colored-line-number
print-issued-lines: true
print-linter-name: true
linters:
disable-all: true
enable:
- unused
linters-settings:
unused:
# Mark all struct fields that have been written to as used.
# Default: true
field-writes-are-uses: false
# Treat IncDec statement (e.g. `i++` or `i--`) as both read and write operation instead of just write.
# Default: false
post-statements-are-reads: true
# Mark all exported identifiers as used.
# Default: true
exported-is-used: false
# Mark all exported fields as used.
# default: true
exported-fields-are-used: false
# Mark all function parameters as used.
# default: true
parameters-are-used: false
# Mark all local variables as used.
# default: true
local-variables-are-used: false
# Mark all identifiers inside generated files as used.
# Default: true
generated-is-used: false When I run main.go:27:6: func `unusedFunc2` is unused (unused)
func unusedFunc2() string { But when I use main.go:23:6: unreachable func: UnusedFunc1
main.go:27:6: unreachable func: unusedFunc2 Can you please tell me how I can achieve the same result with the "unused" linter as with the deadcode? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
What happen when you use golangci-lint 1.59.0 ? 1.54.0 is old |
Beta Was this translation helpful? Give feedback.
-
I don't think it's possible because reporting unused for exported functions is asking for false positives. If they're public you don't know who uses them. I get it makes sense in your own private code base but form a static analysis perspective an exported function can be used externally and static analysis is done on package level. Some discussions around the different alternatives and when/why |
Beta Was this translation helpful? Give feedback.
I think it's not the same
deadcode
, I think it's the tool by the Go team.