From 0bbb8005bb1bff4e2f797625581d8c197526fb86 Mon Sep 17 00:00:00 2001 From: David Jennes Date: Wed, 27 Jul 2022 02:11:09 +0200 Subject: [PATCH] Fix bunch of warnings --- CHANGELOG.md | 8 ++++---- Sources/Extension.swift | 2 +- Sources/Inheritence.swift | 6 ++---- Sources/Parser.swift | 2 +- Sources/Variable.swift | 3 ++- Tests/StencilTests/LexerSpec.swift | 2 +- Tests/StencilTests/VariableSpec.swift | 6 +++--- 7 files changed, 14 insertions(+), 15 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 61c9c05..2905ca3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -179,7 +179,7 @@ _None_ - The `{% for %}` tag can now iterate over tuples, structures and classes via their stored properties. [Ilya Puchka](https://github.com/ilyapuchka) - [#172](https://github.com/stencilproject/Stencil/pull/173) + [#173](https://github.com/stencilproject/Stencil/pull/173) - Added `split` filter. [Ilya Puchka](https://github.com/ilyapuchka) [#187](https://github.com/stencilproject/Stencil/pull/187) @@ -288,7 +288,7 @@ _None_ ### Bug Fixes - You can now use literal filter arguments which contain quotes. - [#98](https://github.com/kylef/Stencil/pull/98) + [#98](https://github.com/stencilproject/Stencil/pull/98) ## 0.8.0 @@ -432,10 +432,10 @@ _None_ - Variables (`{{ variable.5 }}`) that reference an array index at an unknown index will now resolve to `nil` instead of causing a crash. - [#72](https://github.com/kylef/Stencil/issues/72) + [#72](https://github.com/stencilproject/Stencil/issues/72) - Templates can now extend templates that extend other templates. - [#60](https://github.com/kylef/Stencil/issues/60) + [#60](https://github.com/stencilproject/Stencil/issues/60) - If comparisons will now treat 0 and below numbers as negative. diff --git a/Sources/Extension.swift b/Sources/Extension.swift index a91b4ab..26bfae7 100644 --- a/Sources/Extension.swift +++ b/Sources/Extension.swift @@ -36,7 +36,7 @@ open class Extension { /// Registers a template filter with the given name public func registerFilter(_ name: String, filter: @escaping (Any?, [Any?]) throws -> Any?) { - filters[name] = .arguments({ value, args, _ in try filter(value, args) }) + filters[name] = .arguments { value, args, _ in try filter(value, args) } } /// Registers a template filter with the given name diff --git a/Sources/Inheritence.swift b/Sources/Inheritence.swift index fcacdf0..87e5896 100644 --- a/Sources/Inheritence.swift +++ b/Sources/Inheritence.swift @@ -35,10 +35,8 @@ class BlockContext { extension Collection { func any(_ closure: (Iterator.Element) -> Bool) -> Iterator.Element? { - for element in self { - if closure(element) { - return element - } + for element in self where closure(element) { + return element } return nil diff --git a/Sources/Parser.swift b/Sources/Parser.swift index 0181552..355e632 100644 --- a/Sources/Parser.swift +++ b/Sources/Parser.swift @@ -1,5 +1,5 @@ public func until(_ tags: [String]) -> ((TokenParser, Token) -> Bool) { - return { parser, token in + return { _, token in if let name = token.components.first { for tag in tags where name == tag { return true diff --git a/Sources/Variable.swift b/Sources/Variable.swift index 122fa4a..995706c 100644 --- a/Sources/Variable.swift +++ b/Sources/Variable.swift @@ -48,7 +48,8 @@ public struct Variable: Equatable, Resolvable { /// Resolve the variable in the given context public func resolve(_ context: Context) throws -> Any? { - if variable.count > 1 && ((variable.hasPrefix("'") && variable.hasSuffix("'")) || (variable.hasPrefix("\"") && variable.hasSuffix("\""))) { + if variable.count > 1 && + ((variable.hasPrefix("'") && variable.hasSuffix("'")) || (variable.hasPrefix("\"") && variable.hasSuffix("\""))) { // String literal return String(variable[variable.index(after: variable.startIndex) ..< variable.index(before: variable.endIndex)]) } diff --git a/Tests/StencilTests/LexerSpec.swift b/Tests/StencilTests/LexerSpec.swift index 4eb7e6b..7961458 100644 --- a/Tests/StencilTests/LexerSpec.swift +++ b/Tests/StencilTests/LexerSpec.swift @@ -117,7 +117,7 @@ final class LexerTests: XCTestCase { } func testPerformance() throws { - let path = Path(#file as String) + ".." + "fixtures" + "huge.html" + let path = Path(#file as String) + ".." + "fixtures" + "huge.html" let content: String = try path.read() measure { diff --git a/Tests/StencilTests/VariableSpec.swift b/Tests/StencilTests/VariableSpec.swift index e25da2e..e834064 100644 --- a/Tests/StencilTests/VariableSpec.swift +++ b/Tests/StencilTests/VariableSpec.swift @@ -63,7 +63,7 @@ final class VariableTests: XCTestCase { let result = try variable.resolve(self.context) as? String try expect(result) == "name" } - + it("can resolve a string literal with one double quote") { let variable = Variable("\"") let result = try variable.resolve(self.context) as? String @@ -75,13 +75,13 @@ final class VariableTests: XCTestCase { let result = try variable.resolve(self.context) as? String try expect(result) == "name" } - + it("can resolve a string literal with one single quote") { let variable = Variable("'") let result = try variable.resolve(self.context) as? String try expect(result).to.beNil() } - + it("can resolve an integer literal") { let variable = Variable("5") let result = try variable.resolve(self.context) as? Int