diff --git a/.golangci.yml b/.golangci.yml index 6cdaa44..17495c2 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -1,12 +1,5 @@ -run: - concurrency: 4 - deadline: 5m - timeout: 5m - -output: - sort-results: true - linters: + # https://golangci-lint.run/usage/linters/#enabled-by-default enable: - asciicheck - depguard @@ -26,6 +19,8 @@ linters: - unconvert linters-settings: + gofmt: + simplify: true depguard: rules: main: @@ -36,11 +31,26 @@ linters-settings: desc: "Use 'errors' or 'fmt' instead of github.com/pkg/errors" - pkg: "golang.org/x/exp/slices" desc: "Use 'slices' instead." + revive: # https://github.com/mgechev/revive/blob/master/defaults.toml # https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md + enable-all-rules: true + ignore-generated-header: true + severity: warning rules: - # A lot of false positives: incorrectly identifies channel draining as "empty code block". - # See https://github.com/mgechev/revive/issues/386 - - name: empty-block + - name: line-length-limit + severity: error + arguments: [120] + - name: add-constant + disabled: true + - name: cognitive-complexity + disabled: true + - name: cyclomatic + disabled: true + - name: unused-receiver disabled: true + - name: unhandled-error + arguments: + - "fmt.Println" + - "fmt.Printf" diff --git a/cmd/app/main.go b/cmd/app/main.go index 39ccbd6..10233dd 100644 --- a/cmd/app/main.go +++ b/cmd/app/main.go @@ -7,8 +7,8 @@ import ( ) func main() { - config := config.NewConfig() - mc := mouse.NewController(config) - trayIcon := tray.NewTray(mc, config) + conf := config.NewConfig() + mc := mouse.NewController(conf) + trayIcon := tray.NewTray(mc, conf) trayIcon.Run() } diff --git a/internal/mouse/mouse.go b/internal/mouse/mouse.go index 0d8bc53..4c42572 100644 --- a/internal/mouse/mouse.go +++ b/internal/mouse/mouse.go @@ -10,24 +10,24 @@ import ( ) type Controller struct { - config *config.Config + conf *config.Config LastX, LastY int } -func NewController(config *config.Config) *Controller { +func NewController(conf *config.Config) *Controller { return &Controller{ - config: config, + conf: conf, } } func (c *Controller) MoveMouse() { - for c.config.Enabled { + for c.conf.Enabled { // Sleep before the check c.sleep() // Check if the current time is within working hours. // If not, there is no reason to move the cursor. - isWorkingHours := utils.IsInWorkingHours(c.config.WorkingHoursInterval) + isWorkingHours := utils.IsInWorkingHours(c.conf.WorkingHoursInterval) if !isWorkingHours { continue } diff --git a/internal/tray/tray.go b/internal/tray/tray.go index 2c01466..1ffb51e 100644 --- a/internal/tray/tray.go +++ b/internal/tray/tray.go @@ -31,14 +31,14 @@ func loadIcon() ([]byte, error) { type Tray struct { mouseController *mouse.Controller - config *config.Config + conf *config.Config workingHoursMenuItems map[string]*systray.MenuItem } -func NewTray(mouseController *mouse.Controller, config *config.Config) *Tray { +func NewTray(mouseController *mouse.Controller, conf *config.Config) *Tray { return &Tray{ mouseController: mouseController, - config: config, + conf: conf, workingHoursMenuItems: make(map[string]*systray.MenuItem), } } @@ -66,19 +66,19 @@ func (t *Tray) onReady() { mQuit := systray.AddMenuItem("Quit", "Quit the application") // Hide the enable option since it's already enabled by default - if t.config.Enabled { + if t.conf.Enabled { mEnable.Hide() } else { mDisable.Hide() } // Add interval selection submenu items - for _, hours := range t.config.WorkingHours { + for _, hours := range t.conf.WorkingHours { t.addWorkingHoursItems(mWorkingHours, hours) } // Set a marker for the default working hours interval - t.workingHoursMenuItems[t.config.WorkingHoursInterval].Check() + t.workingHoursMenuItems[t.conf.WorkingHoursInterval].Check() workingHoursIntervalClicks := t.createWorkingHoursIntervalClicksChannel() @@ -86,22 +86,22 @@ func (t *Tray) onReady() { for { select { case <-mEnable.ClickedCh: - t.config.Enabled = true + t.conf.Enabled = true mEnable.Hide() mDisable.Show() mWorkingHours.Enable() go t.mouseController.MoveMouse() case <-mDisable.ClickedCh: - t.config.Enabled = false + t.conf.Enabled = false mDisable.Hide() mEnable.Show() mWorkingHours.Disable() case workingHoursInterval := <-workingHoursIntervalClicks: // When an hours interval item is clicked, update the workingHoursInterval interval and checkmarks - t.config.SetWorkingHoursInterval(workingHoursInterval) - t.updateNightModeIntervalChecks(t.config.WorkingHoursInterval) + t.conf.SetWorkingHoursInterval(workingHoursInterval) + t.updateNightModeIntervalChecks(t.conf.WorkingHoursInterval) case <-mAbout.ClickedCh: - if err := utils.OpenWebPage(t.config.GitRepo); err != nil { + if err := utils.OpenWebPage(t.conf.GitRepo); err != nil { panic(err) } case <-mQuit.ClickedCh: @@ -112,7 +112,7 @@ func (t *Tray) onReady() { }() // Start moving the mouse in a circle immediately if enabled - if t.config.Enabled { + if t.conf.Enabled { go t.mouseController.MoveMouse() } } diff --git a/internal/utils/utils.go b/internal/utils/utils.go index b6e2bc7..631c0fa 100644 --- a/internal/utils/utils.go +++ b/internal/utils/utils.go @@ -24,10 +24,7 @@ func OpenWebPage(url string) error { return errors.New("unsupported platform") } - if err := cmd.Start(); err != nil { - return err - } - return nil + return cmd.Start() } func IsInWorkingHours(timeWindow string) bool {