Skip to content

Commit

Permalink
Reenable multiple linters (#67)
Browse files Browse the repository at this point in the history
* Update `golangci` file accordingly and reenable multiple linters

Signed-off-by: Arrobo, Gabriel <[email protected]>

* Enable `gofmt` linter

Signed-off-by: Arrobo, Gabriel <[email protected]>

* Enable `gci` linter

Signed-off-by: Arrobo, Gabriel <[email protected]>

* Enable `gofumpt` linter

Signed-off-by: Arrobo, Gabriel <[email protected]>

* Enable `whitespace` linter

Signed-off-by: Arrobo, Gabriel <[email protected]>

* Enable `whitespace` and `unconvert` linters

Signed-off-by: Arrobo, Gabriel <[email protected]>

* Enable `predeclared` linter

Signed-off-by: Arrobo, Gabriel <[email protected]>

* Update `.gitignore` file

Signed-off-by: Arrobo, Gabriel <[email protected]>

* Remove unused file

Signed-off-by: Arrobo, Gabriel <[email protected]>

* Address linter issues in sub-module

Signed-off-by: Arrobo, Gabriel <[email protected]>

---------

Signed-off-by: Arrobo, Gabriel <[email protected]>
  • Loading branch information
gab-arrobo authored Nov 7, 2024
1 parent 255d8c7 commit 5060448
Show file tree
Hide file tree
Showing 23 changed files with 222 additions and 258 deletions.
20 changes: 0 additions & 20 deletions .fossa.yml

This file was deleted.

8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# SPDX-FileCopyrightText: 2024 Intel Corporation
# Copyright 2019 Communication Service/Software Laboratory, National Chiao Tung University (free5gc.org)
#
# SPDX-License-Identifier: Apache-2.0
Expand All @@ -17,3 +18,10 @@ cscope.*
# mac
.DS_Store

# debug
*.log
*.pcap
vendor*

# coverage
./coverage
106 changes: 45 additions & 61 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# SPDX-FileCopyrightText: 2024 Intel Corporation
# SPDX-FileCopyrightText: 2021 Open Networking Foundation <[email protected]>
# Copyright 2019 free5GC.org
#
Expand Down Expand Up @@ -28,19 +29,6 @@ run:
# default is true. Enables skipping of directories:
# vendor$, third_party$, testdata$, examples$, Godeps$, builtin$
skip-dirs-use-default: true
# which files to skip: they will be analyzed, but issues from them
# won't be reported. Default value is empty list, but there is
# no need to include all autogenerated files, we confidently recognize
# autogenerated files. If it's not please let us know.
# "/" will be replaced by current OS file path separator to properly work
# on Windows.
skip-files:
- "api_.*\\.go$"
- "model_.*\\.go$"
- "routers.go"
- "client.go"
- "configuration.go"
- "nas.go"
# by default isn't set. If set we pass it to "go list -mod={option}". From "go help modules":
# If invoked with -mod=readonly, the go command is disallowed from the implicit
# automatic updating of go.mod described above. Instead, it fails when any changes
Expand All @@ -56,7 +44,7 @@ run:
# output configuration options
output:
# colored-line-number|line-number|json|tab|checkstyle|code-climate, default is "colored-line-number"
format: colored-line-number
formats: colored-line-number
# print lines of code with issue, default is true
print-issued-lines: true
# print linter name in the end of issue text, default is true
Expand Down Expand Up @@ -99,7 +87,7 @@ linters-settings:
# To check which checks are enabled run `GL_DEBUG=gocritic golangci-lint run`
# By default list of stable checks is used.
enabled-checks:
# - rangeValCopy
#- rangeValCopy
# Which checks should be disabled; can't be combined with 'enabled-checks'; default is empty
disabled-checks:
- regexpMust
Expand Down Expand Up @@ -139,29 +127,31 @@ linters-settings:
# minimal confidence for issues, default is 0.8
min-confidence: 0.8
gomnd:
settings:
mnd:
# the list of enabled checks, see https://github.com/tommy-muehle/go-mnd/#checks for description.
checks: argument,case,condition,operation,return,assign
# the list of enabled checks, see https://github.com/tommy-muehle/go-mnd/#checks for description.
checks:
- argument
- case
- condition
- operation
- return
- assign
gomodguard:
allowed:
modules: # List of allowed modules
# - gopkg.in/yaml.v2
# - gopkg.in/yaml.v2
domains: # List of allowed module domains
# - golang.org
# - golang.org
blocked:
modules: # List of blocked modules
# - github.com/uudashr/go-module: # Blocked module
# recommendations: # Recommended modules that should be used instead (Optional)
# - golang.org/x/mod
# reason: "`mod` is the official go.mod parser library." # Reason why the recommended module should be used (Optional)
# - github.com/uudashr/go-module: # Blocked module
# recommendations: # Recommended modules that should be used instead (Optional)
# - golang.org/x/mod
# reason: "`mod` is the official go.mod parser library." # Reason why the recommended module should be used (Optional)
versions: # List of blocked module version constraints
# - github.com/mitchellh/go-homedir: # Blocked module with version constraint
# version: "< 1.1.0" # Version constraint, see https://github.com/Masterminds/semver#basic-comparisons
# reason: "testing if blocked version constraint works." # Reason why the version constraint exists. (Optional)
# - github.com/mitchellh/go-homedir: # Blocked module with version constraint
# version: "< 1.1.0" # Version constraint, see https://github.com/Masterminds/semver#basic-comparisons
# reason: "testing if blocked version constraint works." # Reason why the version constraint exists. (Optional)
govet:
# report about shadowed variables
check-shadowing: true
# settings per analyzer
settings:
printf: # analyzer name, run `go tool vet help` to see all analyzers
Expand All @@ -170,12 +160,10 @@ linters-settings:
- (github.com/golangci/golangci-lint/pkg/logutils.Log).Warnf
- (github.com/golangci/golangci-lint/pkg/logutils.Log).Errorf
- (github.com/golangci/golangci-lint/pkg/logutils.Log).Fatalf
# enable or disable analyzers by name
enable:
- atomicalign
enable-all: false
# enable all analyzers
enable-all: true
disable:
- shadow
- fieldalignment
disable-all: false
depguard:
list-type: blacklist
Expand Down Expand Up @@ -209,8 +197,6 @@ linters-settings:
whitespace:
multi-if: false # Enforces newlines (or comments) after every multi-line if statement
multi-func: false # Enforces newlines (or comments) after every multi-line function signature
gci:
local-prefixes: "bitbucket.org"
misspell:
#locale: US
ignore-words:
Expand All @@ -234,38 +220,36 @@ linters-settings:
# Allow leading comments to be separated with empty liens
allow-separated-leading-comment: false
custom:
# Each custom linter should have a unique name.
# Each custom linter should have a unique name.

linters:
enable:
# - gofmt
- gofmt
# - govet
# - errcheck
# - staticcheck
# - unused
# - gosimple
# - ineffassign
# - typecheck
- unused
- gosimple
- ineffassign
- typecheck
# Additional
# - lll
# - godox
# - gomnd
# - goconst
- godox
# - mnd
- goconst
# - gocognit
# - maligned
# - nestif
# - gomodguard
# - nakedret
# - gci
# - misspell
# - gofumpt
# - whitespace
# - unconvert
# - predeclared
# - noctx
# - dogsled
- nakedret
- gci
- misspell
- gofumpt
- whitespace
- unconvert
- predeclared
- noctx
- dogsled
# - bodyclose
# - asciicheck
- asciicheck
# - stylecheck
# - unparam
# - wsl
Expand All @@ -280,7 +264,7 @@ issues:
exclude:
# Excluding configuration per-path, per-linter, per-text and per-source
exclude-rules:
# Exclude some linters from running on tests files.
# Exclude some linters from running on tests files.
# Independently from option `exclude` we use default exclude patterns,
# it can be disabled by this option. To list all
# excluded by default patterns execute `golangci-lint run --help`.
Expand All @@ -291,7 +275,7 @@ issues:
exclude-case-sensitive: false
# The list of ids of default excludes to include or disable. By default it's empty.
include:
#- EXC0002 # disable excluding of issues about comments from golint
#- EXC0002 # disable excluding of issues about comments from golint
# Maximum issues count per one linter. Set to 0 to disable. Default is 50.
#max-issues-per-linter: 0
# Maximum count of issues with the same text. Set to 0 to disable. Default is 3.
Expand Down Expand Up @@ -327,5 +311,5 @@ severity:
# Only affects out formats that support setting severity information.
rules:
- linters:
- gomnd
- gomnd
severity: ignore
12 changes: 7 additions & 5 deletions drsm/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ const (
)

type Options struct {
ResIdSize int32 //size in bits e.g. 32 bit, 24 bit.
ResIdSize int32 // size in bits e.g. 32 bit, 24 bit.
Mode DrsmMode
ResourceValidCb func(int32) bool // return if ID is in use or not used
IpPool map[string]string
Expand All @@ -52,10 +52,12 @@ type DrsmInterface interface {
func InitDRSM(sharedPoolName string, myid PodId, db DbInfo, opt *Options) (DrsmInterface, error) {
logger.DrsmLog.Debugln("client id:", myid)

d := &Drsm{sharedPoolName: sharedPoolName,
clientId: myid,
db: db,
mode: ResourceClient}
d := &Drsm{
sharedPoolName: sharedPoolName,
clientId: myid,
db: db,
mode: ResourceClient,
}

d.ConstuctDrsm(opt)

Expand Down
2 changes: 1 addition & 1 deletion drsm/chunk.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import (

func (c *chunk) GetOwner() *PodId {
return &c.Owner

}

func (d *Drsm) GetNewChunk() (*chunk, error) {
Expand Down Expand Up @@ -106,6 +105,7 @@ func getChunIdFromDocId(id string) int32 {
}
return 0
}

func isChunkDoc(id string) bool {
z := strings.Split(id, "-")
if len(z) == 2 && z[0] == "chunkid" {
Expand Down
2 changes: 1 addition & 1 deletion drsm/drsm.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ func (d *Drsm) ConstuctDrsm(opt *Options) {
d.globalChunkTblMutex = sync.Mutex{}
d.initIpam(opt)

//connect to DB
// connect to DB
d.mongo, _ = MongoDBLibrary.NewMongoClient(d.db.Url, d.db.Name)
logger.DrsmLog.Debugln("mongoClient is created", d.db.Name)

Expand Down
2 changes: 1 addition & 1 deletion drsm/scan.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func (c *chunk) scanChunk(d *Drsm) {
return
}
}
//no one is writing on stopScan for now. We will use it eventually
// no one is writing on stopScan for now. We will use it eventually
case <-c.stopScan:
logger.DrsmLog.Debugf("received Stop Scan. Closing scan for %v", c.Id)
return
Expand Down
18 changes: 8 additions & 10 deletions drsm/updates.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"time"

"github.com/omec-project/util/logger"

"go.mongodb.org/mongo-driver/bson"
"go.mongodb.org/mongo-driver/mongo"
)
Expand Down Expand Up @@ -99,15 +98,14 @@ func (d *Drsm) handleDbUpdates() {
pipeline := mongo.Pipeline{}

for {
//create stream to monitor actions on the collection
// create stream to monitor actions on the collection
updateStream, err := collection.Watch(context.TODO(), pipeline)

if err != nil {
time.Sleep(5000 * time.Millisecond)
continue
}
routineCtx, _ := context.WithCancel(context.Background())
//run routine to get messages from stream
// run routine to get messages from stream
iterateChangeStream(d, routineCtx, updateStream)
}
}
Expand All @@ -131,26 +129,26 @@ func iterateChangeStream(d *Drsm, routineCtx context.Context, stream *mongo.Chan
var s streamDoc
bsonBytes, _ := bson.Marshal(data)
bson.Unmarshal(bsonBytes, &s)
//logger.DrsmLog.Debugf("iterate stream : ", data)
//logger.DrsmLog.Debugf("\ndecoded stream bson %+v \n", s)
// logger.DrsmLog.Debugf("iterate stream : ", data)
// logger.DrsmLog.Debugf("\ndecoded stream bson %+v \n", s)
switch s.OpType {
case "insert":
full := &s.Full
switch full.Type {
case "keepalive":
//logger.DrsmLog.Debugf("insert keepalive document")
// logger.DrsmLog.Debugf("insert keepalive document")
pod, found := d.podMap[full.PodId]
if !found {
d.addPod(full)
} else {
logger.DrsmLog.Debugln("keepalive insert document: found existing podId", pod)
}
case "chunk":
//logger.DrsmLog.Debugln("insert chunk document")
// logger.DrsmLog.Debugln("insert chunk document")
d.addChunk(full)
}
case "update":
//logger.DrsmLog.Debugln("update operations")
// logger.DrsmLog.Debugln("update operations")
if isChunkDoc(s.DId.Id) {
// update on chunkId..
// looks like chunk owner getting change
Expand Down Expand Up @@ -196,7 +194,7 @@ func (d *Drsm) punchLiveness() {
}

for range ticker.C {
//logger.DrsmLog.Debugln("update keepalive time")
// logger.DrsmLog.Debugln("update keepalive time")
filter := bson.M{"_id": d.clientId.PodName}

timein := time.Now().Local().Add(20 * time.Second)
Expand Down
6 changes: 3 additions & 3 deletions fsm/fsm.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,9 @@ func NewFSM(transitions Transitions, callbacks Callbacks) (*FSM, error) {

// SendEvent triggers a callback with an event, and do transition after callback if need
// There are 3 types of callback:
// - on exit callback: call when fsm leave one state, with ExitEvent event
// - event callback: call when user trigger a user-defined event
// - on entry callback: call when fsm enter one state, with EntryEvent event
// - on exit callback: call when fsm leave one state, with ExitEvent event
// - event callback: call when user trigger a user-defined event
// - on entry callback: call when fsm enter one state, with EntryEvent event
func (fsm *FSM) SendEvent(state *State, event EventType, args ArgsType) error {
key := eventKey{
From: state.Current(),
Expand Down
2 changes: 1 addition & 1 deletion http2_util/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func NewServer(bindAddr string, preMasterSecretLogPath string, handler http.Hand
}

if preMasterSecretLogPath != "" {
preMasterSecretFile, err := os.OpenFile(preMasterSecretLogPath, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0600)
preMasterSecretFile, err := os.OpenFile(preMasterSecretLogPath, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0o600)
if err != nil {
return server, fmt.Errorf("create pre-master-secret log [%s] fail: %s", preMasterSecretLogPath, err)
}
Expand Down
Loading

0 comments on commit 5060448

Please sign in to comment.