Skip to content

Commit

Permalink
Merge pull request #832 from realm/swift3.0
Browse files Browse the repository at this point in the history
Migrate to Swift 3.0
  • Loading branch information
jpsim authored Dec 2, 2016
2 parents bb515d3 + aff5c7f commit 64f67cc
Show file tree
Hide file tree
Showing 135 changed files with 1,369 additions and 1,375 deletions.
2 changes: 1 addition & 1 deletion .swiftlint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ included:
- Source
- Tests
excluded:
- Tests/SwiftLintFramework/Resources
- Tests/SwiftLintFrameworkTests/Resources
opt_in_rules:
- empty_count
3 changes: 3 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ matrix:
- script: set -o pipefail && script/cibuild | xcpretty
osx_image: xcode8
env: JOB=Xcode8
- script: swift test
osx_image: xcode8
env: JOB=SPM
exclude:
- script: placeholder # workaround for https://github.com/travis-ci/travis-ci/issues/4681

Expand Down
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@

##### Breaking

* None.
* SwiftLint now requires Xcode 8.x and Swift 3.0 to build.
APIs have not yet been adapted to conform to the Swift 3 API Design
Guidelines but will shortly.
[JP Simard](https://github.com/jpsim),
[Norio Nomura](https://github.com/norio-nomura)

##### Enhancements

Expand Down
2 changes: 1 addition & 1 deletion Cartfile
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
github "jpsim/SourceKitten" "master"
github "scottrhoyt/SwiftyTextTable" ~> 0.3.1
github "scottrhoyt/SwiftyTextTable" ~> 0.5.0
4 changes: 2 additions & 2 deletions Cartfile.private
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
github "Carthage/Commandant" ~> 0.10.1
github "Carthage/Commandant" ~> 0.11
github "jspahrsummers/xcconfigs" "master"
github "behrang/YamlSwift" ~> 1.5
github "behrang/YamlSwift" ~> 3.0
14 changes: 7 additions & 7 deletions Cartfile.resolved
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
github "antitypical/Result" "2.1.3"
github "drmohundro/SWXMLHash" "2.5.1"
github "scottrhoyt/SwiftyTextTable" "0.3.1"
github "behrang/YamlSwift" "1.5.0"
github "jspahrsummers/xcconfigs" "e2d4f524ab910fc4211ded76d090cc86df361ebb"
github "Carthage/Commandant" "0.10.1"
github "jpsim/SourceKitten" "798ce07577c2f192ea150ddfee83499bccfdd538"
github "antitypical/Result" "3.0.0"
github "drmohundro/SWXMLHash" "3.0.2"
github "scottrhoyt/SwiftyTextTable" "0.5.0"
github "behrang/YamlSwift" "3.1.0"
github "jspahrsummers/xcconfigs" "cc451b08e052b6146f5caf66bc1120420c529c7b"
github "Carthage/Commandant" "0.11.1"
github "jpsim/SourceKitten" "4e17c83ba08a07d8f992bcac67140d7b5cbb0e77"
2 changes: 1 addition & 1 deletion Carthage/Checkouts/SourceKitten
Submodule SourceKitten updated 133 files
2 changes: 1 addition & 1 deletion Carthage/Checkouts/xcconfigs
6 changes: 3 additions & 3 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ let package = Package(
]),
],
dependencies: [
.Package(url: "https://github.com/jpsim/SourceKitten.git", majorVersion: 0, minor: 13),
.Package(url: "https://github.com/behrang/YamlSwift.git", majorVersion: 1, minor: 4),
.Package(url: "https://github.com/scottrhoyt/SwiftyTextTable.git", majorVersion: 0, minor: 3),
.Package(url: "https://github.com/jpsim/SourceKitten.git", majorVersion: 0, minor: 15),
.Package(url: "https://github.com/behrang/YamlSwift.git", majorVersion: 3),
.Package(url: "https://github.com/scottrhoyt/SwiftyTextTable.git", majorVersion: 0, minor: 5),
]
)
2 changes: 1 addition & 1 deletion Source/SwiftLintFramework/Extensions/Array+SwiftLint.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import Foundation

extension Array {
static func arrayOf(obj: AnyObject?) -> [Element]? {
static func array(of obj: Any?) -> [Element]? {
if let array = obj as? [Element] {
return array
} else if let obj = obj as? Element {
Expand Down
33 changes: 17 additions & 16 deletions Source/SwiftLintFramework/Extensions/File+Cache.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import SourceKittenFramework

private var responseCache = Cache({file -> [String: SourceKitRepresentable]? in
do {
return try Request.EditorOpen(file).failableSend()
return try Request.editorOpen(file: file).failableSend()
} catch let error as Request.Error {
queuedPrintError(error.description)
return nil
Expand All @@ -38,14 +38,14 @@ private var queueForRebuild = [Structure]()

private struct Cache<T> {

private var values = [String: T]()
private var factory: File -> T
fileprivate var values = [String: T]()
fileprivate var factory: (File) -> T

private init(_ factory: File -> T) {
fileprivate init(_ factory: @escaping (File) -> T) {
self.factory = factory
}

private mutating func get(file: File) -> T {
fileprivate mutating func get(_ file: File) -> T {
let key = file.cacheKey
if let value = values[key] {
return value
Expand All @@ -55,20 +55,20 @@ private struct Cache<T> {
return value
}

private mutating func invalidate(file: File) {
fileprivate mutating func invalidate(_ file: File) {
if let key = file.path {
values.removeValueForKey(key)
values.removeValue(forKey: key)
}
}

private mutating func clear() {
values.removeAll(keepCapacity: false)
fileprivate mutating func clear() {
values.removeAll(keepingCapacity: false)
}
}

extension File {

private var cacheKey: String {
fileprivate var cacheKey: String {
return path ?? contents
}

Expand All @@ -81,7 +81,7 @@ extension File {
let value: [String: SourceKitRepresentable]? = nil
responseCache.values[cacheKey] = value
} else {
responseCache.values.removeValueForKey(cacheKey)
responseCache.values.removeValue(forKey: cacheKey)
}
}
}
Expand Down Expand Up @@ -141,7 +141,7 @@ extension File {

public func invalidateCache() {
responseCache.invalidate(self)
assertHandlers.removeValueForKey(cacheKey)
assertHandlers.removeValue(forKey: cacheKey)
structureCache.invalidate(self)
syntaxMapCache.invalidate(self)
syntaxTokensByLinesCache.invalidate(self)
Expand All @@ -167,7 +167,7 @@ extension File {
}
}

private func substructureForDict(dict: [String: SourceKitRepresentable]) ->
private func substructureForDict(_ dict: [String: SourceKitRepresentable]) ->
[[String: SourceKitRepresentable]]? {
return (dict["key.substructure"] as? [SourceKitRepresentable])?.flatMap {
$0 as? [String: SourceKitRepresentable]
Expand All @@ -177,9 +177,10 @@ private func substructureForDict(dict: [String: SourceKitRepresentable]) ->
private func rebuildAllDeclarationsByType() {
let allDeclarationsByType = queueForRebuild.flatMap { structure -> (String, [String])? in
guard let firstSubstructureDict = substructureForDict(structure.dictionary)?.first,
name = firstSubstructureDict["key.name"] as? String,
kind = (firstSubstructureDict["key.kind"] as? String).flatMap(SwiftDeclarationKind.init)
where kind == .Protocol,
let name = firstSubstructureDict["key.name"] as? String,
let kind = (firstSubstructureDict["key.kind"] as? String)
.flatMap(SwiftDeclarationKind.init),
kind == .protocol,
let substructure = substructureForDict(firstSubstructureDict) else {
return nil
}
Expand Down
Loading

0 comments on commit 64f67cc

Please sign in to comment.