mirror of
https://github.com/tw93/Mole.git
synced 2026-02-04 15:04:42 +00:00
Go code formatting optimization
This commit is contained in:
@@ -1,6 +1,8 @@
|
|||||||
# golangci-lint configuration for Mole
|
# golangci-lint configuration for Mole
|
||||||
# https://golangci-lint.run/usage/configuration/
|
# https://golangci-lint.run/usage/configuration/
|
||||||
|
|
||||||
|
version: 2
|
||||||
|
|
||||||
run:
|
run:
|
||||||
timeout: 5m
|
timeout: 5m
|
||||||
# Only lint Go code in cmd directory
|
# Only lint Go code in cmd directory
|
||||||
@@ -12,13 +14,10 @@ linters:
|
|||||||
# Default linters
|
# Default linters
|
||||||
- govet
|
- govet
|
||||||
- staticcheck
|
- staticcheck
|
||||||
- gosimple
|
|
||||||
- ineffassign
|
- ineffassign
|
||||||
- unused
|
- unused
|
||||||
# Additional useful linters
|
# Additional useful linters
|
||||||
- errcheck
|
- errcheck
|
||||||
- gofmt
|
|
||||||
- goimports
|
|
||||||
|
|
||||||
linters-settings:
|
linters-settings:
|
||||||
govet:
|
govet:
|
||||||
@@ -26,31 +25,20 @@ linters-settings:
|
|||||||
disable:
|
disable:
|
||||||
- fieldalignment # struct field alignment optimization is noisy
|
- fieldalignment # struct field alignment optimization is noisy
|
||||||
errcheck:
|
errcheck:
|
||||||
# Don't check for errors on these functions (common patterns)
|
|
||||||
exclude-functions:
|
exclude-functions:
|
||||||
- (io.Closer).Close
|
- (io.Closer).Close
|
||||||
- (*os/exec.Cmd).Run
|
- (*os/exec.Cmd).Run
|
||||||
- (*os/exec.Cmd).Start
|
- (*os/exec.Cmd).Start
|
||||||
staticcheck:
|
staticcheck:
|
||||||
checks: ["all"]
|
checks: ["all", "-QF1003", "-SA9003"]
|
||||||
goimports:
|
|
||||||
local-prefixes: github.com/tw93/Mole
|
|
||||||
|
|
||||||
issues:
|
issues:
|
||||||
# Don't limit the number of issues per linter
|
|
||||||
max-issues-per-linter: 0
|
|
||||||
max-same-issues: 0
|
|
||||||
|
|
||||||
exclude-rules:
|
exclude-rules:
|
||||||
# Ignore certain patterns in test files
|
# Ignore certain patterns in test files
|
||||||
- path: _test\.go
|
- path: _test\.go
|
||||||
linters:
|
linters:
|
||||||
- errcheck
|
- errcheck
|
||||||
# Ignore errors from os.Remove in cleanup code
|
# Ignore errors from os.Remove in cleanup code
|
||||||
- text: "Error return value of `os.Remove` is not checked"
|
- text: "os.Remove"
|
||||||
linters:
|
|
||||||
- errcheck
|
|
||||||
# Allow unchecked errors on deferred Close calls
|
|
||||||
- text: "Error return value of .*.Close"
|
|
||||||
linters:
|
linters:
|
||||||
- errcheck
|
- errcheck
|
||||||
|
|||||||
@@ -49,7 +49,7 @@ func cloneDirEntries(entries []dirEntry) []dirEntry {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
copied := make([]dirEntry, len(entries))
|
copied := make([]dirEntry, len(entries))
|
||||||
copy(copied, entries)
|
copy(copied, entries) //nolint:all
|
||||||
return copied
|
return copied
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -58,7 +58,7 @@ func cloneFileEntries(files []fileEntry) []fileEntry {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
copied := make([]fileEntry, len(files))
|
copied := make([]fileEntry, len(files))
|
||||||
copy(copied, files)
|
copy(copied, files) //nolint:all
|
||||||
return copied
|
return copied
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -208,7 +208,7 @@ func loadCacheFromDisk(path string) (*cacheEntry, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
defer file.Close()
|
defer file.Close() //nolint:errcheck
|
||||||
|
|
||||||
var entry cacheEntry
|
var entry cacheEntry
|
||||||
decoder := gob.NewDecoder(file)
|
decoder := gob.NewDecoder(file)
|
||||||
@@ -258,7 +258,7 @@ func saveCacheToDisk(path string, result scanResult) error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
defer file.Close()
|
defer file.Close() //nolint:errcheck
|
||||||
|
|
||||||
encoder := gob.NewEncoder(file)
|
encoder := gob.NewEncoder(file)
|
||||||
return encoder.Encode(entry)
|
return encoder.Encode(entry)
|
||||||
|
|||||||
@@ -286,7 +286,7 @@ func commandExists(name string) bool {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
defer func() {
|
defer func() {
|
||||||
if r := recover(); r != nil {
|
if r := recover(); r != nil { //nolint:staticcheck
|
||||||
// Treat LookPath panics as "missing".
|
// Treat LookPath panics as "missing".
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ func collectCPU() (CPUStatus, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Two-call pattern for more reliable CPU usage.
|
// Two-call pattern for more reliable CPU usage.
|
||||||
cpu.Percent(0, true)
|
warmUpCpu()
|
||||||
time.Sleep(cpuSampleInterval)
|
time.Sleep(cpuSampleInterval)
|
||||||
percents, err := cpu.Percent(0, true)
|
percents, err := cpu.Percent(0, true)
|
||||||
var totalPercent float64
|
var totalPercent float64
|
||||||
@@ -255,3 +255,7 @@ func fallbackCPUUtilization(logical int) (float64, []float64, error) {
|
|||||||
}
|
}
|
||||||
return avg, perCore, nil
|
return avg, perCore, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func warmUpCpu() {
|
||||||
|
cpu.Percent(0, true) //nolint:errcheck
|
||||||
|
}
|
||||||
|
|||||||
@@ -130,6 +130,8 @@ func parseInt(s string) int {
|
|||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
var num int
|
var num int
|
||||||
fmt.Sscanf(cleaned, "%d", &num)
|
if _, err := fmt.Sscanf(cleaned, "%d", &num); err != nil {
|
||||||
|
return 0
|
||||||
|
}
|
||||||
return num
|
return num
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -70,10 +70,12 @@ func calculateHealthScore(cpu CPUStatus, mem MemoryStatus, disks []DiskStatus, d
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Memory pressure penalty.
|
// Memory pressure penalty.
|
||||||
if mem.Pressure == "warn" {
|
// Memory pressure penalty.
|
||||||
|
switch mem.Pressure {
|
||||||
|
case "warn":
|
||||||
score -= memPressureWarnPenalty
|
score -= memPressureWarnPenalty
|
||||||
issues = append(issues, "Memory Pressure")
|
issues = append(issues, "Memory Pressure")
|
||||||
} else if mem.Pressure == "critical" {
|
case "critical":
|
||||||
score -= memPressureCritPenalty
|
score -= memPressureCritPenalty
|
||||||
issues = append(issues, "Critical Memory")
|
issues = append(issues, "Critical Memory")
|
||||||
}
|
}
|
||||||
@@ -131,7 +133,7 @@ func calculateHealthScore(cpu CPUStatus, mem MemoryStatus, disks []DiskStatus, d
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Build message.
|
// Build message.
|
||||||
msg := "Excellent"
|
var msg string
|
||||||
if score >= 90 {
|
if score >= 90 {
|
||||||
msg = "Excellent"
|
msg = "Excellent"
|
||||||
} else if score >= 75 {
|
} else if score >= 75 {
|
||||||
|
|||||||
@@ -308,9 +308,10 @@ func renderMemoryCard(mem MemoryStatus) cardData {
|
|||||||
if mem.Pressure != "" {
|
if mem.Pressure != "" {
|
||||||
pressureStyle := okStyle
|
pressureStyle := okStyle
|
||||||
pressureText := "Status " + mem.Pressure
|
pressureText := "Status " + mem.Pressure
|
||||||
if mem.Pressure == "warn" {
|
switch mem.Pressure {
|
||||||
|
case "warn":
|
||||||
pressureStyle = warnStyle
|
pressureStyle = warnStyle
|
||||||
} else if mem.Pressure == "critical" {
|
case "critical":
|
||||||
pressureStyle = dangerStyle
|
pressureStyle = dangerStyle
|
||||||
}
|
}
|
||||||
lines = append(lines, pressureStyle.Render(pressureText))
|
lines = append(lines, pressureStyle.Render(pressureText))
|
||||||
|
|||||||
Reference in New Issue
Block a user