Skip to content

Commit

Permalink
-fix linter and format warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
sbenedicadb committed Jan 6, 2021
1 parent 42d077d commit 828a459
Show file tree
Hide file tree
Showing 16 changed files with 39 additions and 42 deletions.
14 changes: 7 additions & 7 deletions Sources/AEPRulesEngine/ConditionEvaluator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,12 @@
public class ConditionEvaluator: Evaluating {
fileprivate let LOG_TAG = "ConditionEvaluator"
var operators: [String: Any] = [:]

// MARK: - Evaluating

public func evaluate<A>(operation: String, lhs: A) -> Result<Bool, RulesFailure> {
let op = operators[getHash(operation: operation, typeA: A.self)] as? ((A) -> Bool)

guard let op_ = op else {
let message = "No operator defined for \(getHash(operation: operation, typeA: A.self))"
Log.trace(label: LOG_TAG, message)
Expand All @@ -38,16 +39,16 @@ public class ConditionEvaluator: Evaluating {
}
}

extension ConditionEvaluator {
public func addUnaryOperator<A>(operation: String, closure: @escaping (A) -> Bool) {
public extension ConditionEvaluator {
func addUnaryOperator<A>(operation: String, closure: @escaping (A) -> Bool) {
operators[getHash(operation: operation, typeA: A.self)] = closure
}

public func addComparisonOperator<A, B>(operation: String, closure: @escaping (A, B) -> Bool) {
func addComparisonOperator<A, B>(operation: String, closure: @escaping (A, B) -> Bool) {
operators[getHash(operation: operation, typeA: A.self, typeB: B.self)] = closure
}

public func addComparisonOperator<A>(operation: String, type _: A.Type, closure: @escaping (A, A) -> Bool) {
func addComparisonOperator<A>(operation: String, type _: A.Type, closure: @escaping (A, A) -> Bool) {
operators[getHash(operation: operation, typeA: A.self, typeB: A.self)] = closure
}

Expand Down Expand Up @@ -81,7 +82,6 @@ public extension ConditionEvaluator {
}

private func addDefaultOperators() {

addComparisonOperator(operation: "and", type: Bool.self, closure: { $0 && $1 })
addComparisonOperator(operation: "or", type: Bool.self, closure: { $0 || $1 })

Expand Down
2 changes: 1 addition & 1 deletion Sources/AEPRulesEngine/Context.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
This file is licensed to you under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License. You may obtain a copy
of the License at http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under
the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
OF ANY KIND, either express or implied. See the License for the specific language
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public struct ComparisonExpression<A, B>: Evaluable {
}

// MARK: - Evaluable

public func evaluate(in context: Context) -> Result<Bool, RulesFailure> {
Log.trace(label: LOG_TAG, "Evaluating \(lhs) - \(operationName) - \(rhs)")
let resolvedLhs = lhs(context)
Expand Down
4 changes: 2 additions & 2 deletions Sources/AEPRulesEngine/Expression/Operand.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ public enum Operand<T> {
}
}

extension Operand {
public init(mustache: String) {
public extension Operand {
init(mustache: String) {
let tokens = try? TemplateParser.parse(mustache).get()
if let tokens = tokens, tokens.count > 0, case let .mustache(token) = tokens[0].type {
self = .token(token)
Expand Down
2 changes: 1 addition & 1 deletion Sources/AEPRulesEngine/Log/Log.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import Foundation
/// The `Log` class will be dormant unless its static `logging` variable is initialized.
/// To enable logging from the RulesEngine, implement a class that conforms to the
/// `Logging` protocol and use an instance of it to set the `Log.logging` variable.
public class Log {
public enum Log {
public static var logging: Logging?
/// Used to print more verbose information.
/// - Parameters:
Expand Down
6 changes: 3 additions & 3 deletions Sources/AEPRulesEngine/Log/LogLevel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
This file is licensed to you under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License. You may obtain a copy
of the License at http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under
the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
OF ANY KIND, either express or implied. See the License for the specific language
Expand All @@ -17,7 +17,7 @@ public enum LogLevel: Int, Comparable {
case warning = 1
case debug = 2
case trace = 3

/// Compares two `LogLevel`s for order
/// - Parameters:
/// - lhs: the first `LogLevel` to be compared
Expand All @@ -26,7 +26,7 @@ public enum LogLevel: Int, Comparable {
public static func < (lhs: LogLevel, rhs: LogLevel) -> Bool {
lhs.rawValue < rhs.rawValue
}

public func toString() -> String {
switch self {
case .trace:
Expand Down
2 changes: 1 addition & 1 deletion Sources/AEPRulesEngine/RulesFailure.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
This file is licensed to you under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License. You may obtain a copy
of the License at http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under
the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
OF ANY KIND, either express or implied. See the License for the specific language
Expand Down
4 changes: 2 additions & 2 deletions Sources/AEPRulesEngine/Template/MustacheError.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
This file is licensed to you under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License. You may obtain a copy
of the License at http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under
the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
OF ANY KIND, either express or implied. See the License for the specific language
Expand All @@ -15,7 +15,7 @@ import Foundation
public struct MustacheError: Error {
/// Eventual error message
public let message: String?

public init(message: String? = nil) {
self.message = message
}
Expand Down
12 changes: 6 additions & 6 deletions Sources/AEPRulesEngine/Template/ParserTagDelimiters.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
This file is licensed to you under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License. You may obtain a copy
of the License at http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under
the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
OF ANY KIND, either express or implied. See the License for the specific language
Expand All @@ -14,23 +14,23 @@ import Foundation

struct ParserTagDelimiters {
let tagDelimiterPair: DelimiterPair

init(_ tagDelimiterPair: DelimiterPair) {
self.tagDelimiterPair = tagDelimiterPair
}

var startTag: String {
return tagDelimiterPair.0
}

var startTagLength: Int {
return startTag.count
}

var endTag: String {
return tagDelimiterPair.1
}

var endTagLength: Int {
return endTag.count
}
Expand Down
2 changes: 1 addition & 1 deletion Sources/AEPRulesEngine/Template/TemplateParser.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import Foundation
/// A pair of tag delimiters, such as `("{{", "}}")`.
public typealias DelimiterPair = (String, String)

public struct TemplateParser {
public enum TemplateParser {
static let DefaultTagDelimiterPair: DelimiterPair = ("{{", "}}")

static func parse(_ templateString: String, tagDelimiterPair: DelimiterPair = TemplateParser.DefaultTagDelimiterPair) -> Result<[Segment], Error> {
Expand Down
10 changes: 5 additions & 5 deletions Sources/AEPRulesEngine/Transformer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
This file is licensed to you under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License. You may obtain a copy
of the License at http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under
the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
OF ANY KIND, either express or implied. See the License for the specific language
Expand All @@ -14,15 +14,15 @@ import Foundation

public class Transformer: Transforming {
var transformations: [String: Transformation] = [:]

public init() {}

public func register(name: String, transformation: @escaping Transformation) {
transformations[name] = transformation
}

// MARK: - Transforming

public func transform(name: String, parameter: Any) -> Any {
guard let transformation = transformations[name] else {
return parameter
Expand Down
1 change: 0 additions & 1 deletion Sources/AEPRulesEngine/Transforming.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,3 @@ public typealias Transformation = (Any) -> Any
public protocol Transforming {
func transform(name: String, parameter: Any) -> Any
}

13 changes: 6 additions & 7 deletions Tests/AEPRulesEngineTests/UnitTests/OperandTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,22 @@ import XCTest
@testable import AEPRulesEngine

class OperandTests: XCTestCase {

func testMustacheNoneValue() {
let mustache = Operand<String>(mustache: "")
XCTAssertEqual("<None>", String(describing: mustache))
}
func testDoubleValue(){

func testDoubleValue() {
let operand = Operand(floatLiteral: 1.2)
XCTAssertEqual("<Value: 1.2>", String(describing: operand))
}
func testBoolValue(){

func testBoolValue() {
let operand = Operand(booleanLiteral: true)
XCTAssertEqual("<Value: true>", String(describing: operand))
}
func testNilValue(){

func testNilValue() {
let operand: Operand<String> = nil
XCTAssertEqual("<None>", String(describing: operand))
}
Expand Down
4 changes: 2 additions & 2 deletions Tests/AEPRulesEngineTests/UnitTests/ParserTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ class ParserTests: XCTestCase {
let result = template.render(data: ["test": "value"], transformers: Transformer())
XCTAssertEqual("sdfdfdvalueaaa", result)
}

func testCustomizedTokenFormat() {
let template = Template(templateString: "sdfdfd[[test]]aaa", tagDelimiterPair: ("[[","]]"))
let template = Template(templateString: "sdfdfd[[test]]aaa", tagDelimiterPair: ("[[", "]]"))
let result = template.render(data: ["test": "value"], transformers: Transformer())
XCTAssertEqual("sdfdfdvalueaaa", result)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import XCTest

class RulesEngineLogLevelTests: XCTestCase {

func testLogLevelComparison() {
XCTAssertTrue(LogLevel.error < LogLevel.warning)
XCTAssertTrue(LogLevel.warning < LogLevel.debug)
Expand Down
2 changes: 1 addition & 1 deletion Tests/AEPRulesEngineTests/UnitTests/RulesEngineTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class RulesEngineTests: XCTestCase {
let rule = TestRule(condition: andCondition)
rulesEngine.addRules(rules: [rule])
var passed = true
var error:RulesFailure?
var error: RulesFailure?
rulesEngine.trace { result, _, _, failure in
passed = result
error = failure
Expand Down

0 comments on commit 828a459

Please sign in to comment.