Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Adds staticcheck and unused lint check #41

Merged
merged 1 commit into from
Jan 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -221,8 +221,8 @@ linters:
- gofmt
- govet
# - errcheck
# - staticcheck
# - unused
- staticcheck
- unused
# - gosimple
- ineffassign
- typecheck
Expand Down
3 changes: 1 addition & 2 deletions factory/factory.go
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI, I know io/ioutil is deprecated. So, os should be used instead, but for some reason I do not see that this change is needed for the lint check to pass when staticcheck and unused are enabled

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is strange, here's the golang ci output when I enable those checks and prior to making the changes:

guillaume@potiron:~/code/udr$ golangci-lint run -v --config ./.golangci.yml
INFO [config_reader] Used config file .golangci.yml 
INFO [lintersdb] Active 14 linters: [asciicheck bodyclose dogsled godox gofmt govet ineffassign misspell nakedret noctx predeclared staticcheck unconvert unused] 
INFO [loader] Go packages loading at mode 575 (types_sizes|deps|files|imports|name|compiled_files|exports_file) took 142.052844ms 
INFO [runner/filename_unadjuster] Pre-built 0 adjustments in 3.366162ms 
INFO [linters_context/goanalysis] analyzers took 178.55217ms with top 10 stages: buildir: 102.73302ms, buildssa: 55.782148ms, gofmt: 1.216444ms, nilness: 1.179526ms, fact_purity: 1.0634ms, misspell: 939.943µs, SA5012: 916.323µs, fact_deprecated: 884.799µs, printf: 858.124µs, typedness: 850.968µs 
INFO [runner] Processors filtering stat (out/in): max_same_issues: 4/4, path_prettifier: 4/4, diff: 4/4, skip_dirs: 4/4, identifier_marker: 4/4, exclude: 4/4, uniq_by_line: 4/4, max_per_file_from_linter: 4/4, severity-rules: 4/4, filename_unadjuster: 4/4, skip_files: 4/4, sort_results: 4/4, autogenerated_exclude: 4/4, path_prefixer: 4/4, nolint: 4/4, max_from_linter: 4/4, source_code: 4/4, path_shortener: 4/4, fixer: 4/4, cgo: 4/4, exclude-rules: 4/4 
INFO [runner] processing took 676.194µs with stages: nolint: 489.072µs, identifier_marker: 57.408µs, autogenerated_exclude: 38.8µs, source_code: 33.463µs, path_prettifier: 27.734µs, skip_dirs: 11.985µs, skip_files: 6.97µs, cgo: 2.341µs, max_same_issues: 1.969µs, uniq_by_line: 1.312µs, path_shortener: 1.078µs, max_from_linter: 902ns, severity-rules: 753ns, filename_unadjuster: 717ns, max_per_file_from_linter: 629ns, fixer: 263ns, exclude-rules: 236ns, diff: 190ns, exclude: 174ns, sort_results: 113ns, path_prefixer: 85ns 
INFO [runner] linters took 250.163303ms with stages: goanalysis_metalinter: 249.434163ms 
factory/factory.go:15:2: SA1019: "io/ioutil" has been deprecated since Go 1.19: As of Go 1.16, the same functionality is now provided by package [io] or package [os], and those implementations should be preferred in new code. See the specific function documentation for details. (staticcheck)
        "io/ioutil"
        ^
service/init.go:46:3: field `heartBeatTimer` is unused (unused)
                heartBeatTimer string
                ^
service/init.go:368:4: SA4006: this value of `err` is never used (staticcheck)
                        nfProfile, err = udr.BuildAndSendRegisterNFInstance()
                        ^
service/init.go:372:3: SA4006: this value of `err` is never used (staticcheck)
                nfProfile, err = udr.BuildAndSendRegisterNFInstance()
                ^
INFO File cache stats: 5 entries of total size 24.8KiB 
INFO Memory: 5 samples, avg is 77.9MB, max is 161.3MB 
INFO Execution took 398.976934ms  

Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ package factory

import (
"fmt"
"io/ioutil"
"os"

"gopkg.in/yaml.v2"
Expand Down Expand Up @@ -43,7 +42,7 @@ func init() {

// TODO: Support configuration update from REST api
func InitConfigFactory(f string) error {
if content, err := ioutil.ReadFile(f); err != nil {
if content, err := os.ReadFile(f); err != nil {
return err
} else {
UdrConfig = Config{}
Expand Down
9 changes: 7 additions & 2 deletions service/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,7 @@ type UDR struct{}
type (
// Config information.
Config struct {
udrcfg string
heartBeatTimer string
udrcfg string
}
)

Expand Down Expand Up @@ -366,10 +365,16 @@ func (udr *UDR) UpdateNF() {
problemDetails.Status == 404 || problemDetails.Status == 400 {
//register with NRF full profile
nfProfile, err = udr.BuildAndSendRegisterNFInstance()
if err != nil {
initLog.Errorf("UDR register to NRF Error[%s]", err.Error())
}
}
} else if err != nil {
initLog.Errorf("UDR update to NRF Error[%s]", err.Error())
nfProfile, err = udr.BuildAndSendRegisterNFInstance()
if err != nil {
initLog.Errorf("UDR register to NRF Error[%s]", err.Error())
}
}

if nfProfile.HeartBeatTimer != 0 {
Expand Down