Skip to content

Commit ca05a2c

Browse files
committed
Enable revive linter, and fix a bunch of warnings
I took the set of enabled checks from revive's recommended configuration [1], and removed some that I didn't like. There might be other useful checks in revive that we might want to enable, but this is a nice improvement already. The bulk of the changes here are removing unnecessary else statements after returns, but there are a few others too. [1] https://github.com/mgechev/revive?tab=readme-ov-file#recommended-configuration
1 parent 7aa426f commit ca05a2c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+150
-168
lines changed

.golangci.yml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ linters:
1111
- nakedret
1212
- nolintlint
1313
- prealloc
14+
- revive
1415
- thelper
1516
- tparallel
1617
- unconvert
@@ -76,6 +77,20 @@ linters:
7677

7778
dot-import-whitelist:
7879
- github.com/jesseduffield/lazygit/pkg/integration/components
80+
revive:
81+
severity: warning
82+
rules:
83+
- name: atomic
84+
- name: context-as-argument
85+
- name: context-keys-type
86+
- name: error-naming
87+
- name: var-declaration
88+
- name: package-comments
89+
- name: range
90+
- name: time-naming
91+
- name: indent-error-flow
92+
- name: errorf
93+
- name: superfluous-else
7994
exclusions:
8095
generated: lax
8196
presets:

pkg/app/app.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,9 +86,9 @@ func newLogger(cfg config.AppConfigurer) *logrus.Entry {
8686
log.Fatal(err)
8787
}
8888
return logs.NewDevelopmentLogger(logPath)
89-
} else {
90-
return logs.NewProductionLogger()
9189
}
90+
91+
return logs.NewProductionLogger()
9292
}
9393

9494
// NewApp bootstrap a new application

pkg/app/daemon/rebase.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,8 @@ type TodoLine struct {
2121
func (self *TodoLine) ToString() string {
2222
if self.Action == "break" {
2323
return self.Action + "\n"
24-
} else {
25-
return self.Action + " " + self.Commit.Hash() + " " + self.Commit.Name + "\n"
2624
}
25+
return self.Action + " " + self.Commit.Hash() + " " + self.Commit.Name + "\n"
2726
}
2827

2928
func TodoLinesToString(todoLines []TodoLine) string {

pkg/commands/git_commands/branch_loader.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -356,9 +356,8 @@ func parseDifference(track string, regexStr string) string {
356356
match := re.FindStringSubmatch(track)
357357
if len(match) > 1 {
358358
return match[1]
359-
} else {
360-
return "0"
361359
}
360+
return "0"
362361
}
363362

364363
// TODO: only look at the new reflog commits, and otherwise store the recencies in

pkg/commands/git_commands/commit.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,9 +149,8 @@ func (self *CommitCommands) CommitEditorCmdObj() *oscommands.CmdObj {
149149
func (self *CommitCommands) signoffFlag() string {
150150
if self.UserConfig().Git.Commit.SignOff {
151151
return "--signoff"
152-
} else {
153-
return ""
154152
}
153+
return ""
155154
}
156155

157156
func (self *CommitCommands) GetCommitMessage(commitHash string) (string, error) {

pkg/commands/git_commands/deps_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ func buildGitCommon(deps commonDeps) *GitCommon {
9797

9898
func buildRepo() *gogit.Repository {
9999
// TODO: think of a way to actually mock this out
100-
var repo *gogit.Repository = nil
100+
var repo *gogit.Repository
101101
return repo
102102
}
103103

pkg/commands/git_commands/git_command_builder.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,8 @@ func (self *GitCommandBuilder) ArgIf(condition bool, ifTrue ...string) *GitComma
3232
func (self *GitCommandBuilder) ArgIfElse(condition bool, ifTrue string, ifFalse string) *GitCommandBuilder {
3333
if condition {
3434
return self.Arg(ifTrue)
35-
} else {
36-
return self.Arg(ifFalse)
3735
}
36+
return self.Arg(ifFalse)
3837
}
3938

4039
func (self *GitCommandBuilder) Config(value string) *GitCommandBuilder {

pkg/commands/git_commands/rebase.go

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -327,9 +327,8 @@ func (self *RebaseCommands) MoveFixupCommitDown(commits []*models.Commit, target
327327
func todoFromCommit(commit *models.Commit) utils.Todo {
328328
if commit.Action == todo.UpdateRef {
329329
return utils.Todo{Ref: commit.Name}
330-
} else {
331-
return utils.Todo{Hash: commit.Hash()}
332330
}
331+
return utils.Todo{Hash: commit.Hash()}
333332
}
334333

335334
// Sets the action for the given commits in the git-rebase-todo file
@@ -412,9 +411,9 @@ func (self *RebaseCommands) BeginInteractiveRebaseForCommit(
412411
instruction: daemon.NewInsertBreakInstruction(),
413412
keepCommitsThatBecomeEmpty: keepCommitsThatBecomeEmpty,
414413
}).Run()
415-
} else {
416-
return self.BeginInteractiveRebaseForCommitRange(commits, commitIndex, commitIndex, keepCommitsThatBecomeEmpty)
417414
}
415+
416+
return self.BeginInteractiveRebaseForCommitRange(commits, commitIndex, commitIndex, keepCommitsThatBecomeEmpty)
418417
}
419418

420419
func (self *RebaseCommands) BeginInteractiveRebaseForCommitRange(
@@ -574,7 +573,7 @@ func getBaseHashOrRoot(commits []*models.Commit, index int) string {
574573
// at time of writing)
575574
if index < len(commits) {
576575
return commits[index].Hash()
577-
} else {
578-
return "--root"
579576
}
577+
578+
return "--root"
580579
}

pkg/commands/git_commands/repo_paths.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ type RepoPaths struct {
2121
isBareRepo bool
2222
}
2323

24-
var gitPathFormatVersion GitVersion = GitVersion{2, 31, 0, ""}
24+
var gitPathFormatVersion = GitVersion{2, 31, 0, ""}
2525

2626
// Path to the current worktree. If we're in the main worktree, this will
2727
// be the same as RepoPath()

pkg/commands/git_commands/repo_paths_test.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -184,9 +184,7 @@ func TestGetRepoPaths(t *testing.T) {
184184
Expected: nil,
185185
Err: func(getRevParseArgs argFn) error {
186186
args := strings.Join(getRevParseArgs(), " ")
187-
return errors.New(
188-
fmt.Sprintf("'git %v --show-toplevel --absolute-git-dir --git-common-dir --is-bare-repository --show-superproject-working-tree' failed: fatal: invalid gitfile format: /path/to/repo/worktree2/.git", args),
189-
)
187+
return fmt.Errorf("'git %v --show-toplevel --absolute-git-dir --git-common-dir --is-bare-repository --show-superproject-working-tree' failed: fatal: invalid gitfile format: /path/to/repo/worktree2/.git", args)
190188
},
191189
},
192190
}

0 commit comments

Comments
 (0)