Fix lint errors

This commit is contained in:
世界
2026-05-14 22:53:22 +08:00
parent 4b55717612
commit 2c2e08e608
38 changed files with 284 additions and 333 deletions
+6 -6
View File
@@ -220,20 +220,20 @@ func parseISCDhcpd(file *os.File, ipToMAC map[netip.Addr]net.HardwareAddr, ipToH
if !inLease {
continue
}
if strings.HasPrefix(line, "hardware ethernet ") {
macString := strings.TrimSuffix(strings.TrimPrefix(line, "hardware ethernet "), ";")
if rest, ok := strings.CutPrefix(line, "hardware ethernet "); ok {
macString := strings.TrimSuffix(rest, ";")
parsed, macErr := net.ParseMAC(macString)
if macErr == nil {
currentMAC = parsed
}
} else if strings.HasPrefix(line, "client-hostname ") {
hostname := strings.TrimSuffix(strings.TrimPrefix(line, "client-hostname "), ";")
} else if rest, ok := strings.CutPrefix(line, "client-hostname "); ok {
hostname := strings.TrimSuffix(rest, ";")
hostname = strings.Trim(hostname, "\"")
if hostname != "" {
currentHostname = hostname
}
} else if strings.HasPrefix(line, "binding state ") {
state := strings.TrimSuffix(strings.TrimPrefix(line, "binding state "), ";")
} else if rest, ok := strings.CutPrefix(line, "binding state "); ok {
state := strings.TrimSuffix(rest, ";")
currentActive = state == "active"
}
}
+2 -6
View File
@@ -2,6 +2,7 @@ package rule
import (
"net/netip"
"slices"
"strings"
"github.com/sagernet/sing-box/adapter"
@@ -84,12 +85,7 @@ func (r *IPCIDRItem) Match(metadata *adapter.InboundContext) bool {
// does not expose any address answers for matching.
return metadata.IPCIDRAcceptEmpty
}
for _, address := range addresses {
if r.ipSet.Contains(address) {
return true
}
}
return false
return slices.ContainsFunc(addresses, r.ipSet.Contains)
}
if metadata.Destination.IsIP() {
return r.ipSet.Contains(metadata.Destination.Addr)
+3 -4
View File
@@ -2,6 +2,7 @@ package rule
import (
"regexp"
"slices"
"strings"
"github.com/sagernet/sing-box/adapter"
@@ -42,10 +43,8 @@ func (r *PackageNameRegexItem) Match(metadata *adapter.InboundContext) bool {
return false
}
for _, matcher := range r.matchers {
for _, packageName := range metadata.ProcessInfo.AndroidPackageNames {
if matcher.MatchString(packageName) {
return true
}
if slices.ContainsFunc(metadata.ProcessInfo.AndroidPackageNames, matcher.MatchString) {
return true
}
}
return false
+3 -4
View File
@@ -1,6 +1,7 @@
package rule
import (
"slices"
"strings"
"github.com/sagernet/sing-box/adapter"
@@ -31,10 +32,8 @@ func (r *DNSResponseRecordItem) Match(metadata *adapter.InboundContext) bool {
}
records := r.selector(metadata.DNSResponse)
for _, expected := range r.records {
for _, record := range records {
if expected.Match(record) {
return true
}
if slices.ContainsFunc(records, expected.Match) {
return true
}
}
return false
-3
View File
@@ -769,7 +769,6 @@ func TestDNSAddressLimitIgnoresDestinationAddresses(t *testing.T) {
},
}
for _, testCase := range testCases {
testCase := testCase
t.Run(testCase.name, func(t *testing.T) {
t.Parallel()
rule := dnsRuleForTest(func(rule *abstractDefaultRule) {
@@ -825,7 +824,6 @@ func TestDNSLegacyAddressLimitPreLookupDefersDirectRules(t *testing.T) {
},
}
for _, testCase := range testCases {
testCase := testCase
t.Run(testCase.name, func(t *testing.T) {
t.Parallel()
@@ -925,7 +923,6 @@ func TestDNSLegacyInvertAddressLimitPreLookupRegression(t *testing.T) {
},
}
for _, testCase := range testCases {
testCase := testCase
t.Run(testCase.name, func(t *testing.T) {
t.Parallel()