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/
|
.conche/
|
||||||
.build/
|
.build/
|
||||||
|
.swiftpm/
|
||||||
Packages/
|
Packages/
|
||||||
Package.pins
|
Package.pins
|
||||||
*.xcodeproj
|
*.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:
|
opt_in_rules:
|
||||||
- anyobject_protocol
|
- anyobject_protocol
|
||||||
- array_init
|
- array_init
|
||||||
- attributes
|
- attributes
|
||||||
|
- closure_body_length
|
||||||
- closure_end_indentation
|
- closure_end_indentation
|
||||||
- closure_spacing
|
- closure_spacing
|
||||||
|
- collection_alignment
|
||||||
|
- contains_over_filter_count
|
||||||
|
- contains_over_filter_is_empty
|
||||||
- contains_over_first_not_nil
|
- contains_over_first_not_nil
|
||||||
|
- contains_over_range_nil_comparison
|
||||||
- convenience_type
|
- convenience_type
|
||||||
- discouraged_optional_boolean
|
- discouraged_optional_boolean
|
||||||
- discouraged_optional_collection
|
- discouraged_optional_collection
|
||||||
|
- duplicate_enum_cases
|
||||||
|
- duplicate_imports
|
||||||
|
- empty_collection_literal
|
||||||
- empty_count
|
- empty_count
|
||||||
- empty_string
|
- empty_string
|
||||||
- fallthrough
|
- fallthrough
|
||||||
- fatal_error_message
|
- fatal_error_message
|
||||||
- first_where
|
- first_where
|
||||||
|
- flatmap_over_map_reduce
|
||||||
- force_unwrapping
|
- force_unwrapping
|
||||||
- implicit_return
|
- identical_operands
|
||||||
- implicitly_unwrapped_optional
|
- inert_defer
|
||||||
- joined_default_parameter
|
- joined_default_parameter
|
||||||
|
- last_where
|
||||||
|
- legacy_hashing
|
||||||
|
- legacy_random
|
||||||
- literal_expression_end_indentation
|
- literal_expression_end_indentation
|
||||||
- lower_acl_than_parent
|
- lower_acl_than_parent
|
||||||
- modifier_order
|
- modifier_order
|
||||||
- multiline_arguments
|
- multiline_arguments
|
||||||
- multiline_function_chains
|
- multiline_function_chains
|
||||||
|
- multiline_literal_brackets
|
||||||
- multiline_parameters
|
- multiline_parameters
|
||||||
|
- multiline_parameters_brackets
|
||||||
|
- nslocalizedstring_key
|
||||||
|
- nsobject_prefer_isequal
|
||||||
- number_separator
|
- number_separator
|
||||||
|
- object_literal
|
||||||
- operator_usage_whitespace
|
- operator_usage_whitespace
|
||||||
- overridden_super_call
|
- overridden_super_call
|
||||||
- override_in_extension
|
- override_in_extension
|
||||||
|
- prefer_self_type_over_type_of_self
|
||||||
- private_action
|
- private_action
|
||||||
- private_outlet
|
- private_outlet
|
||||||
- prohibited_super_call
|
- prohibited_super_call
|
||||||
|
- raw_value_for_camel_cased_codable_enum
|
||||||
|
- reduce_boolean
|
||||||
|
- reduce_into
|
||||||
- redundant_nil_coalescing
|
- redundant_nil_coalescing
|
||||||
|
- redundant_objc_attribute
|
||||||
- sorted_first_last
|
- sorted_first_last
|
||||||
- sorted_imports
|
- sorted_imports
|
||||||
|
- static_operator
|
||||||
|
- strong_iboutlet
|
||||||
|
- toggle_bool
|
||||||
- trailing_closure
|
- trailing_closure
|
||||||
- unavailable_function
|
- unavailable_function
|
||||||
- unneeded_parentheses_in_closure_argument
|
- 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_parameter_alignment_on_call
|
||||||
|
- vertical_whitespace_closing_braces
|
||||||
|
- vertical_whitespace_opening_braces
|
||||||
|
- xct_specific_matcher
|
||||||
- yoda_condition
|
- yoda_condition
|
||||||
|
# Enable this again once we remove old swift support
|
||||||
|
# - optional_enum_case_matching
|
||||||
|
# - legacy_multiple
|
||||||
|
|
||||||
# Rules customization
|
# Rules customization
|
||||||
|
closure_body_length:
|
||||||
|
warning: 25
|
||||||
|
|
||||||
line_length:
|
line_length:
|
||||||
warning: 120
|
warning: 120
|
||||||
error: 200
|
error: 200
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ sudo: required
|
|||||||
dist: trusty
|
dist: trusty
|
||||||
install:
|
install:
|
||||||
- if [ "$TRAVIS_OS_NAME" == "linux" ]; then eval "$(curl -sL https://swiftenv.fuller.li/install.sh)"; fi
|
- 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
|
sudo installer -pkg /tmp/SwiftLint.pkg -target /; fi
|
||||||
script:
|
script:
|
||||||
- swift test
|
- swift test
|
||||||
|
|||||||
@@ -1,13 +1,13 @@
|
|||||||
public struct Environment {
|
public struct Environment {
|
||||||
public let templateClass: Template.Type
|
public let templateClass: Template.Type
|
||||||
public var extensions: [Extension]
|
public var extensions: [Extension]
|
||||||
|
|
||||||
public var loader: Loader?
|
public var loader: Loader?
|
||||||
|
|
||||||
public init(loader: Loader? = nil,
|
public init(
|
||||||
extensions: [Extension] = [],
|
loader: Loader? = nil,
|
||||||
templateClass: Template.Type = Template.self) {
|
extensions: [Extension] = [],
|
||||||
|
templateClass: Template.Type = Template.self
|
||||||
|
) {
|
||||||
self.templateClass = templateClass
|
self.templateClass = templateClass
|
||||||
self.loader = loader
|
self.loader = loader
|
||||||
self.extensions = extensions + [DefaultExtension()]
|
self.extensions = extensions + [DefaultExtension()]
|
||||||
@@ -44,5 +44,4 @@ public struct Environment {
|
|||||||
template.environment = self
|
template.environment = self
|
||||||
return try template.render(context)
|
return try template.render(context)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -55,7 +55,6 @@ public protocol ErrorReporter: AnyObject {
|
|||||||
}
|
}
|
||||||
|
|
||||||
open class SimpleErrorReporter: ErrorReporter {
|
open class SimpleErrorReporter: ErrorReporter {
|
||||||
|
|
||||||
open func renderError(_ error: Error) -> String {
|
open func renderError(_ error: Error) -> String {
|
||||||
guard let templateError = error as? TemplateSyntaxError else { return error.localizedDescription }
|
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
|
let description = templateError.token.map(describe(token:)) ?? templateError.reason
|
||||||
descriptions.append(description)
|
descriptions.append(description)
|
||||||
return descriptions.joined(separator: "\n")
|
return descriptions.joined(separator: "\n")
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -113,7 +113,6 @@ final class InExpression: Expression, InfixOperator, CustomStringConvertible {
|
|||||||
|
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
final class OrExpression: Expression, InfixOperator, CustomStringConvertible {
|
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)
|
var lines = content.components(separatedBy: .newlines)
|
||||||
let firstLine = (indentFirst ? indentation : "") + lines.removeFirst()
|
let firstLine = (indentFirst ? indentation : "") + lines.removeFirst()
|
||||||
let result = lines.reduce([firstLine]) { result, line in
|
let result = lines.reduce(into: [firstLine]) { result, line in
|
||||||
result + [(line.isEmpty ? "" : "\(indentation)\(line)")]
|
result.append(line.isEmpty ? "" : "\(indentation)\(line)")
|
||||||
}
|
}
|
||||||
return result.joined(separator: "\n")
|
return result.joined(separator: "\n")
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -63,11 +63,8 @@ class ExtendsNode: NodeType {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let blockNodes = parsedNodes.compactMap { $0 as? BlockNode }
|
let blockNodes = parsedNodes.compactMap { $0 as? BlockNode }
|
||||||
|
let nodes = blockNodes.reduce(into: [String: BlockNode]()) { accumulator, node in
|
||||||
let nodes = blockNodes.reduce([String: BlockNode]()) { accumulator, node -> [String: BlockNode] in
|
accumulator[node.name] = node
|
||||||
var dict = accumulator
|
|
||||||
dict[node.name] = node
|
|
||||||
return dict
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return ExtendsNode(templateName: Variable(bits[1]), blocks: nodes, token: token)
|
return ExtendsNode(templateName: Variable(bits[1]), blocks: nodes, token: token)
|
||||||
@@ -185,5 +182,4 @@ class BlockNode: NodeType {
|
|||||||
}
|
}
|
||||||
return childContext
|
return childContext
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -108,7 +108,6 @@ struct Lexer {
|
|||||||
let offset = templateString.distance(from: line.range.lowerBound, to: range.lowerBound)
|
let offset = templateString.distance(from: line.range.lowerBound, to: range.lowerBound)
|
||||||
return (line.content, line.number, offset)
|
return (line.content, line.number, offset)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class Scanner {
|
class Scanner {
|
||||||
|
|||||||
@@ -87,7 +87,6 @@ public class TokenParser {
|
|||||||
public func compileResolvable(_ token: String, containedIn containingToken: Token) throws -> Resolvable {
|
public func compileResolvable(_ token: String, containedIn containingToken: Token) throws -> Resolvable {
|
||||||
return try environment.compileResolvable(token, containedIn: containingToken)
|
return try environment.compileResolvable(token, containedIn: containingToken)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
extension Environment {
|
extension Environment {
|
||||||
@@ -180,7 +179,6 @@ extension Environment {
|
|||||||
public func compileExpression(components: [String], containedIn token: Token) throws -> Expression {
|
public func compileExpression(components: [String], containedIn token: Token) throws -> Expression {
|
||||||
return try IfExpressionParser.parser(components: components, environment: self, token: token).parse()
|
return try IfExpressionParser.parser(components: components, environment: self, token: token).parse()
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://en.wikipedia.org/wiki/Levenshtein_distance#Iterative_with_two_matrix_rows
|
// https://en.wikipedia.org/wiki/Levenshtein_distance#Iterative_with_two_matrix_rows
|
||||||
|
|||||||
@@ -50,17 +50,17 @@ open class Template: ExpressibleByStringLiteral {
|
|||||||
// MARK: ExpressibleByStringLiteral
|
// MARK: ExpressibleByStringLiteral
|
||||||
|
|
||||||
// Create a templaVte with a template string literal
|
// 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)
|
self.init(templateString: value)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create a template with a template string literal
|
// 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)
|
self.init(stringLiteral: value)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create a template with a template string literal
|
// 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)
|
self.init(stringLiteral: value)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -189,7 +189,6 @@ public struct RangeVariable: Resolvable {
|
|||||||
let range = min(lower, upper)...max(lower, upper)
|
let range = min(lower, upper)...max(lower, upper)
|
||||||
return lower > upper ? Array(range.reversed()) : Array(range)
|
return lower > upper ? Array(range.reversed()) : Array(range)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func normalize(_ current: Any?) -> Any? {
|
func normalize(_ current: Any?) -> Any? {
|
||||||
|
|||||||
@@ -133,7 +133,7 @@ final class EnvironmentTests: XCTestCase {
|
|||||||
token: "name|unknown"
|
token: "name|unknown"
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
it("reports error in variable tag") {
|
it("reports error in variable tag") {
|
||||||
self.template = "{{ }}"
|
self.template = "{{ }}"
|
||||||
try self.expectError(reason: "Missing variable name", token: " ")
|
try self.expectError(reason: "Missing variable name", token: " ")
|
||||||
@@ -261,11 +261,13 @@ final class EnvironmentIncludeTemplateTests: XCTestCase {
|
|||||||
function: String = #function
|
function: String = #function
|
||||||
) throws {
|
) throws {
|
||||||
var expectedError = expectedSyntaxError(token: token, template: template, description: reason)
|
var expectedError = expectedSyntaxError(token: token, template: template, description: reason)
|
||||||
expectedError.stackTrace = [expectedSyntaxError(
|
expectedError.stackTrace = [
|
||||||
token: includedToken,
|
expectedSyntaxError(
|
||||||
template: includedTemplate,
|
token: includedToken,
|
||||||
description: reason
|
template: includedTemplate,
|
||||||
).token].compactMap { $0 }
|
description: reason
|
||||||
|
).token
|
||||||
|
].compactMap { $0 }
|
||||||
|
|
||||||
let error = try expect(
|
let error = try expect(
|
||||||
self.environment.render(template: self.template, context: ["target": "World"]),
|
self.environment.render(template: self.template, context: ["target": "World"]),
|
||||||
@@ -368,11 +370,13 @@ final class EnvironmentBaseAndChildTemplateTests: XCTestCase {
|
|||||||
) throws {
|
) throws {
|
||||||
var expectedError = expectedSyntaxError(token: childToken, template: childTemplate, description: reason)
|
var expectedError = expectedSyntaxError(token: childToken, template: childTemplate, description: reason)
|
||||||
if let baseToken = baseToken {
|
if let baseToken = baseToken {
|
||||||
expectedError.stackTrace = [expectedSyntaxError(
|
expectedError.stackTrace = [
|
||||||
token: baseToken,
|
expectedSyntaxError(
|
||||||
template: baseTemplate,
|
token: baseToken,
|
||||||
description: reason
|
template: baseTemplate,
|
||||||
).token].compactMap { $0 }
|
description: reason
|
||||||
|
).token
|
||||||
|
].compactMap { $0 }
|
||||||
}
|
}
|
||||||
let error = try expect(
|
let error = try expect(
|
||||||
self.environment.render(template: self.childTemplate, context: ["target": "World"]),
|
self.environment.render(template: self.childTemplate, context: ["target": "World"]),
|
||||||
|
|||||||
@@ -325,10 +325,12 @@ final class FilterTests: XCTestCase {
|
|||||||
let template = Template(templateString: """
|
let template = Template(templateString: """
|
||||||
{{ value|indent:2 }}
|
{{ value|indent:2 }}
|
||||||
""")
|
""")
|
||||||
let result = try template.render(Context(dictionary: ["value": """
|
let result = try template.render(Context(dictionary: [
|
||||||
|
"value": """
|
||||||
One
|
One
|
||||||
Two
|
Two
|
||||||
"""]))
|
"""
|
||||||
|
]))
|
||||||
try expect(result) == """
|
try expect(result) == """
|
||||||
One
|
One
|
||||||
Two
|
Two
|
||||||
@@ -339,10 +341,12 @@ final class FilterTests: XCTestCase {
|
|||||||
let template = Template(templateString: """
|
let template = Template(templateString: """
|
||||||
{{ value|indent:2,"\t" }}
|
{{ value|indent:2,"\t" }}
|
||||||
""")
|
""")
|
||||||
let result = try template.render(Context(dictionary: ["value": """
|
let result = try template.render(Context(dictionary: [
|
||||||
|
"value": """
|
||||||
One
|
One
|
||||||
Two
|
Two
|
||||||
"""]))
|
"""
|
||||||
|
]))
|
||||||
try expect(result) == """
|
try expect(result) == """
|
||||||
One
|
One
|
||||||
\t\tTwo
|
\t\tTwo
|
||||||
@@ -353,10 +357,12 @@ final class FilterTests: XCTestCase {
|
|||||||
let template = Template(templateString: """
|
let template = Template(templateString: """
|
||||||
{{ value|indent:2," ",true }}
|
{{ value|indent:2," ",true }}
|
||||||
""")
|
""")
|
||||||
let result = try template.render(Context(dictionary: ["value": """
|
let result = try template.render(Context(dictionary: [
|
||||||
|
"value": """
|
||||||
One
|
One
|
||||||
Two
|
Two
|
||||||
"""]))
|
"""
|
||||||
|
]))
|
||||||
try expect(result) == """
|
try expect(result) == """
|
||||||
One
|
One
|
||||||
Two
|
Two
|
||||||
@@ -367,14 +373,16 @@ final class FilterTests: XCTestCase {
|
|||||||
let template = Template(templateString: """
|
let template = Template(templateString: """
|
||||||
{{ value|indent }}
|
{{ value|indent }}
|
||||||
""")
|
""")
|
||||||
let result = try template.render(Context(dictionary: ["value": """
|
let result = try template.render(Context(dictionary: [
|
||||||
|
"value": """
|
||||||
One
|
One
|
||||||
|
|
||||||
|
|
||||||
Two
|
Two
|
||||||
|
|
||||||
|
|
||||||
"""]))
|
"""
|
||||||
|
]))
|
||||||
try expect(result) == """
|
try expect(result) == """
|
||||||
One
|
One
|
||||||
|
|
||||||
|
|||||||
@@ -127,7 +127,8 @@ final class LexerTests: XCTestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func testCombiningDiaeresis() throws {
|
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 templateString = "ü\n{% if test %}ü{% endif %}\n{% if ü %}ü{% endif %}\n"
|
||||||
let lexer = Lexer(templateString: templateString)
|
let lexer = Lexer(templateString: templateString)
|
||||||
let tokens = lexer.tokenize()
|
let tokens = lexer.tokenize()
|
||||||
|
|||||||
Reference in New Issue
Block a user