danger-localizationlinter 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (136) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +20 -0
  3. data/.travis.yml +12 -0
  4. data/Gemfile +6 -0
  5. data/Gemfile.lock +167 -0
  6. data/Guardfile +21 -0
  7. data/LICENSE.txt +22 -0
  8. data/README.md +62 -0
  9. data/Rakefile +25 -0
  10. data/danger-localizationlinter.gemspec +60 -0
  11. data/ext/localizationlinter/helper/validate_wording_cli.rb +21 -0
  12. data/ext/localizationlinter/localizationlinter.rb +331 -0
  13. data/ext/localizationlinter/swiftgen_localizables_check.stencil +36 -0
  14. data/lib/danger_localizationlinter.rb +3 -0
  15. data/lib/danger_plugin.rb +3 -0
  16. data/lib/localizationlinter/gem_version.rb +5 -0
  17. data/lib/localizationlinter/plugin.rb +96 -0
  18. data/spec/Test/Podfile +6 -0
  19. data/spec/Test/Podfile.lock +16 -0
  20. data/spec/Test/Pods/SwiftGen/CHANGELOG.md +1357 -0
  21. data/spec/Test/Pods/SwiftGen/LICENCE +21 -0
  22. data/spec/Test/Pods/SwiftGen/README.md +892 -0
  23. data/spec/Test/Pods/SwiftGen/bin/swiftgen +0 -0
  24. data/spec/Test/Pods/SwiftGen/lib/Commander.framework/Commander +0 -0
  25. data/spec/Test/Pods/SwiftGen/lib/Commander.framework/Resources/Info.plist +48 -0
  26. data/spec/Test/Pods/SwiftGen/lib/Commander.framework/Versions/A/Commander +0 -0
  27. data/spec/Test/Pods/SwiftGen/lib/Commander.framework/Versions/A/Resources/Info.plist +48 -0
  28. data/spec/Test/Pods/SwiftGen/lib/Commander.framework/Versions/A/_CodeSignature/CodeResources +132 -0
  29. data/spec/Test/Pods/SwiftGen/lib/Commander.framework/Versions/Current/Commander +0 -0
  30. data/spec/Test/Pods/SwiftGen/lib/Commander.framework/Versions/Current/Resources/Info.plist +48 -0
  31. data/spec/Test/Pods/SwiftGen/lib/Commander.framework/Versions/Current/_CodeSignature/CodeResources +132 -0
  32. data/spec/Test/Pods/SwiftGen/lib/Kanna.framework/Kanna +0 -0
  33. data/spec/Test/Pods/SwiftGen/lib/Kanna.framework/Resources/Info.plist +48 -0
  34. data/spec/Test/Pods/SwiftGen/lib/Kanna.framework/Versions/A/Kanna +0 -0
  35. data/spec/Test/Pods/SwiftGen/lib/Kanna.framework/Versions/A/Resources/Info.plist +48 -0
  36. data/spec/Test/Pods/SwiftGen/lib/Kanna.framework/Versions/A/_CodeSignature/CodeResources +132 -0
  37. data/spec/Test/Pods/SwiftGen/lib/Kanna.framework/Versions/Current/Kanna +0 -0
  38. data/spec/Test/Pods/SwiftGen/lib/Kanna.framework/Versions/Current/Resources/Info.plist +48 -0
  39. data/spec/Test/Pods/SwiftGen/lib/Kanna.framework/Versions/Current/_CodeSignature/CodeResources +132 -0
  40. data/spec/Test/Pods/SwiftGen/lib/PathKit.framework/PathKit +0 -0
  41. data/spec/Test/Pods/SwiftGen/lib/PathKit.framework/Resources/Info.plist +48 -0
  42. data/spec/Test/Pods/SwiftGen/lib/PathKit.framework/Versions/A/PathKit +0 -0
  43. data/spec/Test/Pods/SwiftGen/lib/PathKit.framework/Versions/A/Resources/Info.plist +48 -0
  44. data/spec/Test/Pods/SwiftGen/lib/PathKit.framework/Versions/A/_CodeSignature/CodeResources +132 -0
  45. data/spec/Test/Pods/SwiftGen/lib/PathKit.framework/Versions/Current/PathKit +0 -0
  46. data/spec/Test/Pods/SwiftGen/lib/PathKit.framework/Versions/Current/Resources/Info.plist +48 -0
  47. data/spec/Test/Pods/SwiftGen/lib/PathKit.framework/Versions/Current/_CodeSignature/CodeResources +132 -0
  48. data/spec/Test/Pods/SwiftGen/lib/Stencil.framework/Resources/Info.plist +48 -0
  49. data/spec/Test/Pods/SwiftGen/lib/Stencil.framework/Stencil +0 -0
  50. data/spec/Test/Pods/SwiftGen/lib/Stencil.framework/Versions/A/Resources/Info.plist +48 -0
  51. data/spec/Test/Pods/SwiftGen/lib/Stencil.framework/Versions/A/Stencil +0 -0
  52. data/spec/Test/Pods/SwiftGen/lib/Stencil.framework/Versions/A/_CodeSignature/CodeResources +132 -0
  53. data/spec/Test/Pods/SwiftGen/lib/Stencil.framework/Versions/Current/Resources/Info.plist +48 -0
  54. data/spec/Test/Pods/SwiftGen/lib/Stencil.framework/Versions/Current/Stencil +0 -0
  55. data/spec/Test/Pods/SwiftGen/lib/Stencil.framework/Versions/Current/_CodeSignature/CodeResources +132 -0
  56. data/spec/Test/Pods/SwiftGen/lib/StencilSwiftKit.framework/Resources/Info.plist +48 -0
  57. data/spec/Test/Pods/SwiftGen/lib/StencilSwiftKit.framework/StencilSwiftKit +0 -0
  58. data/spec/Test/Pods/SwiftGen/lib/StencilSwiftKit.framework/Versions/A/Resources/Info.plist +48 -0
  59. data/spec/Test/Pods/SwiftGen/lib/StencilSwiftKit.framework/Versions/A/StencilSwiftKit +0 -0
  60. data/spec/Test/Pods/SwiftGen/lib/StencilSwiftKit.framework/Versions/A/_CodeSignature/CodeResources +132 -0
  61. data/spec/Test/Pods/SwiftGen/lib/StencilSwiftKit.framework/Versions/Current/Resources/Info.plist +48 -0
  62. data/spec/Test/Pods/SwiftGen/lib/StencilSwiftKit.framework/Versions/Current/StencilSwiftKit +0 -0
  63. data/spec/Test/Pods/SwiftGen/lib/StencilSwiftKit.framework/Versions/Current/_CodeSignature/CodeResources +132 -0
  64. data/spec/Test/Pods/SwiftGen/lib/SwiftGenKit.framework/Resources/Info.plist +48 -0
  65. data/spec/Test/Pods/SwiftGen/lib/SwiftGenKit.framework/SwiftGenKit +0 -0
  66. data/spec/Test/Pods/SwiftGen/lib/SwiftGenKit.framework/Versions/A/Resources/Info.plist +48 -0
  67. data/spec/Test/Pods/SwiftGen/lib/SwiftGenKit.framework/Versions/A/SwiftGenKit +0 -0
  68. data/spec/Test/Pods/SwiftGen/lib/SwiftGenKit.framework/Versions/A/_CodeSignature/CodeResources +132 -0
  69. data/spec/Test/Pods/SwiftGen/lib/SwiftGenKit.framework/Versions/Current/Resources/Info.plist +48 -0
  70. data/spec/Test/Pods/SwiftGen/lib/SwiftGenKit.framework/Versions/Current/SwiftGenKit +0 -0
  71. data/spec/Test/Pods/SwiftGen/lib/SwiftGenKit.framework/Versions/Current/_CodeSignature/CodeResources +132 -0
  72. data/spec/Test/Pods/SwiftGen/lib/Yams.framework/Resources/Info.plist +48 -0
  73. data/spec/Test/Pods/SwiftGen/lib/Yams.framework/Versions/A/Resources/Info.plist +48 -0
  74. data/spec/Test/Pods/SwiftGen/lib/Yams.framework/Versions/A/Yams +0 -0
  75. data/spec/Test/Pods/SwiftGen/lib/Yams.framework/Versions/A/_CodeSignature/CodeResources +132 -0
  76. data/spec/Test/Pods/SwiftGen/lib/Yams.framework/Versions/Current/Resources/Info.plist +48 -0
  77. data/spec/Test/Pods/SwiftGen/lib/Yams.framework/Versions/Current/Yams +0 -0
  78. data/spec/Test/Pods/SwiftGen/lib/Yams.framework/Versions/Current/_CodeSignature/CodeResources +132 -0
  79. data/spec/Test/Pods/SwiftGen/lib/Yams.framework/Yams +0 -0
  80. data/spec/Test/Pods/SwiftGen/templates/colors/literals-swift4.stencil +43 -0
  81. data/spec/Test/Pods/SwiftGen/templates/colors/literals-swift5.stencil +43 -0
  82. data/spec/Test/Pods/SwiftGen/templates/colors/swift4.stencil +84 -0
  83. data/spec/Test/Pods/SwiftGen/templates/colors/swift5.stencil +84 -0
  84. data/spec/Test/Pods/SwiftGen/templates/coredata/swift4.stencil +211 -0
  85. data/spec/Test/Pods/SwiftGen/templates/coredata/swift5.stencil +211 -0
  86. data/spec/Test/Pods/SwiftGen/templates/fonts/swift4.stencil +110 -0
  87. data/spec/Test/Pods/SwiftGen/templates/fonts/swift5.stencil +113 -0
  88. data/spec/Test/Pods/SwiftGen/templates/ib/scenes-swift4.stencil +157 -0
  89. data/spec/Test/Pods/SwiftGen/templates/ib/scenes-swift5.stencil +159 -0
  90. data/spec/Test/Pods/SwiftGen/templates/ib/segues-swift4.stencil +60 -0
  91. data/spec/Test/Pods/SwiftGen/templates/ib/segues-swift5.stencil +60 -0
  92. data/spec/Test/Pods/SwiftGen/templates/json/inline-swift4.stencil +82 -0
  93. data/spec/Test/Pods/SwiftGen/templates/json/inline-swift5.stencil +82 -0
  94. data/spec/Test/Pods/SwiftGen/templates/json/runtime-swift4.stencil +112 -0
  95. data/spec/Test/Pods/SwiftGen/templates/json/runtime-swift5.stencil +112 -0
  96. data/spec/Test/Pods/SwiftGen/templates/plist/inline-swift4.stencil +82 -0
  97. data/spec/Test/Pods/SwiftGen/templates/plist/inline-swift5.stencil +82 -0
  98. data/spec/Test/Pods/SwiftGen/templates/plist/runtime-swift4.stencil +117 -0
  99. data/spec/Test/Pods/SwiftGen/templates/plist/runtime-swift5.stencil +117 -0
  100. data/spec/Test/Pods/SwiftGen/templates/strings/flat-swift4.stencil +97 -0
  101. data/spec/Test/Pods/SwiftGen/templates/strings/flat-swift5.stencil +97 -0
  102. data/spec/Test/Pods/SwiftGen/templates/strings/objc-h.stencil +66 -0
  103. data/spec/Test/Pods/SwiftGen/templates/strings/objc-m.stencil +90 -0
  104. data/spec/Test/Pods/SwiftGen/templates/strings/structured-swift4.stencil +102 -0
  105. data/spec/Test/Pods/SwiftGen/templates/strings/structured-swift5.stencil +102 -0
  106. data/spec/Test/Pods/SwiftGen/templates/xcassets/swift4.stencil +266 -0
  107. data/spec/Test/Pods/SwiftGen/templates/xcassets/swift5.stencil +274 -0
  108. data/spec/Test/Pods/SwiftGen/templates/yaml/inline-swift4.stencil +92 -0
  109. data/spec/Test/Pods/SwiftGen/templates/yaml/inline-swift5.stencil +92 -0
  110. data/spec/Test/Test.xcodeproj/project.pbxproj +406 -0
  111. data/spec/Test/Test.xcodeproj/project.xcworkspace/contents.xcworkspacedata +7 -0
  112. data/spec/Test/Test.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist +8 -0
  113. data/spec/Test/Test.xcworkspace/contents.xcworkspacedata +10 -0
  114. data/spec/Test/Test.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist +8 -0
  115. data/spec/Test/Test/AppDelegate.swift +36 -0
  116. data/spec/Test/Test/Assets.xcassets/AccentColor.colorset/Contents.json +11 -0
  117. data/spec/Test/Test/Assets.xcassets/AppIcon.appiconset/Contents.json +98 -0
  118. data/spec/Test/Test/Assets.xcassets/Contents.json +6 -0
  119. data/spec/Test/Test/ContentView.swift +21 -0
  120. data/spec/Test/Test/Info.plist +62 -0
  121. data/spec/Test/Test/SceneDelegate.swift +63 -0
  122. data/spec/Test/Test/all_target_main_language.yml +1 -0
  123. data/spec/Test/Test/en.lproj/LaunchScreen.storyboard +25 -0
  124. data/spec/Test/Test/en.lproj/localizable.strings +3 -0
  125. data/spec/Test/Test/fr.lproj/LaunchScreen.storyboard +25 -0
  126. data/spec/Test/Test/fr.lproj/localizable.strings +3 -0
  127. data/spec/localizationofficer_spec.rb +116 -0
  128. data/spec/spec_helper.rb +67 -0
  129. data/spec/support/fixtures/all_target_main_language.yml +1 -0
  130. data/spec/support/fixtures/resources/TEST/en.lproj/Localizable.strings +8 -0
  131. data/spec/support/fixtures/resources/TEST/en.lproj/Localizable.stringsdict +30 -0
  132. data/spec/support/fixtures/resources/TEST_KO/en.lproj/Localizable.strings +11 -0
  133. data/spec/support/fixtures/resources/TEST_KO/en.lproj/Localizable.stringsdict +30 -0
  134. data/spec/support/fixtures/resources/TEST_KO/fr.lproj/Localizable.strings +11 -0
  135. data/spec/support/fixtures/resources/TEST_KO/fr.lproj/Localizable.stringsdict +30 -0
  136. metadata +491 -0
@@ -0,0 +1,43 @@
1
+ // swiftlint:disable all
2
+ // Generated using SwiftGen — https://github.com/SwiftGen/SwiftGen
3
+
4
+ {% if palettes %}
5
+ {% set enumName %}{{param.enumName|default:"ColorName"}}{% endset %}
6
+ {% set accessModifier %}{% if param.publicAccess %}public{% else %}internal{% endif %}{% endset %}
7
+ #if os(OSX)
8
+ import AppKit
9
+ {% if enumName != 'NSColor' %}{{accessModifier}} enum {{enumName}} { }{% endif %}
10
+ #elseif os(iOS) || os(tvOS) || os(watchOS)
11
+ import UIKit
12
+ {% if enumName != 'UIColor' %}{{accessModifier}} enum {{enumName}} { }{% endif %}
13
+ #endif
14
+
15
+ // swiftlint:disable superfluous_disable_command
16
+ // swiftlint:disable file_length
17
+
18
+ // MARK: - Colors
19
+
20
+ // swiftlint:disable identifier_name line_length type_body_length
21
+ {{accessModifier}} extension {{enumName}} {
22
+ {% macro h2f hex %}{{hex|hexToInt|int255toFloat}}{% endmacro %}
23
+ {% macro enumBlock colors accessPrefix %}
24
+ {% for color in colors %}
25
+ /// 0x{{color.red}}{{color.green}}{{color.blue}}{{color.alpha}} (r: {{color.red|hexToInt}}, g: {{color.green|hexToInt}}, b: {{color.blue|hexToInt}}, a: {{color.alpha|hexToInt}})
26
+ {{accessPrefix}}static let {{color.name|swiftIdentifier:"pretty"|lowerFirstWord|escapeReservedKeywords}} = #colorLiteral(red: {% call h2f color.red %}, green: {% call h2f color.green %}, blue: {% call h2f color.blue %}, alpha: {% call h2f color.alpha %})
27
+ {% endfor %}
28
+ {% endmacro %}
29
+ {% if palettes.count > 1 or param.forceFileNameEnum %}
30
+ {% set accessPrefix %}{{accessModifier}} {% endset %}
31
+ {% for palette in palettes %}
32
+ enum {{palette.name|swiftIdentifier:"pretty"|escapeReservedKeywords}} {
33
+ {% filter indent:2 %}{% call enumBlock palette.colors accessPrefix %}{% endfilter %}
34
+ }
35
+ {% endfor %}
36
+ {% else %}
37
+ {% call enumBlock palettes.first.colors "" %}
38
+ {% endif %}
39
+ }
40
+ // swiftlint:enable identifier_name line_length type_body_length
41
+ {% else %}
42
+ // No color found
43
+ {% endif %}
@@ -0,0 +1,84 @@
1
+ // swiftlint:disable all
2
+ // Generated using SwiftGen — https://github.com/SwiftGen/SwiftGen
3
+
4
+ {% if palettes %}
5
+ {% set colorAlias %}{{param.colorAliasName|default:"Color"}}{% endset %}
6
+ {% set accessModifier %}{% if param.publicAccess %}public{% else %}internal{% endif %}{% endset %}
7
+ #if os(OSX)
8
+ import AppKit.NSColor
9
+ {{accessModifier}} typealias {{colorAlias}} = NSColor
10
+ #elseif os(iOS) || os(tvOS) || os(watchOS)
11
+ import UIKit.UIColor
12
+ {{accessModifier}} typealias {{colorAlias}} = UIColor
13
+ #endif
14
+
15
+ // swiftlint:disable superfluous_disable_command file_length implicit_return
16
+
17
+ // MARK: - Colors
18
+
19
+ // swiftlint:disable identifier_name line_length type_body_length
20
+ {% set enumName %}{{param.enumName|default:"ColorName"}}{% endset %}
21
+ {{accessModifier}} struct {{enumName}} {
22
+ {{accessModifier}} let rgbaValue: UInt32
23
+ {{accessModifier}} var color: {{colorAlias}} { return {{colorAlias}}(named: self) }
24
+
25
+ {% macro rgbaValue color %}0x{{color.red}}{{color.green}}{{color.blue}}{{color.alpha}}{% endmacro %}
26
+ {% macro enumBlock colors %}
27
+ {% for color in colors %}
28
+ /// <span style="display:block;width:3em;height:2em;border:1px solid black;background:#{{color.red}}{{color.green}}{{color.blue}}"></span>
29
+ /// Alpha: {{color.alpha|hexToInt|int255toFloat|percent}} <br/> (0x{{color.red}}{{color.green}}{{color.blue}}{{color.alpha}})
30
+ {{accessModifier}} static let {{color.name|swiftIdentifier:"pretty"|lowerFirstWord|escapeReservedKeywords}} = {{enumName}}(rgbaValue: {% call rgbaValue color %})
31
+ {% endfor %}
32
+ {% endmacro %}
33
+ {% if palettes.count > 1 or param.forceFileNameEnum %}
34
+ {% for palette in palettes %}
35
+ {{accessModifier}} enum {{palette.name|swiftIdentifier:"pretty"|escapeReservedKeywords}} {
36
+ {% filter indent:2 %}{% call enumBlock palette.colors %}{% endfilter %}
37
+ }
38
+ {% endfor %}
39
+ {% else %}
40
+ {% call enumBlock palettes.first.colors %}
41
+ {% endif %}
42
+ }
43
+ // swiftlint:enable identifier_name line_length type_body_length
44
+
45
+ // MARK: - Implementation Details
46
+
47
+ internal extension {{colorAlias}} {
48
+ convenience init(rgbaValue: UInt32) {
49
+ let components = RGBAComponents(rgbaValue: rgbaValue).normalized
50
+ self.init(red: components[0], green: components[1], blue: components[2], alpha: components[3])
51
+ }
52
+ }
53
+
54
+ private struct RGBAComponents {
55
+ let rgbaValue: UInt32
56
+
57
+ private var shifts: [UInt32] {
58
+ [
59
+ rgbaValue >> 24, // red
60
+ rgbaValue >> 16, // green
61
+ rgbaValue >> 8, // blue
62
+ rgbaValue // alpha
63
+ ]
64
+ }
65
+
66
+ private var components: [CGFloat] {
67
+ shifts.map {
68
+ CGFloat($0 & 0xff)
69
+ }
70
+ }
71
+
72
+ var normalized: [CGFloat] {
73
+ components.map { $0 / 255.0 }
74
+ }
75
+ }
76
+
77
+ {{accessModifier}} extension {{colorAlias}} {
78
+ convenience init(named color: {{enumName}}) {
79
+ self.init(rgbaValue: color.rgbaValue)
80
+ }
81
+ }
82
+ {% else %}
83
+ // No color found
84
+ {% endif %}
@@ -0,0 +1,84 @@
1
+ // swiftlint:disable all
2
+ // Generated using SwiftGen — https://github.com/SwiftGen/SwiftGen
3
+
4
+ {% if palettes %}
5
+ {% set colorAlias %}{{param.colorAliasName|default:"Color"}}{% endset %}
6
+ {% set accessModifier %}{% if param.publicAccess %}public{% else %}internal{% endif %}{% endset %}
7
+ #if os(OSX)
8
+ import AppKit.NSColor
9
+ {{accessModifier}} typealias {{colorAlias}} = NSColor
10
+ #elseif os(iOS) || os(tvOS) || os(watchOS)
11
+ import UIKit.UIColor
12
+ {{accessModifier}} typealias {{colorAlias}} = UIColor
13
+ #endif
14
+
15
+ // swiftlint:disable superfluous_disable_command file_length implicit_return
16
+
17
+ // MARK: - Colors
18
+
19
+ // swiftlint:disable identifier_name line_length type_body_length
20
+ {% set enumName %}{{param.enumName|default:"ColorName"}}{% endset %}
21
+ {{accessModifier}} struct {{enumName}} {
22
+ {{accessModifier}} let rgbaValue: UInt32
23
+ {{accessModifier}} var color: {{colorAlias}} { return {{colorAlias}}(named: self) }
24
+
25
+ {% macro rgbaValue color %}0x{{color.red}}{{color.green}}{{color.blue}}{{color.alpha}}{% endmacro %}
26
+ {% macro enumBlock colors %}
27
+ {% for color in colors %}
28
+ /// <span style="display:block;width:3em;height:2em;border:1px solid black;background:#{{color.red}}{{color.green}}{{color.blue}}"></span>
29
+ /// Alpha: {{color.alpha|hexToInt|int255toFloat|percent}} <br/> (0x{{color.red}}{{color.green}}{{color.blue}}{{color.alpha}})
30
+ {{accessModifier}} static let {{color.name|swiftIdentifier:"pretty"|lowerFirstWord|escapeReservedKeywords}} = {{enumName}}(rgbaValue: {% call rgbaValue color %})
31
+ {% endfor %}
32
+ {% endmacro %}
33
+ {% if palettes.count > 1 or param.forceFileNameEnum %}
34
+ {% for palette in palettes %}
35
+ {{accessModifier}} enum {{palette.name|swiftIdentifier:"pretty"|escapeReservedKeywords}} {
36
+ {% filter indent:2 %}{% call enumBlock palette.colors %}{% endfilter %}
37
+ }
38
+ {% endfor %}
39
+ {% else %}
40
+ {% call enumBlock palettes.first.colors %}
41
+ {% endif %}
42
+ }
43
+ // swiftlint:enable identifier_name line_length type_body_length
44
+
45
+ // MARK: - Implementation Details
46
+
47
+ internal extension {{colorAlias}} {
48
+ convenience init(rgbaValue: UInt32) {
49
+ let components = RGBAComponents(rgbaValue: rgbaValue).normalized
50
+ self.init(red: components[0], green: components[1], blue: components[2], alpha: components[3])
51
+ }
52
+ }
53
+
54
+ private struct RGBAComponents {
55
+ let rgbaValue: UInt32
56
+
57
+ private var shifts: [UInt32] {
58
+ [
59
+ rgbaValue >> 24, // red
60
+ rgbaValue >> 16, // green
61
+ rgbaValue >> 8, // blue
62
+ rgbaValue // alpha
63
+ ]
64
+ }
65
+
66
+ private var components: [CGFloat] {
67
+ shifts.map {
68
+ CGFloat($0 & 0xff)
69
+ }
70
+ }
71
+
72
+ var normalized: [CGFloat] {
73
+ components.map { $0 / 255.0 }
74
+ }
75
+ }
76
+
77
+ {{accessModifier}} extension {{colorAlias}} {
78
+ convenience init(named color: {{enumName}}) {
79
+ self.init(rgbaValue: color.rgbaValue)
80
+ }
81
+ }
82
+ {% else %}
83
+ // No color found
84
+ {% endif %}
@@ -0,0 +1,211 @@
1
+ // swiftlint:disable all
2
+ // Generated using SwiftGen — https://github.com/SwiftGen/SwiftGen
3
+
4
+ // swiftlint:disable superfluous_disable_command implicit_return
5
+ // swiftlint:disable sorted_imports
6
+ import CoreData
7
+ import Foundation
8
+ {% for import in param.extraImports %}
9
+ import {{ import }}
10
+ {% empty %}
11
+ {# If extraImports is a single String instead of an array, `for` considers it empty but we still have to check if there's a single String value #}
12
+ {% if param.extraImports %}import {{ param.extraImports }}{% endif %}
13
+ {% endfor %}
14
+
15
+ // swiftlint:disable attributes file_length vertical_whitespace_closing_braces
16
+ // swiftlint:disable identifier_name line_length type_body_length
17
+ {% set accessModifier %}{% if param.publicAccess %}public{% else %}internal{% endif %}{% endset %}
18
+
19
+ {% for model in models %}
20
+ {% for name, entity in model.entities %}
21
+ {% set superclass %}{{ model.entities[entity.superEntity].className|default:"NSManagedObject" }}{% endset %}
22
+ {% set entityClassName %}{{ entity.className|default:"NSManagedObject" }}{% endset %}
23
+ // MARK: - {{ entity.name }}
24
+
25
+ {% if not entity.shouldGenerateCode %}
26
+ // Note: '{{ entity.name }}' has codegen enabled for Xcode, skipping code generation.
27
+
28
+ {% elif entityClassName|contains:"." %}
29
+ // Warning: '{{ entityClassName }}' cannot be a valid type name, skipping code generation.
30
+
31
+ {% else %}
32
+ {% if param.generateObjcName %}
33
+ @objc({{ entityClassName }})
34
+ {% endif %}
35
+ {{ accessModifier }} class {{ entityClassName }}: {{ superclass }} {
36
+ {% set override %}{% if superclass != "NSManagedObject" %}override {% endif %}{% endset %}
37
+ {{ override }}{{ accessModifier }} class var entityName: String {
38
+ return "{{ entity.name }}"
39
+ }
40
+
41
+ {{ override }}{{ accessModifier }} class func entity(in managedObjectContext: NSManagedObjectContext) -> NSEntityDescription? {
42
+ return NSEntityDescription.entity(forEntityName: entityName, in: managedObjectContext)
43
+ }
44
+
45
+ @available(*, deprecated, renamed: "makeFetchRequest", message: "To avoid collisions with the less concrete method in `NSManagedObject`, please use `makeFetchRequest()` instead.")
46
+ @nonobjc {{ accessModifier }} class func fetchRequest() -> NSFetchRequest<{{ entityClassName }}> {
47
+ return NSFetchRequest<{{ entityClassName }}>(entityName: entityName)
48
+ }
49
+
50
+ @nonobjc {{ accessModifier }} class func makeFetchRequest() -> NSFetchRequest<{{ entityClassName }}> {
51
+ return NSFetchRequest<{{ entityClassName }}>(entityName: entityName)
52
+ }
53
+
54
+ // swiftlint:disable discouraged_optional_boolean discouraged_optional_collection
55
+ {% for attribute in entity.attributes %}
56
+ {% if attribute.userInfo.RawType %}
57
+ {% set rawType attribute.userInfo.RawType %}
58
+ {% set unwrapOptional attribute.userInfo.unwrapOptional %}
59
+ {{ accessModifier }} var {{ attribute.name }}: {{ rawType }}{% if not unwrapOptional %}?{% endif %} {
60
+ get {
61
+ let key = "{{ attribute.name }}"
62
+ willAccessValue(forKey: key)
63
+ defer { didAccessValue(forKey: key) }
64
+
65
+ {% if unwrapOptional %}
66
+ guard let value = primitiveValue(forKey: key) as? {{ rawType }}.RawValue,
67
+ let result = {{ rawType }}(rawValue: value) else {
68
+ fatalError("Could not convert value for key '\(key)' to type '{{ rawType }}'")
69
+ }
70
+ return result
71
+ {% else %}
72
+ guard let value = primitiveValue(forKey: key) as? {{ rawType }}.RawValue else {
73
+ return nil
74
+ }
75
+ return {{ rawType }}(rawValue: value)
76
+ {% endif %}
77
+ }
78
+ set {
79
+ let key = "{{ attribute.name }}"
80
+ willChangeValue(forKey: key)
81
+ defer { didChangeValue(forKey: key) }
82
+
83
+ setPrimitiveValue(newValue{% if not unwrapOptional %}?{% endif %}.rawValue, forKey: key)
84
+ }
85
+ }
86
+ {% elif attribute.usesScalarValueType and attribute.isOptional %}
87
+ {{ accessModifier }} var {{ attribute.name }}: {{ attribute.typeName }}? {
88
+ get {
89
+ let key = "{{ attribute.name }}"
90
+ willAccessValue(forKey: key)
91
+ defer { didAccessValue(forKey: key) }
92
+
93
+ return primitiveValue(forKey: key) as? {{ attribute.typeName }}
94
+ }
95
+ set {
96
+ let key = "{{ attribute.name }}"
97
+ willChangeValue(forKey: key)
98
+ defer { didChangeValue(forKey: key) }
99
+
100
+ setPrimitiveValue(newValue, forKey: key)
101
+ }
102
+ }
103
+ {% else %}
104
+ @NSManaged {{ accessModifier }} var {{ attribute.name }}: {{ attribute.typeName }}{% if attribute.isOptional %}?{% endif %}
105
+ {% endif %}
106
+ {% endfor %}
107
+ {% for relationship in entity.relationships %}
108
+ {% if relationship.isToMany %}
109
+ @NSManaged {{ accessModifier }} var {{ relationship.name }}: {% if relationship.isOrdered %}NSOrderedSet{% else %}Set<{{ model.entities[relationship.destinationEntity].className|default:"NSManagedObject" }}>{% endif %}{% if relationship.isOptional %}?{% endif %}
110
+ {% else %}
111
+ @NSManaged {{ accessModifier }} var {{ relationship.name }}: {{ model.entities[relationship.destinationEntity].className|default:"NSManagedObject" }}{% if relationship.isOptional %}?{% endif %}
112
+ {% endif %}
113
+ {% endfor %}
114
+ {% for fetchedProperty in entity.fetchedProperties %}
115
+ @NSManaged {{ accessModifier }} var {{ fetchedProperty.name }}: [{{ fetchedProperty.fetchRequest.entity }}]
116
+ {% endfor %}
117
+ // swiftlint:enable discouraged_optional_boolean discouraged_optional_collection
118
+ }
119
+
120
+ {% for relationship in entity.relationships where relationship.isToMany %}
121
+ {% set destinationEntityClassName %}{{ model.entities[relationship.destinationEntity].className|default:"NSManagedObject" }}{% endset %}
122
+ {% set collectionClassName %}{% if relationship.isOrdered %}NSOrderedSet{% else %}Set<{{ destinationEntityClassName }}>{% endif %}{% endset %}
123
+ {% set relationshipName %}{{ relationship.name | upperFirstLetter }}{% endset %}
124
+ // MARK: Relationship {{ relationshipName }}
125
+
126
+ extension {{ entityClassName }} {
127
+ {% if relationship.isOrdered %}
128
+ @objc(insertObject:in{{ relationshipName }}AtIndex:)
129
+ @NSManaged public func insertInto{{ relationshipName }}(_ value: {{ destinationEntityClassName }}, at idx: Int)
130
+
131
+ @objc(removeObjectFrom{{ relationshipName }}AtIndex:)
132
+ @NSManaged public func removeFrom{{ relationshipName }}(at idx: Int)
133
+
134
+ @objc(insert{{ relationshipName }}:atIndexes:)
135
+ @NSManaged public func insertInto{{ relationshipName }}(_ values: [{{ destinationEntityClassName }}], at indexes: NSIndexSet)
136
+
137
+ @objc(remove{{ relationshipName }}AtIndexes:)
138
+ @NSManaged public func removeFrom{{ relationshipName }}(at indexes: NSIndexSet)
139
+
140
+ @objc(replaceObjectIn{{ relationshipName }}AtIndex:withObject:)
141
+ @NSManaged public func replace{{ relationshipName }}(at idx: Int, with value: {{ destinationEntityClassName }})
142
+
143
+ @objc(replace{{ relationshipName }}AtIndexes:with{{ relationshipName }}:)
144
+ @NSManaged public func replace{{ relationshipName }}(at indexes: NSIndexSet, with values: [{{ destinationEntityClassName }}])
145
+
146
+ {% endif %}
147
+ @objc(add{{ relationshipName }}Object:)
148
+ @NSManaged public func addTo{{ relationshipName }}(_ value: {{ destinationEntityClassName }})
149
+
150
+ @objc(remove{{ relationshipName }}Object:)
151
+ @NSManaged public func removeFrom{{ relationshipName }}(_ value: {{ destinationEntityClassName }})
152
+
153
+ @objc(add{{ relationshipName }}:)
154
+ @NSManaged public func addTo{{ relationshipName }}(_ values: {{ collectionClassName }})
155
+
156
+ @objc(remove{{ relationshipName }}:)
157
+ @NSManaged public func removeFrom{{ relationshipName }}(_ values: {{ collectionClassName }})
158
+ }
159
+
160
+ {% endfor %}
161
+ {% if model.fetchRequests[entity.name].count > 0 %}
162
+ // MARK: Fetch Requests
163
+
164
+ extension {{ entityClassName }} {
165
+ {% for fetchRequest in model.fetchRequests[entity.name] %}
166
+ {% set resultTypeName %}{% filter removeNewlines:"leading" %}
167
+ {% if fetchRequest.resultType == "Object" %}
168
+ {{ entityClassName }}
169
+ {% elif fetchRequest.resultType == "Object ID" %}
170
+ NSManagedObjectID
171
+ {% elif fetchRequest.resultType == "Dictionary" %}
172
+ [String: Any]
173
+ {% endif %}
174
+ {% endfilter %}{% endset %}
175
+ class func fetch{{ fetchRequest.name | upperFirstLetter }}({% filter removeNewlines:"leading" %}
176
+ managedObjectContext: NSManagedObjectContext
177
+ {% for variableName, variableType in fetchRequest.substitutionVariables %}
178
+ , {{ variableName | lowerFirstWord }}: {{ variableType }}
179
+ {% endfor %}
180
+ {% endfilter %}) throws -> [{{ resultTypeName }}] {
181
+ guard let persistentStoreCoordinator = managedObjectContext.persistentStoreCoordinator else {
182
+ fatalError("Managed object context has no persistent store coordinator for getting fetch request templates")
183
+ }
184
+ let model = persistentStoreCoordinator.managedObjectModel
185
+ let substitutionVariables: [String: Any] = [
186
+ {% for variableName, variableType in fetchRequest.substitutionVariables %}
187
+ "{{ variableName }}": {{ variableName | lowerFirstWord }}{{ "," if not forloop.last }}
188
+ {% empty %}
189
+ :
190
+ {% endfor %}
191
+ ]
192
+
193
+ guard let fetchRequest = model.fetchRequestFromTemplate(withName: "{{ fetchRequest.name }}", substitutionVariables: substitutionVariables) else {
194
+ fatalError("No fetch request template named '{{ fetchRequest.name }}' found.")
195
+ }
196
+
197
+ guard let result = try managedObjectContext.fetch(fetchRequest) as? [{{ resultTypeName }}] else {
198
+ fatalError("Unable to cast fetch result to correct result type.")
199
+ }
200
+
201
+ return result
202
+ }
203
+
204
+ {% endfor %}
205
+ }
206
+
207
+ {% endif %}
208
+ {% endif %}
209
+ {% endfor %}
210
+ {% endfor %}
211
+ // swiftlint:enable identifier_name line_length type_body_length
@@ -0,0 +1,211 @@
1
+ // swiftlint:disable all
2
+ // Generated using SwiftGen — https://github.com/SwiftGen/SwiftGen
3
+
4
+ // swiftlint:disable superfluous_disable_command implicit_return
5
+ // swiftlint:disable sorted_imports
6
+ import CoreData
7
+ import Foundation
8
+ {% for import in param.extraImports %}
9
+ import {{ import }}
10
+ {% empty %}
11
+ {# If extraImports is a single String instead of an array, `for` considers it empty but we still have to check if there's a single String value #}
12
+ {% if param.extraImports %}import {{ param.extraImports }}{% endif %}
13
+ {% endfor %}
14
+
15
+ // swiftlint:disable attributes file_length vertical_whitespace_closing_braces
16
+ // swiftlint:disable identifier_name line_length type_body_length
17
+ {% set accessModifier %}{% if param.publicAccess %}public{% else %}internal{% endif %}{% endset %}
18
+
19
+ {% for model in models %}
20
+ {% for name, entity in model.entities %}
21
+ {% set superclass %}{{ model.entities[entity.superEntity].className|default:"NSManagedObject" }}{% endset %}
22
+ {% set entityClassName %}{{ entity.className|default:"NSManagedObject" }}{% endset %}
23
+ // MARK: - {{ entity.name }}
24
+
25
+ {% if not entity.shouldGenerateCode %}
26
+ // Note: '{{ entity.name }}' has codegen enabled for Xcode, skipping code generation.
27
+
28
+ {% elif entityClassName|contains:"." %}
29
+ // Warning: '{{ entityClassName }}' cannot be a valid type name, skipping code generation.
30
+
31
+ {% else %}
32
+ {% if param.generateObjcName %}
33
+ @objc({{ entityClassName }})
34
+ {% endif %}
35
+ {{ accessModifier }} class {{ entityClassName }}: {{ superclass }} {
36
+ {% set override %}{% if superclass != "NSManagedObject" %}override {% endif %}{% endset %}
37
+ {{ override }}{{ accessModifier }} class var entityName: String {
38
+ return "{{ entity.name }}"
39
+ }
40
+
41
+ {{ override }}{{ accessModifier }} class func entity(in managedObjectContext: NSManagedObjectContext) -> NSEntityDescription? {
42
+ return NSEntityDescription.entity(forEntityName: entityName, in: managedObjectContext)
43
+ }
44
+
45
+ @available(*, deprecated, renamed: "makeFetchRequest", message: "To avoid collisions with the less concrete method in `NSManagedObject`, please use `makeFetchRequest()` instead.")
46
+ @nonobjc {{ accessModifier }} class func fetchRequest() -> NSFetchRequest<{{ entityClassName }}> {
47
+ return NSFetchRequest<{{ entityClassName }}>(entityName: entityName)
48
+ }
49
+
50
+ @nonobjc {{ accessModifier }} class func makeFetchRequest() -> NSFetchRequest<{{ entityClassName }}> {
51
+ return NSFetchRequest<{{ entityClassName }}>(entityName: entityName)
52
+ }
53
+
54
+ // swiftlint:disable discouraged_optional_boolean discouraged_optional_collection
55
+ {% for attribute in entity.attributes %}
56
+ {% if attribute.userInfo.RawType %}
57
+ {% set rawType attribute.userInfo.RawType %}
58
+ {% set unwrapOptional attribute.userInfo.unwrapOptional %}
59
+ {{ accessModifier }} var {{ attribute.name }}: {{ rawType }}{% if not unwrapOptional %}?{% endif %} {
60
+ get {
61
+ let key = "{{ attribute.name }}"
62
+ willAccessValue(forKey: key)
63
+ defer { didAccessValue(forKey: key) }
64
+
65
+ {% if unwrapOptional %}
66
+ guard let value = primitiveValue(forKey: key) as? {{ rawType }}.RawValue,
67
+ let result = {{ rawType }}(rawValue: value) else {
68
+ fatalError("Could not convert value for key '\(key)' to type '{{ rawType }}'")
69
+ }
70
+ return result
71
+ {% else %}
72
+ guard let value = primitiveValue(forKey: key) as? {{ rawType }}.RawValue else {
73
+ return nil
74
+ }
75
+ return {{ rawType }}(rawValue: value)
76
+ {% endif %}
77
+ }
78
+ set {
79
+ let key = "{{ attribute.name }}"
80
+ willChangeValue(forKey: key)
81
+ defer { didChangeValue(forKey: key) }
82
+
83
+ setPrimitiveValue(newValue{% if not unwrapOptional %}?{% endif %}.rawValue, forKey: key)
84
+ }
85
+ }
86
+ {% elif attribute.usesScalarValueType and attribute.isOptional %}
87
+ {{ accessModifier }} var {{ attribute.name }}: {{ attribute.typeName }}? {
88
+ get {
89
+ let key = "{{ attribute.name }}"
90
+ willAccessValue(forKey: key)
91
+ defer { didAccessValue(forKey: key) }
92
+
93
+ return primitiveValue(forKey: key) as? {{ attribute.typeName }}
94
+ }
95
+ set {
96
+ let key = "{{ attribute.name }}"
97
+ willChangeValue(forKey: key)
98
+ defer { didChangeValue(forKey: key) }
99
+
100
+ setPrimitiveValue(newValue, forKey: key)
101
+ }
102
+ }
103
+ {% else %}
104
+ @NSManaged {{ accessModifier }} var {{ attribute.name }}: {{ attribute.typeName }}{% if attribute.isOptional %}?{% endif %}
105
+ {% endif %}
106
+ {% endfor %}
107
+ {% for relationship in entity.relationships %}
108
+ {% if relationship.isToMany %}
109
+ @NSManaged {{ accessModifier }} var {{ relationship.name }}: {% if relationship.isOrdered %}NSOrderedSet{% else %}Set<{{ model.entities[relationship.destinationEntity].className|default:"NSManagedObject" }}>{% endif %}{% if relationship.isOptional %}?{% endif %}
110
+ {% else %}
111
+ @NSManaged {{ accessModifier }} var {{ relationship.name }}: {{ model.entities[relationship.destinationEntity].className|default:"NSManagedObject" }}{% if relationship.isOptional %}?{% endif %}
112
+ {% endif %}
113
+ {% endfor %}
114
+ {% for fetchedProperty in entity.fetchedProperties %}
115
+ @NSManaged {{ accessModifier }} var {{ fetchedProperty.name }}: [{{ fetchedProperty.fetchRequest.entity }}]
116
+ {% endfor %}
117
+ // swiftlint:enable discouraged_optional_boolean discouraged_optional_collection
118
+ }
119
+
120
+ {% for relationship in entity.relationships where relationship.isToMany %}
121
+ {% set destinationEntityClassName %}{{ model.entities[relationship.destinationEntity].className|default:"NSManagedObject" }}{% endset %}
122
+ {% set collectionClassName %}{% if relationship.isOrdered %}NSOrderedSet{% else %}Set<{{ destinationEntityClassName }}>{% endif %}{% endset %}
123
+ {% set relationshipName %}{{ relationship.name | upperFirstLetter }}{% endset %}
124
+ // MARK: Relationship {{ relationshipName }}
125
+
126
+ extension {{ entityClassName }} {
127
+ {% if relationship.isOrdered %}
128
+ @objc(insertObject:in{{ relationshipName }}AtIndex:)
129
+ @NSManaged public func insertInto{{ relationshipName }}(_ value: {{ destinationEntityClassName }}, at idx: Int)
130
+
131
+ @objc(removeObjectFrom{{ relationshipName }}AtIndex:)
132
+ @NSManaged public func removeFrom{{ relationshipName }}(at idx: Int)
133
+
134
+ @objc(insert{{ relationshipName }}:atIndexes:)
135
+ @NSManaged public func insertInto{{ relationshipName }}(_ values: [{{ destinationEntityClassName }}], at indexes: NSIndexSet)
136
+
137
+ @objc(remove{{ relationshipName }}AtIndexes:)
138
+ @NSManaged public func removeFrom{{ relationshipName }}(at indexes: NSIndexSet)
139
+
140
+ @objc(replaceObjectIn{{ relationshipName }}AtIndex:withObject:)
141
+ @NSManaged public func replace{{ relationshipName }}(at idx: Int, with value: {{ destinationEntityClassName }})
142
+
143
+ @objc(replace{{ relationshipName }}AtIndexes:with{{ relationshipName }}:)
144
+ @NSManaged public func replace{{ relationshipName }}(at indexes: NSIndexSet, with values: [{{ destinationEntityClassName }}])
145
+
146
+ {% endif %}
147
+ @objc(add{{ relationshipName }}Object:)
148
+ @NSManaged public func addTo{{ relationshipName }}(_ value: {{ destinationEntityClassName }})
149
+
150
+ @objc(remove{{ relationshipName }}Object:)
151
+ @NSManaged public func removeFrom{{ relationshipName }}(_ value: {{ destinationEntityClassName }})
152
+
153
+ @objc(add{{ relationshipName }}:)
154
+ @NSManaged public func addTo{{ relationshipName }}(_ values: {{ collectionClassName }})
155
+
156
+ @objc(remove{{ relationshipName }}:)
157
+ @NSManaged public func removeFrom{{ relationshipName }}(_ values: {{ collectionClassName }})
158
+ }
159
+
160
+ {% endfor %}
161
+ {% if model.fetchRequests[entity.name].count > 0 %}
162
+ // MARK: Fetch Requests
163
+
164
+ extension {{ entityClassName }} {
165
+ {% for fetchRequest in model.fetchRequests[entity.name] %}
166
+ {% set resultTypeName %}{% filter removeNewlines:"leading" %}
167
+ {% if fetchRequest.resultType == "Object" %}
168
+ {{ entityClassName }}
169
+ {% elif fetchRequest.resultType == "Object ID" %}
170
+ NSManagedObjectID
171
+ {% elif fetchRequest.resultType == "Dictionary" %}
172
+ [String: Any]
173
+ {% endif %}
174
+ {% endfilter %}{% endset %}
175
+ class func fetch{{ fetchRequest.name | upperFirstLetter }}({% filter removeNewlines:"leading" %}
176
+ managedObjectContext: NSManagedObjectContext
177
+ {% for variableName, variableType in fetchRequest.substitutionVariables %}
178
+ , {{ variableName | lowerFirstWord }}: {{ variableType }}
179
+ {% endfor %}
180
+ {% endfilter %}) throws -> [{{ resultTypeName }}] {
181
+ guard let persistentStoreCoordinator = managedObjectContext.persistentStoreCoordinator else {
182
+ fatalError("Managed object context has no persistent store coordinator for getting fetch request templates")
183
+ }
184
+ let model = persistentStoreCoordinator.managedObjectModel
185
+ let substitutionVariables: [String: Any] = [
186
+ {% for variableName, variableType in fetchRequest.substitutionVariables %}
187
+ "{{ variableName }}": {{ variableName | lowerFirstWord }}{{ "," if not forloop.last }}
188
+ {% empty %}
189
+ :
190
+ {% endfor %}
191
+ ]
192
+
193
+ guard let fetchRequest = model.fetchRequestFromTemplate(withName: "{{ fetchRequest.name }}", substitutionVariables: substitutionVariables) else {
194
+ fatalError("No fetch request template named '{{ fetchRequest.name }}' found.")
195
+ }
196
+
197
+ guard let result = try managedObjectContext.fetch(fetchRequest) as? [{{ resultTypeName }}] else {
198
+ fatalError("Unable to cast fetch result to correct result type.")
199
+ }
200
+
201
+ return result
202
+ }
203
+
204
+ {% endfor %}
205
+ }
206
+
207
+ {% endif %}
208
+ {% endif %}
209
+ {% endfor %}
210
+ {% endfor %}
211
+ // swiftlint:enable identifier_name line_length type_body_length