Skip to content

Commit

Permalink
Remove lineBreakBeforeControlFlowKeywords and format
Browse files Browse the repository at this point in the history
  • Loading branch information
DePasqualeOrg committed Dec 26, 2024
1 parent 15225cb commit 93263e4
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 114 deletions.
23 changes: 11 additions & 12 deletions .swift-format
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
{
"version": 1,
"indentation": {
"spaces": 4
},
"lineLength" : 120,
"maximumBlankLines": 1,
"respectsExistingLineBreaks": true,
"lineBreakBeforeControlFlowKeywords": true,
"lineBreakBeforeEachArgument": true,
"multiElementCollectionTrailingCommas": true,
"spacesAroundRangeFormationOperators": true
}
"version": 1,
"indentation": {
"spaces": 4
},
"lineLength": 120,
"maximumBlankLines": 1,
"respectsExistingLineBreaks": true,
"lineBreakBeforeEachArgument": true,
"multiElementCollectionTrailingCommas": true,
"spacesAroundRangeFormationOperators": true
}
12 changes: 4 additions & 8 deletions Sources/Environment.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,14 @@ class Environment {
args in
if let arg = args.first as? NumericValue {
return arg.value as! Int % 2 != 0
}
else {
} else {
throw JinjaError.runtime("Cannot apply test 'odd' to type: \(type(of:args.first))")
}
},
"even": { args in
if let arg = args.first as? NumericValue {
return arg.value as! Int % 2 == 0
}
else {
} else {
throw JinjaError.runtime("Cannot apply test 'even' to type: \(type(of:args.first))")
}
},
Expand Down Expand Up @@ -209,12 +207,10 @@ class Environment {
do {
if let value = try self.resolve(name: name).variables[name] {
return value
}
else {
} else {
return UndefinedValue()
}
}
catch {
} catch {
return UndefinedValue()
}
}
Expand Down
3 changes: 1 addition & 2 deletions Sources/Lexer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -279,8 +279,7 @@ func tokenize(_ source: String, options: PreprocessOptions = PreprocessOptions()
if type == .in, tokens.last?.type == .not {
_ = tokens.popLast()
tokens.append(Token(value: "not in", type: .notIn))
}
else {
} else {
tokens.append(Token(value: word, type: type))
}

Expand Down
21 changes: 7 additions & 14 deletions Sources/Parser.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@ func parse(tokens: [Token]) throws -> Program {
if let identifier = argument as? Identifier {
let value = try parseExpression()
argument = KeywordArgumentExpression(key: identifier, value: value as! Expression)
}
else {
} else {
throw JinjaError.syntax("Expected identifier for keyword argument")
}
}
Expand Down Expand Up @@ -89,8 +88,7 @@ func parse(tokens: [Token]) throws -> Program {
slices.append(nil)
current += 1
isSlice = true
}
else {
} else {
try slices.append(parseExpression())
if typeof(.colon) {
current += 1
Expand Down Expand Up @@ -131,8 +129,7 @@ func parse(tokens: [Token]) throws -> Program {
if computed {
property = try parseMemberExpressionArgumentsList()
try expect(type: .closeSquareBracket, error: "Expected closing square bracket")
}
else {
} else {
property = try parsePrimaryExpression()
if !(property is Identifier) {
throw JinjaError.syntax("Expected identifier following dot operator")
Expand Down Expand Up @@ -193,14 +190,12 @@ func parse(tokens: [Token]) throws -> Program {
var filter = try parsePrimaryExpression()
if let boolLiteralFilter = filter as? BoolLiteral {
filter = Identifier(value: String(boolLiteralFilter.value))
}
else if filter is NullLiteral {
} else if filter is NullLiteral {
filter = Identifier(value: "none")
}
if let test = filter as? Identifier {
operand = TestExpression(operand: operand as! Expression, negate: negate, test: test)
}
else {
} else {
throw JinjaError.syntax("Expected identifier for the test")
}
}
Expand Down Expand Up @@ -254,8 +249,7 @@ func parse(tokens: [Token]) throws -> Program {

if let right {
return right
}
else {
} else {
return try parseComparisonExpression()
}
}
Expand Down Expand Up @@ -347,8 +341,7 @@ func parse(tokens: [Token]) throws -> Program {
if typeof(.elseIf) {
try expect(type: .elseIf, error: "Expected elseif token")
try alternate.append(parseIfStatement())
}
else {
} else {
try expect(type: .else, error: "Expected else token")
try expect(type: .closeStatement, error: "Expected closing statement token")

Expand Down
Loading

0 comments on commit 93263e4

Please sign in to comment.