Skip to content

Commit

Permalink
Fix lint errors
Browse files Browse the repository at this point in the history
  • Loading branch information
mbrt committed Oct 1, 2024
1 parent a4c5f31 commit 710c6ee
Show file tree
Hide file tree
Showing 16 changed files with 92 additions and 68 deletions.
11 changes: 0 additions & 11 deletions .golangci.yml

This file was deleted.

2 changes: 1 addition & 1 deletion cmd/gmailctl/cmd/apply_cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ to make them match your local configuration file.
By default apply uses the configuration file inside the config
directory [config.jsonnet].`,
Run: func(cmd *cobra.Command, args []string) {
Run: func(*cobra.Command, []string) {
f := applyFilename
if f == "" {
f = configFilenameFromDir(cfgDir)
Expand Down
2 changes: 1 addition & 1 deletion cmd/gmailctl/cmd/debug_cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ filter applies to the intended emails.
By default debug uses the configuration file inside the config
directory config.jsonnet].`,
Run: func(cmd *cobra.Command, args []string) {
Run: func(*cobra.Command, []string) {
f := debugFilename
if f == "" {
f = configFilenameFromDir(cfgDir)
Expand Down
2 changes: 1 addition & 1 deletion cmd/gmailctl/cmd/diff_cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ configuration and the current Gmail settings of your account.
By default diff uses the configuration file inside the config
directory [config.jsonnet].`,
Run: func(cmd *cobra.Command, args []string) {
Run: func(*cobra.Command, []string) {
f := diffFilename
if f == "" {
f = configFilenameFromDir(cfgDir)
Expand Down
2 changes: 1 addition & 1 deletion cmd/gmailctl/cmd/download_cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ move to gmailctl.
WARNING: This functionality is experimental. After downloading, verify
that no diff is detected with the remote filters by using the 'diff'
command.`,
Run: func(cmd *cobra.Command, args []string) {
Run: func(*cobra.Command, []string) {
if err := download(downloadOutput); err != nil {
fatal(err)
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/gmailctl/cmd/edit_cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ environment variable.
By default edit uses the configuration file inside the config
directory [config.jsonnet].`,
Run: func(cmd *cobra.Command, args []string) {
Run: func(*cobra.Command, []string) {
f := editFilename
if f == "" {
f = configFilenameFromDir(cfgDir)
Expand Down
2 changes: 1 addition & 1 deletion cmd/gmailctl/cmd/export_cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ them with other people.
By default export uses the configuration file inside the config
directory [config.jsonnet].`,
Run: func(cmd *cobra.Command, args []string) {
Run: func(*cobra.Command, []string) {
f := exportFilename
if f == "" {
f = configFilenameFromDir(cfgDir)
Expand Down
2 changes: 1 addition & 1 deletion cmd/gmailctl/cmd/init_cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ var initCmd = &cobra.Command{
Long: `The init command initialize the Gmail configuration, asking
you for details and guiding you through the process of
setting up the API authorizations and initial settings.`,
Run: func(cmd *cobra.Command, args []string) {
Run: func(*cobra.Command, []string) {
var err error
if initReset {
err = resetConfig()
Expand Down
18 changes: 9 additions & 9 deletions cmd/gmailctl/cmd/root_cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,15 @@ func init() {

// initConfig reads in config file and ENV variables if set.
func initConfig() {
if cfgDir != "" {
if cfgDir == "" {
// Use config file from the flag.
} else {
// Find home directory.
usr, err := user.Current()
if err != nil {
fmt.Println(err)
os.Exit(1)
}
cfgDir = path.Join(usr.HomeDir, ".gmailctl")
return
}
// Find home directory.
usr, err := user.Current()
if err != nil {
fmt.Println(err)
os.Exit(1)
}
cfgDir = path.Join(usr.HomeDir, ".gmailctl")
}
2 changes: 1 addition & 1 deletion cmd/gmailctl/cmd/test_cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ List of unsupported constructs:
By default test uses the configuration file inside the config
directory [config.jsonnet].`,
Run: func(cmd *cobra.Command, args []string) {
Run: func(*cobra.Command, []string) {
f := testFilename
if f == "" {
f = configFilenameFromDir(cfgDir)
Expand Down
2 changes: 1 addition & 1 deletion cmd/gmailctl/cmd/version_cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
var versionCmd = &cobra.Command{
Use: "version",
Short: "Print gmailctl version and exit",
Run: func(cmd *cobra.Command, args []string) {
Run: func(*cobra.Command, []string) {
fmt.Println(version)
},
}
Expand Down
68 changes: 34 additions & 34 deletions internal/engine/filter/diff_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
)

func TestNoDiff(t *testing.T) {
old := Filters{
prev := Filters{
{
ID: "abcdefg",
Criteria: Criteria{
Expand All @@ -21,7 +21,7 @@ func TestNoDiff(t *testing.T) {
},
},
}
new := Filters{
curr := Filters{
{
Criteria: Criteria{
From: "[email protected]",
Expand All @@ -32,14 +32,14 @@ func TestNoDiff(t *testing.T) {
},
}

fd, err := Diff(old, new, false)
fd, err := Diff(prev, curr, false)
assert.Nil(t, err)
// No difference even if the ID is present in only one of them.
assert.True(t, fd.Empty())
}

func TestDiffOutput(t *testing.T) {
old := Filters{
prev := Filters{
{
ID: "abcdefg",
Criteria: Criteria{
Expand All @@ -52,7 +52,7 @@ func TestDiffOutput(t *testing.T) {
},
},
}
new := Filters{
curr := Filters{
{
Criteria: Criteria{
From: "{[email protected] [email protected]}",
Expand All @@ -65,7 +65,7 @@ func TestDiffOutput(t *testing.T) {
},
}

fd, err := Diff(old, new, false)
fd, err := Diff(prev, curr, false)
assert.Nil(t, err)

expected := `
Expand Down Expand Up @@ -93,7 +93,7 @@ func TestDiffOutput(t *testing.T) {
}

func TestDiffOutputWithGmailSearchURL(t *testing.T) {
old := Filters{
prev := Filters{
{
ID: "abcdefg",
Criteria: Criteria{
Expand All @@ -106,7 +106,7 @@ func TestDiffOutputWithGmailSearchURL(t *testing.T) {
},
},
}
new := Filters{
curr := Filters{
{
Criteria: Criteria{
From: "{[email protected] [email protected]}",
Expand All @@ -119,7 +119,7 @@ func TestDiffOutputWithGmailSearchURL(t *testing.T) {
},
}

fd, err := Diff(old, new, true)
fd, err := Diff(prev, curr, true)
assert.Nil(t, err)

expected := `
Expand Down Expand Up @@ -184,8 +184,8 @@ func someFilters() Filters {
}

func TestDiffAddRemove(t *testing.T) {
old := someFilters()
new := Filters{
prev := someFilters()
curr := Filters{
{
Criteria: Criteria{
From: "{[email protected] [email protected]}",
Expand Down Expand Up @@ -213,18 +213,18 @@ func TestDiffAddRemove(t *testing.T) {
},
}

fd, err := Diff(old, new, false)
fd, err := Diff(prev, curr, false)
expected := FiltersDiff{
Added: Filters{new[0]},
Removed: Filters{old[1]},
Added: Filters{curr[0]},
Removed: Filters{prev[1]},
}
assert.Nil(t, err)
assert.Equal(t, expected, fd)
}

func TestDiffReorder(t *testing.T) {
old := someFilters()
new := Filters{
prev := someFilters()
curr := Filters{
{
Criteria: Criteria{
To: "[email protected]",
Expand Down Expand Up @@ -252,15 +252,15 @@ func TestDiffReorder(t *testing.T) {
},
}

fd, err := Diff(old, new, false)
fd, err := Diff(prev, curr, false)
assert.Nil(t, err)
assert.Len(t, fd.Added, 0)
assert.Len(t, fd.Removed, 0)
}

func TestDiffModify(t *testing.T) {
old := someFilters()
new := Filters{
prev := someFilters()
curr := Filters{
{
Criteria: Criteria{
From: "[email protected]",
Expand Down Expand Up @@ -288,18 +288,18 @@ func TestDiffModify(t *testing.T) {
},
}

fd, err := Diff(old, new, false)
fd, err := Diff(prev, curr, false)
expected := FiltersDiff{
Added: Filters{new[1]},
Removed: Filters{old[1]},
Added: Filters{curr[1]},
Removed: Filters{prev[1]},
}
assert.Nil(t, err)
assert.Equal(t, expected, fd)
}

func TestDiffAdd(t *testing.T) {
old := someFilters()
new := Filters{
prev := someFilters()
curr := Filters{
{
Criteria: Criteria{
From: "[email protected]",
Expand Down Expand Up @@ -336,17 +336,17 @@ func TestDiffAdd(t *testing.T) {
},
}

fd, err := Diff(old, new, false)
fd, err := Diff(prev, curr, false)
expected := FiltersDiff{
Added: Filters{new[2]},
Added: Filters{curr[2]},
}
assert.Nil(t, err)
assert.Equal(t, expected, fd)
}

func TestDiffRemove(t *testing.T) {
old := someFilters()
new := Filters{
prev := someFilters()
curr := Filters{
{
Criteria: Criteria{
To: "[email protected]",
Expand All @@ -358,18 +358,18 @@ func TestDiffRemove(t *testing.T) {
},
}

fd, err := Diff(old, new, false)
fd, err := Diff(prev, curr, false)
expected := FiltersDiff{
Removed: Filters{old[2], old[0]},
Removed: Filters{prev[2], prev[0]},
}

assert.Nil(t, err)
assert.Equal(t, expected, fd)
}

func TestDuplicate(t *testing.T) {
old := Filters{}
new := Filters{
prev := Filters{}
curr := Filters{
{
Criteria: Criteria{
From: "[email protected]",
Expand All @@ -388,10 +388,10 @@ func TestDuplicate(t *testing.T) {
},
}

fd, err := Diff(old, new, false)
fd, err := Diff(prev, curr, false)
assert.Nil(t, err)
// Only one of the two identical filters is present
assert.Equal(t, new[1:], fd.Added)
assert.Equal(t, curr[1:], fd.Added)
}

func TestIndent(t *testing.T) {
Expand Down
1 change: 1 addition & 0 deletions internal/engine/filter/filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ func indent(query string, level int) string {
return "\n" + strings.TrimRight(indented.String(), "\n ")
}

//revive:disable:cyclomatic High complexity, needs some refactoring
func indentInternal(queryReader io.RuneReader, out *bytes.Buffer, level int) bool {
type parseState int
const (
Expand Down
10 changes: 5 additions & 5 deletions internal/engine/label/diff.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ func (d LabelsDiff) Empty() bool {
}

func (d LabelsDiff) String() string {
var old, new []string
var old, curr []string

Check warning on line 77 in internal/engine/label/diff.go

View check run for this annotation

Codecov / codecov/patch

internal/engine/label/diff.go#L77

Added line #L77 was not covered by tests

cleanup := func(l Label) Label {
// Get rid of distracting information in the diff.
Expand All @@ -86,20 +86,20 @@ func (d LabelsDiff) String() string {

for _, ml := range d.Modified {
old = append(old, cleanup(ml.Old).String()+"\n")
new = append(new, ml.New.String()+"\n")
curr = append(curr, ml.New.String()+"\n")

Check warning on line 89 in internal/engine/label/diff.go

View check run for this annotation

Codecov / codecov/patch

internal/engine/label/diff.go#L89

Added line #L89 was not covered by tests
}

for _, l := range d.Removed {
old = append(old, cleanup(l).String()+"\n")
}

for _, l := range d.Added {
new = append(new, l.String()+"\n")
curr = append(curr, l.String()+"\n")

Check warning on line 97 in internal/engine/label/diff.go

View check run for this annotation

Codecov / codecov/patch

internal/engine/label/diff.go#L97

Added line #L97 was not covered by tests
}

s, err := difflib.GetUnifiedDiffString(difflib.UnifiedDiff{
A: old,
B: new,
B: curr,

Check warning on line 102 in internal/engine/label/diff.go

View check run for this annotation

Codecov / codecov/patch

internal/engine/label/diff.go#L102

Added line #L102 was not covered by tests
FromFile: "Current",
ToFile: "TO BE APPLIED",
Context: 3,
Expand All @@ -108,7 +108,7 @@ func (d LabelsDiff) String() string {
// We can't get a diff apparently, let's make something up here
return fmt.Sprintf("Removed:\n%s\nAdded:\n%sModified:%s",
strings.Join(old, "\n"),
strings.Join(new, "\n"),
strings.Join(curr, "\n"),

Check warning on line 111 in internal/engine/label/diff.go

View check run for this annotation

Codecov / codecov/patch

internal/engine/label/diff.go#L111

Added line #L111 was not covered by tests
fmt.Sprint(d.Modified),
)
}
Expand Down
1 change: 1 addition & 0 deletions internal/errors/err.go
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,7 @@ func (w indentWriter) Write(b []byte) (int, error) {
i++
}
// Look for the next newline.
//revive:disable:empty-block This is intentional to find the next newline.
for j = i; j < len(b) && b[j] != '\n'; j++ {
}
// Write everything up to the newline, or the end of buffer.
Expand Down
Loading

0 comments on commit 710c6ee

Please sign in to comment.