Skip to content

Commit

Permalink
/issues/4351 - Added swiftlint rules for print(), println() and os_lo…
Browse files Browse the repository at this point in the history
…g() and replaced more print() usages with MXLog.debug()
  • Loading branch information
stefanceriu committed Jun 3, 2021
1 parent 32628b9 commit a6cf9dc
Show file tree
Hide file tree
Showing 12 changed files with 39 additions and 19 deletions.
24 changes: 22 additions & 2 deletions .swiftlint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,28 @@ type_name:

custom_rules:
ns_log_deprecation:
regex: "NSLog"
regex: "\\b(NSLog)\\b"
match_kinds: identifier
message: "MXLog should be used instead of NSLog"
message: "MXLog should be used instead of NSLog()"
severity: error

print_deprecation:
regex: "\\b(print)\\b"
match_kinds: identifier
message: "MXLog should be used instead of print()"
severity: error

print_ln_deprecation:
regex: "\\b(println)\\b"
match_kinds: identifier
message: "MXLog should be used instead of println()"
severity: error

os_log_deprecation:
regex: "\\b(os_log)\\b"
match_kinds: identifier
message: "MXLog should be used instead of os_log()"
severity: error



2 changes: 1 addition & 1 deletion Riot/Modules/Camera/CameraAccessAlertPresenter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ final class CameraAccessAlertPresenter {
let settingsAction = UIAlertAction(title: settingsActionTitle, style: .default, handler: { _ in
UIApplication.shared.open(settingsURL, options: [:], completionHandler: { (succeed) in
if !succeed {
print("[CameraPresenter] Fails to open settings")
MXLog.debug("[CameraPresenter] Fails to open settings")
}
})
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ final class KeyBackupRecoverFromRecoveryKeyViewController: UIViewController {
do {
documentContent = try String(contentsOf: documentURL)
} catch {
print("Error: \(error)")
MXLog.debug("Error: \(error)")
documentContent = nil
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ final class KeyVerificationSelfVerifyWaitViewModel: KeyVerificationSelfVerifyWai
private func loadData() {

if !self.isNewSignIn {
print("[KeyVerificationSelfVerifyWaitViewModel] loadData: Send a verification request to all devices")
MXLog.debug("[KeyVerificationSelfVerifyWaitViewModel] loadData: Send a verification request to all devices")

let keyVerificationService = KeyVerificationService()
self.verificationManager.requestVerificationByToDevice(withUserId: self.session.myUserId, deviceIds: nil, methods: keyVerificationService.supportedKeyVerificationMethods(), success: { [weak self] (keyVerificationRequest) in
Expand All @@ -93,7 +93,7 @@ final class KeyVerificationSelfVerifyWaitViewModel: KeyVerificationSelfVerifyWai
if session.state >= MXSessionStateRunning {

// Always send request instead of waiting for an incoming one as per recent EW changes
print("[KeyVerificationSelfVerifyWaitViewModel] loadData: Send a verification request to all devices instead of waiting")
MXLog.debug("[KeyVerificationSelfVerifyWaitViewModel] loadData: Send a verification request to all devices instead of waiting")

let keyVerificationService = KeyVerificationService()
self.verificationManager.requestVerificationByToDevice(withUserId: self.session.myUserId, deviceIds: nil, methods: keyVerificationService.supportedKeyVerificationMethods(), success: { [weak self] (keyVerificationRequest) in
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ final class EditHistoryCoordinatorBridgePresenter: NSObject {

func createEventFormatter(session: MXSession) -> EventFormatter? {
guard let formatter = EventFormatter(matrixSession: session) else {
print("[EditHistoryCoordinatorBridgePresenter] createEventFormatter: Cannot build formatter")
MXLog.debug("[EditHistoryCoordinatorBridgePresenter] createEventFormatter: Cannot build formatter")
return nil
}

Expand Down
8 changes: 4 additions & 4 deletions Riot/Modules/Room/EditHistory/EditHistoryViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -94,12 +94,12 @@ final class EditHistoryViewModel: EditHistoryViewModelType {

private func loadMoreHistory() {
guard self.canLoadMoreHistory() else {
print("[EditHistoryViewModel] loadMoreHistory: pending loading or all data loaded")
MXLog.debug("[EditHistoryViewModel] loadMoreHistory: pending loading or all data loaded")
return
}

guard self.operation == nil else {
print("[EditHistoryViewModel] loadMoreHistory: operation already pending")
MXLog.debug("[EditHistoryViewModel] loadMoreHistory: operation already pending")
return
}

Expand Down Expand Up @@ -212,7 +212,7 @@ final class EditHistoryViewModel: EditHistoryViewModelType {
private func process(editEvent: MXEvent) -> EditHistoryMessage? {
// Create a temporary MXEvent that represents this edition
guard let editedEvent = self.event.editedEvent(fromReplacementEvent: editEvent) else {
print("[EditHistoryViewModel] processEditEvent: Cannot build edited event: \(editEvent.eventId ?? "")")
MXLog.debug("[EditHistoryViewModel] processEditEvent: Cannot build edited event: \(editEvent.eventId ?? "")")
return nil
}

Expand All @@ -223,7 +223,7 @@ final class EditHistoryViewModel: EditHistoryViewModelType {

let formatterError = UnsafeMutablePointer<MXKEventFormatterError>.allocate(capacity: 1)
guard let message = self.formatter.attributedString(from: event, with: nil, error: formatterError) else {
print("[EditHistoryViewModel] processEditEvent: cannot format(error: \(formatterError)) event: \(event.eventId ?? "")")
MXLog.debug("[EditHistoryViewModel] processEditEvent: cannot format(error: \(formatterError)) event: \(event.eventId ?? "")")
return nil
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ extension EmojiMartStore: Decodable {
do {
emojiItem = try emojisContainer.decode(EmojiItem.self, forKey: emojiKey)
} catch {
print("[EmojiJSONStore] init(from decoder: Decoder) failed to parse emojiItem \(emojiKey) with error: \(error)")
MXLog.debug("[EmojiJSONStore] init(from decoder: Decoder) failed to parse emojiItem \(emojiKey) with error: \(error)")
emojiItem = nil
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ extension EmojiMartStore: Decodable {
do {
emojiItem = try emojisContainer.decode(EmojiItem.self, forKey: emojiKey)
} catch {
print("[EmojiJSONStore] init(from decoder: Decoder) failed to parse emojiItem \(emojiKey) with error: \(error)")
MXLog.debug("[EmojiJSONStore] init(from decoder: Decoder) failed to parse emojiItem \(emojiKey) with error: \(error)")
emojiItem = nil
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,12 +97,12 @@ final class ReactionHistoryViewModel: ReactionHistoryViewModelType {

private func loadMoreHistory() {
guard self.canLoadMoreHistory() else {
print("[ReactionHistoryViewModel] loadMoreHistory: pending loading or all data loaded")
MXLog.debug("[ReactionHistoryViewModel] loadMoreHistory: pending loading or all data loaded")
return
}

guard self.operation == nil else {
print("[ReactionHistoryViewModel] loadMoreHistory: operation already pending")
MXLog.debug("[ReactionHistoryViewModel] loadMoreHistory: operation already pending")
return
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ final class SecretsRecoveryWithKeyViewController: UIViewController {
do {
documentContent = try String(contentsOf: documentURL)
} catch {
print("[SecretsRecoveryWithKeyViewController] Error: \(error)")
MXLog.debug("[SecretsRecoveryWithKeyViewController] Error: \(error)")
documentContent = nil
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ final class ServiceTermsModalScreenViewModel: ServiceTermsModalScreenViewModelTy
if let policies = terms?.policiesData(forLanguage: Bundle.mxk_language(), defaultLanguage: Bundle.mxk_fallbackLanguage()) {
return policies
} else {
print("[ServiceTermsModalScreenViewModel] processTerms: Error: No terms for \(String(describing: terms))")
MXLog.debug("[ServiceTermsModalScreenViewModel] processTerms: Error: No terms for \(String(describing: terms))")
return []
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ final class SettingsIdentityServerViewModel: SettingsIdentityServerViewModelType
viewStateUpdate(.loading)

self.checkIdentityServerValidity(identityServer: newIdentityServer) { (identityServerValidityResponse) in
print("[SettingsIdentityServerViewModel] checkCanAddIdentityServer: \(newIdentityServer). Validity: \(identityServerValidityResponse)")
MXLog.debug("[SettingsIdentityServerViewModel] checkCanAddIdentityServer: \(newIdentityServer). Validity: \(identityServerValidityResponse)")

switch identityServerValidityResponse {
case .success(let identityServerValidity):
Expand All @@ -119,7 +119,7 @@ final class SettingsIdentityServerViewModel: SettingsIdentityServerViewModelType
switch response {
case .success(let accessToken):
guard let accessToken = accessToken else {
print("[SettingsIdentityServerViewModel] accessToken: Error: No access token")
MXLog.debug("[SettingsIdentityServerViewModel] accessToken: Error: No access token")
viewStateUpdate(.error(SettingsIdentityServerViewModelError.unknown))
return
}
Expand Down

0 comments on commit a6cf9dc

Please sign in to comment.