Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Develop #27

Merged
merged 15 commits into from
Aug 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 39 additions & 16 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,18 +36,33 @@ concurrency:
cancel-in-progress: true

jobs:
swiftlint:
name: SwiftLint
runs-on: macos-14
# lint_code:
# name: Lint Code
# runs-on: macos-14
# steps:
# - name: Checkout
# uses: actions/checkout@v4
# - name: Install SwiftLint
# run: brew install swiftlint
# - name: Lint
# run: |
# set -o pipefail
# swiftlint lint --quiet | sed -E 's/^(.*):([0-9]+):([0-9]+): (warning|error|[^:]+): (.*)/::\4 title=Lint error,file=\1,line=\2,col=\3::\5\n\1:\2:\3/'

lint_code:
name: Lint Code
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Install SwiftLint
run: brew install swiftlint
with:
fetch-depth: 0 # Full git history is needed to get a proper list of changed files
- name: Lint
run: |
set -o pipefail
swiftlint lint --quiet | sed -E 's/^(.*):([0-9]+):([0-9]+): (warning|error|[^:]+): (.*)/::\4 title=Lint error,file=\1,line=\2,col=\3::\5\n\1:\2:\3/'
uses: mtgto/swift-format-action@main
with:
configuration_file: .swift-format # Please comment out if you won't specify configuration file
all_files: false # default is false
max_warnings: -1 # default is -1 (infinity)

### ref: https://github.com/Alamofire/Alamofire/blob/master/.github/workflows/ci.yml
test_macOS:
Expand Down Expand Up @@ -96,7 +111,7 @@ jobs:
token: ${{ secrets.CODECOV_TOKEN }}
fail_ci_if_error: true
verbose: true
needs: swiftlint
needs: lint_code

test_Catalyst:
name: ${{ matrix.name }}
Expand All @@ -118,7 +133,7 @@ jobs:
- uses: actions/checkout@v4
- name: Catalyst
run: set -o pipefail && env NSUnbufferedIO=YES xcodebuild -project "TLDExtractSwift.xcodeproj" -scheme "TLDExtractSwift" -destination "platform=macOS" clean test 2>&1 | xcbeautify --renderer github-actions
needs: swiftlint
needs: lint_code

test_iOS:
name: ${{ matrix.name }}
Expand Down Expand Up @@ -149,7 +164,7 @@ jobs:
- uses: actions/checkout@v4
- name: ${{ matrix.name }}
run: set -o pipefail && env NSUnbufferedIO=YES xcodebuild -project "TLDExtractSwift.xcodeproj" -scheme "TLDExtractSwift" -destination "${{ matrix.destination }}" clean test 2>&1 | xcbeautify --renderer github-actions
needs: swiftlint
needs: lint_code

test_tvOS:
name: ${{ matrix.name }}
Expand Down Expand Up @@ -180,7 +195,7 @@ jobs:
- uses: actions/checkout@v4
- name: ${{ matrix.name }}
run: set -o pipefail && env NSUnbufferedIO=YES xcodebuild -project "TLDExtractSwift.xcodeproj" -scheme "TLDExtractSwift" -destination "${{ matrix.destination }}" clean test 2>&1 | xcbeautify --renderer github-actions
needs: swiftlint
needs: lint_code

test_visionOS:
name: ${{ matrix.name }}
Expand All @@ -202,7 +217,7 @@ jobs:
- uses: actions/checkout@v4
- name: ${{ matrix.name }}
run: set -o pipefail && env NSUnbufferedIO=YES xcodebuild -project "TLDExtractSwift.xcodeproj" -scheme "${{ matrix.scheme }}" -destination "${{ matrix.destination }}" clean test 2>&1 | xcbeautify --renderer github-actions
needs: swiftlint
needs: lint_code

test_watchOS:
name: ${{ matrix.name }}
Expand Down Expand Up @@ -233,7 +248,7 @@ jobs:
- uses: actions/checkout@v4
- name: ${{ matrix.name }}
run: set -o pipefail && env NSUnbufferedIO=YES xcodebuild -project "TLDExtractSwift.xcodeproj" -scheme "TLDExtractSwift" -destination "${{ matrix.destination }}" clean test 2>&1 | xcbeautify --renderer github-actions
needs: swiftlint
needs: lint_code

SPM:
name: ${{ matrix.name }}
Expand Down Expand Up @@ -273,7 +288,15 @@ jobs:
- uses: actions/checkout@v4
- name: Test SPM
run: swift test -c debug 2>&1 | ${{ matrix.outputFilter }}
needs: [test_macOS, test_Catalyst, test_iOS, test_tvOS, test_watchOS, test_visionOS]
needs:
[
test_macOS,
test_Catalyst,
test_iOS,
test_tvOS,
test_watchOS,
test_visionOS,
]

carthage:
name: ${{ matrix.name }}
Expand Down Expand Up @@ -307,7 +330,7 @@ jobs:
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Run SwiftLint and Build Carthage for ${{ matrix.platform }}
- name: Build Carthage for ${{ matrix.platform }}
run: |
carthage build \
--no-skip-current \
Expand Down
3 changes: 3 additions & 0 deletions .hound.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
swift:
enabled: true
config_file: .swift-format
69 changes: 69 additions & 0 deletions .swift-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
{
"fileScopedDeclarationPrivacy" : {
"accessLevel" : "private"
},
"indentation" : {
"spaces" : 4
},
"indentConditionalCompilationBlocks" : false,
"indentSwitchCaseLabels" : false,
"lineBreakAroundMultilineExpressionChainComponents" : false,
"lineBreakBeforeControlFlowKeywords" : false,
"lineBreakBeforeEachArgument" : true,
"lineBreakBeforeEachGenericRequirement" : false,
"lineLength" : 200,
"maximumBlankLines" : 1,
"multiElementCollectionTrailingCommas" : true,
"noAssignmentInExpressions" : {
"allowedFunctions" : [
"XCTAssertNoThrow"
]
},
"prioritizeKeepingFunctionOutputTogether" : false,
"respectsExistingLineBreaks" : true,
"rules" : {
"AllPublicDeclarationsHaveDocumentation" : false,
"AlwaysUseLiteralForEmptyCollectionInit" : false,
"AlwaysUseLowerCamelCase" : true,
"AmbiguousTrailingClosureOverload" : true,
"BeginDocumentationCommentWithOneLineSummary" : false,
"DoNotUseSemicolons" : true,
"DontRepeatTypeInStaticProperties" : true,
"FileScopedDeclarationPrivacy" : true,
"FullyIndirectEnum" : true,
"GroupNumericLiterals" : true,
"IdentifiersMustBeASCII" : true,
"NeverForceUnwrap" : false,
"NeverUseForceTry" : false,
"NeverUseImplicitlyUnwrappedOptionals" : false,
"NoAccessLevelOnExtensionDeclaration" : false,
"NoAssignmentInExpressions" : true,
"NoBlockComments" : false,
"NoCasesWithOnlyFallthrough" : true,
"NoEmptyTrailingClosureParentheses" : true,
"NoLabelsInCasePatterns" : true,
"NoLeadingUnderscores" : false,
"NoParensAroundConditions" : true,
"NoPlaygroundLiterals" : true,
"NoVoidReturnOnFunctionSignature" : true,
"OmitExplicitReturns" : false,
"OneCasePerLine" : true,
"OneVariableDeclarationPerLine" : true,
"OnlyOneTrailingClosureArgument" : true,
"OrderedImports" : true,
"ReplaceForEachWithForLoop" : true,
"ReturnVoidInsteadOfEmptyTuple" : true,
"TypeNamesShouldBeCapitalized" : true,
"UseEarlyExits" : false,
"UseLetInEveryBoundCaseVariable" : false,
"UseShorthandTypeNames" : true,
"UseSingleLinePropertyGetter" : true,
"UseSynthesizedInitializer" : false,
"UseTripleSlashForDocumentationComments" : true,
"UseWhereClausesInForLoops" : false,
"ValidateDocumentationComments" : false
},
"spacesAroundRangeFormationOperators" : false,
"tabWidth" : 4,
"version" : 1
}
7 changes: 0 additions & 7 deletions .swiftlint.yml
Original file line number Diff line number Diff line change
@@ -1,17 +1,10 @@
# at v0.6.0
disabled_rules:
- identifier_name
- trailing_whitespace
- todo

line_length: 960
function_body_length: 100

identifier_name:
excluded:
- id
- ok

excluded:
- Source/SPMPSL.swift
- Tests
Expand Down
2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ let package = Package(
targets: ["TLDExtractSwift"])
],
dependencies: [
.package(url: "https://github.com/gumob/PunycodeSwift.git", .upToNextMajor(from: "3.0.0")),
.package(url: "https://github.com/gumob/PunycodeSwift.git", .upToNextMajor(from: "3.0.0"))
],
targets: [
.target(
Expand Down
3 changes: 1 addition & 2 deletions Source/Extension.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
//
// Created by kojirof on 2018-11-17.
// Copyright (c) 2018 Gumob. All rights reserved.
// Created by Kojiro futamura on 2018-11-17.
//

import Foundation
Expand Down
13 changes: 7 additions & 6 deletions Source/Model.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
//
// Created by kojirof on 2018-11-17.
// Copyright (c) 2018 Gumob. All rights reserved.
// Created by Kojiro futamura on 2018-11-17.
//

import Foundation
Expand Down Expand Up @@ -66,10 +65,12 @@ extension PSLData {
let secondDomain: String? = delta == 0 ? nil : hostComponents[delta - 1]
let subDomain: String? = delta < 2 ? nil : hostComponents.prefix(delta - 1).joined(separator: ".")

return TLDResult(rootDomain: rootDomain,
topLevelDomain: topLevelDomain,
secondLevelDomain: secondDomain,
subDomain: subDomain)
return TLDResult(
rootDomain: rootDomain,
topLevelDomain: topLevelDomain,
secondLevelDomain: secondDomain,
subDomain: subDomain
)
}
}

Expand Down
27 changes: 13 additions & 14 deletions Source/Parser.swift
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
//
// Created by kojirof on 2018/11/16.
// Copyright © 2018 Gumob. All rights reserved.
// Created by Kojiro futamura on 2018/11/16.
//

import Foundation

#if SWIFT_PACKAGE
import Punycode
#endif
Expand All @@ -25,9 +25,7 @@ internal class PSLParser {
}

internal func parse(data: Data?) throws -> PSLDataSet {
guard let data: Data = data,
let str: String = String(data: data, encoding: .utf8),
str.count > 0 else {
guard let data: Data = data, let str: String = String(data: data, encoding: .utf8), str.count > 0 else {
throw TLDExtractError.pslParseError(message: nil)
}

Expand All @@ -49,9 +47,9 @@ internal class PSLParser {
#endif
}
return PSLDataSet(
exceptions: exceptions,
wildcards: wildcards,
normals: normals
exceptions: exceptions,
wildcards: wildcards,
normals: normals
)
}
}
Expand All @@ -68,8 +66,7 @@ internal class TLDParser {
let hostComponents: [String] = host.lowercased().components(separatedBy: ".")
/// Search exceptions first, then search wildcards if not match
let matchClosure: (PSLData) -> Bool = { $0.matches(hostComponents: hostComponents) }
let pslData: PSLData? = self.pslDataSet.exceptions.first(where: matchClosure) ??
self.pslDataSet.wildcards.first(where: matchClosure)
let pslData: PSLData? = self.pslDataSet.exceptions.first(where: matchClosure) ?? self.pslDataSet.wildcards.first(where: matchClosure)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line Length Violation: Line should be 120 characters or less: currently 141 characters (line_length)

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line Length Violation: Line should be 120 characters or less: currently 141 characters (line_length)

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line Length Violation: Line should be 120 characters or less: currently 141 characters (line_length)

return pslData?.parse(hostComponents: hostComponents)
}

Expand Down Expand Up @@ -100,9 +97,11 @@ internal class TLDParser {
let subDomainRange: Range<Int> = (hostComponents.startIndex)..<(max(secondDomainRange.lowerBound, hostComponents.startIndex))
let subDomain: String? = subDomainRange.endIndex >= 1 ? hostComponents[subDomainRange].joined(separator: ".") : nil

return TLDResult(rootDomain: rootDomain,
topLevelDomain: topLevelDomain,
secondLevelDomain: secondDomain,
subDomain: subDomain)
return TLDResult(
rootDomain: rootDomain,
topLevelDomain: topLevelDomain,
secondLevelDomain: secondDomain,
subDomain: subDomain
)
}
}
5 changes: 2 additions & 3 deletions Source/SPMPSL.swift
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
//
// File.swift
//
//
// Created by Zachary Gorak on 2/16/20.
//
// swift-format-ignore-file
//

import Foundation

Expand Down
11 changes: 5 additions & 6 deletions Source/TLDExtract.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
// TLDExtract.swift
// TLDExtract
//
// Created by kojirof on 2018/11/16.
// Copyright © 2018 Gumob. All rights reserved.
// Created by Kojiro futamura on 2018/11/16.
//

import Foundation
Expand All @@ -26,8 +25,9 @@ public class TLDExtract {
self.tldParser = TLDParser(dataSet: dataSet)
#else
let url: URL = Bundle.current.url(
forResource: useFrozenData ? "public_suffix_list_frozen" : "public_suffix_list",
withExtension: "dat")!
forResource: useFrozenData ? "public_suffix_list_frozen" : "public_suffix_list",
withExtension: "dat"
)!
let data: Data = try Data(contentsOf: url)
let dataSet = try PSLParser().parse(data: data)
self.tldParser = TLDParser(dataSet: dataSet)
Expand All @@ -42,8 +42,7 @@ public class TLDExtract {
if quick {
return self.tldParser.parseNormals(host: host)
} else {
return self.tldParser.parseExceptionsAndWildcards(host: host) ??
self.tldParser.parseNormals(host: host)
return self.tldParser.parseExceptionsAndWildcards(host: host) ?? self.tldParser.parseNormals(host: host)
}
}
}
Expand Down
3 changes: 1 addition & 2 deletions Source/TLDExtractError.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
//
// Created by kojirof on 2018-11-17.
// Copyright (c) 2018 Gumob. All rights reserved.
// Created by Kojiro futamura on 2018-11-17.
//

import Foundation
Expand Down
Loading
Loading