Skip to content

Commit

Permalink
Bump up golangci-lint and fix lint errors
Browse files Browse the repository at this point in the history
  • Loading branch information
hackerwins committed Nov 3, 2023
1 parent fb3e3ab commit 3855dc4
Show file tree
Hide file tree
Showing 10 changed files with 53 additions and 57 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ on:
branches: [ main ]

env:
GO_VERSION: '1.19.2'
GO_VERSION: '1.20'

jobs:
build:
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ default: help
tools: ## install tools for developing yorkie
go install github.com/gogo/protobuf/[email protected]
go install github.com/gogo/protobuf/[email protected]
go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.50.0
go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.55.1

proto: ## generate proto files
protoc \
Expand Down
2 changes: 1 addition & 1 deletion cmd/yorkie/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ func Delete() error {
}

// Preload read configuration file for viper before running command
func Preload(cmd *cobra.Command, args []string) error {
func Preload(_ *cobra.Command, _ []string) error {
configPathValue, err := configPath()
if err != nil {
fmt.Fprintln(os.Stderr, "get config path: %w", err)
Expand Down
8 changes: 2 additions & 6 deletions pkg/document/crdt/text.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,9 +135,7 @@ func (t *Text) String() string {

node := t.rgaTreeSplit.initialHead.next
for node != nil {
if node.createdAt().Compare(t.createdAt) == 0 {
// last line
} else if node.removedAt == nil {
if node.createdAt().Compare(t.createdAt) != 0 && node.removedAt == nil {
values = append(values, node.String())
}
node = node.next
Expand All @@ -152,9 +150,7 @@ func (t *Text) Marshal() string {

node := t.rgaTreeSplit.initialHead.next
for node != nil {
if node.createdAt().Compare(t.createdAt) == 0 {
// last line
} else if node.removedAt == nil {
if node.createdAt().Compare(t.createdAt) != 0 && node.removedAt == nil {
values = append(values, node.Marshal())
}
node = node.next
Expand Down
4 changes: 2 additions & 2 deletions pkg/llrb/llrb_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ func (k *intKey) Compare(other llrb.Key) int {
return 1
} else if k.key < o.key {
return -1
} else {
return 0
}

return 0
}

type intValue struct {
Expand Down
66 changes: 32 additions & 34 deletions server/backend/database/memory/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func (d *DB) Close() error {

// FindProjectInfoByPublicKey returns a project by public key.
func (d *DB) FindProjectInfoByPublicKey(
ctx context.Context,
_ context.Context,
publicKey string,
) (*database.ProjectInfo, error) {
txn := d.db.Txn(false)
Expand All @@ -77,7 +77,7 @@ func (d *DB) FindProjectInfoByPublicKey(

// FindProjectInfoByName returns a project by the given name.
func (d *DB) FindProjectInfoByName(
ctx context.Context,
_ context.Context,
owner types.ID,
name string,
) (*database.ProjectInfo, error) {
Expand All @@ -98,7 +98,7 @@ func (d *DB) FindProjectInfoByName(
}

// FindProjectInfoByID returns a project by the given id.
func (d *DB) FindProjectInfoByID(ctx context.Context, id types.ID) (*database.ProjectInfo, error) {
func (d *DB) FindProjectInfoByID(_ context.Context, id types.ID) (*database.ProjectInfo, error) {
txn := d.db.Txn(false)
defer txn.Abort()
raw, err := txn.First(tblProjects, "id", id.String())
Expand Down Expand Up @@ -134,7 +134,7 @@ func (d *DB) EnsureDefaultUserAndProject(

// ensureDefaultUserInfo creates the default user if it does not exist.
func (d *DB) ensureDefaultUserInfo(
ctx context.Context,
_ context.Context,
username,
password string,
) (*database.UserInfo, error) {
Expand Down Expand Up @@ -167,7 +167,7 @@ func (d *DB) ensureDefaultUserInfo(

// ensureDefaultProjectInfo creates the default project if it does not exist.
func (d *DB) ensureDefaultProjectInfo(
ctx context.Context,
_ context.Context,
defaultUserID types.ID,
defaultClientDeactivateThreshold string,
) (*database.ProjectInfo, error) {
Expand Down Expand Up @@ -196,7 +196,7 @@ func (d *DB) ensureDefaultProjectInfo(

// CreateProjectInfo creates a new project.
func (d *DB) CreateProjectInfo(
ctx context.Context,
_ context.Context,
name string,
owner types.ID,
clientDeactivateThreshold string,
Expand Down Expand Up @@ -226,7 +226,7 @@ func (d *DB) CreateProjectInfo(

// listProjectInfos returns all project infos rotationally.
func (d *DB) listProjectInfos(
ctx context.Context,
_ context.Context,
pageSize int,
housekeepingLastProjectID types.ID,
) ([]*database.ProjectInfo, error) {
Expand Down Expand Up @@ -264,7 +264,7 @@ func (d *DB) listProjectInfos(

// ListProjectInfos returns all project infos owned by owner.
func (d *DB) ListProjectInfos(
ctx context.Context,
_ context.Context,
owner types.ID,
) ([]*database.ProjectInfo, error) {
txn := d.db.Txn(false)
Expand Down Expand Up @@ -295,7 +295,7 @@ func (d *DB) ListProjectInfos(

// UpdateProjectInfo updates the given project.
func (d *DB) UpdateProjectInfo(
ctx context.Context,
_ context.Context,
owner types.ID,
id types.ID,
fields *types.UpdatableProjectFields,
Expand Down Expand Up @@ -338,7 +338,7 @@ func (d *DB) UpdateProjectInfo(

// CreateUserInfo creates a new user.
func (d *DB) CreateUserInfo(
ctx context.Context,
_ context.Context,
username string,
hashedPassword string,
) (*database.UserInfo, error) {
Expand All @@ -364,7 +364,7 @@ func (d *DB) CreateUserInfo(
}

// FindUserInfo finds a user by the given username.
func (d *DB) FindUserInfo(ctx context.Context, username string) (*database.UserInfo, error) {
func (d *DB) FindUserInfo(_ context.Context, username string) (*database.UserInfo, error) {
txn := d.db.Txn(false)
defer txn.Abort()

Expand All @@ -380,9 +380,7 @@ func (d *DB) FindUserInfo(ctx context.Context, username string) (*database.UserI
}

// ListUserInfos returns all users.
func (d *DB) ListUserInfos(
ctx context.Context,
) ([]*database.UserInfo, error) {
func (d *DB) ListUserInfos(_ context.Context) ([]*database.UserInfo, error) {
txn := d.db.Txn(false)
defer txn.Abort()

Expand All @@ -405,7 +403,7 @@ func (d *DB) ListUserInfos(

// ActivateClient activates a client.
func (d *DB) ActivateClient(
ctx context.Context,
_ context.Context,
projectID types.ID,
key string,
) (*database.ClientInfo, error) {
Expand Down Expand Up @@ -444,7 +442,7 @@ func (d *DB) ActivateClient(
}

// DeactivateClient deactivates a client.
func (d *DB) DeactivateClient(ctx context.Context, projectID, clientID types.ID) (*database.ClientInfo, error) {
func (d *DB) DeactivateClient(_ context.Context, projectID, clientID types.ID) (*database.ClientInfo, error) {
if err := clientID.Validate(); err != nil {
return nil, err
}
Expand Down Expand Up @@ -480,7 +478,7 @@ func (d *DB) DeactivateClient(ctx context.Context, projectID, clientID types.ID)
}

// FindClientInfoByID finds a client by ID.
func (d *DB) FindClientInfoByID(ctx context.Context, projectID, clientID types.ID) (*database.ClientInfo, error) {
func (d *DB) FindClientInfoByID(_ context.Context, projectID, clientID types.ID) (*database.ClientInfo, error) {
if err := clientID.Validate(); err != nil {
return nil, err
}
Expand All @@ -507,7 +505,7 @@ func (d *DB) FindClientInfoByID(ctx context.Context, projectID, clientID types.I
// UpdateClientInfoAfterPushPull updates the client from the given clientInfo
// after handling PushPull.
func (d *DB) UpdateClientInfoAfterPushPull(
ctx context.Context,
_ context.Context,
clientInfo *database.ClientInfo,
docInfo *database.DocInfo,
) error {
Expand Down Expand Up @@ -567,7 +565,7 @@ func (d *DB) UpdateClientInfoAfterPushPull(

// findDeactivateCandidatesPerProject finds the clients that need housekeeping per project.
func (d *DB) findDeactivateCandidatesPerProject(
ctx context.Context,
_ context.Context,
project *database.ProjectInfo,
candidatesLimit int,
) ([]*database.ClientInfo, error) {
Expand Down Expand Up @@ -642,7 +640,7 @@ func (d *DB) FindDeactivateCandidates(
// createDocIfNotExist condition is true, create the document if it does not
// exist.
func (d *DB) FindDocInfoByKeyAndOwner(
ctx context.Context,
_ context.Context,
projectID types.ID,
clientID types.ID,
key key.Key,
Expand Down Expand Up @@ -703,7 +701,7 @@ func (d *DB) FindDocInfoByKeyAndOwner(

// FindDocInfoByKey finds the document of the given key.
func (d *DB) FindDocInfoByKey(
ctx context.Context,
_ context.Context,
projectID types.ID,
key key.Key,
) (*database.DocInfo, error) {
Expand All @@ -723,7 +721,7 @@ func (d *DB) FindDocInfoByKey(

// FindDocInfoByID finds a docInfo of the given ID.
func (d *DB) FindDocInfoByID(
ctx context.Context,
_ context.Context,
projectID types.ID,
id types.ID,
) (*database.DocInfo, error) {
Expand All @@ -749,7 +747,7 @@ func (d *DB) FindDocInfoByID(

// UpdateDocInfoStatusToRemoved updates the status of the document to removed.
func (d *DB) UpdateDocInfoStatusToRemoved(
ctx context.Context,
_ context.Context,
projectID types.ID,
id types.ID,
) error {
Expand Down Expand Up @@ -787,7 +785,7 @@ func (d *DB) UpdateDocInfoStatusToRemoved(
// CreateChangeInfos stores the given changes and doc info. If the
// removeDoc condition is true, mark IsRemoved to true in doc info.
func (d *DB) CreateChangeInfos(
ctx context.Context,
_ context.Context,
projectID types.ID,
docInfo *database.DocInfo,
initialServerSeq int64,
Expand Down Expand Up @@ -860,7 +858,7 @@ func (d *DB) CreateChangeInfos(
// PurgeStaleChanges delete changes before the smallest in `syncedseqs` to
// save storage.
func (d *DB) PurgeStaleChanges(
ctx context.Context,
_ context.Context,
docID types.ID,
) error {
txn := d.db.Txn(true)
Expand Down Expand Up @@ -931,7 +929,7 @@ func (d *DB) FindChangesBetweenServerSeqs(

// FindChangeInfosBetweenServerSeqs returns the changeInfos between two server sequences.
func (d *DB) FindChangeInfosBetweenServerSeqs(
ctx context.Context,
_ context.Context,
docID types.ID,
from int64,
to int64,
Expand Down Expand Up @@ -963,7 +961,7 @@ func (d *DB) FindChangeInfosBetweenServerSeqs(

// CreateSnapshotInfo stores the snapshot of the given document.
func (d *DB) CreateSnapshotInfo(
ctx context.Context,
_ context.Context,
docID types.ID,
doc *document.InternalDocument,
) error {
Expand All @@ -990,7 +988,7 @@ func (d *DB) CreateSnapshotInfo(
}

// FindSnapshotInfoByID returns the snapshot by the given id.
func (d *DB) FindSnapshotInfoByID(ctx context.Context, id types.ID) (*database.SnapshotInfo, error) {
func (d *DB) FindSnapshotInfoByID(_ context.Context, id types.ID) (*database.SnapshotInfo, error) {
txn := d.db.Txn(false)
defer txn.Abort()
raw, err := txn.First(tblSnapshots, "id", id.String())
Expand All @@ -1006,7 +1004,7 @@ func (d *DB) FindSnapshotInfoByID(ctx context.Context, id types.ID) (*database.S

// FindClosestSnapshotInfo finds the last snapshot of the given document.
func (d *DB) FindClosestSnapshotInfo(
ctx context.Context,
_ context.Context,
docID types.ID,
serverSeq int64,
includeSnapshot bool,
Expand Down Expand Up @@ -1051,7 +1049,7 @@ func (d *DB) FindClosestSnapshotInfo(

// FindMinSyncedSeqInfo finds the minimum synced sequence info.
func (d *DB) FindMinSyncedSeqInfo(
ctx context.Context,
_ context.Context,
docID types.ID,
) (*database.SyncedSeqInfo, error) {
txn := d.db.Txn(false)
Expand Down Expand Up @@ -1130,7 +1128,7 @@ func (d *DB) UpdateAndFindMinSyncedTicket(

// UpdateSyncedSeq updates the syncedSeq of the given client.
func (d *DB) UpdateSyncedSeq(
ctx context.Context,
_ context.Context,
clientInfo *database.ClientInfo,
docID types.ID,
serverSeq int64,
Expand Down Expand Up @@ -1194,7 +1192,7 @@ func (d *DB) UpdateSyncedSeq(

// FindDocInfosByPaging returns the documentInfos of the given paging.
func (d *DB) FindDocInfosByPaging(
ctx context.Context,
_ context.Context,
projectID types.ID,
paging types.Paging[types.ID],
) ([]*database.DocInfo, error) {
Expand Down Expand Up @@ -1244,7 +1242,7 @@ func (d *DB) FindDocInfosByPaging(

// FindDocInfosByQuery returns the docInfos which match the given query.
func (d *DB) FindDocInfosByQuery(
ctx context.Context,
_ context.Context,
projectID types.ID,
query string,
pageSize int,
Expand Down Expand Up @@ -1275,7 +1273,7 @@ func (d *DB) FindDocInfosByQuery(

// IsDocumentAttached returns whether the document is attached to clients.
func (d *DB) IsDocumentAttached(
ctx context.Context,
_ context.Context,
projectID types.ID,
docID types.ID,
excludeClientID types.ID,
Expand Down
13 changes: 9 additions & 4 deletions server/backend/database/mongo/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ import (
"github.com/yorkie-team/yorkie/server/logging"
)

const (
// StatusKey is the key of the status field.
StatusKey = "status"
)

// Client is a client that connects to Mongo DB and reads or saves Yorkie data.
type Client struct {
config *Config
Expand Down Expand Up @@ -593,8 +598,8 @@ func (c *Client) UpdateClientInfoAfterPushPull(
clientDocInfoKey + "client_seq": clientDocInfo.ClientSeq,
},
"$set": bson.M{
clientDocInfoKey + "status": clientDocInfo.Status,
"updated_at": clientInfo.UpdatedAt,
clientDocInfoKey + StatusKey: clientDocInfo.Status,
"updated_at": clientInfo.UpdatedAt,
},
}

Expand All @@ -608,7 +613,7 @@ func (c *Client) UpdateClientInfoAfterPushPull(
"$set": bson.M{
clientDocInfoKey + "server_seq": 0,
clientDocInfoKey + "client_seq": 0,
clientDocInfoKey + "status": clientDocInfo.Status,
clientDocInfoKey + StatusKey: clientDocInfo.Status,
"updated_at": clientInfo.UpdatedAt,
},
}
Expand Down Expand Up @@ -866,7 +871,7 @@ func (c *Client) UpdateDocInfoStatusToRemoved(
// CreateChangeInfos stores the given changes and doc info.
func (c *Client) CreateChangeInfos(
ctx context.Context,
projectID types.ID,
_ types.ID,
docInfo *database.DocInfo,
initialServerSeq int64,
changes []*change.Change,
Expand Down
Loading

0 comments on commit 3855dc4

Please sign in to comment.