Update SwiftLint to 0.39.2 (#295)
* Update SwiftLint to 0.39.2 * Enable a bunch of extra rules * Fix all warnings * Ignore this Xcode generated folder Co-authored-by: Olivier Halligon <olivier@halligon.net>
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -1,5 +1,6 @@
|
||||
.conche/
|
||||
.build/
|
||||
.swiftpm/
|
||||
Packages/
|
||||
Package.pins
|
||||
*.xcodeproj
|
||||
|
||||
@@ -1,45 +1,90 @@
|
||||
swiftlint_version: 0.39.2
|
||||
|
||||
disabled_rules:
|
||||
# Remove this once we remove old swift support
|
||||
- implicit_return
|
||||
|
||||
opt_in_rules:
|
||||
- anyobject_protocol
|
||||
- array_init
|
||||
- attributes
|
||||
- closure_body_length
|
||||
- closure_end_indentation
|
||||
- closure_spacing
|
||||
- collection_alignment
|
||||
- contains_over_filter_count
|
||||
- contains_over_filter_is_empty
|
||||
- contains_over_first_not_nil
|
||||
- contains_over_range_nil_comparison
|
||||
- convenience_type
|
||||
- discouraged_optional_boolean
|
||||
- discouraged_optional_collection
|
||||
- duplicate_enum_cases
|
||||
- duplicate_imports
|
||||
- empty_collection_literal
|
||||
- empty_count
|
||||
- empty_string
|
||||
- fallthrough
|
||||
- fatal_error_message
|
||||
- first_where
|
||||
- flatmap_over_map_reduce
|
||||
- force_unwrapping
|
||||
- implicit_return
|
||||
- implicitly_unwrapped_optional
|
||||
- identical_operands
|
||||
- inert_defer
|
||||
- joined_default_parameter
|
||||
- last_where
|
||||
- legacy_hashing
|
||||
- legacy_random
|
||||
- literal_expression_end_indentation
|
||||
- lower_acl_than_parent
|
||||
- modifier_order
|
||||
- multiline_arguments
|
||||
- multiline_function_chains
|
||||
- multiline_literal_brackets
|
||||
- multiline_parameters
|
||||
- multiline_parameters_brackets
|
||||
- nslocalizedstring_key
|
||||
- nsobject_prefer_isequal
|
||||
- number_separator
|
||||
- object_literal
|
||||
- operator_usage_whitespace
|
||||
- overridden_super_call
|
||||
- override_in_extension
|
||||
- prefer_self_type_over_type_of_self
|
||||
- private_action
|
||||
- private_outlet
|
||||
- prohibited_super_call
|
||||
- raw_value_for_camel_cased_codable_enum
|
||||
- reduce_boolean
|
||||
- reduce_into
|
||||
- redundant_nil_coalescing
|
||||
- redundant_objc_attribute
|
||||
- sorted_first_last
|
||||
- sorted_imports
|
||||
- static_operator
|
||||
- strong_iboutlet
|
||||
- toggle_bool
|
||||
- trailing_closure
|
||||
- unavailable_function
|
||||
- unneeded_parentheses_in_closure_argument
|
||||
- unowned_variable_capture
|
||||
- unused_capture_list
|
||||
- unused_control_flow_label
|
||||
- unused_declaration
|
||||
- unused_setter_value
|
||||
- vertical_parameter_alignment_on_call
|
||||
- vertical_whitespace_closing_braces
|
||||
- vertical_whitespace_opening_braces
|
||||
- xct_specific_matcher
|
||||
- yoda_condition
|
||||
# Enable this again once we remove old swift support
|
||||
# - optional_enum_case_matching
|
||||
# - legacy_multiple
|
||||
|
||||
# Rules customization
|
||||
closure_body_length:
|
||||
warning: 25
|
||||
|
||||
line_length:
|
||||
warning: 120
|
||||
error: 200
|
||||
|
||||
@@ -15,7 +15,7 @@ sudo: required
|
||||
dist: trusty
|
||||
install:
|
||||
- if [ "$TRAVIS_OS_NAME" == "linux" ]; then eval "$(curl -sL https://swiftenv.fuller.li/install.sh)"; fi
|
||||
- if [ "$TRAVIS_OS_NAME" == "osx" ]; then wget --output-document /tmp/SwiftLint.pkg https://github.com/realm/SwiftLint/releases/download/0.27.0/SwiftLint.pkg &&
|
||||
- if [ "$TRAVIS_OS_NAME" == "osx" ]; then wget --output-document /tmp/SwiftLint.pkg https://github.com/realm/SwiftLint/releases/download/0.39.2/SwiftLint.pkg &&
|
||||
sudo installer -pkg /tmp/SwiftLint.pkg -target /; fi
|
||||
script:
|
||||
- swift test
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
public struct Environment {
|
||||
public let templateClass: Template.Type
|
||||
public var extensions: [Extension]
|
||||
|
||||
public var loader: Loader?
|
||||
|
||||
public init(loader: Loader? = nil,
|
||||
extensions: [Extension] = [],
|
||||
templateClass: Template.Type = Template.self) {
|
||||
|
||||
public init(
|
||||
loader: Loader? = nil,
|
||||
extensions: [Extension] = [],
|
||||
templateClass: Template.Type = Template.self
|
||||
) {
|
||||
self.templateClass = templateClass
|
||||
self.loader = loader
|
||||
self.extensions = extensions + [DefaultExtension()]
|
||||
@@ -44,5 +44,4 @@ public struct Environment {
|
||||
template.environment = self
|
||||
return try template.render(context)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -55,7 +55,6 @@ public protocol ErrorReporter: AnyObject {
|
||||
}
|
||||
|
||||
open class SimpleErrorReporter: ErrorReporter {
|
||||
|
||||
open func renderError(_ error: Error) -> String {
|
||||
guard let templateError = error as? TemplateSyntaxError else { return error.localizedDescription }
|
||||
|
||||
@@ -74,10 +73,9 @@ open class SimpleErrorReporter: ErrorReporter {
|
||||
"""
|
||||
}
|
||||
|
||||
var descriptions = templateError.stackTrace.reduce([]) { $0 + [describe(token: $1)] }
|
||||
var descriptions = templateError.stackTrace.reduce(into: []) { $0.append(describe(token: $1)) }
|
||||
let description = templateError.token.map(describe(token:)) ?? templateError.reason
|
||||
descriptions.append(description)
|
||||
return descriptions.joined(separator: "\n")
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -113,7 +113,6 @@ final class InExpression: Expression, InfixOperator, CustomStringConvertible {
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
final class OrExpression: Expression, InfixOperator, CustomStringConvertible {
|
||||
|
||||
@@ -108,8 +108,8 @@ func indent(_ content: String, indentation: String, indentFirst: Bool) -> String
|
||||
|
||||
var lines = content.components(separatedBy: .newlines)
|
||||
let firstLine = (indentFirst ? indentation : "") + lines.removeFirst()
|
||||
let result = lines.reduce([firstLine]) { result, line in
|
||||
result + [(line.isEmpty ? "" : "\(indentation)\(line)")]
|
||||
let result = lines.reduce(into: [firstLine]) { result, line in
|
||||
result.append(line.isEmpty ? "" : "\(indentation)\(line)")
|
||||
}
|
||||
return result.joined(separator: "\n")
|
||||
}
|
||||
|
||||
@@ -63,11 +63,8 @@ class ExtendsNode: NodeType {
|
||||
}
|
||||
|
||||
let blockNodes = parsedNodes.compactMap { $0 as? BlockNode }
|
||||
|
||||
let nodes = blockNodes.reduce([String: BlockNode]()) { accumulator, node -> [String: BlockNode] in
|
||||
var dict = accumulator
|
||||
dict[node.name] = node
|
||||
return dict
|
||||
let nodes = blockNodes.reduce(into: [String: BlockNode]()) { accumulator, node in
|
||||
accumulator[node.name] = node
|
||||
}
|
||||
|
||||
return ExtendsNode(templateName: Variable(bits[1]), blocks: nodes, token: token)
|
||||
@@ -185,5 +182,4 @@ class BlockNode: NodeType {
|
||||
}
|
||||
return childContext
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -108,7 +108,6 @@ struct Lexer {
|
||||
let offset = templateString.distance(from: line.range.lowerBound, to: range.lowerBound)
|
||||
return (line.content, line.number, offset)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class Scanner {
|
||||
|
||||
@@ -87,7 +87,6 @@ public class TokenParser {
|
||||
public func compileResolvable(_ token: String, containedIn containingToken: Token) throws -> Resolvable {
|
||||
return try environment.compileResolvable(token, containedIn: containingToken)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
extension Environment {
|
||||
@@ -180,7 +179,6 @@ extension Environment {
|
||||
public func compileExpression(components: [String], containedIn token: Token) throws -> Expression {
|
||||
return try IfExpressionParser.parser(components: components, environment: self, token: token).parse()
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// https://en.wikipedia.org/wiki/Levenshtein_distance#Iterative_with_two_matrix_rows
|
||||
|
||||
@@ -50,17 +50,17 @@ open class Template: ExpressibleByStringLiteral {
|
||||
// MARK: ExpressibleByStringLiteral
|
||||
|
||||
// Create a templaVte with a template string literal
|
||||
public convenience required init(stringLiteral value: String) {
|
||||
public required convenience init(stringLiteral value: String) {
|
||||
self.init(templateString: value)
|
||||
}
|
||||
|
||||
// Create a template with a template string literal
|
||||
public convenience required init(extendedGraphemeClusterLiteral value: StringLiteralType) {
|
||||
public required convenience init(extendedGraphemeClusterLiteral value: StringLiteralType) {
|
||||
self.init(stringLiteral: value)
|
||||
}
|
||||
|
||||
// Create a template with a template string literal
|
||||
public convenience required init(unicodeScalarLiteral value: StringLiteralType) {
|
||||
public required convenience init(unicodeScalarLiteral value: StringLiteralType) {
|
||||
self.init(stringLiteral: value)
|
||||
}
|
||||
|
||||
|
||||
@@ -189,7 +189,6 @@ public struct RangeVariable: Resolvable {
|
||||
let range = min(lower, upper)...max(lower, upper)
|
||||
return lower > upper ? Array(range.reversed()) : Array(range)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func normalize(_ current: Any?) -> Any? {
|
||||
|
||||
@@ -261,11 +261,13 @@ final class EnvironmentIncludeTemplateTests: XCTestCase {
|
||||
function: String = #function
|
||||
) throws {
|
||||
var expectedError = expectedSyntaxError(token: token, template: template, description: reason)
|
||||
expectedError.stackTrace = [expectedSyntaxError(
|
||||
token: includedToken,
|
||||
template: includedTemplate,
|
||||
description: reason
|
||||
).token].compactMap { $0 }
|
||||
expectedError.stackTrace = [
|
||||
expectedSyntaxError(
|
||||
token: includedToken,
|
||||
template: includedTemplate,
|
||||
description: reason
|
||||
).token
|
||||
].compactMap { $0 }
|
||||
|
||||
let error = try expect(
|
||||
self.environment.render(template: self.template, context: ["target": "World"]),
|
||||
@@ -368,11 +370,13 @@ final class EnvironmentBaseAndChildTemplateTests: XCTestCase {
|
||||
) throws {
|
||||
var expectedError = expectedSyntaxError(token: childToken, template: childTemplate, description: reason)
|
||||
if let baseToken = baseToken {
|
||||
expectedError.stackTrace = [expectedSyntaxError(
|
||||
token: baseToken,
|
||||
template: baseTemplate,
|
||||
description: reason
|
||||
).token].compactMap { $0 }
|
||||
expectedError.stackTrace = [
|
||||
expectedSyntaxError(
|
||||
token: baseToken,
|
||||
template: baseTemplate,
|
||||
description: reason
|
||||
).token
|
||||
].compactMap { $0 }
|
||||
}
|
||||
let error = try expect(
|
||||
self.environment.render(template: self.childTemplate, context: ["target": "World"]),
|
||||
|
||||
@@ -325,10 +325,12 @@ final class FilterTests: XCTestCase {
|
||||
let template = Template(templateString: """
|
||||
{{ value|indent:2 }}
|
||||
""")
|
||||
let result = try template.render(Context(dictionary: ["value": """
|
||||
let result = try template.render(Context(dictionary: [
|
||||
"value": """
|
||||
One
|
||||
Two
|
||||
"""]))
|
||||
"""
|
||||
]))
|
||||
try expect(result) == """
|
||||
One
|
||||
Two
|
||||
@@ -339,10 +341,12 @@ final class FilterTests: XCTestCase {
|
||||
let template = Template(templateString: """
|
||||
{{ value|indent:2,"\t" }}
|
||||
""")
|
||||
let result = try template.render(Context(dictionary: ["value": """
|
||||
let result = try template.render(Context(dictionary: [
|
||||
"value": """
|
||||
One
|
||||
Two
|
||||
"""]))
|
||||
"""
|
||||
]))
|
||||
try expect(result) == """
|
||||
One
|
||||
\t\tTwo
|
||||
@@ -353,10 +357,12 @@ final class FilterTests: XCTestCase {
|
||||
let template = Template(templateString: """
|
||||
{{ value|indent:2," ",true }}
|
||||
""")
|
||||
let result = try template.render(Context(dictionary: ["value": """
|
||||
let result = try template.render(Context(dictionary: [
|
||||
"value": """
|
||||
One
|
||||
Two
|
||||
"""]))
|
||||
"""
|
||||
]))
|
||||
try expect(result) == """
|
||||
One
|
||||
Two
|
||||
@@ -367,14 +373,16 @@ final class FilterTests: XCTestCase {
|
||||
let template = Template(templateString: """
|
||||
{{ value|indent }}
|
||||
""")
|
||||
let result = try template.render(Context(dictionary: ["value": """
|
||||
let result = try template.render(Context(dictionary: [
|
||||
"value": """
|
||||
One
|
||||
|
||||
|
||||
Two
|
||||
|
||||
|
||||
"""]))
|
||||
"""
|
||||
]))
|
||||
try expect(result) == """
|
||||
One
|
||||
|
||||
|
||||
@@ -127,7 +127,8 @@ final class LexerTests: XCTestCase {
|
||||
}
|
||||
|
||||
func testCombiningDiaeresis() throws {
|
||||
// the symbol "ü" in the `templateString` is unusually encoded as 0x75 0xCC 0x88 (LATIN SMALL LETTER U + COMBINING DIAERESIS) instead of 0xC3 0xBC (LATIN SMALL LETTER U WITH DIAERESIS)
|
||||
// the symbol "ü" in the `templateString` is unusually encoded as 0x75 0xCC 0x88 (LATIN SMALL LETTER U + COMBINING
|
||||
// DIAERESIS) instead of 0xC3 0xBC (LATIN SMALL LETTER U WITH DIAERESIS)
|
||||
let templateString = "ü\n{% if test %}ü{% endif %}\n{% if ü %}ü{% endif %}\n"
|
||||
let lexer = Lexer(templateString: templateString)
|
||||
let tokens = lexer.tokenize()
|
||||
|
||||
Reference in New Issue
Block a user