Skip to content

Commit

Permalink
Merge pull request #1 from reddavis/feature/equatable
Browse files Browse the repository at this point in the history
If Value is equatable, make the wrapper equatable
  • Loading branch information
reddavis authored Mar 2, 2022
2 parents 6133dfb + fe24e0c commit 50532a5
Show file tree
Hide file tree
Showing 17 changed files with 304 additions and 185 deletions.
12 changes: 12 additions & 0 deletions .github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# These are supported funding model platforms

github: reddavis
patreon: # Replace with a single Patreon username
open_collective: # Replace with a single Open Collective username
ko_fi: # Replace with a single Ko-fi username
tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel
community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry
liberapay: # Replace with a single Liberapay username
issuehunt: # Replace with a single IssueHunt username
otechie: # Replace with a single Otechie username
custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2']
19 changes: 19 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: CI

on:
push:
branches: [ main ]
pull_request:
branches: [ main ]

jobs:
ios-latest:
name: Unit Test - iOS 15.2, Xcode 13.2
runs-on: macOS-11
env:
DEVELOPER_DIR: /Applications/Xcode_13.2.app/Contents/Developer
steps:
- uses: actions/checkout@v2
- name: Run Tests
run: Scripts/test -d "OS=15.2,name=iPhone 13 Pro"

20 changes: 20 additions & 0 deletions .github/workflows/swiftlint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: SwiftLint

on:
pull_request:
paths:
- '.github/workflows/swiftlint.yml'
- '.swiftlint.yml'
- '**/*.swift'

jobs:
SwiftLint:
runs-on: ubuntu-latest
steps:
- name: Swiftlint
uses: norio-nomura/[email protected]
with:
args: --strict
env:
WORKING_DIRECTORY: Validate
DIFF_BASE: ${{ github.base_ref }}
34 changes: 34 additions & 0 deletions .swiftlint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
only_rules:
- closure_spacing
- colon
- empty_count
- fatal_error_message
- force_cast
- force_try
- force_unwrapping
- implicitly_unwrapped_optional
- legacy_cggeometry_functions
- legacy_constant
- legacy_constructor
- legacy_nsgeometry_functions
- operator_usage_whitespace
- redundant_string_enum_value
- return_arrow_whitespace
- trailing_newline
- type_name
- unused_optional_binding
- vertical_whitespace
- void_return
- custom_rules

custom_rules:
no_direct_standard_out_logs:
name: "Writing log messages directly to standard out is disallowed"
regex: "(\\bprint|\\bdebugPrint|\\bdump|Swift\\.print|Swift\\.debugPrint|Swift\\.dump)\\s*\\("
match_kinds:
- identifier
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`"
severity: error

vertical_whitespace:
max_empty_lines: 4
16 changes: 4 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,6 @@ dependencies: [
]
```

## Note

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.

## Documentation

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


struct ContentView: View
{
struct ContentView: View {
@Validate(.presence()) var name: String = ""

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

```swift
public extension Validation
{
public extension Validation {
/// Validate an optional value is present.
///
/// If the value is nil, it is considered invalid.
Expand All @@ -92,11 +86,9 @@ public extension Validation
/// - Returns: A Validation instance.
static func presence<T>(
message: String? = nil
) -> Validation<Optional<T>>
{
) -> Validation<Optional<T>> {
.init { value in
if value == nil
{
if value == nil {
throw ValidationError.build(message: message)
}
}
Expand Down
47 changes: 28 additions & 19 deletions Validate.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,6 @@
/* End PBXBuildFile section */

/* Begin PBXContainerItemProxy section */
A4AD9E002714873F007890AD /* PBXContainerItemProxy */ = {
isa = PBXContainerItemProxy;
containerPortal = A4AD9DEB2714873F007890AD /* Project object */;
proxyType = 1;
remoteGlobalIDString = A4AD9DF32714873F007890AD;
remoteInfo = Validate;
};
A4AD9E3F27186975007890AD /* PBXContainerItemProxy */ = {
isa = PBXContainerItemProxy;
containerPortal = A4AD9DEB2714873F007890AD /* Project object */;
Expand Down Expand Up @@ -273,7 +266,6 @@
buildRules = (
);
dependencies = (
A4AD9E012714873F007890AD /* PBXTargetDependency */,
);
name = ValidateTests;
productName = ValidateTests;
Expand Down Expand Up @@ -407,11 +399,6 @@
/* End PBXSourcesBuildPhase section */

/* Begin PBXTargetDependency section */
A4AD9E012714873F007890AD /* PBXTargetDependency */ = {
isa = PBXTargetDependency;
target = A4AD9DF32714873F007890AD /* Validate */;
targetProxy = A4AD9E002714873F007890AD /* PBXContainerItemProxy */;
};
A4AD9E4027186975007890AD /* PBXTargetDependency */ = {
isa = PBXTargetDependency;
target = A4AD9DF32714873F007890AD /* Validate */;
Expand Down Expand Up @@ -545,10 +532,10 @@
A4AD9E092714873F007890AD /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
CODE_SIGN_STYLE = Automatic;
CODE_SIGN_STYLE = Manual;
CURRENT_PROJECT_VERSION = 1;
DEFINES_MODULE = YES;
DEVELOPMENT_TEAM = CF43K35J9C;
DEVELOPMENT_TEAM = "";
DYLIB_COMPATIBILITY_VERSION = 1;
DYLIB_CURRENT_VERSION = 1;
DYLIB_INSTALL_NAME_BASE = "@rpath";
Expand All @@ -563,7 +550,11 @@
MARKETING_VERSION = 1.0;
PRODUCT_BUNDLE_IDENTIFIER = com.reddavis.Validate;
PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)";
PROVISIONING_PROFILE_SPECIFIER = "";
"PROVISIONING_PROFILE_SPECIFIER[sdk=macosx*]" = "";
SDKROOT = "";
SKIP_INSTALL = YES;
SUPPORTED_PLATFORMS = "iphonesimulator iphoneos watchsimulator watchos macosx appletvsimulator appletvos";
SWIFT_EMIT_LOC_STRINGS = YES;
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = "1,2";
Expand All @@ -573,10 +564,10 @@
A4AD9E0A2714873F007890AD /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
CODE_SIGN_STYLE = Automatic;
CODE_SIGN_STYLE = Manual;
CURRENT_PROJECT_VERSION = 1;
DEFINES_MODULE = YES;
DEVELOPMENT_TEAM = CF43K35J9C;
DEVELOPMENT_TEAM = "";
DYLIB_COMPATIBILITY_VERSION = 1;
DYLIB_CURRENT_VERSION = 1;
DYLIB_INSTALL_NAME_BASE = "@rpath";
Expand All @@ -591,7 +582,11 @@
MARKETING_VERSION = 1.0;
PRODUCT_BUNDLE_IDENTIFIER = com.reddavis.Validate;
PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)";
PROVISIONING_PROFILE_SPECIFIER = "";
"PROVISIONING_PROFILE_SPECIFIER[sdk=macosx*]" = "";
SDKROOT = "";
SKIP_INSTALL = YES;
SUPPORTED_PLATFORMS = "iphonesimulator iphoneos watchsimulator watchos macosx appletvsimulator appletvos";
SWIFT_EMIT_LOC_STRINGS = YES;
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = "1,2";
Expand All @@ -601,10 +596,12 @@
A4AD9E0C2714873F007890AD /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
ALLOW_TARGET_PLATFORM_SPECIALIZATION = YES;
ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES;
CODE_SIGN_IDENTITY = "-";
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 1;
DEVELOPMENT_TEAM = CF43K35J9C;
DEVELOPMENT_TEAM = "";
GENERATE_INFOPLIST_FILE = YES;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
Expand All @@ -614,6 +611,11 @@
MARKETING_VERSION = 1.0;
PRODUCT_BUNDLE_IDENTIFIER = com.reddavis.ValidateTests;
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
"PROVISIONING_PROFILE_SPECIFIER[sdk=macosx*]" = "";
SDKROOT = "";
SUPPORTED_PLATFORMS = "watchsimulator watchos macosx iphonesimulator iphoneos appletvsimulator appletvos";
SUPPORTS_MACCATALYST = NO;
SWIFT_EMIT_LOC_STRINGS = NO;
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = "1,2";
Expand All @@ -623,10 +625,12 @@
A4AD9E0D2714873F007890AD /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
ALLOW_TARGET_PLATFORM_SPECIALIZATION = YES;
ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES;
CODE_SIGN_IDENTITY = "-";
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 1;
DEVELOPMENT_TEAM = CF43K35J9C;
DEVELOPMENT_TEAM = "";
GENERATE_INFOPLIST_FILE = YES;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
Expand All @@ -636,6 +640,11 @@
MARKETING_VERSION = 1.0;
PRODUCT_BUNDLE_IDENTIFIER = com.reddavis.ValidateTests;
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
"PROVISIONING_PROFILE_SPECIFIER[sdk=macosx*]" = "";
SDKROOT = "";
SUPPORTED_PLATFORMS = "watchsimulator watchos macosx iphonesimulator iphoneos appletvsimulator appletvos";
SUPPORTS_MACCATALYST = NO;
SWIFT_EMIT_LOC_STRINGS = NO;
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = "1,2";
Expand Down
78 changes: 78 additions & 0 deletions Validate.xcodeproj/xcshareddata/xcschemes/Validate.xcscheme
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1320"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
buildImplicitDependencies = "YES">
<BuildActionEntries>
<BuildActionEntry
buildForTesting = "YES"
buildForRunning = "YES"
buildForProfiling = "YES"
buildForArchiving = "YES"
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "A4AD9DF32714873F007890AD"
BuildableName = "Validate.framework"
BlueprintName = "Validate"
ReferencedContainer = "container:Validate.xcodeproj">
</BuildableReference>
</BuildActionEntry>
</BuildActionEntries>
</BuildAction>
<TestAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES">
<Testables>
<TestableReference
skipped = "NO"
testExecutionOrdering = "random">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "A4AD9DFD2714873F007890AD"
BuildableName = "ValidateTests.xctest"
BlueprintName = "ValidateTests"
ReferencedContainer = "container:Validate.xcodeproj">
</BuildableReference>
</TestableReference>
</Testables>
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
debugDocumentVersioning = "YES"
debugServiceExtension = "internal"
allowLocationSimulation = "YES">
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
shouldUseLaunchSchemeArgsEnv = "YES"
savedToolIdentifier = ""
useCustomWorkingDirectory = "NO"
debugDocumentVersioning = "YES">
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "A4AD9DF32714873F007890AD"
BuildableName = "Validate.framework"
BlueprintName = "Validate"
ReferencedContainer = "container:Validate.xcodeproj">
</BuildableReference>
</MacroExpansion>
</ProfileAction>
<AnalyzeAction
buildConfiguration = "Debug">
</AnalyzeAction>
<ArchiveAction
buildConfiguration = "Release"
revealArchiveInOrganizer = "YES">
</ArchiveAction>
</Scheme>
16 changes: 5 additions & 11 deletions Validate/Source/Extensions/NSRegularExpression+Extension.swift
Original file line number Diff line number Diff line change
@@ -1,26 +1,20 @@
import Foundation


extension NSRegularExpression
{
extension NSRegularExpression {
// MARK: Initialization

convenience init(_ pattern: String, options: NSRegularExpression.Options)
{
do
{
convenience init(_ pattern: String, options: NSRegularExpression.Options) {
do {
try self.init(pattern: pattern, options: options)
}
catch
{
} catch {
preconditionFailure("Invalid regex pattern: \(pattern)")
}
}

// MARK: Matches

func matches(_ value: String) -> Bool
{
func matches(_ value: String) -> Bool {
let range = NSRange(location: 0, length: value.utf16.count)
return self.firstMatch(in: value, options: [], range: range) != nil
}
Expand Down
5 changes: 2 additions & 3 deletions Validate/Source/Extensions/Sequence+Extension.swift
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import Foundation


public extension Sequence where Element: Error
{
var localizedDescriptions: [String] {
extension Sequence where Element: Error {
public var localizedDescriptions: [String] {
self.map { $0.localizedDescription }
}
}
Loading

0 comments on commit 50532a5

Please sign in to comment.