1
0
mirror of https://github.com/AvengeMedia/DankMaterialShell.git synced 2026-01-24 21:42:51 -05:00

core: fix golang-ci lints and add a config

This commit is contained in:
bbedward
2025-11-30 00:12:45 -05:00
parent f6874fbcad
commit dde426658f
17 changed files with 125 additions and 39 deletions

View File

@@ -367,7 +367,7 @@ func SyncDMSConfigs(dmsPath string, logFunc func(string), sudoPassword string) e
}
}
runSudoCmd(sudoPassword, "rm", "-f", link.target)
runSudoCmd(sudoPassword, "rm", "-f", link.target) //nolint:errcheck
if err := runSudoCmd(sudoPassword, "ln", "-sf", link.source, link.target); err != nil {
logFunc(fmt.Sprintf("⚠ Warning: Failed to create symlink for %s: %v", link.desc, err))

View File

@@ -77,7 +77,7 @@ func (d *DiscoveryConfig) FindJSONFiles() ([]string, error) {
func expandPath(path string) (string, error) {
expandedPath := os.ExpandEnv(path)
if filepath.HasPrefix(expandedPath, "~") {
if strings.HasPrefix(expandedPath, "~") {
home, err := os.UserHomeDir()
if err != nil {
return "", err

View File

@@ -5,6 +5,7 @@ import (
"fmt"
"os"
"path/filepath"
"strings"
"github.com/AvengeMedia/DankMaterialShell/core/internal/keybinds"
)
@@ -118,7 +119,7 @@ func (j *JSONFileProvider) GetCheatSheet() (*keybinds.CheatSheet, error) {
func expandPath(path string) (string, error) {
expandedPath := os.ExpandEnv(path)
if filepath.HasPrefix(expandedPath, "~") {
if strings.HasPrefix(expandedPath, "~") {
home, err := os.UserHomeDir()
if err != nil {
return "", err

View File

@@ -64,7 +64,7 @@ func (l *FileLogger) writeToFile(message string) {
redacted := l.redactPassword(message)
timestamp := time.Now().Format("15:04:05.000")
l.writer.WriteString(fmt.Sprintf("[%s] %s\n", timestamp, redacted))
l.writer.WriteString(fmt.Sprintf("[%s] %s\n", timestamp, redacted)) //nolint:errcheck
l.writer.Flush()
}
@@ -93,7 +93,7 @@ func (l *FileLogger) Close() error {
defer l.mu.Unlock()
footer := fmt.Sprintf("\n=== DankInstall Log End ===\nCompleted: %s\n", time.Now().Format(time.RFC3339))
l.writer.WriteString(footer)
l.writer.WriteString(footer) //nolint:errcheck
l.writer.Flush()
if err := l.file.Sync(); err != nil {

View File

@@ -93,7 +93,7 @@ func (m *Manager) Install(plugin Plugin) error {
if !repoExists {
if err := m.gitClient.PlainClone(repoPath, plugin.Repo); err != nil {
m.fs.RemoveAll(repoPath)
m.fs.RemoveAll(repoPath) //nolint:errcheck
return fmt.Errorf("failed to clone repository: %w", err)
}
} else {
@@ -130,7 +130,7 @@ func (m *Manager) Install(plugin Plugin) error {
}
} else {
if err := m.gitClient.PlainClone(pluginPath, plugin.Repo); err != nil {
m.fs.RemoveAll(pluginPath)
m.fs.RemoveAll(pluginPath) //nolint:errcheck
return fmt.Errorf("failed to clone plugin: %w", err)
}
}

View File

@@ -98,7 +98,7 @@ func (b *DDCBackend) probeDDCDevice(bus int) (*ddcDevice, error) {
}
dummy := make([]byte, 32)
syscall.Read(fd, dummy)
syscall.Read(fd, dummy) //nolint:errcheck
writebuf := []byte{0x00}
n, err := syscall.Write(fd, writebuf)

View File

@@ -13,8 +13,7 @@ type DBusConn interface {
}
type LogindBackend struct {
conn DBusConn
connOnce bool
conn DBusConn
}
func NewLogindBackend() (*LogindBackend, error) {

View File

@@ -251,14 +251,14 @@ func (m *Manager) CreatePrinter(name, deviceURI, ppd string, shared bool, errorP
}
if usedPkHelper {
m.pkHelper.PrinterSetEnabled(name, true)
m.pkHelper.PrinterSetAcceptJobs(name, true, "")
m.pkHelper.PrinterSetEnabled(name, true) //nolint:errcheck
m.pkHelper.PrinterSetAcceptJobs(name, true, "") //nolint:errcheck
} else {
if err := m.client.ResumePrinter(name); isAuthError(err) && m.pkHelper != nil {
m.pkHelper.PrinterSetEnabled(name, true)
m.pkHelper.PrinterSetEnabled(name, true) //nolint:errcheck
}
if err := m.client.AcceptJobs(name); isAuthError(err) && m.pkHelper != nil {
m.pkHelper.PrinterSetAcceptJobs(name, true, "")
m.pkHelper.PrinterSetAcceptJobs(name, true, "") //nolint:errcheck
}
}

View File

@@ -11,6 +11,8 @@ import (
"github.com/AvengeMedia/DankMaterialShell/core/internal/errdefs"
"github.com/AvengeMedia/DankMaterialShell/core/internal/log"
"github.com/godbus/dbus/v5"
"golang.org/x/text/cases"
"golang.org/x/text/language"
)
const (
@@ -118,12 +120,6 @@ func (a *SecretAgent) GetSecrets(
log.Infof("[SecretAgent] GetSecrets called: path=%s, setting=%s, hints=%v, flags=%d",
path, settingName, hints, flags)
const (
NM_SECRET_AGENT_GET_SECRETS_FLAG_ALLOW_INTERACTION = 0x1
NM_SECRET_AGENT_GET_SECRETS_FLAG_REQUEST_NEW = 0x2
NM_SECRET_AGENT_GET_SECRETS_FLAG_USER_REQUESTED = 0x4
)
connType, displayName, vpnSvc := readConnTypeAndName(conn)
ssid := readSSID(conn)
fields := fieldsNeeded(settingName, hints)
@@ -378,7 +374,7 @@ func (a *SecretAgent) GetSecrets(
}
if settingName == "vpn" && a.backend != nil && (vpnUsername != "" || reply.Save) {
pw, _ := reply.Secrets["password"]
pw := reply.Secrets["password"]
a.backend.pendingVPNSaveMu.Lock()
a.backend.pendingVPNSave = &pendingVPNCredentials{
ConnectionPath: string(path),
@@ -620,11 +616,12 @@ func vpnFieldMeta(field, vpnService string) (label string, isSecret bool) {
case "private-key-password":
return "Private Key Password", true
}
titleCaser := cases.Title(language.English)
if strings.HasSuffix(field, "password") || strings.HasSuffix(field, "secret") ||
strings.HasSuffix(field, "pass") || strings.HasSuffix(field, "psk") {
return strings.Title(strings.ReplaceAll(field, "-", " ")), true
return titleCaser.String(strings.ReplaceAll(field, "-", " ")), true
}
return strings.Title(strings.ReplaceAll(field, "-", " ")), false
return titleCaser.String(strings.ReplaceAll(field, "-", " ")), false
}
func readVPNPasswordFlags(conn map[string]nmVariantMap, settingName string) uint32 {

View File

@@ -2,14 +2,12 @@ package network
import (
"fmt"
"sync"
)
type HybridIwdNetworkdBackend struct {
wifi *IWDBackend
l3 *SystemdNetworkdBackend
onStateChange func()
stateMutex sync.RWMutex
}
func NewHybridIwdNetworkdBackend(w *IWDBackend, n *SystemdNetworkdBackend) (*HybridIwdNetworkdBackend, error) {
@@ -120,7 +118,7 @@ func (b *HybridIwdNetworkdBackend) ConnectWiFi(req ConnectionRequest) error {
ws, err := b.wifi.GetCurrentState()
if err == nil && ws.WiFiDevice != "" {
b.l3.EnsureDhcpUp(ws.WiFiDevice)
b.l3.EnsureDhcpUp(ws.WiFiDevice) //nolint:errcheck
}
return nil

View File

@@ -5,6 +5,7 @@ import (
"sync"
"time"
"github.com/AvengeMedia/DankMaterialShell/core/internal/log"
"github.com/godbus/dbus/v5"
)
@@ -159,6 +160,7 @@ func (b *IWDBackend) OnUserCanceledPrompt() {
if cancelledSSID != "" {
if err := b.ForgetWiFiNetwork(cancelledSSID); err != nil {
log.Warnf("failed to forget cancelled WiFi network %s: %v", cancelledSSID, err)
}
}

View File

@@ -319,7 +319,6 @@ func handleConnection(conn net.Conn) {
capsData, _ := json.Marshal(caps)
conn.Write(capsData)
conn.Write([]byte("\n"))
scanner := bufio.NewScanner(conn)
for scanner.Scan() {
line := scanner.Bytes()

View File

@@ -72,10 +72,10 @@ func (m Model) viewSelectTerminal() string {
b.WriteString(title)
b.WriteString("\n\n")
options := []struct {
var options []struct {
name string
description string
}{}
}
if m.osInfo != nil && m.osInfo.Distribution.ID == "gentoo" {
options = []struct {

View File

@@ -7,6 +7,8 @@ import (
"os/exec"
"path/filepath"
"strings"
"github.com/AvengeMedia/DankMaterialShell/core/internal/log"
)
type VersionInfo struct {
@@ -33,7 +35,11 @@ func (d *DefaultVersionFetcher) GetCurrentVersion(dmsPath string) (string, error
if err != nil {
return "", err
}
defer os.Chdir(originalDir)
defer func() {
if err := os.Chdir(originalDir); err != nil {
log.Warnf("failed to change back to original directory: %v", err)
}
}()
if err := os.Chdir(dmsPath); err != nil {
return "", fmt.Errorf("failed to change to DMS directory: %w", err)
@@ -70,7 +76,11 @@ func (d *DefaultVersionFetcher) GetLatestVersion(dmsPath string) (string, error)
if err != nil {
return "", err
}
defer os.Chdir(originalDir)
defer func() {
if err := os.Chdir(originalDir); err != nil {
log.Warnf("failed to change back to original directory: %v", err)
}
}()
if err := os.Chdir(dmsPath); err != nil {
return "", fmt.Errorf("failed to change to DMS directory: %w", err)
@@ -85,7 +95,9 @@ func (d *DefaultVersionFetcher) GetLatestVersion(dmsPath string) (string, error)
if _, err := tagCmd.Output(); err == nil {
// Add timeout to git fetch to prevent hanging
fetchCmd := exec.Command("timeout", "5s", "git", "fetch", "origin", "--tags", "--quiet")
fetchCmd.Run()
if err := fetchCmd.Run(); err != nil {
log.Debugf("git fetch tags failed (continuing with local tags): %v", err)
}
latestTagCmd := exec.Command("git", "tag", "-l", "v*", "--sort=-version:refname")
latestTagOutput, err := latestTagCmd.Output()
@@ -109,7 +121,9 @@ func (d *DefaultVersionFetcher) GetLatestVersion(dmsPath string) (string, error)
// Add timeout to git fetch to prevent hanging
fetchCmd := exec.Command("timeout", "5s", "git", "fetch", "origin", currentBranch, "--quiet")
fetchCmd.Run()
if err := fetchCmd.Run(); err != nil {
log.Debugf("git fetch branch failed (continuing with local ref): %v", err)
}
remoteRevCmd := exec.Command("git", "rev-parse", "--short", fmt.Sprintf("origin/%s", currentBranch))
remoteRevOutput, err := remoteRevCmd.Output()
@@ -236,10 +250,10 @@ func CompareVersions(v1, v2 string) int {
for i := 0; i < maxLen; i++ {
var p1, p2 int
if i < len(parts1) {
fmt.Sscanf(parts1[i], "%d", &p1)
fmt.Sscanf(parts1[i], "%d", &p1) //nolint:errcheck
}
if i < len(parts2) {
fmt.Sscanf(parts2[i], "%d", &p2)
fmt.Sscanf(parts2[i], "%d", &p2) //nolint:errcheck
}
if p1 < p2 {