fix: fixed swiftlint warnings (#1386)

This commit is contained in:
Serhiy Mytrovtsiy
2023-04-01 16:58:05 +02:00
parent 4314de533c
commit 3c9a3722bf
20 changed files with 75 additions and 89 deletions

View File

@@ -7,6 +7,7 @@ disabled_rules:
- implicit_getter
- redundant_optional_initialization
- large_tuple
- function_body_length
opt_in_rules:
- control_statement
@@ -40,13 +41,9 @@ identifier_name:
line_length: 200
function_body_length:
- 80
- 100
type_body_length:
- 450
- 600
- 500
- 700
file_length:
- 1200

View File

@@ -89,7 +89,6 @@ public class BarChart: WidgetWrapper {
fatalError("init(coder:) has not been implemented")
}
// swiftlint:disable function_body_length
public override func draw(_ dirtyRect: NSRect) {
super.draw(dirtyRect)

View File

@@ -8,7 +8,6 @@
//
// Copyright © 2020 Serhiy Mytrovtsiy. All rights reserved.
//
// swiftlint:disable function_body_length
import Cocoa

View File

@@ -499,7 +499,7 @@ public class SpeedWidget: WidgetWrapper {
Store.shared.set(key: "\(self.title)_\(self.type.rawValue)_value", value: self.valueState)
self.display()
if !self.valueState && self.icon == .none {
if !self.valueState && self.icon.isEmpty {
NotificationCenter.default.post(name: .toggleModule, object: nil, userInfo: ["module": self.title, "state": false])
self.state = false
} else if !self.state {

View File

@@ -728,8 +728,7 @@ public extension UnitTemperature {
}
}
// swiftlint:disable identifier_name
public func Temperature(_ value: Double, defaultUnit: UnitTemperature = UnitTemperature.celsius, fractionDigits: Int = 0) -> String {
public func temperature(_ value: Double, defaultUnit: UnitTemperature = UnitTemperature.celsius, fractionDigits: Int = 0) -> String {
let formatter = MeasurementFormatter()
formatter.locale = Locale.init(identifier: "en_US")
formatter.numberFormatter.maximumFractionDigits = fractionDigits

View File

@@ -139,6 +139,7 @@ open class Module: Module_p {
// swiftlint:disable empty_count
if self.config.widgetsConfig.count != 0 {
// swiftlint:enable empty_count
self.initWidgets()
} else {
debug("Module started without widget", log: self.log)

View File

@@ -103,7 +103,7 @@ open class Reader<T>: NSObject, ReaderInternal_p {
self.ready = true
self.readyCallback()
debug("Reader is ready", log: self.log)
} else if self.value == nil && value != nil {
} else if self.value == nil && value == nil {
if self.nilCallbackCounter > 5 {
error("Callback receive nil value more than 5 times. Please check this reader!", log: self.log)
self.stop()

View File

@@ -28,14 +28,12 @@ public enum widget_t: String {
case state = "state"
public func new(module: String, config: NSDictionary, defaultWidget: widget_t) -> Widget? {
guard let widgetConfig: NSDictionary = config[self.rawValue] as? NSDictionary else { return nil }
var image: NSImage? = nil
var preview: widget_p? = nil
var item: widget_p? = nil
guard let widgetConfig: NSDictionary = config[self.rawValue] as? NSDictionary else {
return nil
}
switch self {
case .mini:
preview = Mini(title: module, config: widgetConfig, preview: true)
@@ -98,6 +96,8 @@ public enum widget_t: String {
case is SensorsWidget:
if module == "Sensors" {
width = 25
} else if module == "Clock" {
width = 114
}
case is MemoryWidget:
width = view.bounds.width + 8 + Constants.Widget.spacing*2
@@ -112,7 +112,6 @@ public enum widget_t: String {
width: width - view.frame.origin.x,
height: view.bounds.height
)
image = NSImage(data: view.dataWithPDF(inside: r))
}
@@ -201,7 +200,7 @@ public class Widget {
public var isActive: Bool {
get {
return self.list.contains{ $0 == self.type }
self.list.contains{ $0 == self.type }
}
set {
if newValue {
@@ -216,11 +215,11 @@ public class Widget {
public var sizeCallback: (() -> Void)? = nil
public var log: NextLog {
return NextLog.shared.copy(category: self.module)
NextLog.shared.copy(category: self.module)
}
public var position: Int {
get {
return Store.shared.int(key: "\(self.module)_\(self.type)_position", defaultValue: 0)
Store.shared.int(key: "\(self.module)_\(self.type)_position", defaultValue: 0)
}
set {
Store.shared.set(key: "\(self.module)_\(self.type)_position", value: newValue)

View File

@@ -24,6 +24,7 @@ public struct ColorValue: Equatable {
public static func ==(lhs: ColorValue, rhs: ColorValue) -> Bool {
return lhs.value == rhs.value
}
// swiftlint:enable operator_whitespace
}
public enum AppUpdateInterval: String {

View File

@@ -315,7 +315,7 @@ internal class Popup: PopupWrapper {
self.voltageField?.stringValue = "\(value.voltage.roundTo(decimalPlaces: 2)) V"
let batteryPower = value.voltage * (Double(abs(value.amperage))/1000)
self.batteryPowerField?.stringValue = "\(batteryPower.roundTo(decimalPlaces: 2)) W"
self.temperatureField?.stringValue = Temperature(value.temperature)
self.temperatureField?.stringValue = temperature(value.temperature)
self.powerField?.stringValue = value.isBatteryPowered ? localizedString("Not connected") : "\(value.ACwatts) W"
self.chargingStateField?.stringValue = value.isCharging ? localizedString("Yes") : localizedString("No")

View File

@@ -396,7 +396,7 @@ internal class Popup: PopupWrapper {
}
self.temperatureCircle?.setValue(value)
self.temperatureCircle?.setText(Temperature(value))
self.temperatureCircle?.setText(temperature(value))
self.initializedTemperature = true
}
})

View File

@@ -283,7 +283,6 @@ public class TemperatureReader: Reader<Double> {
}
}
// swiftlint:disable identifier_name
public class FrequencyReader: Reader<Double> {
private typealias PGSample = UInt64
private typealias UDouble = UnsafeMutablePointer<Double>
@@ -296,11 +295,11 @@ public class FrequencyReader: Reader<Double> {
private var bundle: CFBundle? = nil
private var PG_Initialize: PG_InitializePointerFunction? = nil
private var PG_Shutdown: PG_ShutdownPointerFunction? = nil
private var PG_ReadSample: PG_ReadSamplePointerFunction? = nil
private var PGSample_GetIAFrequency: PGSample_GetIAFrequencyPointerFunction? = nil
private var PGSample_Release: PGSample_ReleasePointerFunction? = nil
private var pgIntialize: PG_InitializePointerFunction? = nil
private var pgShutdown: PG_ShutdownPointerFunction? = nil
private var pgReadSample: PG_ReadSamplePointerFunction? = nil
private var pgSampleGetIAFrequency: PGSample_GetIAFrequencyPointerFunction? = nil
private var pgSampleRelease: PGSample_ReleasePointerFunction? = nil
private var sample: PGSample = 0
private var reconnectAttempt: Int = 0
@@ -328,34 +327,34 @@ public class FrequencyReader: Reader<Double> {
return
}
guard let PG_InitializePointer = CFBundleGetFunctionPointerForName(self.bundle, "PG_Initialize" as CFString) else {
guard let pgIntialize = CFBundleGetFunctionPointerForName(self.bundle, "PG_Initialize" as CFString) else {
error("failed to find PG_Initialize", log: self.log)
return
}
guard let PG_ShutdownPointer = CFBundleGetFunctionPointerForName(self.bundle, "PG_Shutdown" as CFString) else {
guard let pgShutdown = CFBundleGetFunctionPointerForName(self.bundle, "PG_Shutdown" as CFString) else {
error("failed to find PG_Shutdown", log: self.log)
return
}
guard let PG_ReadSamplePointer = CFBundleGetFunctionPointerForName(self.bundle, "PG_ReadSample" as CFString) else {
guard let pgReadSample = CFBundleGetFunctionPointerForName(self.bundle, "PG_ReadSample" as CFString) else {
error("failed to find PG_ReadSample", log: self.log)
return
}
guard let PGSample_GetIAFrequencyPointer = CFBundleGetFunctionPointerForName(self.bundle, "PGSample_GetIAFrequency" as CFString) else {
guard let pgSampleGetIAFrequency = CFBundleGetFunctionPointerForName(self.bundle, "PGSample_GetIAFrequency" as CFString) else {
error("failed to find PGSample_GetIAFrequency", log: self.log)
return
}
guard let PGSample_ReleasePointer = CFBundleGetFunctionPointerForName(self.bundle, "PGSample_Release" as CFString) else {
guard let pgSampleRelease = CFBundleGetFunctionPointerForName(self.bundle, "PGSample_Release" as CFString) else {
error("failed to find PGSample_Release", log: self.log)
return
}
self.PG_Initialize = unsafeBitCast(PG_InitializePointer, to: PG_InitializePointerFunction.self)
self.PG_Shutdown = unsafeBitCast(PG_ShutdownPointer, to: PG_ShutdownPointerFunction.self)
self.PG_ReadSample = unsafeBitCast(PG_ReadSamplePointer, to: PG_ReadSamplePointerFunction.self)
self.PGSample_GetIAFrequency = unsafeBitCast(PGSample_GetIAFrequencyPointer, to: PGSample_GetIAFrequencyPointerFunction.self)
self.PGSample_Release = unsafeBitCast(PGSample_ReleasePointer, to: PGSample_ReleasePointerFunction.self)
self.pgIntialize = unsafeBitCast(pgIntialize, to: PG_InitializePointerFunction.self)
self.pgShutdown = unsafeBitCast(pgShutdown, to: PG_ShutdownPointerFunction.self)
self.pgReadSample = unsafeBitCast(pgReadSample, to: PG_ReadSamplePointerFunction.self)
self.pgSampleGetIAFrequency = unsafeBitCast(pgSampleGetIAFrequency, to: PGSample_GetIAFrequencyPointerFunction.self)
self.pgSampleRelease = unsafeBitCast(pgSampleRelease, to: PGSample_ReleasePointerFunction.self)
if let initialize = self.PG_Initialize {
if let initialize = self.pgIntialize {
if !initialize() {
error("IPG initialization failed", log: self.log)
return
@@ -370,14 +369,14 @@ public class FrequencyReader: Reader<Double> {
}
public override func terminate() {
if let shutdown = self.PG_Shutdown {
if let shutdown = self.pgShutdown {
if !shutdown() {
error("IPG shutdown failed", log: self.log)
return
}
}
if let release = self.PGSample_Release {
if let release = self.pgSampleRelease {
if self.sample != 0 {
_ = release(self.sample)
return
@@ -392,7 +391,7 @@ public class FrequencyReader: Reader<Double> {
self.sample = 0
self.terminate()
if let initialize = self.PG_Initialize {
if let initialize = self.pgIntialize {
if !initialize() {
error("IPG initialization failed", log: self.log)
return
@@ -403,13 +402,13 @@ public class FrequencyReader: Reader<Double> {
}
public override func read() {
if !self.isEnabled || self.PG_ReadSample == nil || self.PGSample_GetIAFrequency == nil || self.PGSample_Release == nil {
if !self.isEnabled || self.pgReadSample == nil || self.pgSampleGetIAFrequency == nil || self.pgSampleRelease == nil {
return
}
// first sample initlialization
if self.sample == 0 {
if !self.PG_ReadSample!(0, &self.sample) {
if !self.pgReadSample!(0, &self.sample) {
error("read self.sample failed", log: self.log)
}
return
@@ -420,20 +419,20 @@ public class FrequencyReader: Reader<Double> {
var min: Double = 0
var max: Double = 0
if !self.PG_ReadSample!(0, &local) {
if !self.pgReadSample!(0, &local) {
self.reconnect()
error("read local sample failed", log: self.log)
return
}
defer {
if !self.PGSample_Release!(self.sample) {
if !self.pgSampleRelease!(self.sample) {
error("release self.sample failed", log: self.log)
}
self.sample = local
}
if !self.PGSample_GetIAFrequency!(self.sample, local, &value, &min, &max) {
if !self.pgSampleGetIAFrequency!(self.sample, local, &value, &min, &max) {
error("read frequency failed", log: self.log)
return
}

View File

@@ -52,8 +52,9 @@ public class Disks {
// swiftlint:disable empty_count
public var isEmpty: Bool {
return self.count == 0
self.count == 0
}
// swiftlint:enable empty_count
public func first(where predicate: (drive) -> Bool) -> drive? {
var result: drive?

View File

@@ -13,15 +13,13 @@ import Cocoa
import Kit
internal class Portal: NSStackView, Portal_p {
var name: String
internal var name: String { Disk.name }
private var circle: PieChartView? = nil
private var initialized: Bool = false
init(_ name: String) {
self.name = name
init() {
super.init(frame: NSRect.zero)
self.wantsLayer = true

View File

@@ -227,7 +227,7 @@ private class GPUView: NSStackView {
if id == "temperature" {
circle.setValue(value)
circle.setText(Temperature(value))
circle.setText(temperature(value))
chart.suffix = UnitTemperature.current.symbol
if self.temperatureChart == nil {
@@ -365,7 +365,7 @@ private class GPUDetails: NSView {
}
if let value = value.temperature {
let arr = keyValueRow("\(localizedString("Temperature")):", Temperature(Double(value)))
let arr = keyValueRow("\(localizedString("Temperature")):", Kit.temperature(Double(value)))
self.temperature = arr.last
grid.addRow(with: arr)
num += 1
@@ -419,7 +419,7 @@ private class GPUDetails: NSView {
}
if let value = gpu.temperature {
self.temperature?.stringValue = Temperature(Double(value))
self.temperature?.stringValue = Kit.temperature(Double(value))
}
if let value = gpu.utilization {
self.utilization?.stringValue = "\(Int(value*100))%"

View File

@@ -66,7 +66,6 @@ internal class InfoReader: Reader<GPUs> {
}
}
// swiftlint:disable function_body_length
public override func read() {
guard let accelerators = fetchIOService(kIOAcceleratorClassName) else {
return

View File

@@ -57,14 +57,10 @@ internal class Popup: PopupWrapper {
private var processes: [NetworkProcessView] = []
private var base: DataSizeBase {
get {
return DataSizeBase(rawValue: Store.shared.string(key: "\(self.title)_base", defaultValue: "byte")) ?? .byte
}
DataSizeBase(rawValue: Store.shared.string(key: "\(self.title)_base", defaultValue: "byte")) ?? .byte
}
private var numberOfProcesses: Int {
get {
return Store.shared.int(key: "\(self.title)_processes", defaultValue: 8)
}
Store.shared.int(key: "\(self.title)_processes", defaultValue: 8)
}
private var processesHeight: CGFloat {
get {
@@ -163,12 +159,10 @@ internal class Popup: PopupWrapper {
container.layer?.backgroundColor = NSColor.lightGray.withAlphaComponent(0.1).cgColor
container.layer?.cornerRadius = 3
let chart = NetworkChartView(frame: NSRect(
x: 0,
y: 1,
width: container.frame.width,
height: container.frame.height - 2
), num: 120, outColor: self.uploadColor, inColor: self.downloadColor)
let chart = NetworkChartView(
frame: NSRect(x: 0, y: 1, width: container.frame.width, height: container.frame.height - 2),
num: 120, outColor: self.uploadColor, inColor: self.downloadColor
)
chart.base = self.base
container.addSubview(chart)
self.chart = chart
@@ -409,7 +403,6 @@ internal class Popup: PopupWrapper {
if let v = value {
text = v ? "UP" : "DOWN"
}
self.connectivityField?.stringValue = localizedString(text)
self.connectionInitialized = true
}

View File

@@ -8,7 +8,6 @@
//
// Copyright © 2020 Serhiy Mytrovtsiy. All rights reserved.
//
// swiftlint:disable control_statement
import Cocoa
import Kit
@@ -21,6 +20,7 @@ struct ipResponse: Decodable {
var cc: String
}
// swiftlint:disable control_statement
extension CWPHYMode: CustomStringConvertible {
public var description: String {
switch(self) {
@@ -76,6 +76,7 @@ extension CWChannelBand: CustomStringConvertible {
switch(self) {
case .band2GHz: return "2 GHz"
case .band5GHz: return "5 GHz"
case .band6GHz: return "6 GHz"
case .bandUnknown: return "unknown"
@unknown default: return "unknown"
}
@@ -94,6 +95,7 @@ extension CWChannelWidth: CustomStringConvertible {
}
}
}
// swiftlint:enable control_statement
extension CWChannel {
override public var description: String {

View File

@@ -84,7 +84,7 @@ internal struct Sensor: Sensor_p {
get {
switch self.type {
case .temperature:
return Temperature(value)
return temperature(value)
case .voltage:
let val = value >= 100 ? "\(Int(value))" : String(format: "%.3f", value)
return "\(val)\(unit)"
@@ -103,7 +103,7 @@ internal struct Sensor: Sensor_p {
get {
switch self.type {
case .temperature:
return Temperature(value, fractionDigits: 1)
return temperature(value, fractionDigits: 1)
case .voltage:
let val = value >= 100 ? "\(Int(value))" : String(format: "%.3f", value)
return "\(val)\(unit)"
@@ -122,7 +122,7 @@ internal struct Sensor: Sensor_p {
get {
switch self.type {
case .temperature:
return Temperature(value).replacingOccurrences(of: "C", with: "").replacingOccurrences(of: "F", with: "")
return temperature(value).replacingOccurrences(of: "C", with: "").replacingOccurrences(of: "F", with: "")
case .voltage, .power, .energy, .current:
let val = value >= 9.95 ? "\(Int(round(value)))" : String(format: "%.1f", value)
return "\(val)\(unit)"

View File

@@ -32,15 +32,14 @@ internal enum SMCDataType: String {
case FDS = "{fds"
}
// swiftlint:disable identifier_name
internal enum SMCKeys: UInt8 {
case KERNEL_INDEX = 2
case READ_BYTES = 5
case WRITE_BYTES = 6
case READ_INDEX = 8
case READ_KEYINFO = 9
case READ_PLIMIT = 11
case READ_VERS = 12
case kernelIndex = 2
case readBytes = 5
case writeBytes = 6
case readIndex = 8
case readKeyInfo = 9
case readPLimit = 11
case readVers = 12
}
public enum FanMode: Int {
@@ -319,10 +318,10 @@ public class SMC {
input = SMCKeyData_t()
output = SMCKeyData_t()
input.data8 = SMCKeys.READ_INDEX.rawValue
input.data8 = SMCKeys.readIndex.rawValue
input.data32 = UInt32(i)
result = call(SMCKeys.KERNEL_INDEX.rawValue, input: &input, output: &output)
result = call(SMCKeys.kernelIndex.rawValue, input: &input, output: &output)
if result != kIOReturnSuccess {
continue
}
@@ -480,9 +479,9 @@ public class SMC {
var output = SMCKeyData_t()
input.key = FourCharCode(fromString: value.pointee.key)
input.data8 = SMCKeys.READ_KEYINFO.rawValue
input.data8 = SMCKeys.readKeyInfo.rawValue
result = call(SMCKeys.KERNEL_INDEX.rawValue, input: &input, output: &output)
result = call(SMCKeys.kernelIndex.rawValue, input: &input, output: &output)
if result != kIOReturnSuccess {
return result
}
@@ -490,9 +489,9 @@ public class SMC {
value.pointee.dataSize = UInt32(output.keyInfo.dataSize)
value.pointee.dataType = output.keyInfo.dataType.toString()
input.keyInfo.dataSize = output.keyInfo.dataSize
input.data8 = SMCKeys.READ_BYTES.rawValue
input.data8 = SMCKeys.readBytes.rawValue
result = call(SMCKeys.KERNEL_INDEX.rawValue, input: &input, output: &output)
result = call(SMCKeys.kernelIndex.rawValue, input: &input, output: &output)
if result != kIOReturnSuccess {
return result
}
@@ -507,7 +506,7 @@ public class SMC {
var output = SMCKeyData_t()
input.key = FourCharCode(fromString: value.key)
input.data8 = SMCKeys.WRITE_BYTES.rawValue
input.data8 = SMCKeys.writeBytes.rawValue
input.keyInfo.dataSize = IOByteCount32(value.dataSize)
input.bytes = (value.bytes[0], value.bytes[1], value.bytes[2], value.bytes[3], value.bytes[4], value.bytes[5],
value.bytes[6], value.bytes[7], value.bytes[8], value.bytes[9], value.bytes[10], value.bytes[11],
@@ -516,7 +515,7 @@ public class SMC {
value.bytes[24], value.bytes[25], value.bytes[26], value.bytes[27], value.bytes[28], value.bytes[29],
value.bytes[30], value.bytes[31])
let result = self.call(SMCKeys.KERNEL_INDEX.rawValue, input: &input, output: &output)
let result = self.call(SMCKeys.kernelIndex.rawValue, input: &input, output: &output)
if result != kIOReturnSuccess {
return result
}