Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

static var to static let #2642

Merged
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions HomeAssistant.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -4834,7 +4834,7 @@
);
mainGroup = B657A8DD1CA646EB00121384;
packageReferences = (
427692E12B98B82500F24321 /* XCLocalSwiftPackageReference "Sources/PushServer/SharedPush" */,
427692E12B98B82500F24321 /* XCLocalSwiftPackageReference "SharedPush" */,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

got these changes just by running the project 🤷

);
productRefGroup = B657A8E71CA646EB00121384 /* Products */;
projectDirPath = "";
Expand Down Expand Up @@ -8133,7 +8133,7 @@
/* End XCConfigurationList section */

/* Begin XCLocalSwiftPackageReference section */
427692E12B98B82500F24321 /* XCLocalSwiftPackageReference "Sources/PushServer/SharedPush" */ = {
427692E12B98B82500F24321 /* XCLocalSwiftPackageReference "SharedPush" */ = {
isa = XCLocalSwiftPackageReference;
relativePath = Sources/PushServer/SharedPush;
};
Expand Down
2 changes: 1 addition & 1 deletion Sources/App/Scenes/SceneManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ struct SceneManagerPreSceneCompatibility {

class SceneManager {
// types too hard here
fileprivate static var activityUserInfoKeyResolver = "resolver"
fileprivate static let activityUserInfoKeyResolver = "resolver"

private struct PendingResolver {
private var handleBlock: (Any) -> Void
Expand Down
2 changes: 1 addition & 1 deletion Sources/App/Scenes/WindowScenesManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import Shared
import UIKit

final class WindowScenesManager {
static var shared = WindowScenesManager()
static let shared = WindowScenesManager()
private(set) var windowSizeObservers: [WindowSizeObserver] = []

func sceneDidBecomeActive(_ scene: UIWindowScene) {
Expand Down
6 changes: 3 additions & 3 deletions Sources/App/Scenes/WindowSizeObserver.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,13 @@
}

enum ScenesWindowSizeConfig {
static var defaultSceneLastestSystemFrameDataKey = "default-scene-latest-system-frame-data"
private static let defaultSceneLatestSystemFrameDataKey = "default-scene-latest-system-frame-data"
bgoncal marked this conversation as resolved.
Show resolved Hide resolved
private static var defaultSceneLatestSystemFrameData: Data? {
get {
prefs.data(forKey: ScenesWindowSizeConfig.defaultSceneLastestSystemFrameDataKey)
prefs.data(forKey: ScenesWindowSizeConfig.defaultSceneLatestSystemFrameDataKey)
}
set {
prefs.set(newValue, forKey: ScenesWindowSizeConfig.defaultSceneLastestSystemFrameDataKey)
prefs.set(newValue, forKey: ScenesWindowSizeConfig.defaultSceneLatestSystemFrameDataKey)

Check warning on line 41 in Sources/App/Scenes/WindowSizeObserver.swift

View check run for this annotation

Codecov / codecov/patch

Sources/App/Scenes/WindowSizeObserver.swift#L41

Added line #L41 was not covered by tests
}
}

Expand Down
10 changes: 5 additions & 5 deletions Sources/App/Settings/SettingsViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ class SettingsViewController: HAFormViewController {
init(rawValue: Int) { self.rawValue = rawValue }
init(integerLiteral value: IntegerLiteralType) { self.init(rawValue: value) }

static var servers: ContentSection = 0b1
static var general: ContentSection = 0b10
static var integrations: ContentSection = 0b100
static var help: ContentSection = 0b1000
static var all = ContentSection(rawValue: ~0b0)
static let servers: ContentSection = 0b1
static let general: ContentSection = 0b10
static let integrations: ContentSection = 0b100
static let help: ContentSection = 0b1000
static let all = ContentSection(rawValue: ~0b0)
}

let contentSections: ContentSection
Expand Down
1 change: 0 additions & 1 deletion Sources/App/WebView/WebViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ final class WebViewController: UIViewController, WKNavigationDelegate, WKUIDeleg
private let refreshControl = UIRefreshControl()
private let sidebarGestureRecognizer: UIScreenEdgePanGestureRecognizer

private var keepAliveTimer: Timer?
private var initialURL: URL?
private var barCodeScannerController: UIViewController?

Expand Down
4 changes: 2 additions & 2 deletions Sources/Extensions/AppIntents/IntentActionAppEntity.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import Shared

@available(iOS 16.0, macOS 13.0, watchOS 9.0, tvOS 16.0, *)
struct IntentActionAppEntity: AppEntity {
static var typeDisplayRepresentation = TypeDisplayRepresentation(name: "Action")
static let typeDisplayRepresentation = TypeDisplayRepresentation(name: "Action")

struct IntentActionAppEntityQuery: EntityQuery, EntityStringQuery {
func entities(for identifiers: [IntentActionAppEntity.ID]) async throws -> [IntentActionAppEntity] {
Expand All @@ -25,7 +25,7 @@ struct IntentActionAppEntity: AppEntity {
}
}

static var defaultQuery = IntentActionAppEntityQuery()
static let defaultQuery = IntentActionAppEntityQuery()

var id: String // if your identifier is not a String, conform the entity to EntityIdentifierConvertible.
var displayString: String
Expand Down
4 changes: 2 additions & 2 deletions Sources/Extensions/AppIntents/PerformAction.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import Shared
struct PerformAction: AppIntent, CustomIntentMigratedAppIntent, PredictableIntent {
static let intentClassName = "PerformActionIntent"

static var title: LocalizedStringResource = "Perform Action"
static var description = IntentDescription("Performs an action defined in the app")
static let title: LocalizedStringResource = "Perform Action"
static let description = IntentDescription("Performs an action defined in the app")

@Parameter(title: "Action")
var action: IntentActionAppEntity?
Expand Down
4 changes: 2 additions & 2 deletions Sources/Extensions/AppIntents/WidgetActionsAppIntent.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ struct WidgetActionsAppIntent: AppIntent, WidgetConfigurationIntent, CustomInten
ProgressReportingIntent {
static let intentClassName = "WidgetActionsIntent"

static var title: LocalizedStringResource = "Actions"
static var description = IntentDescription("View and run actions")
static let title: LocalizedStringResource = "Actions"
static let description = IntentDescription("View and run actions")

@Parameter(
title: "Actions",
Expand Down
2 changes: 1 addition & 1 deletion Sources/Extensions/Widgets/Actions/WidgetActions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -73,5 +73,5 @@ struct LegacyWidgetActions: Widget {
}

enum WidgetActionSupportedFamilies {
static var families: [WidgetFamily] = [.systemSmall, .systemMedium, .systemLarge, .systemExtraLarge]
static let families: [WidgetFamily] = [.systemSmall, .systemMedium, .systemLarge, .systemExtraLarge]
}
2 changes: 1 addition & 1 deletion Sources/MacBridge/MacBridgeNetworkMonitor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import Foundation
import SystemConfiguration

class MacBridgeNetworkMonitor {
static var connectivityDidChangeNotification: Notification.Name = .init("ha_connectivityDidChange")
static let connectivityDidChangeNotification: Notification.Name = .init("ha_connectivityDidChange")

private let wifiClient: CWWiFiClient
private var scStore: SCDynamicStore!
Expand Down
2 changes: 1 addition & 1 deletion Sources/Shared/API/Fixtures/ServerFixture.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import Foundation
import Shared

enum ServerFixture {
static var standard = Server(identifier: "123", getter: {
static let standard = Server(identifier: "123", getter: {
.init(
name: "A Name",
connection: .init(
Expand Down
2 changes: 1 addition & 1 deletion Sources/Shared/API/HAAPI.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public class HomeAssistantAPI {
public static let didConnectNotification = Notification.Name(rawValue: "HomeAssistantAPIConnected")

public private(set) var manager: Alamofire.Session!
public static var unauthenticatedManager: Alamofire.Session = configureSessionManager()
public static let unauthenticatedManager: Alamofire.Session = configureSessionManager()

public let tokenManager: TokenManager
public var server: Server
Expand Down
4 changes: 2 additions & 2 deletions Sources/Shared/API/MJPEGStreamer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import Foundation
import UIKit

class MJPEGStreamerSessionDelegate: SessionDelegate {
static var didReceiveResponse: Notification.Name = .init(rawValue: "MJPEGStreamerSessionDelegateDidReceiveResponse")
static var taskUserInfoKey: AnyHashable = "taskUserInfoKey"
static let didReceiveResponse: Notification.Name = .init(rawValue: "MJPEGStreamerSessionDelegateDidReceiveResponse")
static let taskUserInfoKey: AnyHashable = "taskUserInfoKey"

// if/when alamofire also implements this again, we need to update to handle it as the breakpoint between images
override func urlSession(
Expand Down
6 changes: 3 additions & 3 deletions Sources/Shared/API/Models/ModelManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public class ModelManager: ServerObserver {
]
}

public static var defaults: [Self] = [
public static let defaults: [Self] = [
CleanupDefinition(
model: LocationHistoryEntry.self,
createdKey: #keyPath(LocationHistoryEntry.CreatedAt)
Expand Down Expand Up @@ -229,7 +229,7 @@ public class ModelManager: ServerObserver {
})
}

public static var defaults: [Self] = [
public static let defaults: [Self] = [
.states(domain: "zone", type: RLMZone.self),
.states(domain: "scene", type: RLMScene.self),
]
Expand Down Expand Up @@ -257,7 +257,7 @@ public class ModelManager: ServerObserver {
_ modelManager: ModelManager
) -> Promise<Void>

public static var defaults: [Self] = [
public static let defaults: [Self] = [
FetchDefinition(update: { api, queue, manager in
api.GetMobileAppConfig().then(on: queue) {
when(fulfilled: [
Expand Down
2 changes: 1 addition & 1 deletion Sources/Shared/API/Server.swift
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ public struct ServerInfo: Codable, Equatable {
}

public final class Server: Hashable, Comparable, CustomStringConvertible {
public static var historicId: Identifier<Server> = "historic"
public static let historicId: Identifier<Server> = "historic"

public let identifier: Identifier<Server>
public var info: ServerInfo {
Expand Down
2 changes: 1 addition & 1 deletion Sources/Shared/Common/ObjectMapperTransformers.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
}

public extension DateFormatter {
static var iso8601Milliseconds: DateFormatter = {
static let iso8601Milliseconds: DateFormatter = {

Check warning on line 31 in Sources/Shared/Common/ObjectMapperTransformers.swift

View check run for this annotation

Codecov / codecov/patch

Sources/Shared/Common/ObjectMapperTransformers.swift#L31

Added line #L31 was not covered by tests
let formatter = DateFormatter()
formatter.locale = Locale(identifier: "en_US_POSIX")
formatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ss.SSSZ"
Expand Down
4 changes: 2 additions & 2 deletions Sources/Shared/Common/URLComponents+WidgetAuthenticity.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ public extension URL {
}

public extension URLComponents {
private static var authenticityName = "widgetAuthenticity"
private static var serverName = "server"
private static let authenticityName = "widgetAuthenticity"
private static let serverName = "server"

mutating func insertWidgetAuthenticity() {
queryItems = (queryItems ?? []) + [
Expand Down
1 change: 0 additions & 1 deletion Sources/Shared/Environment/Constants.swift
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,6 @@ public extension Version {
static let canSendDeviceID: Version = .init(minor: 104)
static let pedometerIconsAvailable: Version = .init(minor: 105)
static let tagWebhookAvailable: Version = .init(minor: 114, prerelease: "b5")
static let tagPlatformTrigger: Version = .init(minor: 115, prerelease: "any0")
bgoncal marked this conversation as resolved.
Show resolved Hide resolved
static let actionSyncing: Version = .init(minor: 115, prerelease: "any0")
static let localPushConfirm: Version = .init(major: 2021, minor: 10, prerelease: "any0")
static let externalBusCommandRestart: Version = .init(major: 2021, minor: 12, prerelease: "b6")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public class LocalPushManager {
public let server: Server
public weak var delegate: LocalPushManagerDelegate?

public static var stateDidChange: Notification.Name = .init(rawValue: "LocalPushManagerStateDidChange")
public static let stateDidChange: Notification.Name = .init(rawValue: "LocalPushManagerStateDidChange")

public enum State: Equatable, Codable {
case establishing
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
public struct PushProviderConfiguration: Codable {
public static var providerConfigurationKey = "ha_configurations"
public static let providerConfigurationKey = "ha_configurations"

public var serverIdentifier: Identifier<Server>
public var settingsKey: String
Comment on lines -4 to -5
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that cases like this - where it's a data type - shouldn't force the non-static members to be let - that's already done by the mutability state of the struct. It's not in and of itself wrong to copy a struct and mutate the value for some reason, as long as the values are valid state changes -- which the type can guard if it wants.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since there is no real impact now, I will merge this PR as-is, we can always change it to var on demand of course when needed to actually do something with the struct.

public let serverIdentifier: Identifier<Server>
public let settingsKey: String

public init(serverIdentifier: Identifier<Server>, settingsKey: String) {
self.serverIdentifier = serverIdentifier
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import ObjectMapper
import UserNotifications

public extension UNNotificationContent {
private static var separator: String = "@duplicate_identifier-"
private static let separator: String = "@duplicate_identifier-"

static func uncombinedAction(from identifier: String) -> String {
if identifier.contains(separator), let substring = identifier.components(separatedBy: separator).first {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import Shared

@available(iOS 16.0, *)
final class CarPlayServersListTemplate: CarPlayTemplateProvider {
private(set) static var carPlayPreferredServerKey = "carPlay-server"
static let carPlayPreferredServerKey = "carPlay-server"

private let viewModel: CarPlayServerListViewModel

Expand Down
Loading