Skip to content

Commit

Permalink
Enable vertical whitespace rules in SwiftLint
Browse files Browse the repository at this point in the history
and fix violations
  • Loading branch information
jpsim committed Dec 2, 2018
1 parent 7afd7cc commit 0e862ca
Show file tree
Hide file tree
Showing 143 changed files with 2 additions and 187 deletions.
2 changes: 2 additions & 0 deletions .swiftlint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ opt_in_rules:
- unneeded_parentheses_in_closure_argument
- untyped_error_in_catch
- vertical_parameter_alignment_on_call
- vertical_whitespace_closing_braces
- vertical_whitespace_opening_braces
- yoda_condition

identifier_name:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ private extension String {
#endif

extension Configuration {

// MARK: Caching Configurations By Path (In-Memory)

private static var cachedConfigurationsByPath = [String: Configuration]()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,6 @@ extension Configuration {
optInRules: [String] = [],
whitelistRules: [String] = [],
ruleList: RuleList) {

// Deprecation warning for "enabled_rules"
if dict[Key.enabledRules.rawValue] != nil {
queuedPrintError("'\(Key.enabledRules.rawValue)' has been renamed to " +
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import SourceKittenFramework

extension Dictionary where Key: ExpressibleByStringLiteral {

/// Accessibility.
var accessibility: String? {
return self["key.accessibility"] as? String
Expand Down
1 change: 0 additions & 1 deletion Source/SwiftLintFramework/Extensions/File+Cache.swift
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@ private class Cache<T> {
}

extension File {

fileprivate var cacheKey: String {
return path ?? contents
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import Foundation
import SourceKittenFramework

extension Structure {

/// Returns array of tuples containing "key.kind" and "byteRange" from Structure
/// that contains the byte offset. Returns all kinds if no parameter specified.
///
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,4 @@ extension SwiftDeclarationKind {
.`associatedtype`,
.`enum`
]

}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ extension SyntaxMap {
///
/// - Parameter byteRange: byte based NSRange
internal func tokens(inByteRange byteRange: NSRange) -> [SyntaxToken] {

func intersect(_ token: SyntaxToken) -> Bool {
return NSRange(location: token.offset, length: token.length)
.intersects(byteRange)
Expand Down
2 changes: 0 additions & 2 deletions Source/SwiftLintFramework/Helpers/NamespaceCollector.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,7 @@ struct NamespaceCollector {
private func findAllElements(in dictionary: [String: SourceKitRepresentable],
of types: Set<SwiftDeclarationKind>,
namespace: [String] = []) -> [Element] {

return dictionary.substructure.flatMap { subDict -> [Element] in

var elements: [Element] = []
guard let element = Element(dictionary: subDict, namespace: namespace) else {
return elements
Expand Down
1 change: 0 additions & 1 deletion Source/SwiftLintFramework/Models/AccessControlLevel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ public enum AccessControlLevel: String, CustomStringConvertible {
var isPrivate: Bool {
return self == .private || self == .fileprivate
}

}

extension AccessControlLevel: Comparable {
Expand Down
3 changes: 0 additions & 3 deletions Source/SwiftLintFramework/Models/Configuration.swift
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ public struct Configuration: Hashable {
swiftlintVersion: String? = nil,
cachePath: String? = nil,
indentation: IndentationStyle = .default) {

if let pinnedVersion = swiftlintVersion, pinnedVersion != Version.current.value {
queuedPrintError("Currently running SwiftLint \(Version.current.value) but " +
"configuration specified version \(pinnedVersion).")
Expand Down Expand Up @@ -92,7 +91,6 @@ public struct Configuration: Hashable {
cachePath: String?,
rootPath: String? = nil,
indentation: IndentationStyle) {

self.rulesMode = rulesMode
self.included = included
self.excluded = excluded
Expand Down Expand Up @@ -239,7 +237,6 @@ private func enabledRules(from configuredRules: [Rule],
// Same here
if containsDuplicateIdentifiers(validDisabledRuleIdentifiers)
|| containsDuplicateIdentifiers(validOptInRuleIdentifiers) {

return nil
}
return configuredRules.filter { rule in
Expand Down
1 change: 0 additions & 1 deletion Source/SwiftLintFramework/Models/RuleDescription.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,4 @@ public struct RuleDescription: Equatable {
public static func == (lhs: RuleDescription, rhs: RuleDescription) -> Bool {
return lhs.identifier == rhs.identifier
}

}
3 changes: 0 additions & 3 deletions Source/SwiftLintFramework/Protocols/CallPairRule.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import SourceKittenFramework
internal protocol CallPairRule: Rule {}

extension CallPairRule {

/**
Validates the given file for pairs of expressions where the first part of the expression
is a method call (with or without parameters) having the given `callNameSuffix` and the
Expand Down Expand Up @@ -65,7 +64,6 @@ extension CallPairRule {
private func methodCall(forByteOffset byteOffset: Int, excludingOffset: Int,
dictionary: [String: SourceKitRepresentable],
predicate: ([String: SourceKitRepresentable]) -> Bool) -> Int? {

if let kindString = dictionary.kind,
SwiftExpressionKind(rawValue: kindString) == .call,
let bodyOffset = dictionary.offset,
Expand All @@ -90,5 +88,4 @@ extension CallPairRule {

return nil
}

}
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
internal struct DiscouragedOptionalBooleanRuleExamples {

static let nonTriggeringExamples = [

// Global variable
"var foo: Bool",
"var foo: [String: Bool]",
Expand Down Expand Up @@ -53,7 +51,6 @@ internal struct DiscouragedOptionalBooleanRuleExamples {
]

static let triggeringExamples = [

// Global variable
"var foo: ↓Bool?",
"var foo: [String: ↓Bool?]",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
internal struct DiscouragedOptionalCollectionExamples {

static let nonTriggeringExamples = [

// Global variable
"var foo: [Int]",
"var foo: [String: Int]",
Expand Down Expand Up @@ -57,7 +55,6 @@ internal struct DiscouragedOptionalCollectionExamples {
]

static let triggeringExamples = [

// Global variable
"↓var foo: [Int]?",
"↓var foo: [String: Int]?",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ public struct DiscouragedOptionalCollectionRule: ASTRule, OptInRule, Configurati
public func validate(file: File,
kind: SwiftDeclarationKind,
dictionary: [String: SourceKitRepresentable]) -> [StyleViolation] {

let offsets = variableViolations(file: file, kind: kind, dictionary: dictionary) +
functionViolations(file: file, kind: kind, dictionary: dictionary)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import SourceKittenFramework
private typealias SourceKittenElement = [String: SourceKitRepresentable]

public struct ExplicitACLRule: OptInRule, ConfigurationProviderRule, AutomaticTestableRule {

public var configuration = SeverityConfiguration(.warning)

public init() {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ public struct ExplicitEnumRawValueRule: ASTRule, OptInRule, ConfigurationProvide
}

private func violatingOffsetsForEnum(dictionary: [String: SourceKitRepresentable]) -> [Int] {

let locs = substructureElements(of: dictionary, matching: .enumcase)
.compactMap { substructureElements(of: $0, matching: .enumelement) }
.flatMap(enumElementsMissingInitExpr)
Expand All @@ -72,7 +71,6 @@ public struct ExplicitEnumRawValueRule: ASTRule, OptInRule, ConfigurationProvide

private func enumElementsMissingInitExpr(
_ enumElements: [[String: SourceKitRepresentable]]) -> [[String: SourceKitRepresentable]] {

return enumElements
.filter { !$0.elements.contains { $0.kind == "source.lang.swift.structure.elem.init_expr" } }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import Foundation
import SourceKittenFramework

public struct ExplicitInitRule: ASTRule, ConfigurationProviderRule, CorrectableRule, OptInRule, AutomaticTestableRule {

public var configuration = SeverityConfiguration(.warning)

public init() {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ public struct ExplicitTypeInterfaceRule: ASTRule, OptInRule, ConfigurationProvid

public func validate(file: File, kind: SwiftDeclarationKind,
dictionary: [String: SourceKitRepresentable]) -> [StyleViolation] {

guard configuration.allowedKinds.contains(kind),
!containsType(dictionary: dictionary),
(!configuration.allowRedundancy || !assigneeIsInitCall(file: file, dictionary: dictionary)),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,6 @@ public struct ExtensionAccessModifierRule: ASTRule, ConfigurationProviderRule, O
private func declarationsViolations(file: File, acl: AccessControlLevel,
declarationOffsets: [Int],
dictionary: [String: SourceKitRepresentable]) -> [StyleViolation] {

guard let offset = dictionary.offset, let length = dictionary.length,
case let contents = file.contents.bridge(),
let range = contents.byteRangeToNSRange(start: offset, length: length) else {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import SourceKittenFramework

public struct FallthroughRule: ConfigurationProviderRule, OptInRule, AutomaticTestableRule {

public var configuration = SeverityConfiguration(.warning)

public init() {}
Expand Down
2 changes: 0 additions & 2 deletions Source/SwiftLintFramework/Rules/Idiomatic/ForWhereRule.swift
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ public struct ForWhereRule: ASTRule, ConfigurationProviderRule, AutomaticTestabl

public func validate(file: File, kind: StatementKind,
dictionary: [String: SourceKitRepresentable]) -> [StyleViolation] {

guard kind == .forEach,
let subDictionary = forBody(dictionary: dictionary),
subDictionary.substructure.count == 1,
Expand Down Expand Up @@ -144,5 +143,4 @@ public struct ForWhereRule: ASTRule, ConfigurationProviderRule, AutomaticTestabl
return !file.match(pattern: "\\|\\||&&", with: [], range: range).isEmpty
}.isEmpty
}

}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import SourceKittenFramework

public struct ForceCastRule: ConfigurationProviderRule, AutomaticTestableRule {

public var configuration = SeverityConfiguration(.error)

public init() {}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import SourceKittenFramework

public struct ForceTryRule: ConfigurationProviderRule, AutomaticTestableRule {

public var configuration = SeverityConfiguration(.error)

public init() {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import Foundation
import SourceKittenFramework

public struct ForceUnwrappingRule: OptInRule, ConfigurationProviderRule, AutomaticTestableRule {

public var configuration = SeverityConfiguration(.warning)

public init() {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,5 +66,4 @@ public struct ImplicitlyUnwrappedOptionalRule: ASTRule, ConfigurationProviderRul
location: location)
]
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import Foundation
import SourceKittenFramework

public struct LegacyConstantRule: CorrectableRule, ConfigurationProviderRule, AutomaticTestableRule {

public var configuration = SeverityConfiguration(.warning)

public init() {}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
internal struct LegacyConstantRuleExamples {

static let nonTriggeringExamples = [
"CGRect.infinite",
"CGPoint.zero",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import Foundation
import SourceKittenFramework

public struct LegacyConstructorRule: ASTRule, CorrectableRule, ConfigurationProviderRule, AutomaticTestableRule {

public var configuration = SeverityConfiguration(.warning)

public init() {}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import SourceKittenFramework

public struct LegacyRandomRule: ASTRule, OptInRule, ConfigurationProviderRule, AutomaticTestableRule {

public var configuration = SeverityConfiguration(.warning)

public init() {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,6 @@ private extension String {
func replace(function name: NimbleOperatorRule.MatcherFunction,
with operators: NimbleOperatorRule.Operators,
in range: NSRange) -> String? {

let anything = "\\s*(.*?)\\s*"

let toPattern = ("expect\\(\(anything)\\)\\.to\\(\(name)\\(\(anything)\\)\\)", operators.to)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,6 @@ public struct NoFallthroughOnlyRule: ASTRule, ConfigurationProviderRule, Automat
public func validate(file: File,
kind: StatementKind,
dictionary: [String: SourceKitRepresentable]) -> [StyleViolation] {

guard kind == .case,
let length = dictionary.length,
let offset = dictionary.offset,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import Foundation
import SourceKittenFramework

public struct ObjectLiteralRule: ASTRule, ConfigurationProviderRule, OptInRule {

public var configuration = ObjectLiteralConfiguration()

public init() {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ private extension File {
}

public struct RedundantNilCoalescingRule: OptInRule, CorrectableRule, ConfigurationProviderRule, AutomaticTestableRule {

public var configuration = SeverityConfiguration(.warning)

public init() {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ private let kindsImplyingObjc: Set<SwiftDeclarationAttributeKind> =
[.ibaction, .iboutlet, .ibinspectable, .gkinspectable, .ibdesignable, .nsManaged]

public struct RedundantObjcAttributeRule: ASTRule, ConfigurationProviderRule, AutomaticTestableRule {

public var configuration = SeverityConfiguration(.warning)

public init() {}
Expand Down Expand Up @@ -115,7 +114,6 @@ public struct RedundantObjcAttributeRule: ASTRule, ConfigurationProviderRule, Au
public func validate(file: File,
kind: SwiftDeclarationKind,
dictionary: [String: SourceKitRepresentable]) -> [StyleViolation] {

let enclosedSwiftAttributes = Set(dictionary.enclosedSwiftAttributes)
guard let offset = dictionary.offset,
enclosedSwiftAttributes.contains(.objc),
Expand All @@ -140,7 +138,6 @@ public struct RedundantObjcAttributeRule: ASTRule, ConfigurationProviderRule, Au
}

private extension Dictionary where Key == String, Value == SourceKitRepresentable {

var objcVisibleRanges: [NSRange] {
var ranges = [NSRange]()
func search(in dictionary: [String: SourceKitRepresentable]) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import SourceKittenFramework

public struct RedundantOptionalInitializationRule: ASTRule, CorrectableRule, ConfigurationProviderRule,
AutomaticTestableRule {

public var configuration = SeverityConfiguration(.warning)

public init() {}
Expand Down Expand Up @@ -159,7 +158,6 @@ public struct RedundantOptionalInitializationRule: ASTRule, CorrectableRule, Con
private func typeIsOptional(_ type: String) -> Bool {
return type.hasSuffix("?") || type.hasPrefix("Optional<")
}

}

extension Dictionary where Key == String, Value == SourceKitRepresentable {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import SourceKittenFramework

public struct RedundantTypeAnnotationRule: Rule, OptInRule, CorrectableRule,
ConfigurationProviderRule, AutomaticTestableRule {

public var configuration = SeverityConfiguration(.warning)

public init() {}
Expand Down Expand Up @@ -55,7 +54,6 @@ public struct RedundantTypeAnnotationRule: Rule, OptInRule, CorrectableRule,
)

public func validate(file: File) -> [StyleViolation] {

return violationRanges(in: file).map { range in
StyleViolation(
ruleDescription: type(of: self).description,
Expand All @@ -66,7 +64,6 @@ public struct RedundantTypeAnnotationRule: Rule, OptInRule, CorrectableRule,
}

public func correct(file: File) -> [Correction] {

let violatingRanges = file.ruleEnabled(violatingRanges: violationRanges(in: file), for: self)
var correctedContents = file.contents
var adjustedLocations = [Int]()
Expand Down
Loading

0 comments on commit 0e862ca

Please sign in to comment.