Skip to content

Commit 50532a5

Browse files
authored
Merge pull request #1 from reddavis/feature/equatable
If Value is equatable, make the wrapper equatable
2 parents 6133dfb + fe24e0c commit 50532a5

17 files changed

Lines changed: 304 additions & 185 deletions

File tree

.github/FUNDING.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# These are supported funding model platforms
2+
3+
github: reddavis
4+
patreon: # Replace with a single Patreon username
5+
open_collective: # Replace with a single Open Collective username
6+
ko_fi: # Replace with a single Ko-fi username
7+
tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel
8+
community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry
9+
liberapay: # Replace with a single Liberapay username
10+
issuehunt: # Replace with a single IssueHunt username
11+
otechie: # Replace with a single Otechie username
12+
custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2']

.github/workflows/ci.yml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches: [ main ]
6+
pull_request:
7+
branches: [ main ]
8+
9+
jobs:
10+
ios-latest:
11+
name: Unit Test - iOS 15.2, Xcode 13.2
12+
runs-on: macOS-11
13+
env:
14+
DEVELOPER_DIR: /Applications/Xcode_13.2.app/Contents/Developer
15+
steps:
16+
- uses: actions/checkout@v2
17+
- name: Run Tests
18+
run: Scripts/test -d "OS=15.2,name=iPhone 13 Pro"
19+

.github/workflows/swiftlint.yml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
name: SwiftLint
2+
3+
on:
4+
pull_request:
5+
paths:
6+
- '.github/workflows/swiftlint.yml'
7+
- '.swiftlint.yml'
8+
- '**/*.swift'
9+
10+
jobs:
11+
SwiftLint:
12+
runs-on: ubuntu-latest
13+
steps:
14+
- name: Swiftlint
15+
uses: norio-nomura/action-swiftlint@3.2.1
16+
with:
17+
args: --strict
18+
env:
19+
WORKING_DIRECTORY: Validate
20+
DIFF_BASE: ${{ github.base_ref }}

.swiftlint.yml

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
only_rules:
2+
- closure_spacing
3+
- colon
4+
- empty_count
5+
- fatal_error_message
6+
- force_cast
7+
- force_try
8+
- force_unwrapping
9+
- implicitly_unwrapped_optional
10+
- legacy_cggeometry_functions
11+
- legacy_constant
12+
- legacy_constructor
13+
- legacy_nsgeometry_functions
14+
- operator_usage_whitespace
15+
- redundant_string_enum_value
16+
- return_arrow_whitespace
17+
- trailing_newline
18+
- type_name
19+
- unused_optional_binding
20+
- vertical_whitespace
21+
- void_return
22+
- custom_rules
23+
24+
custom_rules:
25+
no_direct_standard_out_logs:
26+
name: "Writing log messages directly to standard out is disallowed"
27+
regex: "(\\bprint|\\bdebugPrint|\\bdump|Swift\\.print|Swift\\.debugPrint|Swift\\.dump)\\s*\\("
28+
match_kinds:
29+
- identifier
30+
message: "Don't commit `print(…)`, `debugPrint(…)`, or `dump(…)` as they write to standard out in release. Either log to a dedicated logging system or silence this warning in debug-only scenarios explicitly using `// swiftlint:disable:next no_direct_standard_out_logs`"
31+
severity: error
32+
33+
vertical_whitespace:
34+
max_empty_lines: 4

README.md

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,6 @@ dependencies: [
2323
]
2424
```
2525

26-
## Note
27-
28-
Worth noting Validate is still in very early days and API's are expected to change. Saying that, [SEMVER](https://semver.org) will be kept.
29-
3026
## Documentation
3127

3228
[API Reference](https://swift-validate.netlify.app)
@@ -38,8 +34,7 @@ import SwiftUI
3834
import Validate
3935

4036

41-
struct ContentView: View
42-
{
37+
struct ContentView: View {
4338
@Validate(.presence()) var name: String = ""
4439

4540
var body: some View {
@@ -82,8 +77,7 @@ You're not just limited to using the built in validations but can build your own
8277
This is how the built in presence validation is built:
8378

8479
```swift
85-
public extension Validation
86-
{
80+
public extension Validation {
8781
/// Validate an optional value is present.
8882
///
8983
/// If the value is nil, it is considered invalid.
@@ -92,11 +86,9 @@ public extension Validation
9286
/// - Returns: A Validation instance.
9387
static func presence<T>(
9488
message: String? = nil
95-
) -> Validation<Optional<T>>
96-
{
89+
) -> Validation<Optional<T>> {
9790
.init { value in
98-
if value == nil
99-
{
91+
if value == nil {
10092
throw ValidationError.build(message: message)
10193
}
10294
}

Validate.xcodeproj/project.pbxproj

Lines changed: 28 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,6 @@
3232
/* End PBXBuildFile section */
3333

3434
/* Begin PBXContainerItemProxy section */
35-
A4AD9E002714873F007890AD /* PBXContainerItemProxy */ = {
36-
isa = PBXContainerItemProxy;
37-
containerPortal = A4AD9DEB2714873F007890AD /* Project object */;
38-
proxyType = 1;
39-
remoteGlobalIDString = A4AD9DF32714873F007890AD;
40-
remoteInfo = Validate;
41-
};
4235
A4AD9E3F27186975007890AD /* PBXContainerItemProxy */ = {
4336
isa = PBXContainerItemProxy;
4437
containerPortal = A4AD9DEB2714873F007890AD /* Project object */;
@@ -273,7 +266,6 @@
273266
buildRules = (
274267
);
275268
dependencies = (
276-
A4AD9E012714873F007890AD /* PBXTargetDependency */,
277269
);
278270
name = ValidateTests;
279271
productName = ValidateTests;
@@ -407,11 +399,6 @@
407399
/* End PBXSourcesBuildPhase section */
408400

409401
/* Begin PBXTargetDependency section */
410-
A4AD9E012714873F007890AD /* PBXTargetDependency */ = {
411-
isa = PBXTargetDependency;
412-
target = A4AD9DF32714873F007890AD /* Validate */;
413-
targetProxy = A4AD9E002714873F007890AD /* PBXContainerItemProxy */;
414-
};
415402
A4AD9E4027186975007890AD /* PBXTargetDependency */ = {
416403
isa = PBXTargetDependency;
417404
target = A4AD9DF32714873F007890AD /* Validate */;
@@ -545,10 +532,10 @@
545532
A4AD9E092714873F007890AD /* Debug */ = {
546533
isa = XCBuildConfiguration;
547534
buildSettings = {
548-
CODE_SIGN_STYLE = Automatic;
535+
CODE_SIGN_STYLE = Manual;
549536
CURRENT_PROJECT_VERSION = 1;
550537
DEFINES_MODULE = YES;
551-
DEVELOPMENT_TEAM = CF43K35J9C;
538+
DEVELOPMENT_TEAM = "";
552539
DYLIB_COMPATIBILITY_VERSION = 1;
553540
DYLIB_CURRENT_VERSION = 1;
554541
DYLIB_INSTALL_NAME_BASE = "@rpath";
@@ -563,7 +550,11 @@
563550
MARKETING_VERSION = 1.0;
564551
PRODUCT_BUNDLE_IDENTIFIER = com.reddavis.Validate;
565552
PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)";
553+
PROVISIONING_PROFILE_SPECIFIER = "";
554+
"PROVISIONING_PROFILE_SPECIFIER[sdk=macosx*]" = "";
555+
SDKROOT = "";
566556
SKIP_INSTALL = YES;
557+
SUPPORTED_PLATFORMS = "iphonesimulator iphoneos watchsimulator watchos macosx appletvsimulator appletvos";
567558
SWIFT_EMIT_LOC_STRINGS = YES;
568559
SWIFT_VERSION = 5.0;
569560
TARGETED_DEVICE_FAMILY = "1,2";
@@ -573,10 +564,10 @@
573564
A4AD9E0A2714873F007890AD /* Release */ = {
574565
isa = XCBuildConfiguration;
575566
buildSettings = {
576-
CODE_SIGN_STYLE = Automatic;
567+
CODE_SIGN_STYLE = Manual;
577568
CURRENT_PROJECT_VERSION = 1;
578569
DEFINES_MODULE = YES;
579-
DEVELOPMENT_TEAM = CF43K35J9C;
570+
DEVELOPMENT_TEAM = "";
580571
DYLIB_COMPATIBILITY_VERSION = 1;
581572
DYLIB_CURRENT_VERSION = 1;
582573
DYLIB_INSTALL_NAME_BASE = "@rpath";
@@ -591,7 +582,11 @@
591582
MARKETING_VERSION = 1.0;
592583
PRODUCT_BUNDLE_IDENTIFIER = com.reddavis.Validate;
593584
PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)";
585+
PROVISIONING_PROFILE_SPECIFIER = "";
586+
"PROVISIONING_PROFILE_SPECIFIER[sdk=macosx*]" = "";
587+
SDKROOT = "";
594588
SKIP_INSTALL = YES;
589+
SUPPORTED_PLATFORMS = "iphonesimulator iphoneos watchsimulator watchos macosx appletvsimulator appletvos";
595590
SWIFT_EMIT_LOC_STRINGS = YES;
596591
SWIFT_VERSION = 5.0;
597592
TARGETED_DEVICE_FAMILY = "1,2";
@@ -601,10 +596,12 @@
601596
A4AD9E0C2714873F007890AD /* Debug */ = {
602597
isa = XCBuildConfiguration;
603598
buildSettings = {
599+
ALLOW_TARGET_PLATFORM_SPECIALIZATION = YES;
604600
ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES;
601+
CODE_SIGN_IDENTITY = "-";
605602
CODE_SIGN_STYLE = Automatic;
606603
CURRENT_PROJECT_VERSION = 1;
607-
DEVELOPMENT_TEAM = CF43K35J9C;
604+
DEVELOPMENT_TEAM = "";
608605
GENERATE_INFOPLIST_FILE = YES;
609606
LD_RUNPATH_SEARCH_PATHS = (
610607
"$(inherited)",
@@ -614,6 +611,11 @@
614611
MARKETING_VERSION = 1.0;
615612
PRODUCT_BUNDLE_IDENTIFIER = com.reddavis.ValidateTests;
616613
PRODUCT_NAME = "$(TARGET_NAME)";
614+
PROVISIONING_PROFILE_SPECIFIER = "";
615+
"PROVISIONING_PROFILE_SPECIFIER[sdk=macosx*]" = "";
616+
SDKROOT = "";
617+
SUPPORTED_PLATFORMS = "watchsimulator watchos macosx iphonesimulator iphoneos appletvsimulator appletvos";
618+
SUPPORTS_MACCATALYST = NO;
617619
SWIFT_EMIT_LOC_STRINGS = NO;
618620
SWIFT_VERSION = 5.0;
619621
TARGETED_DEVICE_FAMILY = "1,2";
@@ -623,10 +625,12 @@
623625
A4AD9E0D2714873F007890AD /* Release */ = {
624626
isa = XCBuildConfiguration;
625627
buildSettings = {
628+
ALLOW_TARGET_PLATFORM_SPECIALIZATION = YES;
626629
ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES;
630+
CODE_SIGN_IDENTITY = "-";
627631
CODE_SIGN_STYLE = Automatic;
628632
CURRENT_PROJECT_VERSION = 1;
629-
DEVELOPMENT_TEAM = CF43K35J9C;
633+
DEVELOPMENT_TEAM = "";
630634
GENERATE_INFOPLIST_FILE = YES;
631635
LD_RUNPATH_SEARCH_PATHS = (
632636
"$(inherited)",
@@ -636,6 +640,11 @@
636640
MARKETING_VERSION = 1.0;
637641
PRODUCT_BUNDLE_IDENTIFIER = com.reddavis.ValidateTests;
638642
PRODUCT_NAME = "$(TARGET_NAME)";
643+
PROVISIONING_PROFILE_SPECIFIER = "";
644+
"PROVISIONING_PROFILE_SPECIFIER[sdk=macosx*]" = "";
645+
SDKROOT = "";
646+
SUPPORTED_PLATFORMS = "watchsimulator watchos macosx iphonesimulator iphoneos appletvsimulator appletvos";
647+
SUPPORTS_MACCATALYST = NO;
639648
SWIFT_EMIT_LOC_STRINGS = NO;
640649
SWIFT_VERSION = 5.0;
641650
TARGETED_DEVICE_FAMILY = "1,2";
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<Scheme
3+
LastUpgradeVersion = "1320"
4+
version = "1.3">
5+
<BuildAction
6+
parallelizeBuildables = "YES"
7+
buildImplicitDependencies = "YES">
8+
<BuildActionEntries>
9+
<BuildActionEntry
10+
buildForTesting = "YES"
11+
buildForRunning = "YES"
12+
buildForProfiling = "YES"
13+
buildForArchiving = "YES"
14+
buildForAnalyzing = "YES">
15+
<BuildableReference
16+
BuildableIdentifier = "primary"
17+
BlueprintIdentifier = "A4AD9DF32714873F007890AD"
18+
BuildableName = "Validate.framework"
19+
BlueprintName = "Validate"
20+
ReferencedContainer = "container:Validate.xcodeproj">
21+
</BuildableReference>
22+
</BuildActionEntry>
23+
</BuildActionEntries>
24+
</BuildAction>
25+
<TestAction
26+
buildConfiguration = "Debug"
27+
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
28+
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
29+
shouldUseLaunchSchemeArgsEnv = "YES">
30+
<Testables>
31+
<TestableReference
32+
skipped = "NO"
33+
testExecutionOrdering = "random">
34+
<BuildableReference
35+
BuildableIdentifier = "primary"
36+
BlueprintIdentifier = "A4AD9DFD2714873F007890AD"
37+
BuildableName = "ValidateTests.xctest"
38+
BlueprintName = "ValidateTests"
39+
ReferencedContainer = "container:Validate.xcodeproj">
40+
</BuildableReference>
41+
</TestableReference>
42+
</Testables>
43+
</TestAction>
44+
<LaunchAction
45+
buildConfiguration = "Debug"
46+
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
47+
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
48+
launchStyle = "0"
49+
useCustomWorkingDirectory = "NO"
50+
ignoresPersistentStateOnLaunch = "NO"
51+
debugDocumentVersioning = "YES"
52+
debugServiceExtension = "internal"
53+
allowLocationSimulation = "YES">
54+
</LaunchAction>
55+
<ProfileAction
56+
buildConfiguration = "Release"
57+
shouldUseLaunchSchemeArgsEnv = "YES"
58+
savedToolIdentifier = ""
59+
useCustomWorkingDirectory = "NO"
60+
debugDocumentVersioning = "YES">
61+
<MacroExpansion>
62+
<BuildableReference
63+
BuildableIdentifier = "primary"
64+
BlueprintIdentifier = "A4AD9DF32714873F007890AD"
65+
BuildableName = "Validate.framework"
66+
BlueprintName = "Validate"
67+
ReferencedContainer = "container:Validate.xcodeproj">
68+
</BuildableReference>
69+
</MacroExpansion>
70+
</ProfileAction>
71+
<AnalyzeAction
72+
buildConfiguration = "Debug">
73+
</AnalyzeAction>
74+
<ArchiveAction
75+
buildConfiguration = "Release"
76+
revealArchiveInOrganizer = "YES">
77+
</ArchiveAction>
78+
</Scheme>

Validate/Source/Extensions/NSRegularExpression+Extension.swift

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,20 @@
11
import Foundation
22

33

4-
extension NSRegularExpression
5-
{
4+
extension NSRegularExpression {
65
// MARK: Initialization
76

8-
convenience init(_ pattern: String, options: NSRegularExpression.Options)
9-
{
10-
do
11-
{
7+
convenience init(_ pattern: String, options: NSRegularExpression.Options) {
8+
do {
129
try self.init(pattern: pattern, options: options)
13-
}
14-
catch
15-
{
10+
} catch {
1611
preconditionFailure("Invalid regex pattern: \(pattern)")
1712
}
1813
}
1914

2015
// MARK: Matches
2116

22-
func matches(_ value: String) -> Bool
23-
{
17+
func matches(_ value: String) -> Bool {
2418
let range = NSRange(location: 0, length: value.utf16.count)
2519
return self.firstMatch(in: value, options: [], range: range) != nil
2620
}
Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
import Foundation
22

33

4-
public extension Sequence where Element: Error
5-
{
6-
var localizedDescriptions: [String] {
4+
extension Sequence where Element: Error {
5+
public var localizedDescriptions: [String] {
76
self.map { $0.localizedDescription }
87
}
98
}

0 commit comments

Comments
 (0)