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

Update from Hummingbird Project Template #58

Merged
merged 3 commits into from
Nov 28, 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
6 changes: 1 addition & 5 deletions .github/workflows/validate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,12 @@ concurrency:

jobs:
validate:
runs-on: macOS-latest
runs-on: ubuntu-latest
timeout-minutes: 15
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 1
- name: Install Dependencies
run: |
brew install mint
mint install NickLockwood/[email protected] --no-link
- name: run script
run: ./scripts/validate.sh
63 changes: 63 additions & 0 deletions .swift-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
{
"version" : 1,
"indentation" : {
"spaces" : 4
},
"tabWidth" : 4,
"fileScopedDeclarationPrivacy" : {
"accessLevel" : "private"
},
"spacesAroundRangeFormationOperators" : false,
"indentConditionalCompilationBlocks" : false,
"indentSwitchCaseLabels" : false,
"lineBreakAroundMultilineExpressionChainComponents" : false,
"lineBreakBeforeControlFlowKeywords" : false,
"lineBreakBeforeEachArgument" : true,
"lineBreakBeforeEachGenericRequirement" : true,
"lineLength" : 150,
"maximumBlankLines" : 1,
"respectsExistingLineBreaks" : true,
"prioritizeKeepingFunctionOutputTogether" : true,
"multiElementCollectionTrailingCommas" : true,
"rules" : {
"AllPublicDeclarationsHaveDocumentation" : false,
"AlwaysUseLiteralForEmptyCollectionInit" : false,
"AlwaysUseLowerCamelCase" : false,
"AmbiguousTrailingClosureOverload" : true,
"BeginDocumentationCommentWithOneLineSummary" : false,
"DoNotUseSemicolons" : true,
"DontRepeatTypeInStaticProperties" : true,
"FileScopedDeclarationPrivacy" : true,
"FullyIndirectEnum" : true,
"GroupNumericLiterals" : true,
"IdentifiersMustBeASCII" : true,
"NeverForceUnwrap" : false,
"NeverUseForceTry" : false,
"NeverUseImplicitlyUnwrappedOptionals" : false,
"NoAccessLevelOnExtensionDeclaration" : true,
"NoAssignmentInExpressions" : true,
"NoBlockComments" : true,
"NoCasesWithOnlyFallthrough" : true,
"NoEmptyTrailingClosureParentheses" : true,
"NoLabelsInCasePatterns" : true,
"NoLeadingUnderscores" : false,
"NoParensAroundConditions" : true,
"NoVoidReturnOnFunctionSignature" : true,
"OmitExplicitReturns" : true,
"OneCasePerLine" : true,
"OneVariableDeclarationPerLine" : true,
"OnlyOneTrailingClosureArgument" : true,
"OrderedImports" : true,
"ReplaceForEachWithForLoop" : true,
"ReturnVoidInsteadOfEmptyTuple" : true,
"UseEarlyExits" : false,
"UseExplicitNilCheckInConditions" : false,
"UseLetInEveryBoundCaseVariable" : false,
"UseShorthandTypeNames" : true,
"UseSingleLinePropertyGetter" : false,
"UseSynthesizedInitializer" : false,
"UseTripleSlashForDocumentationComments" : true,
"UseWhereClausesInForLoops" : false,
"ValidateDocumentationComments" : false
}
}
26 changes: 0 additions & 26 deletions .swiftformat

This file was deleted.

2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,4 @@ The main development branch of the repository is `main`.

### Formatting

We use Nick Lockwood's SwiftFormat for formatting code. PRs will not be accepted if they haven't be formatted. The current version of SwiftFormat we are using is v0.53.10.
We use Apple's swift-format for formatting code. PRs will not be accepted if they haven't be formatted.
2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ let package = Package(
name: "swift-mustache",
platforms: [.macOS(.v10_15), .iOS(.v13), .tvOS(.v13), .watchOS(.v6)],
products: [
.library(name: "Mustache", targets: ["Mustache"]),
.library(name: "Mustache", targets: ["Mustache"])
],
dependencies: [],
targets: [
Expand Down
6 changes: 3 additions & 3 deletions Sources/Mustache/ContentType.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@ public protocol MustacheContentType: Sendable {
/// Text content type where no character is escaped
struct TextContentType: MustacheContentType {
func escapeText(_ text: String) -> String {
return text
text
}
}

/// HTML content where text is escaped for HTML output
struct HTMLContentType: MustacheContentType {
func escapeText(_ text: String) -> String {
return text.htmlEscape()
text.htmlEscape()
}
}

Expand All @@ -39,7 +39,7 @@ struct HTMLContentType: MustacheContentType {
/// with `MustacheContentTypes.register`.
public enum MustacheContentTypes {
static func get(_ name: String) -> MustacheContentType? {
return self.types[name]
self.types[name]
}

/// Register new content type
Expand Down
2 changes: 1 addition & 1 deletion Sources/Mustache/Context.swift
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ struct MustacheContext {

/// return context with sequence info and sequence element added to stack
func withContentType(_ contentType: MustacheContentType) -> MustacheContext {
return .init(
.init(
stack: self.stack,
sequenceContext: self.sequenceContext,
indentation: self.indentation,
Expand Down
2 changes: 1 addition & 1 deletion Sources/Mustache/Lambda.swift
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,6 @@ public struct MustacheLambda {
}

internal func callAsFunction(_ s: String) -> Any? {
return self.callback(s)
self.callback(s)
}
}
2 changes: 1 addition & 1 deletion Sources/Mustache/Parent.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,5 @@ public protocol MustacheParent {
/// Extend dictionary where the key is a string so that it uses the key values to access
/// it values
extension Dictionary: MustacheParent where Key == String {
public func child(named: String) -> Any? { return self[named] }
public func child(named: String) -> Any? { self[named] }
}
26 changes: 16 additions & 10 deletions Sources/Mustache/Parser.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ struct Parser {
self.position = string.startIndex
}

var buffer: String { return self._storage.buffer }
var buffer: String { self._storage.buffer }
private(set) var position: String.Index
}

Expand All @@ -59,7 +59,10 @@ extension Parser {
/// - Returns: If current character was the one we expected
mutating func read(_ char: Character) throws -> Bool {
let c = try character()
guard c == char else { unsafeRetreat(); return false }
guard c == char else {
unsafeRetreat()
return false
}
return true
}

Expand All @@ -84,7 +87,10 @@ extension Parser {
/// - Returns: If current character is in character set
mutating func read(_ characterSet: Set<Character>) throws -> Bool {
let c = try character()
guard characterSet.contains(c) else { unsafeRetreat(); return false }
guard characterSet.contains(c) else {
unsafeRetreat()
return false
}
return true
}

Expand Down Expand Up @@ -236,7 +242,7 @@ extension Parser {
@discardableResult mutating func read(while: Character) -> Int {
var count = 0
while !self.reachedEnd(),
unsafeCurrent() == `while`
unsafeCurrent() == `while`
{
unsafeAdvance()
count += 1
Expand All @@ -250,7 +256,7 @@ extension Parser {
@discardableResult mutating func read(while keyPath: KeyPath<Character, Bool>) -> Substring {
let startIndex = self.position
while !self.reachedEnd(),
unsafeCurrent()[keyPath: keyPath]
unsafeCurrent()[keyPath: keyPath]
{
unsafeAdvance()
}
Expand All @@ -263,7 +269,7 @@ extension Parser {
@discardableResult mutating func read(while cb: (Character) -> Bool) -> Substring {
let startIndex = self.position
while !self.reachedEnd(),
cb(unsafeCurrent())
cb(unsafeCurrent())
{
unsafeAdvance()
}
Expand All @@ -276,7 +282,7 @@ extension Parser {
@discardableResult mutating func read(while characterSet: Set<Character>) -> Substring {
let startIndex = self.position
while !self.reachedEnd(),
characterSet.contains(unsafeCurrent())
characterSet.contains(unsafeCurrent())
{
unsafeAdvance()
}
Expand All @@ -286,13 +292,13 @@ extension Parser {
/// Return whether we have reached the end of the buffer
/// - Returns: Have we reached the end
func reachedEnd() -> Bool {
return self.position == self.buffer.endIndex
self.position == self.buffer.endIndex
}

/// Return whether we are at the start of the buffer
/// - Returns: Are we are the start
func atStart() -> Bool {
return self.position == self.buffer.startIndex
self.position == self.buffer.startIndex
}
}

Expand Down Expand Up @@ -378,7 +384,7 @@ extension Parser {
// unsafe versions without checks
extension Parser {
func unsafeCurrent() -> Character {
return self.buffer[self.position]
self.buffer[self.position]
}

mutating func unsafeAdvance() {
Expand Down
7 changes: 4 additions & 3 deletions Sources/Mustache/Template+Parser.swift
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,8 @@ extension MustacheTemplate {
}
if self.isStandalone(&parser, state: state) {
setNewLine = true
} else if whiteSpaceBefore.count > 0 {}
} else if whiteSpaceBefore.count > 0 {
}
let sectionTemplate = try parse(&parser, state: state.withSectionName(name, newLine: setNewLine))
tokens.append(.blockExpansion(name: name, default: sectionTemplate, indentation: String(whiteSpaceBefore)))
whiteSpaceBefore = ""
Expand Down Expand Up @@ -415,7 +416,7 @@ extension MustacheTemplate {
nameParser.unsafeAdvance()
// We need to have a `)` for each transform that we've parsed
guard nameParser.read(while: ")") + 1 == existing.count,
nameParser.reachedEnd()
nameParser.reachedEnd()
else {
throw Error.unfinishedName
}
Expand Down Expand Up @@ -512,7 +513,7 @@ extension MustacheTemplate {
}

static func isStandalone(_ parser: inout Parser, state: ParserState) -> Bool {
return state.newLine && self.hasLineFinished(&parser)
state.newLine && self.hasLineFinished(&parser)
}

private static let sectionNameCharsWithoutBrackets = Set<Character>("0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ.-_?*")
Expand Down
2 changes: 1 addition & 1 deletion Sources/Mustache/Template+Render.swift
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ extension MustacheTemplate {
// run transform on the current child
for transform in transforms.reversed() {
if let runnable = child as? MustacheTransformable,
let transformed = runnable.transform(transform)
let transformed = runnable.transform(transform)
{
child = transformed
continue
Expand Down
8 changes: 4 additions & 4 deletions Sources/Mustache/Transform.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,13 @@ public protocol MustacheTransformable {
func transform(_ name: String) -> Any?
}

public extension StringProtocol {
extension StringProtocol {
/// Transform String/Substring
///
/// Transforms available are `capitalized`, `lowercased`, `uppercased` and `reversed`
/// - Parameter name: transform name
/// - Returns: Result
func transform(_ name: String) -> Any? {
public func transform(_ name: String) -> Any? {
switch name {
case "empty":
return isEmpty
Expand Down Expand Up @@ -209,13 +209,13 @@ extension Dictionary: ComparableSequence where Key: Comparable {
}
}

public extension FixedWidthInteger {
extension FixedWidthInteger {
/// Transform FixedWidthInteger
///
/// Transforms available are `plusone`, `minusone`, `odd`, `even`
/// - Parameter name: transform name
/// - Returns: Result
func transform(_ name: String) -> Any? {
public func transform(_ name: String) -> Any? {
switch name {
case "equalzero":
return self == 0
Expand Down
Loading