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

core: apply gopls automatic modernizers (#1198)

This commit is contained in:
Marcus Ramberg
2025-12-29 03:48:56 +01:00
committed by GitHub
parent c281bf3b53
commit ae82716afa
16 changed files with 71 additions and 98 deletions

View File

@@ -179,7 +179,7 @@ func runBrightnessList(cmd *cobra.Command, args []string) {
fmt.Printf("%-*s %-12s %-*s %s\n", idPad, "Device", "Class", namePad, "Name", "Brightness") fmt.Printf("%-*s %-12s %-*s %s\n", idPad, "Device", "Class", namePad, "Name", "Brightness")
sepLen := idPad + 2 + 12 + 2 + namePad + 2 + 15 sepLen := idPad + 2 + 12 + 2 + namePad + 2 + 15
for i := 0; i < sepLen; i++ { for range sepLen {
fmt.Print("─") fmt.Print("─")
} }
fmt.Println() fmt.Println()

View File

@@ -377,7 +377,7 @@ func updateDMSBinary() error {
} }
version := "" version := ""
for _, line := range strings.Split(string(output), "\n") { for line := range strings.SplitSeq(string(output), "\n") {
if strings.Contains(line, "\"tag_name\"") { if strings.Contains(line, "\"tag_name\"") {
parts := strings.Split(line, "\"") parts := strings.Split(line, "\"")
if len(parts) >= 4 { if len(parts) >= 4 {
@@ -443,7 +443,7 @@ func updateDMSBinary() error {
decompressedPath := filepath.Join(tempDir, "dms") decompressedPath := filepath.Join(tempDir, "dms")
if err := os.Chmod(decompressedPath, 0755); err != nil { if err := os.Chmod(decompressedPath, 0o755); err != nil {
return fmt.Errorf("failed to make binary executable: %w", err) return fmt.Errorf("failed to make binary executable: %w", err)
} }

View File

@@ -211,8 +211,8 @@ func checkGroupExists(groupName string) bool {
return false return false
} }
lines := strings.Split(string(data), "\n") lines := strings.SplitSeq(string(data), "\n")
for _, line := range lines { for line := range lines {
if strings.HasPrefix(line, groupName+":") { if strings.HasPrefix(line, groupName+":") {
return true return true
} }
@@ -521,7 +521,7 @@ func enableGreeter() error {
newConfig := strings.Join(finalLines, "\n") newConfig := strings.Join(finalLines, "\n")
tmpFile := "/tmp/greetd-config.toml" tmpFile := "/tmp/greetd-config.toml"
if err := os.WriteFile(tmpFile, []byte(newConfig), 0644); err != nil { if err := os.WriteFile(tmpFile, []byte(newConfig), 0o644); err != nil {
return fmt.Errorf("failed to write temp config: %w", err) return fmt.Errorf("failed to write temp config: %w", err)
} }
@@ -592,8 +592,8 @@ func checkGreeterStatus() error {
if data, err := os.ReadFile(configPath); err == nil { if data, err := os.ReadFile(configPath); err == nil {
configContent := string(data) configContent := string(data)
if strings.Contains(configContent, "dms-greeter") { if strings.Contains(configContent, "dms-greeter") {
lines := strings.Split(configContent, "\n") lines := strings.SplitSeq(configContent, "\n")
for _, line := range lines { for line := range lines {
trimmed := strings.TrimSpace(line) trimmed := strings.TrimSpace(line)
if strings.HasPrefix(trimmed, "command =") || strings.HasPrefix(trimmed, "command=") { if strings.HasPrefix(trimmed, "command =") || strings.HasPrefix(trimmed, "command=") {
parts := strings.SplitN(trimmed, "=", 2) parts := strings.SplitN(trimmed, "=", 2)

View File

@@ -87,20 +87,14 @@ func newDPMSClient() (*dpmsClient, error) {
switch e.Interface { switch e.Interface {
case wlr_output_power.ZwlrOutputPowerManagerV1InterfaceName: case wlr_output_power.ZwlrOutputPowerManagerV1InterfaceName:
powerMgr := wlr_output_power.NewZwlrOutputPowerManagerV1(c.ctx) powerMgr := wlr_output_power.NewZwlrOutputPowerManagerV1(c.ctx)
version := e.Version version := min(e.Version, 1)
if version > 1 {
version = 1
}
if err := registry.Bind(e.Name, e.Interface, version, powerMgr); err == nil { if err := registry.Bind(e.Name, e.Interface, version, powerMgr); err == nil {
c.powerMgr = powerMgr c.powerMgr = powerMgr
} }
case "wl_output": case "wl_output":
output := wlclient.NewOutput(c.ctx) output := wlclient.NewOutput(c.ctx)
version := e.Version version := min(e.Version, 4)
if version > 4 {
version = 4
}
if err := registry.Bind(e.Name, e.Interface, version, output); err == nil { if err := registry.Bind(e.Name, e.Interface, version, output); err == nil {
outputID := fmt.Sprintf("output-%d", output.ID()) outputID := fmt.Sprintf("output-%d", output.ID())
state := &outputState{ state := &outputState{

View File

@@ -7,6 +7,7 @@ import (
"os/exec" "os/exec"
"os/signal" "os/signal"
"path/filepath" "path/filepath"
"slices"
"strconv" "strconv"
"strings" "strings"
"syscall" "syscall"
@@ -371,13 +372,7 @@ func killShell() {
func runShellDaemon(session bool) { func runShellDaemon(session bool) {
isSessionManaged = session isSessionManaged = session
isDaemonChild := false isDaemonChild := slices.Contains(os.Args, "--daemon-child")
for _, arg := range os.Args {
if arg == "--daemon-child" {
isDaemonChild = true
break
}
}
if !isDaemonChild { if !isDaemonChild {
fmt.Fprintf(os.Stderr, "dms %s\n", Version) fmt.Fprintf(os.Stderr, "dms %s\n", Version)
@@ -534,9 +529,9 @@ func runShellDaemon(session bool) {
func parseTargetsFromIPCShowOutput(output string) ipcTargets { func parseTargetsFromIPCShowOutput(output string) ipcTargets {
targets := make(ipcTargets) targets := make(ipcTargets)
var currentTarget string var currentTarget string
for _, line := range strings.Split(output, "\n") { for line := range strings.SplitSeq(output, "\n") {
if strings.HasPrefix(line, "target ") { if after, ok := strings.CutPrefix(line, "target "); ok {
currentTarget = strings.TrimSpace(strings.TrimPrefix(line, "target ")) currentTarget = strings.TrimSpace(after)
targets[currentTarget] = make(map[string][]string) targets[currentTarget] = make(map[string][]string)
} }
if strings.HasPrefix(line, " function") && currentTarget != "" { if strings.HasPrefix(line, " function") && currentTarget != "" {

View File

@@ -3,6 +3,7 @@ package main
import ( import (
"fmt" "fmt"
"os/exec" "os/exec"
"slices"
"strings" "strings"
) )
@@ -36,13 +37,7 @@ func checkSystemdServiceEnabled(serviceName string) (string, bool, error) {
if err != nil { if err != nil {
knownStates := []string{"disabled", "masked", "masked-runtime", "not-found", "enabled", "enabled-runtime", "static", "indirect", "alias"} knownStates := []string{"disabled", "masked", "masked-runtime", "not-found", "enabled", "enabled-runtime", "static", "indirect", "alias"}
isKnownState := false isKnownState := slices.Contains(knownStates, stateStr)
for _, known := range knownStates {
if stateStr == known {
isKnownState = true
break
}
}
if !isKnownState { if !isKnownState {
return stateStr, false, fmt.Errorf("systemctl is-enabled failed: %w (output: %s)", err, stateStr) return stateStr, false, fmt.Errorf("systemctl is-enabled failed: %w (output: %s)", err, stateStr)

View File

@@ -221,10 +221,7 @@ func (p *Picker) handleGlobal(e client.RegistryGlobalEvent) {
case client.OutputInterfaceName: case client.OutputInterfaceName:
output := client.NewOutput(p.ctx) output := client.NewOutput(p.ctx)
version := e.Version version := min(e.Version, 4)
if version > 4 {
version = 4
}
if err := p.registry.Bind(e.Name, e.Interface, version, output); err == nil { if err := p.registry.Bind(e.Name, e.Interface, version, output); err == nil {
p.outputsMu.Lock() p.outputsMu.Lock()
p.outputs[e.Name] = &Output{ p.outputs[e.Name] = &Output{
@@ -239,20 +236,14 @@ func (p *Picker) handleGlobal(e client.RegistryGlobalEvent) {
case wlr_layer_shell.ZwlrLayerShellV1InterfaceName: case wlr_layer_shell.ZwlrLayerShellV1InterfaceName:
layerShell := wlr_layer_shell.NewZwlrLayerShellV1(p.ctx) layerShell := wlr_layer_shell.NewZwlrLayerShellV1(p.ctx)
version := e.Version version := min(e.Version, 4)
if version > 4 {
version = 4
}
if err := p.registry.Bind(e.Name, e.Interface, version, layerShell); err == nil { if err := p.registry.Bind(e.Name, e.Interface, version, layerShell); err == nil {
p.layerShell = layerShell p.layerShell = layerShell
} }
case wlr_screencopy.ZwlrScreencopyManagerV1InterfaceName: case wlr_screencopy.ZwlrScreencopyManagerV1InterfaceName:
screencopy := wlr_screencopy.NewZwlrScreencopyManagerV1(p.ctx) screencopy := wlr_screencopy.NewZwlrScreencopyManagerV1(p.ctx)
version := e.Version version := min(e.Version, 3)
if version > 3 {
version = 3
}
if err := p.registry.Bind(e.Name, e.Interface, version, screencopy); err == nil { if err := p.registry.Bind(e.Name, e.Interface, version, screencopy); err == nil {
p.screencopy = screencopy p.screencopy = screencopy
} }

View File

@@ -1157,7 +1157,7 @@ func drawGlyph(data []byte, stride, width, height, x, y int, r rune, col Color,
rOff, bOff = 2, 0 rOff, bOff = 2, 0
} }
for row := 0; row < fontH; row++ { for row := range fontH {
yy := y + row yy := y + row
if yy < 0 || yy >= height { if yy < 0 || yy >= height {
continue continue
@@ -1165,7 +1165,7 @@ func drawGlyph(data []byte, stride, width, height, x, y int, r rune, col Color,
rowPattern := g[row] rowPattern := g[row]
dstRowOff := yy * stride dstRowOff := yy * stride
for colIdx := 0; colIdx < fontW; colIdx++ { for colIdx := range fontW {
if (rowPattern & (1 << (fontW - 1 - colIdx))) == 0 { if (rowPattern & (1 << (fontW - 1 - colIdx))) == 0 {
continue continue
} }

View File

@@ -14,11 +14,11 @@ func TestSurfaceState_ConcurrentPointerMotion(t *testing.T) {
const goroutines = 50 const goroutines = 50
const iterations = 100 const iterations = 100
for i := 0; i < goroutines; i++ { for i := range goroutines {
wg.Add(1) wg.Add(1)
go func(id int) { go func(id int) {
defer wg.Done() defer wg.Done()
for j := 0; j < iterations; j++ { for j := range iterations {
s.OnPointerMotion(float64(id*10+j), float64(id*10+j)) s.OnPointerMotion(float64(id*10+j), float64(id*10+j))
} }
}(i) }(i)
@@ -34,21 +34,21 @@ func TestSurfaceState_ConcurrentScaleAccess(t *testing.T) {
const goroutines = 30 const goroutines = 30
const iterations = 100 const iterations = 100
for i := 0; i < goroutines/2; i++ { for i := range goroutines / 2 {
wg.Add(1) wg.Add(1)
go func(id int) { go func(id int) {
defer wg.Done() defer wg.Done()
for j := 0; j < iterations; j++ { for range iterations {
s.SetScale(int32(id%3 + 1)) s.SetScale(int32(id%3 + 1))
} }
}(i) }(i)
} }
for i := 0; i < goroutines/2; i++ { for range goroutines / 2 {
wg.Add(1) wg.Add(1)
go func() { go func() {
defer wg.Done() defer wg.Done()
for j := 0; j < iterations; j++ { for range iterations {
scale := s.Scale() scale := s.Scale()
assert.GreaterOrEqual(t, scale, int32(1)) assert.GreaterOrEqual(t, scale, int32(1))
} }
@@ -65,21 +65,21 @@ func TestSurfaceState_ConcurrentLogicalSize(t *testing.T) {
const goroutines = 20 const goroutines = 20
const iterations = 100 const iterations = 100
for i := 0; i < goroutines/2; i++ { for i := range goroutines / 2 {
wg.Add(1) wg.Add(1)
go func(id int) { go func(id int) {
defer wg.Done() defer wg.Done()
for j := 0; j < iterations; j++ { for j := range iterations {
_ = s.OnLayerConfigure(1920+id, 1080+j) _ = s.OnLayerConfigure(1920+id, 1080+j)
} }
}(i) }(i)
} }
for i := 0; i < goroutines/2; i++ { for range goroutines / 2 {
wg.Add(1) wg.Add(1)
go func() { go func() {
defer wg.Done() defer wg.Done()
for j := 0; j < iterations; j++ { for range iterations {
w, h := s.LogicalSize() w, h := s.LogicalSize()
_ = w _ = w
_ = h _ = h
@@ -97,31 +97,31 @@ func TestSurfaceState_ConcurrentIsDone(t *testing.T) {
const goroutines = 30 const goroutines = 30
const iterations = 100 const iterations = 100
for i := 0; i < goroutines/3; i++ { for range goroutines / 3 {
wg.Add(1) wg.Add(1)
go func() { go func() {
defer wg.Done() defer wg.Done()
for j := 0; j < iterations; j++ { for range iterations {
s.OnPointerButton(0x110, 1) s.OnPointerButton(0x110, 1)
} }
}() }()
} }
for i := 0; i < goroutines/3; i++ { for range goroutines / 3 {
wg.Add(1) wg.Add(1)
go func() { go func() {
defer wg.Done() defer wg.Done()
for j := 0; j < iterations; j++ { for range iterations {
s.OnKey(1, 1) s.OnKey(1, 1)
} }
}() }()
} }
for i := 0; i < goroutines/3; i++ { for range goroutines / 3 {
wg.Add(1) wg.Add(1)
go func() { go func() {
defer wg.Done() defer wg.Done()
for j := 0; j < iterations; j++ { for range iterations {
picked, cancelled := s.IsDone() picked, cancelled := s.IsDone()
_ = picked _ = picked
_ = cancelled _ = cancelled
@@ -139,11 +139,11 @@ func TestSurfaceState_ConcurrentIsReady(t *testing.T) {
const goroutines = 20 const goroutines = 20
const iterations = 100 const iterations = 100
for i := 0; i < goroutines; i++ { for range goroutines {
wg.Add(1) wg.Add(1)
go func() { go func() {
defer wg.Done() defer wg.Done()
for j := 0; j < iterations; j++ { for range iterations {
_ = s.IsReady() _ = s.IsReady()
} }
}() }()
@@ -159,11 +159,11 @@ func TestSurfaceState_ConcurrentSwapBuffers(t *testing.T) {
const goroutines = 20 const goroutines = 20
const iterations = 100 const iterations = 100
for i := 0; i < goroutines; i++ { for range goroutines {
wg.Add(1) wg.Add(1)
go func() { go func() {
defer wg.Done() defer wg.Done()
for j := 0; j < iterations; j++ { for range iterations {
s.SwapBuffers() s.SwapBuffers()
} }
}() }()

View File

@@ -21,7 +21,7 @@ func LocateDMSConfig() (string, error) {
dataDirs = "/usr/local/share:/usr/share" dataDirs = "/usr/local/share:/usr/share"
} }
for _, dir := range strings.Split(dataDirs, ":") { for dir := range strings.SplitSeq(dataDirs, ":") {
if dir != "" { if dir != "" {
primaryPaths = append(primaryPaths, filepath.Join(dir, "quickshell", "dms")) primaryPaths = append(primaryPaths, filepath.Join(dir, "quickshell", "dms"))
} }
@@ -33,7 +33,7 @@ func LocateDMSConfig() (string, error) {
configDirs = "/etc/xdg" configDirs = "/etc/xdg"
} }
for _, dir := range strings.Split(configDirs, ":") { for dir := range strings.SplitSeq(configDirs, ":") {
if dir != "" { if dir != "" {
primaryPaths = append(primaryPaths, filepath.Join(dir, "quickshell", "dms")) primaryPaths = append(primaryPaths, filepath.Join(dir, "quickshell", "dms"))
} }

View File

@@ -345,7 +345,7 @@ func EnsureContrastDPSLstar(hexColor, hexBg string, minLc float64, isLightMode b
} }
step := 0.5 step := 0.5
for i := 0; i < 120; i++ { for range 120 {
Lf = math.Max(0, math.Min(100, Lf+dir*step)) Lf = math.Max(0, math.Min(100, Lf+dir*step))
cand := labToHex(Lf, af, bf) cand := labToHex(Lf, af, bf)
if DeltaPhiStarContrast(cand, hexBg, isLightMode) >= minLc { if DeltaPhiStarContrast(cand, hexBg, isLightMode) >= minLc {

View File

@@ -658,7 +658,7 @@ func TestContrastAlgorithmComparison(t *testing.T) {
} }
differentCount := 0 differentCount := 0
for i := 0; i < 16; i++ { for i := range 16 {
if wcagColors[i].Hex != dpsColors[i].Hex { if wcagColors[i].Hex != dpsColors[i].Hex {
differentCount++ differentCount++
} }

View File

@@ -7,6 +7,7 @@ import (
"os/exec" "os/exec"
"path/filepath" "path/filepath"
"runtime" "runtime"
"slices"
"strings" "strings"
"github.com/AvengeMedia/DankMaterialShell/core/internal/deps" "github.com/AvengeMedia/DankMaterialShell/core/internal/deps"
@@ -514,12 +515,9 @@ func (a *ArchDistribution) reorderAURPackages(packages []string) []string {
dmsShell = append(dmsShell, pkg) dmsShell = append(dmsShell, pkg)
} else { } else {
isDep := false isDep := false
for _, dep := range dmsDepencies { if slices.Contains(dmsDepencies, pkg) {
if pkg == dep { deps = append(deps, pkg)
deps = append(deps, pkg) isDep = true
isDep = true
break
}
} }
if !isDep { if !isDep {
others = append(others, pkg) others = append(others, pkg)
@@ -545,7 +543,7 @@ func (a *ArchDistribution) installSingleAURPackage(ctx context.Context, pkg, sud
a.log(fmt.Sprintf("Warning: failed to clean existing cache for %s: %v", pkg, err)) a.log(fmt.Sprintf("Warning: failed to clean existing cache for %s: %v", pkg, err))
} }
if err := os.MkdirAll(buildDir, 0755); err != nil { if err := os.MkdirAll(buildDir, 0o755); err != nil {
return fmt.Errorf("failed to create build directory: %w", err) return fmt.Errorf("failed to create build directory: %w", err)
} }
defer func() { defer func() {

View File

@@ -18,8 +18,8 @@ type ManualPackageInstaller struct {
// parseLatestTagFromGitOutput parses git ls-remote output and returns the latest tag // parseLatestTagFromGitOutput parses git ls-remote output and returns the latest tag
func (m *ManualPackageInstaller) parseLatestTagFromGitOutput(output string) string { func (m *ManualPackageInstaller) parseLatestTagFromGitOutput(output string) string {
lines := strings.Split(output, "\n") lines := strings.SplitSeq(output, "\n")
for _, line := range lines { for line := range lines {
if strings.Contains(line, "refs/tags/") && !strings.Contains(line, "^{}") { if strings.Contains(line, "refs/tags/") && !strings.Contains(line, "^{}") {
parts := strings.Split(line, "refs/tags/") parts := strings.Split(line, "refs/tags/")
if len(parts) > 1 { if len(parts) > 1 {
@@ -103,12 +103,12 @@ func (m *ManualPackageInstaller) installDgop(ctx context.Context, sudoPassword s
} }
cacheDir := filepath.Join(homeDir, ".cache", "dankinstall") cacheDir := filepath.Join(homeDir, ".cache", "dankinstall")
if err := os.MkdirAll(cacheDir, 0755); err != nil { if err := os.MkdirAll(cacheDir, 0o755); err != nil {
return fmt.Errorf("failed to create cache directory: %w", err) return fmt.Errorf("failed to create cache directory: %w", err)
} }
tmpDir := filepath.Join(cacheDir, "dgop-build") tmpDir := filepath.Join(cacheDir, "dgop-build")
if err := os.MkdirAll(tmpDir, 0755); err != nil { if err := os.MkdirAll(tmpDir, 0o755); err != nil {
return fmt.Errorf("failed to create temp directory: %w", err) return fmt.Errorf("failed to create temp directory: %w", err)
} }
defer os.RemoveAll(tmpDir) defer os.RemoveAll(tmpDir)
@@ -160,10 +160,10 @@ func (m *ManualPackageInstaller) installNiri(ctx context.Context, sudoPassword s
homeDir, _ := os.UserHomeDir() homeDir, _ := os.UserHomeDir()
buildDir := filepath.Join(homeDir, ".cache", "dankinstall", "niri-build") buildDir := filepath.Join(homeDir, ".cache", "dankinstall", "niri-build")
tmpDir := filepath.Join(homeDir, ".cache", "dankinstall", "tmp") tmpDir := filepath.Join(homeDir, ".cache", "dankinstall", "tmp")
if err := os.MkdirAll(buildDir, 0755); err != nil { if err := os.MkdirAll(buildDir, 0o755); err != nil {
return fmt.Errorf("failed to create build directory: %w", err) return fmt.Errorf("failed to create build directory: %w", err)
} }
if err := os.MkdirAll(tmpDir, 0755); err != nil { if err := os.MkdirAll(tmpDir, 0o755); err != nil {
return fmt.Errorf("failed to create temp directory: %w", err) return fmt.Errorf("failed to create temp directory: %w", err)
} }
defer func() { defer func() {
@@ -237,12 +237,12 @@ func (m *ManualPackageInstaller) installQuickshell(ctx context.Context, variant
} }
cacheDir := filepath.Join(homeDir, ".cache", "dankinstall") cacheDir := filepath.Join(homeDir, ".cache", "dankinstall")
if err := os.MkdirAll(cacheDir, 0755); err != nil { if err := os.MkdirAll(cacheDir, 0o755); err != nil {
return fmt.Errorf("failed to create cache directory: %w", err) return fmt.Errorf("failed to create cache directory: %w", err)
} }
tmpDir := filepath.Join(cacheDir, "quickshell-build") tmpDir := filepath.Join(cacheDir, "quickshell-build")
if err := os.MkdirAll(tmpDir, 0755); err != nil { if err := os.MkdirAll(tmpDir, 0o755); err != nil {
return fmt.Errorf("failed to create temp directory: %w", err) return fmt.Errorf("failed to create temp directory: %w", err)
} }
defer os.RemoveAll(tmpDir) defer os.RemoveAll(tmpDir)
@@ -273,7 +273,7 @@ func (m *ManualPackageInstaller) installQuickshell(ctx context.Context, variant
} }
buildDir := tmpDir + "/build" buildDir := tmpDir + "/build"
if err := os.MkdirAll(buildDir, 0755); err != nil { if err := os.MkdirAll(buildDir, 0o755); err != nil {
return fmt.Errorf("failed to create build directory: %w", err) return fmt.Errorf("failed to create build directory: %w", err)
} }
@@ -343,12 +343,12 @@ func (m *ManualPackageInstaller) installHyprland(ctx context.Context, sudoPasswo
} }
cacheDir := filepath.Join(homeDir, ".cache", "dankinstall") cacheDir := filepath.Join(homeDir, ".cache", "dankinstall")
if err := os.MkdirAll(cacheDir, 0755); err != nil { if err := os.MkdirAll(cacheDir, 0o755); err != nil {
return fmt.Errorf("failed to create cache directory: %w", err) return fmt.Errorf("failed to create cache directory: %w", err)
} }
tmpDir := filepath.Join(cacheDir, "hyprland-build") tmpDir := filepath.Join(cacheDir, "hyprland-build")
if err := os.MkdirAll(tmpDir, 0755); err != nil { if err := os.MkdirAll(tmpDir, 0o755); err != nil {
return fmt.Errorf("failed to create temp directory: %w", err) return fmt.Errorf("failed to create temp directory: %w", err)
} }
defer os.RemoveAll(tmpDir) defer os.RemoveAll(tmpDir)
@@ -406,12 +406,12 @@ func (m *ManualPackageInstaller) installGhostty(ctx context.Context, sudoPasswor
} }
cacheDir := filepath.Join(homeDir, ".cache", "dankinstall") cacheDir := filepath.Join(homeDir, ".cache", "dankinstall")
if err := os.MkdirAll(cacheDir, 0755); err != nil { if err := os.MkdirAll(cacheDir, 0o755); err != nil {
return fmt.Errorf("failed to create cache directory: %w", err) return fmt.Errorf("failed to create cache directory: %w", err)
} }
tmpDir := filepath.Join(cacheDir, "ghostty-build") tmpDir := filepath.Join(cacheDir, "ghostty-build")
if err := os.MkdirAll(tmpDir, 0755); err != nil { if err := os.MkdirAll(tmpDir, 0o755); err != nil {
return fmt.Errorf("failed to create temp directory: %w", err) return fmt.Errorf("failed to create temp directory: %w", err)
} }
defer os.RemoveAll(tmpDir) defer os.RemoveAll(tmpDir)
@@ -528,7 +528,7 @@ func (m *ManualPackageInstaller) installDankMaterialShell(ctx context.Context, v
} }
configDir := filepath.Dir(dmsPath) configDir := filepath.Dir(dmsPath)
if err := os.MkdirAll(configDir, 0755); err != nil { if err := os.MkdirAll(configDir, 0o755); err != nil {
return fmt.Errorf("failed to create quickshell config directory: %w", err) return fmt.Errorf("failed to create quickshell config directory: %w", err)
} }

View File

@@ -23,7 +23,7 @@ func DefaultDiscoveryConfig() *DiscoveryConfig {
configDirs := os.Getenv("XDG_CONFIG_DIRS") configDirs := os.Getenv("XDG_CONFIG_DIRS")
if configDirs != "" { if configDirs != "" {
for _, dir := range strings.Split(configDirs, ":") { for dir := range strings.SplitSeq(configDirs, ":") {
if dir != "" { if dir != "" {
searchPaths = append(searchPaths, filepath.Join(dir, "DankMaterialShell", "cheatsheets")) searchPaths = append(searchPaths, filepath.Join(dir, "DankMaterialShell", "cheatsheets"))
} }

View File

@@ -12,7 +12,7 @@ func TestNewJSONFileProvider(t *testing.T) {
tmpDir := t.TempDir() tmpDir := t.TempDir()
testFile := filepath.Join(tmpDir, "test.json") testFile := filepath.Join(tmpDir, "test.json")
if err := os.WriteFile(testFile, []byte("{}"), 0644); err != nil { if err := os.WriteFile(testFile, []byte("{}"), 0o644); err != nil {
t.Fatalf("Failed to create test file: %v", err) t.Fatalf("Failed to create test file: %v", err)
} }
@@ -81,7 +81,7 @@ func TestJSONFileProviderGetCheatSheet(t *testing.T) {
} }
}` }`
if err := os.WriteFile(testFile, []byte(content), 0644); err != nil { if err := os.WriteFile(testFile, []byte(content), 0o644); err != nil {
t.Fatalf("Failed to write test file: %v", err) t.Fatalf("Failed to write test file: %v", err)
} }
@@ -135,7 +135,7 @@ func TestJSONFileProviderGetCheatSheetNoProvider(t *testing.T) {
"binds": {} "binds": {}
}` }`
if err := os.WriteFile(testFile, []byte(content), 0644); err != nil { if err := os.WriteFile(testFile, []byte(content), 0o644); err != nil {
t.Fatalf("Failed to write test file: %v", err) t.Fatalf("Failed to write test file: %v", err)
} }
@@ -181,7 +181,7 @@ func TestJSONFileProviderFlatArrayBackwardsCompat(t *testing.T) {
] ]
}` }`
if err := os.WriteFile(testFile, []byte(content), 0644); err != nil { if err := os.WriteFile(testFile, []byte(content), 0o644); err != nil {
t.Fatalf("Failed to write test file: %v", err) t.Fatalf("Failed to write test file: %v", err)
} }
@@ -216,7 +216,7 @@ func TestJSONFileProviderInvalidJSON(t *testing.T) {
tmpDir := t.TempDir() tmpDir := t.TempDir()
testFile := filepath.Join(tmpDir, "invalid.json") testFile := filepath.Join(tmpDir, "invalid.json")
if err := os.WriteFile(testFile, []byte("not valid json"), 0644); err != nil { if err := os.WriteFile(testFile, []byte("not valid json"), 0o644); err != nil {
t.Fatalf("Failed to write test file: %v", err) t.Fatalf("Failed to write test file: %v", err)
} }