Skip to content

Commit

Permalink
Merge pull request #1046 from mpretty-cyro/fix/string-linter-issues
Browse files Browse the repository at this point in the history
Refactored the LintLocalizableStrings script
  • Loading branch information
mpretty-cyro authored Oct 18, 2024
2 parents 8c21b9c + a32af01 commit ef0f73a
Show file tree
Hide file tree
Showing 139 changed files with 843 additions and 486 deletions.
572 changes: 391 additions & 181 deletions Scripts/LintLocalizableStrings.swift

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion Session/Calls/Call Management/SessionCall.swift
Original file line number Diff line number Diff line change
Expand Up @@ -180,9 +180,10 @@ public final class SessionCall: CurrentCallProtocol, WebRTCSessionDelegate {
}
}

// stringlint:ignore_contents
func reportIncomingCallIfNeeded(completion: @escaping (Error?) -> Void) {
guard case .answer = mode else {
SessionCallManager.reportFakeCall(info: "Call not in answer mode") // stringlint:disable
SessionCallManager.reportFakeCall(info: "Call not in answer mode")
return
}

Expand Down
2 changes: 1 addition & 1 deletion Session/Calls/Call Management/SessionCallManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public final class SessionCallManager: NSObject, CallManagerProtocol {
}

static func buildProviderConfiguration(useSystemCallLog: Bool) -> CXProviderConfiguration {
let providerConfiguration = CXProviderConfiguration(localizedName: "Session") // stringlint:disable
let providerConfiguration = CXProviderConfiguration()
providerConfiguration.supportsVideo = true
providerConfiguration.maximumCallGroups = 1
providerConfiguration.maximumCallsPerCallGroup = 1
Expand Down
3 changes: 2 additions & 1 deletion Session/Calls/CallVC.swift
Original file line number Diff line number Diff line change
Expand Up @@ -630,8 +630,9 @@ final class CallVC: UIViewController, VideoPreviewDelegate {
}
}

// stringlint:ignore_contents
@objc private func updateDuration() {
callDurationLabel.text = String(format: "%.2d:%.2d", duration/60, duration%60) // stringlint:disable
callDurationLabel.text = String(format: "%.2d:%.2d", duration/60, duration%60)
duration += 1
}

Expand Down
9 changes: 5 additions & 4 deletions Session/Calls/WebRTC/WebRTCSession+DataChannel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ import Foundation
import SessionUtilitiesKit

extension WebRTCSession: RTCDataChannelDelegate {

// stringlint:ignore_contents
internal func createDataChannel() -> RTCDataChannel? {
let dataChannelConfiguration = RTCDataChannelConfiguration()
dataChannelConfiguration.isOrdered = true
dataChannelConfiguration.isNegotiated = true
dataChannelConfiguration.channelId = 548
guard let dataChannel = peerConnection?.dataChannel(forLabel: "CONTROL", configuration: dataChannelConfiguration) else { // stringlint:disable
guard let dataChannel = peerConnection?.dataChannel(forLabel: "CONTROL", configuration: dataChannelConfiguration) else {
SNLog("[Calls] Couldn't create data channel.")
return nil
}
Expand All @@ -35,13 +35,14 @@ extension WebRTCSession: RTCDataChannelDelegate {
}
}

// stringlint:ignore_contents
public func dataChannel(_ dataChannel: RTCDataChannel, didReceiveMessageWith buffer: RTCDataBuffer) {
if let json = try? JSONSerialization.jsonObject(with: buffer.data, options: [ .fragmentsAllowed ]) as? JSON {
SNLog("[Calls] Data channel did receive data: \(json)")
if let isRemoteVideoEnabled = json["video"] as? Bool { // stringlint:disable
if let isRemoteVideoEnabled = json["video"] as? Bool {
delegate?.isRemoteVideoDidChange(isEnabled: isRemoteVideoEnabled)
}
if let _ = json["hangup"] { // stringlint:disable
if let _ = json["hangup"] {
delegate?.didReceiveHangUpSignal()
}
}
Expand Down
8 changes: 5 additions & 3 deletions Session/Calls/WebRTC/WebRTCSession.swift
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,10 @@ public final class WebRTCSession : NSObject, RTCPeerConnectionDelegate {
public enum WebRTCSessionError: LocalizedError {
case noThread

// stringlint:ignore_contents
public var errorDescription: String? {
switch self {
case .noThread: return "Couldn't find thread for contact." // stringlint:disable
case .noThread: return "Couldn't find thread for contact."
}
}
}
Expand Down Expand Up @@ -392,10 +393,11 @@ public final class WebRTCSession : NSObject, RTCPeerConnectionDelegate {
return RTCMediaConstraints(mandatoryConstraints: mandatory, optionalConstraints: optional)
}

// stringlint:ignore_contents
private func correctSessionDescription(sdp: RTCSessionDescription?) -> RTCSessionDescription? {
guard let sdp = sdp else { return nil }
let cbrSdp = sdp.sdp.description.replace(regex: "(a=fmtp:111 ((?!cbr=).)*)\r?\n", with: "$1;cbr=1\r\n") // stringlint:disable
let finalSdp = cbrSdp.replace(regex: ".+urn:ietf:params:rtp-hdrext:ssrc-audio-level.*\r?\n", with: "") // stringlint:disable
let cbrSdp = sdp.sdp.description.replace(regex: "(a=fmtp:111 ((?!cbr=).)*)\r?\n", with: "$1;cbr=1\r\n")
let finalSdp = cbrSdp.replace(regex: ".+urn:ietf:params:rtp-hdrext:ssrc-audio-level.*\r?\n", with: "")
return RTCSessionDescription(type: sdp.type, sdp: finalSdp)
}

Expand Down
14 changes: 9 additions & 5 deletions Session/Conversations/ConversationVC+Interaction.swift
Original file line number Diff line number Diff line change
Expand Up @@ -721,7 +721,7 @@ extension ConversationVC:

let newText: String = snInputView.text.replacingCharacters(
in: currentMentionStartIndex...,
with: "@\(mentionInfo.profile.displayName(for: self.viewModel.threadData.threadVariant)) " // stringlint:disable
with: "@\(mentionInfo.profile.displayName(for: self.viewModel.threadData.threadVariant)) " // stringlint:ignore
)

snInputView.text = newText
Expand Down Expand Up @@ -756,6 +756,7 @@ extension ConversationVC:
isCharacterBeforeLastWhiteSpaceOrStartOfLine = characterBeforeLast.isWhitespace
}

// stringlint:ignore_start
if lastCharacter == "@" && isCharacterBeforeLastWhiteSpaceOrStartOfLine {
currentMentionStartIndex = lastCharacterIndex
snInputView.showMentionsUI(for: self.viewModel.mentions())
Expand All @@ -770,18 +771,20 @@ extension ConversationVC:
snInputView.showMentionsUI(for: self.viewModel.mentions(for: query))
}
}
// stringlint:ignore_stop
}

func resetMentions() {
currentMentionStartIndex = nil
mentions = []
}

// stringlint:ignore_contents
func replaceMentions(in text: String) -> String {
var result = text
for mention in mentions {
guard let range = result.range(of: "@\(mention.profile.displayName(for: mention.threadVariant))") else { continue } // stringlint:disable
result = result.replacingCharacters(in: range, with: "@\(mention.profile.id)") // stringlint:disable
guard let range = result.range(of: "@\(mention.profile.displayName(for: mention.threadVariant))") else { continue }
result = result.replacingCharacters(in: range, with: "@\(mention.profile.id)")
}

return result
Expand Down Expand Up @@ -2422,7 +2425,7 @@ extension ConversationVC:

// Create URL
let directory: String = Singleton.appContext.temporaryDirectory
let fileName: String = "\(SnodeAPI.currentOffsetTimestampMs()).m4a" // stringlint:disable
let fileName: String = "\(SnodeAPI.currentOffsetTimestampMs()).m4a" // stringlint:ignore
let url: URL = URL(fileURLWithPath: directory).appendingPathComponent(fileName)

// Set up audio session
Expand Down Expand Up @@ -2525,7 +2528,8 @@ extension ConversationVC:
guard let dataSource = dataSourceOrNil else { return SNLog("Couldn't load recorded data.") }

// Create attachment
let fileName = ("messageVoice".localized() as NSString).appendingPathExtension("m4a")
let fileName = ("messageVoice".localized() as NSString)
.appendingPathExtension("m4a") // stringlint:ignore
dataSource.sourceFilename = fileName

let attachment = SignalAttachment.voiceMessageAttachment(dataSource: dataSource, type: .mpeg4Audio)
Expand Down
7 changes: 5 additions & 2 deletions Session/Conversations/ConversationVC.swift
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,10 @@ final class ConversationVC: BaseVC, LibSessionRespondingViewController, Conversa
return result
}()

lazy var recordVoiceMessageActivity = AudioActivity(audioDescription: "Voice message", behavior: .playAndRecord) // stringlint:disable
lazy var recordVoiceMessageActivity = AudioActivity(
audioDescription: "Voice message", // stringlint:ignore
behavior: .playAndRecord
)

lazy var searchController: ConversationSearchController = {
let result: ConversationSearchController = ConversationSearchController(
Expand Down Expand Up @@ -1724,7 +1727,7 @@ final class ConversationVC: BaseVC, LibSessionRespondingViewController, Conversa
func updateUnreadCountView(unreadCount: UInt?) {
let unreadCount: Int = Int(unreadCount ?? 0)
let fontSize: CGFloat = (unreadCount < 10000 ? Values.verySmallFontSize : 8)
unreadCountLabel.text = (unreadCount < 10000 ? "\(unreadCount)" : "9999+") // stringlint:disable
unreadCountLabel.text = (unreadCount < 10000 ? "\(unreadCount)" : "9999+") // stringlint:ignore
unreadCountLabel.font = .boldSystemFont(ofSize: fontSize)
unreadCountView.isHidden = (unreadCount == 0)
}
Expand Down
2 changes: 1 addition & 1 deletion Session/Conversations/ConversationViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public class ConversationViewModel: OWSAudioPlayerDelegate, NavigatableStateHold

return "blockBlockedDescription".localized()

default: return "Thread is blocked. Unblock it?" // Should not happen // stringlint:disable
default: return "blockUnblock".localized() // Should not happen
}
}()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,11 +118,12 @@ final class VoiceMessageRecordingView: UIView {
return result
}()

// stringlint:ignore_contents
private lazy var durationLabel: UILabel = {
let result: UILabel = UILabel()
result.font = .systemFont(ofSize: Values.smallFontSize)
result.themeTextColor = .textPrimary
result.text = "0:00" // stringlint:disable
result.text = "0:00"

return result
}()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,9 @@ class DisappearingMessageTimerView: UIView {
self.updateIcon()
}

// stringlint:ignore_contents
private func updateIcon() {
let imageName: String = "disappearing_message_\(String(format: "%02d", 5 * self.progress))" // stringlint:disable
let imageName: String = "disappearing_message_\(String(format: "%02d", 5 * self.progress))"
self.iconImageView.image = UIImage(named: imageName)?.withRenderingMode(.alwaysTemplate)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,31 @@ final class MediaPlaceholderView: UIView {
cellViewModel.variant == .standardIncoming,
let attachment: Attachment = cellViewModel.attachments?.first
else {
return ("actionsheet_document_black", "file".localized().lowercased()) // Should never occur
return (
"actionsheet_document_black", // stringlint:ignore
"file".localized().lowercased()
) // Should never occur
}

if attachment.isAudio { return ("attachment_audio", "audio".localized().lowercased()) }
if attachment.isImage || attachment.isVideo { return ("actionsheet_camera_roll_black", "media".localized().lowercased()) }

return ("actionsheet_document_black", "file".localized().lowercased())
switch (attachment.isAudio, (attachment.isImage || attachment.isVideo)) {
case (true, _):
return (
"attachment_audio", // stringlint:ignore
"audio".localized().lowercased()
)

case (_, true):
return (
"actionsheet_camera_roll_black", // stringlint:ignore
"media".localized().lowercased()
)

default:
return (
"actionsheet_document_black", // stringlint:disable
"file".localized().lowercased()
)
}
}()

// Image view
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ final class OpenGroupInvitationView: UIView {
let urlLabel = UILabel()
urlLabel.font = .systemFont(ofSize: Values.verySmallFontSize)
urlLabel.text = {
if let range = rawUrl.range(of: "?public_key=") { // stringlint:disable
if let range = rawUrl.range(of: "?public_key=") { // stringlint:ignore
return String(rawUrl[..<range.lowerBound])
}

Expand All @@ -64,7 +64,7 @@ final class OpenGroupInvitationView: UIView {

// Icon
let iconSize = OpenGroupInvitationView.iconSize
let iconName = (isOutgoing ? "Globe" : "Plus") // stringlint:disable
let iconName = (isOutgoing ? "Globe" : "Plus") // stringlint:ignore
let iconImageViewSize = OpenGroupInvitationView.iconImageViewSize
let iconImageView = UIImageView(
image: UIImage(named: iconName)?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ final class QuoteView: UIView {

if let attachment: Attachment = attachment {
let isAudio: Bool = attachment.isAudio
let fallbackImageName: String = (isAudio ? "attachment_audio" : "actionsheet_document_black") // stringlint:disable
let fallbackImageName: String = (isAudio ? "attachment_audio" : "actionsheet_document_black") // stringlint:ignore
let imageView: UIImageView = UIImageView(
image: UIImage(named: fallbackImageName)?
.resized(to: CGSize(width: iconSize, height: iconSize))?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ final class ReactionButton: UIView {
emojiLabel.text = viewModel.emoji.rawValue
numberLabel.text = (viewModel.number < 1000 ?
"\(viewModel.number)" :
String(format: "%.1f", Float(viewModel.number) / 1000) + "k" // stringlint:disable
String(format: "%.1f", Float(viewModel.number) / 1000) + "k" // stringlint:ignore
)
numberLabel.isHidden = (!showNumber && viewModel.number <= 1)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ struct OpenGroupInvitationView_SwiftUI: View {
private static let iconSize: CGFloat = 24
private static let iconImageViewSize: CGFloat = 48

// stringlint:ignore_contents
init(
name: String,
url: String,
Expand All @@ -38,7 +39,7 @@ struct OpenGroupInvitationView_SwiftUI: View {
spacing: Values.mediumSpacing
) {
// Icon
let iconName = (isOutgoing ? "Globe" : "Plus")
let iconName = (isOutgoing ? "Globe" : "Plus") // stringlint:ignore
if let iconImage = UIImage(named: iconName)?
.resized(to: CGSize(width: Self.iconSize, height: Self.iconSize))?
.withRenderingMode(.alwaysTemplate)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import SessionMessagingKit

struct VoiceMessageView_SwiftUI: View {
@State var isPlaying: Bool = false
@State var time: String = "0:00"
@State var speed: String = "1.5ร—"
@State var time: String = "0:00" // stringlint:ignore
@State var speed: String = "1.5ร—" // stringlint:ignore
@State var progress: Double = 0.0

private static let width: CGFloat = 160
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ import SessionUtilitiesKit
}
}

// stringlint:ignore_contents
fileprivate func startAnimation() {
stopAnimation()

Expand Down Expand Up @@ -199,8 +200,8 @@ import SessionUtilitiesKit

let groupAnimation = CAAnimationGroup()
groupAnimation.animations = [
makeAnimation("fillColor", colorValues), // stringlint:disable
makeAnimation("path", pathValues) // stringlint:disable
makeAnimation("fillColor", colorValues),
makeAnimation("path", pathValues)
]
groupAnimation.duration = animationDuration
groupAnimation.repeatCount = MAXFLOAT
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,19 +74,21 @@ public final class VoiceMessageView: UIView {
return result
}()

// stringlint:ignore_contents
private lazy var countdownLabel: UILabel = {
let result: UILabel = UILabel()
result.font = .systemFont(ofSize: Values.smallFontSize)
result.text = "0:00" // stringlint:disable
result.text = "0:00"
result.themeTextColor = .textPrimary

return result
}()

// stringlint:ignore_contents
private lazy var speedUpLabel: UILabel = {
let result: UILabel = UILabel()
result.font = .systemFont(ofSize: Values.smallFontSize)
result.text = "1.5x" // stringlint:disable
result.text = "1.5x"
result.themeTextColor = .textPrimary
result.textAlignment = .center
result.alpha = 0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1097,6 +1097,7 @@ final class VisibleMessageCell: MessageCell, TappableLabelDelegate {
}
}

// stringlint:ignore_contents
static func getBodyAttributedText(
for cellViewModel: MessageViewModel,
theme: Theme,
Expand Down
15 changes: 11 additions & 4 deletions Session/Conversations/Settings/ThreadSettingsViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -515,10 +515,17 @@ class ThreadSettingsViewModel: SessionTableViewModel, NavigationItemSource, Navi
),
confirmationInfo: ConfirmationModal.Info(
title: "groupLeave".localized(),
body: .attributedText(
(currentUserIsClosedGroupAdmin ? "groupDeleteDescription" : "groupLeaveDescription")
.put(key: "group_name", value: threadViewModel.displayName)
.localizedFormatted(baseFont: .boldSystemFont(ofSize: Values.smallFontSize))
body: (currentUserIsClosedGroupAdmin ?
.attributedText(
"groupDeleteDescription"
.put(key: "group_name", value: threadViewModel.displayName)
.localizedFormatted(baseFont: .boldSystemFont(ofSize: Values.smallFontSize))
) :
.attributedText(
"groupLeaveDescription"
.put(key: "group_name", value: threadViewModel.displayName)
.localizedFormatted(baseFont: .boldSystemFont(ofSize: Values.smallFontSize))
)
),
confirmTitle: "leave".localized(),
confirmStyle: .danger,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -551,7 +551,7 @@ extension ReactionListSheet {
emojiLabel.text = emoji
numberLabel.text = (count < 1000 ?
"\(count)" :
String(format: "%.1fk", Float(count) / 1000) // stringlint:disable
String(format: "%.1fk", Float(count) / 1000) // stringlint:ignore
)
snContentView.themeBorderColor = (isCurrentSelection ? .primary : .clear)
}
Expand Down
2 changes: 1 addition & 1 deletion Session/Emoji/EmojiWithSkinTones.swift
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ extension Emoji {
guard withDefaultEmoji else { return recentReactionEmoji }

// Add in our default emoji if desired
let defaultEmoji = ["๐Ÿ˜‚", "๐Ÿฅฐ", "๐Ÿ˜ข", "๐Ÿ˜ก", "๐Ÿ˜ฎ", "๐Ÿ˜ˆ"] // stringlint:disable
let defaultEmoji = ["๐Ÿ˜‚", "๐Ÿฅฐ", "๐Ÿ˜ข", "๐Ÿ˜ก", "๐Ÿ˜ฎ", "๐Ÿ˜ˆ"] // stringlint:ignore
.filter { !recentReactionEmoji.contains($0) }

return Array(recentReactionEmoji
Expand Down
Loading

0 comments on commit ef0f73a

Please sign in to comment.