Skip to content

Commit 719d738

Browse files
committed
Move duplicate warnings to separate function
1 parent 5ecc967 commit 719d738

10 files changed

+32
-102
lines changed

R.swift/Generators/ColorGenerator.swift

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -31,17 +31,7 @@ struct ColorGenerator: Generator {
3131
let name = SwiftIdentifier(name: palette.filename)
3232
let groupedColors = palette.colors.groupBySwiftIdentifiers { $0.0 }
3333

34-
for (sanitizedName, duplicates) in groupedColors.duplicates {
35-
warn("Skipping \(duplicates.count) colors in palette '\(palette.filename)' because symbol '\(sanitizedName)' would be generated for all of these colors: \(duplicates.joinWithSeparator(", "))")
36-
}
37-
38-
let empties = groupedColors.empties
39-
if let empty = empties.first where empties.count == 1 {
40-
warn("Skipping 1 color in palette '\(palette.filename)' because no swift identifier can be generated for image: \(empty)")
41-
}
42-
else if empties.count > 1 {
43-
warn("Skipping \(empties.count) images in palette '\(palette.filename)' because no swift identifier can be generated for all of these images: \(empties.joinWithSeparator(", "))")
44-
}
34+
groupedColors.printWarningsForDuplicatesAndEmpties(source: "color", container: "in palette '\(palette.filename)'", result: "color")
4535

4636
return Struct(
4737
comments: ["This `R.color.\(name)` struct is generated, and contains static references to \(groupedColors.uniques.count) colors."],

R.swift/Generators/ImageGenerator.swift

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,17 +24,7 @@ struct ImageGenerator: Generator {
2424
let allFunctions = assetFolderImageNames + imagesNames
2525
let groupedFunctions = allFunctions.groupBySwiftIdentifiers { $0 }
2626

27-
for (sanitizedName, duplicates) in groupedFunctions.duplicates {
28-
warn("Skipping \(duplicates.count) images because symbol '\(sanitizedName)' would be generated for all of these images: \(duplicates.joinWithSeparator(", "))")
29-
}
30-
31-
let empties = groupedFunctions.empties
32-
if let empty = empties.first where empties.count == 1 {
33-
warn("Skipping 1 image because no swift identifier can be generated for image: \(empty)")
34-
}
35-
else if empties.count > 1 {
36-
warn("Skipping \(empties.count) images because no swift identifier can be generated for all of these images: \(empties.joinWithSeparator(", "))")
37-
}
27+
groupedFunctions.printWarningsForDuplicatesAndEmpties(source: "image", result: "image")
3828

3929
let imageLets = groupedFunctions
4030
.uniques

R.swift/Generators/NibGenerator.swift

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -38,17 +38,7 @@ struct NibGenerator: Generator {
3838
init(nibs: [Nib]) {
3939
let groupedNibs = nibs.groupBySwiftIdentifiers { $0.name }
4040

41-
for (name, duplicates) in groupedNibs.duplicates {
42-
warn("Skipping \(duplicates.count) xibs because symbol '\(name)' would be generated for all of these xibs: \(duplicates.joinWithSeparator(", "))")
43-
}
44-
45-
let empties = groupedNibs.empties
46-
if let empty = empties.first where empties.count == 1 {
47-
warn("Skipping 1 xib because no swift identifier can be generated for xib: \(empty)")
48-
}
49-
else if empties.count > 1 {
50-
warn("Skipping \(empties.count) xibs because no swift identifier can be generated for all of these xibs: \(empties.joinWithSeparator(", "))")
51-
}
41+
groupedNibs.printWarningsForDuplicatesAndEmpties(source: "xib", result: "xib")
5242

5343
internalStruct = Struct(
5444
type: Type(module: .Host, name: "nib"),

R.swift/Generators/ResourceFileGenerator.swift

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,7 @@ struct ResourceFileGenerator: Generator {
1515
init(resourceFiles: [ResourceFile]) {
1616
let groupedResourceFiles = resourceFiles.groupBySwiftIdentifiers { $0.fullname }
1717

18-
for (name, duplicates) in groupedResourceFiles.duplicates {
19-
warn("Skipping \(duplicates.count) resource files because symbol '\(name)' would be generated for all of these files: \(duplicates.joinWithSeparator(", "))")
20-
}
21-
22-
let empties = groupedResourceFiles.empties
23-
if let empty = empties.first where empties.count == 1 {
24-
warn("Skipping 1 resource file because no swift identifier can be generated for file: \(empty)")
25-
}
26-
else if empties.count > 1 {
27-
warn("Skipping \(empties.count) resource files because no swift identifier can be generated for all of these files: \(empties.joinWithSeparator(", "))")
28-
}
18+
groupedResourceFiles.printWarningsForDuplicatesAndEmpties(source: "resource file", result: "file")
2919

3020
let resourceFileProperties: [Property] = groupedResourceFiles
3121
.uniques

R.swift/Generators/ReuseIdentifierGenerator.swift

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,7 @@ struct ReuseIdentifierGenerator: Generator {
2020

2121
let groupedReusables = deduplicatedReusables.groupBySwiftIdentifiers { $0.identifier }
2222

23-
for (name, duplicates) in groupedReusables.duplicates {
24-
warn("Skipping \(duplicates.count) reuseIdentifiers because symbol '\(name)' would be generated for all of these reuseIdentifiers: \(duplicates.joinWithSeparator(", "))")
25-
}
26-
27-
let empties = groupedReusables.empties
28-
if let empty = empties.first where empties.count == 1 {
29-
warn("Skipping 1 reuseIdentifier because no swift identifier can be generated for reuseIdentifier: \(empty)")
30-
}
31-
else if empties.count > 1 {
32-
warn("Skipping \(empties.count) reuseIdentifiers because no swift identifier can be generated for all of these reuseIdentifiers: \(empties.joinWithSeparator(", "))")
33-
}
23+
groupedReusables.printWarningsForDuplicatesAndEmpties(source: "reuseIdentifier", result: "reuseIdentifier")
3424

3525
let reuseIdentifierProperties = groupedReusables
3626
.uniques

R.swift/Generators/SegueGenerator.swift

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -46,17 +46,7 @@ struct SegueGenerator: Generator {
4646
for (sourceType, seguesBySourceType) in deduplicatedSeguesWithInfo.groupBy({ $0.sourceType }) {
4747
let groupedSeguesWithInfo = seguesBySourceType.groupBySwiftIdentifiers { $0.segue.identifier }
4848

49-
for (name, duplicates) in groupedSeguesWithInfo.duplicates {
50-
warn("Skipping \(duplicates.count) segues for '\(sourceType)' because symbol '\(name)' would be generated for all of these segues, but with a different destination or segue type: \(duplicates.joinWithSeparator(", "))")
51-
}
52-
53-
let empties = groupedSeguesWithInfo.empties
54-
if let empty = empties.first where empties.count == 1 {
55-
warn("Skipping 1 segue for '\(sourceType)' because no swift identifier can be generated for segue: \(empty)")
56-
}
57-
else if empties.count > 1 {
58-
warn("Skipping \(empties.count) segues for '\(sourceType)' because no swift identifier can be generated for all of these segues: \(empties.joinWithSeparator(", "))")
59-
}
49+
groupedSeguesWithInfo.printWarningsForDuplicatesAndEmpties(source: "segue", container: "for '\(sourceType)'", result: "segue")
6050

6151
let sts = groupedSeguesWithInfo
6252
.uniques

R.swift/Generators/StoryboardGenerator.swift

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,7 @@ struct StoryboardGenerator: Generator {
1515
init(storyboards: [Storyboard]) {
1616
let groupedStoryboards = storyboards.groupBySwiftIdentifiers { $0.name }
1717

18-
for (name, duplicates) in groupedStoryboards.duplicates {
19-
warn("Skipping \(duplicates.count) storyboards because symbol '\(name)' would be generated for all of these storyboards: \(duplicates.joinWithSeparator(", "))")
20-
}
21-
22-
let empties = groupedStoryboards.empties
23-
if let empty = empties.first where empties.count == 1 {
24-
warn("Skipping 1 storyboard because no swift identifier can be generated for storyboard: \(empty)")
25-
}
26-
else if empties.count > 1 {
27-
warn("Skipping \(empties.count) storyboards because no swift identifier can be generated for all of these storyboards: \(empties.joinWithSeparator(", "))")
28-
}
18+
groupedStoryboards.printWarningsForDuplicatesAndEmpties(source: "storyboard", result: "storyboard")
2919

3020
let storyboardStructs = groupedStoryboards
3121
.uniques

R.swift/Generators/StringsGenerator.swift

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,7 @@ struct StringsGenerator: Generator {
1717
let localized = localizableStrings.groupBy { $0.filename }
1818
let groupedLocalized = localized.groupBySwiftIdentifiers { $0.0 }
1919

20-
for (sanitizedName, duplicates) in groupedLocalized.duplicates {
21-
warn("Skipping \(duplicates.count) strings files because symbol '\(sanitizedName)' would be generated for all of these filenames: \(duplicates.joinWithSeparator(", "))")
22-
}
23-
24-
let empties = groupedLocalized.empties
25-
if let empty = empties.first where empties.count == 1 {
26-
warn("Skipping 1 strings file because no swift identifier can be generated for filename: \(empty)")
27-
}
28-
else if empties.count > 1 {
29-
warn("Skipping \(empties.count) strings files because no swift identifier can be generated for all of these filenames: \(empties.joinWithSeparator(", "))")
30-
}
20+
groupedLocalized.printWarningsForDuplicatesAndEmpties(source: "strings file", result: "file")
3121

3222
externalStruct = Struct(
3323
comments: ["This `R.string` struct is generated, and contains static references to \(groupedLocalized.uniques.count) localization tables."],
@@ -75,17 +65,7 @@ struct StringsGenerator: Generator {
7565
let filenameLocale = ls.locale.withFilename(filename)
7666
let groupedKeys = ls.dictionary.keys.groupBySwiftIdentifiers { $0 }
7767

78-
for (sanitizedName, duplicates) in groupedKeys.duplicates {
79-
warn("Skipping \(duplicates.count) strings in \(filenameLocale) because symbol '\(sanitizedName)' would be generated for all of these keys: \(duplicates.map { "'\($0)'" }.joinWithSeparator(", "))")
80-
}
81-
82-
let empties = groupedKeys.empties
83-
if let empty = empties.first where empties.count == 1 {
84-
warn("Skipping 1 string in \(filenameLocale) because no swift identifier can be generated for key: \(empty)")
85-
}
86-
else if empties.count > 1 {
87-
warn("Skipping \(empties.count) strings in \(filenameLocale) because no swift identifier can be generated for all of these keys: \(empties.joinWithSeparator(", "))")
88-
}
68+
groupedKeys.printWarningsForDuplicatesAndEmpties(source: "string", container: "in \(filenameLocale)", result: "key")
8969

9070
// Save uniques
9171
for key in groupedKeys.uniques {

R.swift/Util/SwiftIdentifier.swift

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,26 @@ struct SwiftNameGroups<T> {
7878
let uniques: [T]
7979
let duplicates: [(SwiftIdentifier, [String])] // Identifiers that result in duplicate Swift names
8080
let empties: [String] // Identifiers (wrapped in quotes) that result in empty swift names
81+
82+
func printWarningsForDuplicatesAndEmpties(source source: String, container: String? = nil, result: String) {
83+
84+
let sourceSingular = [source, container].flatMap { $0 }.joinWithSeparator(" ")
85+
let sourcePlural = ["\(source)s", container].flatMap { $0 }.joinWithSeparator(" ")
86+
87+
let resultSingular = result
88+
let resultPlural = "\(result)s"
89+
90+
for (sanitizedName, dups) in duplicates {
91+
warn("Skipping \(dups.count) \(sourcePlural) because symbol '\(sanitizedName)' would be generated for all of these \(resultPlural): \(dups.joinWithSeparator(", "))")
92+
}
93+
94+
if let empty = empties.first where empties.count == 1 {
95+
warn("Skipping 1 \(sourceSingular) because no swift identifier can be generated for \(resultSingular): \(empty)")
96+
}
97+
else if empties.count > 1 {
98+
warn("Skipping \(empties.count) \(sourcePlural) because no swift identifier can be generated for all of these \(resultPlural): \(empties.joinWithSeparator(", "))")
99+
}
100+
}
81101
}
82102

83103
extension SequenceType {

ResourceApp/ResourceAppTests/ResourceAppTests.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,16 @@ class ResourceAppTests: XCTestCase {
1717
"warning: [R.swift] Skipping 2 xibs because symbol 'duplicate' would be generated for all of these xibs: Duplicate, duplicate",
1818
"warning: [R.swift] Skipping 2 storyboards because symbol 'duplicate' would be generated for all of these storyboards: Duplicate, duplicate",
1919
"warning: [R.swift] Skipping 2 reuseIdentifiers because symbol 'duplicateCellView' would be generated for all of these reuseIdentifiers: DuplicateCellView, duplicateCellView",
20-
"warning: [R.swift] Skipping 2 segues for 'SecondViewController' because symbol 'toFirst' would be generated for all of these segues, but with a different destination or segue type: ToFirst, toFirst",
20+
"warning: [R.swift] Skipping 2 segues for 'SecondViewController' because symbol 'toFirst' would be generated for all of these segues: ToFirst, toFirst",
2121
"warning: [R.swift] Skipping 2 images because symbol 'theAppIcon' would be generated for all of these images: The App Icon, TheAppIcon",
2222
"warning: [R.swift] Skipping 2 images because symbol 'second' would be generated for all of these images: Second, second",
2323
"warning: [R.swift] Skipping 2 resource files because symbol 'duplicateJson' would be generated for all of these files: Duplicate.json, duplicateJson",
2424
"warning: [R.swift] Destination view controller with id Zbd-89-K73 for segue toUnknown in FirstViewController not found in storyboard References. Is this storyboard corrupt?",
2525
"warning: [R.swift] Skipping 1 reuseIdentifier because no swift identifier can be generated for reuseIdentifier: ' '",
2626
"warning: [R.swift] Skipping 2 colors in palette 'My R.swift colors' because symbol 'black' would be generated for all of these colors: Black, Black?",
2727

28-
"warning: [R.swift] Skipping 2 strings files because symbol 'duplicate' would be generated for all of these filenames: Duplicate, Duplicate#",
29-
"warning: [R.swift] Skipping 1 strings file because no swift identifier can be generated for filename: '@@'",
28+
"warning: [R.swift] Skipping 2 strings files because symbol 'duplicate' would be generated for all of these files: Duplicate, Duplicate#",
29+
"warning: [R.swift] Skipping 1 strings file because no swift identifier can be generated for file: '@@'",
3030
"warning: [R.swift] Skipping 1 string in 'Generic' because no swift identifier can be generated for key: '#'",
3131
"warning: [R.swift] Strings file 'Localizable' (en) is missing translations for keys: 'japanese only'",
3232
"warning: [R.swift] Strings file 'Localizable' (es) is missing translations for keys: 'japanese only'",

0 commit comments

Comments
 (0)