From cc6f4adb55efb3575807358f39a1ba7007965857 Mon Sep 17 00:00:00 2001 From: Lukas Kukacka Date: Fri, 28 Sep 2018 19:37:11 +0200 Subject: [PATCH] #489 - Fixed Swiftlint false-positive for Obj-C compatible Strings --- ...4-context-localizable-objc-compatible-customname.swift | 4 ++++ ...-context-localizable-objc-compatible-no-comments.swift | 4 ++++ ...context-localizable-objc-compatible-publicAccess.swift | 4 ++++ .../flat-swift4-context-multiple-objc-compatible.swift | 8 ++++++-- templates/strings/flat-swift4.stencil | 4 ++-- 5 files changed, 20 insertions(+), 4 deletions(-) diff --git a/Tests/Fixtures/Generated/Strings/flat-swift4-context-localizable-objc-compatible-customname.swift b/Tests/Fixtures/Generated/Strings/flat-swift4-context-localizable-objc-compatible-customname.swift index bd6576719..dfb565969 100644 --- a/Tests/Fixtures/Generated/Strings/flat-swift4-context-localizable-objc-compatible-customname.swift +++ b/Tests/Fixtures/Generated/Strings/flat-swift4-context-localizable-objc-compatible-customname.swift @@ -47,6 +47,10 @@ internal final class XCTLoc: NSObject { // MARK: - Implementation Details extension XCTLoc { + private static func tr(_ table: String, _ key: String) -> String { + return NSLocalizedString(key, tableName: table, bundle: Bundle(for: BundleToken.self), comment: "") + } + private static func tr(_ table: String, _ key: String, _ args: CVarArg...) -> String { let format = NSLocalizedString(key, tableName: table, bundle: Bundle(for: BundleToken.self), comment: "") return String(format: format, locale: Locale.current, arguments: args) diff --git a/Tests/Fixtures/Generated/Strings/flat-swift4-context-localizable-objc-compatible-no-comments.swift b/Tests/Fixtures/Generated/Strings/flat-swift4-context-localizable-objc-compatible-no-comments.swift index 8bfddcfc1..87c4feb80 100644 --- a/Tests/Fixtures/Generated/Strings/flat-swift4-context-localizable-objc-compatible-no-comments.swift +++ b/Tests/Fixtures/Generated/Strings/flat-swift4-context-localizable-objc-compatible-no-comments.swift @@ -36,6 +36,10 @@ internal final class L10n: NSObject { // MARK: - Implementation Details extension L10n { + private static func tr(_ table: String, _ key: String) -> String { + return NSLocalizedString(key, tableName: table, bundle: Bundle(for: BundleToken.self), comment: "") + } + private static func tr(_ table: String, _ key: String, _ args: CVarArg...) -> String { let format = NSLocalizedString(key, tableName: table, bundle: Bundle(for: BundleToken.self), comment: "") return String(format: format, locale: Locale.current, arguments: args) diff --git a/Tests/Fixtures/Generated/Strings/flat-swift4-context-localizable-objc-compatible-publicAccess.swift b/Tests/Fixtures/Generated/Strings/flat-swift4-context-localizable-objc-compatible-publicAccess.swift index 557a32fbe..67ecf9a26 100644 --- a/Tests/Fixtures/Generated/Strings/flat-swift4-context-localizable-objc-compatible-publicAccess.swift +++ b/Tests/Fixtures/Generated/Strings/flat-swift4-context-localizable-objc-compatible-publicAccess.swift @@ -47,6 +47,10 @@ public final class L10n: NSObject { // MARK: - Implementation Details extension L10n { + private static func tr(_ table: String, _ key: String) -> String { + return NSLocalizedString(key, tableName: table, bundle: Bundle(for: BundleToken.self), comment: "") + } + private static func tr(_ table: String, _ key: String, _ args: CVarArg...) -> String { let format = NSLocalizedString(key, tableName: table, bundle: Bundle(for: BundleToken.self), comment: "") return String(format: format, locale: Locale.current, arguments: args) diff --git a/Tests/Fixtures/Generated/Strings/flat-swift4-context-multiple-objc-compatible.swift b/Tests/Fixtures/Generated/Strings/flat-swift4-context-multiple-objc-compatible.swift index b22892e65..05918f0e5 100644 --- a/Tests/Fixtures/Generated/Strings/flat-swift4-context-multiple-objc-compatible.swift +++ b/Tests/Fixtures/Generated/Strings/flat-swift4-context-multiple-objc-compatible.swift @@ -12,7 +12,7 @@ import Foundation @objcMembers internal final class L10n: NSObject { @objcMembers @objc(L10nLocalizable) - internal final class Localizable: NSObject { + internal final class Localizable: NSObject { // swiftlint:disable:this attributes /// Some alert body there internal static let alertMessage = L10n.tr("Localizable", "alert_message") /// Title of the alert @@ -45,7 +45,7 @@ internal final class L10n: NSObject { internal static let settingsUserProfileSectionHEADERTITLE = L10n.tr("Localizable", "settings.user_profile_section.HEADER_TITLE") } @objcMembers @objc(L10nLocMultiline) - internal final class LocMultiline: NSObject { + internal final class LocMultiline: NSObject { // swiftlint:disable:this attributes /// multi\nline internal static let multiline = L10n.tr("LocMultiline", "MULTILINE") /// test @@ -63,6 +63,10 @@ internal final class L10n: NSObject { // MARK: - Implementation Details extension L10n { + private static func tr(_ table: String, _ key: String) -> String { + return NSLocalizedString(key, tableName: table, bundle: Bundle(for: BundleToken.self), comment: "") + } + private static func tr(_ table: String, _ key: String, _ args: CVarArg...) -> String { let format = NSLocalizedString(key, tableName: table, bundle: Bundle(for: BundleToken.self), comment: "") return String(format: format, locale: Locale.current, arguments: args) diff --git a/templates/strings/flat-swift4.stencil b/templates/strings/flat-swift4.stencil index 147f910c2..2a2bd216f 100644 --- a/templates/strings/flat-swift4.stencil +++ b/templates/strings/flat-swift4.stencil @@ -50,9 +50,9 @@ import Foundation {% set typeName %}{{table.name|swiftIdentifier:"pretty"|escapeReservedKeywords}}{% endset %} {% if param.objcCompatible %} @objcMembers @objc({{rootTypeName}}{{typeName}}) - {{accessModifier}} final class {{typeName}}: NSObject { + {{accessModifier}} final class {{typeName}}: NSObject { // swiftlint:disable:this attributes {% else %} - {{accessModifier}} enum {{table.name|swiftIdentifier:"pretty"|escapeReservedKeywords}} { + {{accessModifier}} enum {{typeName}} { {% endif %} {% filter indent:2 %}{% call recursiveBlock table.name table.levels %}{% endfilter %} }