Skip to content

Commit

Permalink
Fix an issue with strings that are only ignored in one file
Browse files Browse the repository at this point in the history
  • Loading branch information
xavierLowmiller committed Apr 18, 2021
1 parent a35cf5a commit 2c9fdc6
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 4 deletions.
7 changes: 4 additions & 3 deletions Sources/XcodeDeadStrings/DeadStringData.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@ public struct DeadStringsData {
public init(url: URL, sourcePath: String? = nil, localizationPath: String? = nil) throws {
aliveStrings = try extractStrings(fromFilesAt: url.appendingOptionalPathComponent(sourcePath))
localizedStringResults = extractLocalizedKeys(fromFilesAt: url.appendingOptionalPathComponent(localizationPath))
deadStrings = Set(localizedStringResults
.filter { !$0.isIgnored }
.map(\.key)).subtracting(aliveStrings)
let ignoredKeys = localizedStringResults.filter { $0.isIgnored }.map(\.key)
deadStrings = Set(localizedStringResults.map(\.key))
.subtracting(aliveStrings)
.subtracting(ignoredKeys)
}

public var descriptionByFile: String {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,6 @@

// no_dead_string
"alive_string_2" = "Das wird noch gebraucht";

// Not marked dead here
"alive_string_3" = "Not marked ignored here";
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,6 @@

// no_dead_string
"alive_string_2" = "This is still needed";

// no_dead_string
"alive_string_3" = "Only ignored here";
2 changes: 1 addition & 1 deletion Tests/XcodeDeadStringsTests/ExtractDeadStringsTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ final class DeadStringsDataTests: XCTestCase {
// Then
XCTAssertEqual(deadStringData.deadStrings, ["dead_string", "en_only", "de_only"])
XCTAssertEqual(deadStringData.aliveStrings.count, 38)
XCTAssertEqual(deadStringData.localizedStringResults.count, 24)
XCTAssertEqual(deadStringData.localizedStringResults.count, 26)
XCTAssertEqual(deadStringData.stringsToDelete.count, 2)
let locations: [LocationStringResult] = deadStringData.stringsToDelete.reduce(into: []) {
$0 += $1.value
Expand Down

0 comments on commit 2c9fdc6

Please sign in to comment.