From 7acacf6bdb29414fb2cfa56a7f5bd8219fca0637 Mon Sep 17 00:00:00 2001 From: JP Simard Date: Wed, 12 Jul 2017 09:43:09 -0700 Subject: [PATCH] update dependencies, mostly for SourceKitten 0.18 --- CHANGELOG.md | 7 +++++- Cartfile | 2 +- Cartfile.resolved | 12 +++++----- Carthage/Checkouts/Commandant | 2 +- Carthage/Checkouts/Result | 2 +- Carthage/Checkouts/SWXMLHash | 2 +- Carthage/Checkouts/SourceKitten | 2 +- Carthage/Checkouts/Yams | 2 +- Carthage/Checkouts/xcconfigs | 2 +- Package.swift | 2 +- README.md | 5 +++-- .../Extensions/Collection+PrefixWhile.swift | 22 ------------------- .../NSRegularExpression+SwiftLint.swift | 11 +++++++--- .../Rules/ClosureEndIndentationRule.swift | 2 +- .../SwiftLintFramework/Rules/CommaRule.swift | 6 ++--- .../Rules/ForceUnwrappingRule.swift | 4 ++-- .../Rules/GenericTypeNameRule.swift | 8 +++---- .../Rules/ImplicitReturnRule.swift | 2 +- .../Rules/ReturnArrowWhitespaceRule.swift | 2 +- .../Rules/ShorthandOperatorRule.swift | 2 +- .../Rules/StatementPositionRule.swift | 12 +++++----- .../Rules/UnusedOptionalBindingRule.swift | 2 +- .../VerticalParameterAlignmentRule.swift | 4 ++-- .../Rules/VoidReturnRule.swift | 2 +- SwiftLint.xcodeproj/project.pbxproj | 4 ---- SwiftLintFramework.podspec | 2 +- 26 files changed, 55 insertions(+), 70 deletions(-) delete mode 100644 Source/SwiftLintFramework/Extensions/Collection+PrefixWhile.swift diff --git a/CHANGELOG.md b/CHANGELOG.md index 89c466ea7..766a6d60c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,8 @@ ##### Breaking -* None. +* Xcode 8.3 or later and Swift 3.1 or later are required to build. + [Norio Nomura](https://github.com/norio-nomura) ##### Enhancements @@ -29,6 +30,10 @@ should be separated from other statements by a single blank line. [Uncommon](https://github.com/Uncommon) +* Improve performance when linting and correcting on Linux, matching behavior. + [JP Simard](https://github.com/jpsim) + [#1577](https://github.com/realm/SwiftLint/issues/1577) + ##### Bug Fixes * None. diff --git a/Cartfile b/Cartfile index 003637398..92a362729 100644 --- a/Cartfile +++ b/Cartfile @@ -1,2 +1,2 @@ -github "jpsim/SourceKitten" ~> 0.17 +github "jpsim/SourceKitten" ~> 0.18 github "scottrhoyt/SwiftyTextTable" ~> 0.5.0 diff --git a/Cartfile.resolved b/Cartfile.resolved index 9c25eb98e..1a7570f3d 100644 --- a/Cartfile.resolved +++ b/Cartfile.resolved @@ -1,7 +1,7 @@ -github "Carthage/Commandant" "16bcee12f48564c87bb13830f5320d21257e15b8" -github "antitypical/Result" "3.2.2" -github "drmohundro/SWXMLHash" "3.1.0" -github "jpsim/SourceKitten" "0.17.6" -github "jpsim/Yams" "0.3.2" -github "jspahrsummers/xcconfigs" "2055f18efbe18e77408f7f43947f7ad92b2d4ff0" +github "Carthage/Commandant" "9bce2e76cf7e0beb6aaa7db0738c6bea6633df30" +github "antitypical/Result" "3.2.3" +github "drmohundro/SWXMLHash" "4.1.0" +github "jpsim/SourceKitten" "0.18.0" +github "jpsim/Yams" "0.3.3" +github "jspahrsummers/xcconfigs" "4ac967d12f72c2ccc7f34d163268d09296923a7c" github "scottrhoyt/SwiftyTextTable" "0.5.0" diff --git a/Carthage/Checkouts/Commandant b/Carthage/Checkouts/Commandant index 16bcee12f..9bce2e76c 160000 --- a/Carthage/Checkouts/Commandant +++ b/Carthage/Checkouts/Commandant @@ -1 +1 @@ -Subproject commit 16bcee12f48564c87bb13830f5320d21257e15b8 +Subproject commit 9bce2e76cf7e0beb6aaa7db0738c6bea6633df30 diff --git a/Carthage/Checkouts/Result b/Carthage/Checkouts/Result index f460dee9c..c84461852 160000 --- a/Carthage/Checkouts/Result +++ b/Carthage/Checkouts/Result @@ -1 +1 @@ -Subproject commit f460dee9c9de710463c91a505c1b4a566de7621c +Subproject commit c8446185238659a2b27c0261f64ff1254291d07d diff --git a/Carthage/Checkouts/SWXMLHash b/Carthage/Checkouts/SWXMLHash index 10b0b412a..209a7b437 160000 --- a/Carthage/Checkouts/SWXMLHash +++ b/Carthage/Checkouts/SWXMLHash @@ -1 +1 @@ -Subproject commit 10b0b412a39542d19d002d6ff9f00d1a158332d9 +Subproject commit 209a7b437b514b7fc3ac2beecbe267b25c03f2d5 diff --git a/Carthage/Checkouts/SourceKitten b/Carthage/Checkouts/SourceKitten index 91d9d5b20..9b2867db9 160000 --- a/Carthage/Checkouts/SourceKitten +++ b/Carthage/Checkouts/SourceKitten @@ -1 +1 @@ -Subproject commit 91d9d5b20876da2afcbf34664bccc0bfd26088c7 +Subproject commit 9b2867db9f1cb3138fb5a77f7993e05c64899ab1 diff --git a/Carthage/Checkouts/Yams b/Carthage/Checkouts/Yams index acf403cb0..0728fc42e 160000 --- a/Carthage/Checkouts/Yams +++ b/Carthage/Checkouts/Yams @@ -1 +1 @@ -Subproject commit acf403cb0d950a2d58ea8c63ce001deac2fde222 +Subproject commit 0728fc42e9db36f457183fba6bad1508cfd43423 diff --git a/Carthage/Checkouts/xcconfigs b/Carthage/Checkouts/xcconfigs index 2055f18ef..4ac967d12 160000 --- a/Carthage/Checkouts/xcconfigs +++ b/Carthage/Checkouts/xcconfigs @@ -1 +1 @@ -Subproject commit 2055f18efbe18e77408f7f43947f7ad92b2d4ff0 +Subproject commit 4ac967d12f72c2ccc7f34d163268d09296923a7c diff --git a/Package.swift b/Package.swift index 1c2f6869e..995dd3ea6 100644 --- a/Package.swift +++ b/Package.swift @@ -10,7 +10,7 @@ let package = Package( ]), ], dependencies: [ - .Package(url: "https://github.com/jpsim/SourceKitten.git", majorVersion: 0, minor: 17), + .Package(url: "https://github.com/jpsim/SourceKitten.git", majorVersion: 0, minor: 18), .Package(url: "https://github.com/jpsim/Yams.git", majorVersion: 0, minor: 3), .Package(url: "https://github.com/scottrhoyt/SwiftyTextTable.git", majorVersion: 0, minor: 5), ] diff --git a/README.md b/README.md index 886692015..2744746af 100644 --- a/README.md +++ b/README.md @@ -53,7 +53,7 @@ running it. ### Compiling from source: You can also build from source by cloning this project and running -`git submodule update --init --recursive; make install` (Xcode 8.0 or later). +`git submodule update --init --recursive; make install` (Xcode 8.3 or later). ## Usage @@ -90,7 +90,8 @@ Alternatively, if you've installed SwiftLint via CocoaPods the script should loo To run `swiftlint autocorrect` on save in Xcode, install the [SwiftLintXcode](https://github.com/ypresto/SwiftLintXcode) plugin from Alcatraz. -⚠ ️This plugin will not work with Xcode 8 without disabling SIP. This is not recommended. +⚠ ️This plugin will not work with Xcode 8 or later without disabling SIP. +This is not recommended. ### AppCode diff --git a/Source/SwiftLintFramework/Extensions/Collection+PrefixWhile.swift b/Source/SwiftLintFramework/Extensions/Collection+PrefixWhile.swift deleted file mode 100644 index 02aecc69a..000000000 --- a/Source/SwiftLintFramework/Extensions/Collection+PrefixWhile.swift +++ /dev/null @@ -1,22 +0,0 @@ -// -// Collection+PrefixWhile.swift -// SwiftLint -// -// Created by Marcelo Fabri on 06/14/17. -// Copyright © 2017 Realm. All rights reserved. -// - -import Foundation - -#if !swift(>=3.1) -extension Collection { - // from https://github.com/apple/swift/blob/4b0597a8/stdlib/public/core/Collection.swift#L1558 - func prefix(while predicate: (Iterator.Element) throws -> Bool) rethrows -> SubSequence { - var end = startIndex - while try end != endIndex && predicate(self[end]) { - formIndex(after: &end) - } - return self[startIndex..=3.1) -public typealias NSRegularExpression = RegularExpression -#endif public typealias NSTextCheckingResult = TextCheckingResult +#else +#if !swift(>=4.0) +extension NSTextCheckingResult { + internal func range(at idx: Int) -> NSRange { + return rangeAt(idx) + } +} +#endif #endif private var regexCache = [RegexCacheKey: NSRegularExpression]() diff --git a/Source/SwiftLintFramework/Rules/ClosureEndIndentationRule.swift b/Source/SwiftLintFramework/Rules/ClosureEndIndentationRule.swift index 222dce304..72e1a1ba6 100644 --- a/Source/SwiftLintFramework/Rules/ClosureEndIndentationRule.swift +++ b/Source/SwiftLintFramework/Rules/ClosureEndIndentationRule.swift @@ -106,7 +106,7 @@ public struct ClosureEndIndentationRule: ASTRule, OptInRule, ConfigurationProvid let contents = file.contents.bridge() guard let range = contents.byteRangeToNSRange(start: nameOffset, length: nameLength), let match = newLineRegex.matches(in: file.contents, options: [], - range: range).last?.rangeAt(1), + range: range).last?.range(at: 1), let methodByteRange = contents.NSRangeToByteRange(start: match.location, length: match.length) else { return nameOffset diff --git a/Source/SwiftLintFramework/Rules/CommaRule.swift b/Source/SwiftLintFramework/Rules/CommaRule.swift index fce77c383..349fd71a9 100644 --- a/Source/SwiftLintFramework/Rules/CommaRule.swift +++ b/Source/SwiftLintFramework/Rules/CommaRule.swift @@ -104,12 +104,12 @@ public struct CommaRule: CorrectableRule, ConfigurationProviderRule { if match.numberOfRanges != 5 { return nil } // Number of Groups in regexp var indexStartRange = 1 - if match.rangeAt(indexStartRange).location == NSNotFound { + if match.range(at: indexStartRange).location == NSNotFound { indexStartRange += 2 } // check first captured range - let firstRange = match.rangeAt(indexStartRange) + let firstRange = match.range(at: indexStartRange) guard let matchByteFirstRange = nsstring .NSRangeToByteRange(start: firstRange.location, length: firstRange.length) else { return nil } @@ -128,7 +128,7 @@ public struct CommaRule: CorrectableRule, ConfigurationProviderRule { } // check second captured range - let secondRange = match.rangeAt(indexStartRange + 1) + let secondRange = match.range(at: indexStartRange + 1) guard let matchByteSecondRange = nsstring .NSRangeToByteRange(start: secondRange.location, length: secondRange.length) else { return nil } diff --git a/Source/SwiftLintFramework/Rules/ForceUnwrappingRule.swift b/Source/SwiftLintFramework/Rules/ForceUnwrappingRule.swift index 11220aaaa..42608ac0d 100644 --- a/Source/SwiftLintFramework/Rules/ForceUnwrappingRule.swift +++ b/Source/SwiftLintFramework/Rules/ForceUnwrappingRule.swift @@ -84,8 +84,8 @@ public struct ForceUnwrappingRule: OptInRule, ConfigurationProviderRule { file: File) -> NSRange? { if match.numberOfRanges < 3 { return nil } - let firstRange = match.rangeAt(1) - let secondRange = match.rangeAt(2) + let firstRange = match.range(at: 1) + let secondRange = match.range(at: 2) guard let matchByteFirstRange = nsstring .NSRangeToByteRange(start: firstRange.location, length: firstRange.length), diff --git a/Source/SwiftLintFramework/Rules/GenericTypeNameRule.swift b/Source/SwiftLintFramework/Rules/GenericTypeNameRule.swift index 286d5af97..a6c4ba4b1 100644 --- a/Source/SwiftLintFramework/Rules/GenericTypeNameRule.swift +++ b/Source/SwiftLintFramework/Rules/GenericTypeNameRule.swift @@ -82,7 +82,7 @@ public struct GenericTypeNameRule: ASTRule, ConfigurationProviderRule { guard tokens.first == .keyword, Set(tokens.dropFirst()) == [.identifier], let match = genericTypeRegex.firstMatch(in: file.contents, options: [], - range: range)?.rangeAt(1) else { + range: range)?.range(at: 1) else { return [] } @@ -101,7 +101,7 @@ public struct GenericTypeNameRule: ASTRule, ConfigurationProviderRule { case let start = nameOffset + nameLength, case let length = bodyOffset - start, let range = contents.byteRangeToNSRange(start: start, length: length), - let match = genericTypeRegex.firstMatch(in: file.contents, options: [], range: range)?.rangeAt(1) else { + let match = genericTypeRegex.firstMatch(in: file.contents, options: [], range: range)?.range(at: 1) else { return [] } @@ -116,7 +116,7 @@ public struct GenericTypeNameRule: ASTRule, ConfigurationProviderRule { let length = dictionary.nameLength, case let contents = file.contents.bridge(), let range = contents.byteRangeToNSRange(start: offset, length: length), - let match = genericTypeRegex.firstMatch(in: file.contents, options: [], range: range)?.rangeAt(1), + let match = genericTypeRegex.firstMatch(in: file.contents, options: [], range: range)?.range(at: 1), match.location < minParameterOffset(parameters: dictionary.enclosedVarParameters, file: file) else { return [] } @@ -219,7 +219,7 @@ extension String { return (self, range) } - let trimmedRange = match.rangeAt(1) + let trimmedRange = match.range(at: 1) return (bridged.substring(with: trimmedRange), trimmedRange) } } diff --git a/Source/SwiftLintFramework/Rules/ImplicitReturnRule.swift b/Source/SwiftLintFramework/Rules/ImplicitReturnRule.swift index fac2efdb0..b2c7afc52 100644 --- a/Source/SwiftLintFramework/Rules/ImplicitReturnRule.swift +++ b/Source/SwiftLintFramework/Rules/ImplicitReturnRule.swift @@ -79,7 +79,7 @@ public struct ImplicitReturnRule: ConfigurationProviderRule, CorrectableRule, Op return nil } - return result.rangeAt(1) + return result.range(at: 1) } } } diff --git a/Source/SwiftLintFramework/Rules/ReturnArrowWhitespaceRule.swift b/Source/SwiftLintFramework/Rules/ReturnArrowWhitespaceRule.swift index a36b29646..c1491fd87 100644 --- a/Source/SwiftLintFramework/Rules/ReturnArrowWhitespaceRule.swift +++ b/Source/SwiftLintFramework/Rules/ReturnArrowWhitespaceRule.swift @@ -78,7 +78,7 @@ public struct ReturnArrowWhitespaceRule: CorrectableRule, ConfigurationProviderR guard result.numberOfRanges > (replacementsByIndex.keys.max() ?? 0) else { break } for (index, string) in replacementsByIndex { - if let range = contents.nsrangeToIndexRange(result.rangeAt(index)) { + if let range = contents.nsrangeToIndexRange(result.range(at: index)) { contents.replaceSubrange(range, with: string) break } diff --git a/Source/SwiftLintFramework/Rules/ShorthandOperatorRule.swift b/Source/SwiftLintFramework/Rules/ShorthandOperatorRule.swift index feeb4f3a2..ee54a064c 100644 --- a/Source/SwiftLintFramework/Rules/ShorthandOperatorRule.swift +++ b/Source/SwiftLintFramework/Rules/ShorthandOperatorRule.swift @@ -83,7 +83,7 @@ public struct ShorthandOperatorRule: ConfigurationProviderRule { // byteRanges will have the ranges of captured groups let byteRanges: [NSRange?] = (1.. Bool { diff --git a/Source/SwiftLintFramework/Rules/VerticalParameterAlignmentRule.swift b/Source/SwiftLintFramework/Rules/VerticalParameterAlignmentRule.swift index 9f0a68fc0..5e3f02db8 100644 --- a/Source/SwiftLintFramework/Rules/VerticalParameterAlignmentRule.swift +++ b/Source/SwiftLintFramework/Rules/VerticalParameterAlignmentRule.swift @@ -64,7 +64,7 @@ public struct VerticalParameterAlignmentRule: ASTRule, ConfigurationProviderRule let nameLength = dictionary.nameLength, let nameRange = contents.byteRangeToNSRange(start: nameOffset, length: nameLength), let paramStart = regex(pattern).firstMatch(in: file.contents, - options: [], range: nameRange)?.rangeAt(1).location, + options: [], range: nameRange)?.range(at: 1).location, let (startLine, startCharacter) = contents.lineAndCharacter(forCharacterOffset: paramStart), let (endLine, _) = contents.lineAndCharacter(forByteOffset: nameOffset + nameLength - 1), endLine > startLine else { @@ -77,7 +77,7 @@ public struct VerticalParameterAlignmentRule: ASTRule, ConfigurationProviderRule let violationLocations = linesRange.flatMap { lineIndex -> Int? in let line = file.lines[lineIndex - 1] guard let paramRange = paramRegex.firstMatch(in: file.contents, options: [], - range: line.range)?.rangeAt(1), + range: line.range)?.range(at: 1), let (_, paramCharacter) = contents.lineAndCharacter(forCharacterOffset: paramRange.location), paramCharacter != startCharacter else { return nil diff --git a/Source/SwiftLintFramework/Rules/VoidReturnRule.swift b/Source/SwiftLintFramework/Rules/VoidReturnRule.swift index 05bae6c9f..4674aafd8 100644 --- a/Source/SwiftLintFramework/Rules/VoidReturnRule.swift +++ b/Source/SwiftLintFramework/Rules/VoidReturnRule.swift @@ -64,7 +64,7 @@ public struct VoidReturnRule: ConfigurationProviderRule, CorrectableRule { let excludingPattern = "(\(pattern))\\s*(throws\\s+)?->" return file.match(pattern: pattern, excludingSyntaxKinds: kinds, excludingPattern: excludingPattern, - exclusionMapping: { $0.rangeAt(1) }).flatMap { + exclusionMapping: { $0.range(at: 1) }).flatMap { let parensRegex = regex(parensPattern) return parensRegex.firstMatch(in: file.contents, options: [], range: $0)?.range } diff --git a/SwiftLint.xcodeproj/project.pbxproj b/SwiftLint.xcodeproj/project.pbxproj index 8b409b1a3..a0ab2818d 100644 --- a/SwiftLint.xcodeproj/project.pbxproj +++ b/SwiftLint.xcodeproj/project.pbxproj @@ -146,7 +146,6 @@ D47A510E1DB29EEB00A4CC21 /* SwitchCaseOnNewlineRule.swift in Sources */ = {isa = PBXBuildFile; fileRef = D47A510D1DB29EEB00A4CC21 /* SwitchCaseOnNewlineRule.swift */; }; D47A51101DB2DD4800A4CC21 /* AttributesRule.swift in Sources */ = {isa = PBXBuildFile; fileRef = D47A510F1DB2DD4800A4CC21 /* AttributesRule.swift */; }; D47F31151EC918B600E3E1CA /* ProtocolPropertyAccessorsOrderRule.swift in Sources */ = {isa = PBXBuildFile; fileRef = D47F31141EC918B600E3E1CA /* ProtocolPropertyAccessorsOrderRule.swift */; }; - D48668C21EF164340068CA84 /* Collection+PrefixWhile.swift in Sources */ = {isa = PBXBuildFile; fileRef = D4B69E841EF12F7A00FBBD97 /* Collection+PrefixWhile.swift */; }; D48AE2CC1DFB58C5001C6A4A /* AttributesRulesExamples.swift in Sources */ = {isa = PBXBuildFile; fileRef = D48AE2CB1DFB58C5001C6A4A /* AttributesRulesExamples.swift */; }; D4998DE71DF191380006E05D /* AttributesRuleTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = D4998DE61DF191380006E05D /* AttributesRuleTests.swift */; }; D4998DE91DF194F20006E05D /* FileHeaderRuleTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = D4998DE81DF194F20006E05D /* FileHeaderRuleTests.swift */; }; @@ -465,7 +464,6 @@ D4B022A31E105636007E5297 /* GenericTypeNameRule.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = GenericTypeNameRule.swift; sourceTree = ""; }; D4B022AF1E109816007E5297 /* CharacterSet+LinuxHack.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "CharacterSet+LinuxHack.swift"; sourceTree = ""; }; D4B022B11E10B613007E5297 /* RedundantVoidReturnRule.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RedundantVoidReturnRule.swift; sourceTree = ""; }; - D4B69E841EF12F7A00FBBD97 /* Collection+PrefixWhile.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Collection+PrefixWhile.swift"; sourceTree = ""; }; D4C0E46E1E3D973600C560F2 /* ForWhereRule.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ForWhereRule.swift; sourceTree = ""; }; D4C27BFD1E12D53F00DF713E /* Version.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Version.swift; sourceTree = ""; }; D4C27BFF1E12DFF500DF713E /* LinterCacheTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = LinterCacheTests.swift; sourceTree = ""; }; @@ -1042,7 +1040,6 @@ D47079AA1DFDCF7A00027086 /* SwiftExpressionKind.swift */, E87E4A081BFB9CAE00FCFE46 /* SyntaxKind+SwiftLint.swift */, 6CC4259A1C77046200AEA885 /* SyntaxMap+SwiftLint.swift */, - D4B69E841EF12F7A00FBBD97 /* Collection+PrefixWhile.swift */, ); path = Extensions; sourceTree = ""; @@ -1309,7 +1306,6 @@ E87E4A091BFB9CAE00FCFE46 /* SyntaxKind+SwiftLint.swift in Sources */, 3B0B14541C505D6300BE82F7 /* SeverityConfiguration.swift in Sources */, E88198551BEA949A00333A11 /* ControlStatementRule.swift in Sources */, - D48668C21EF164340068CA84 /* Collection+PrefixWhile.swift in Sources */, E57B23C11B1D8BF000DEA512 /* ReturnArrowWhitespaceRule.swift in Sources */, E816194E1BFBFEAB00946723 /* ForceTryRule.swift in Sources */, E88198541BEA945100333A11 /* CommaRule.swift in Sources */, diff --git a/SwiftLintFramework.podspec b/SwiftLintFramework.podspec index 2e1c6b38c..33e8a2738 100644 --- a/SwiftLintFramework.podspec +++ b/SwiftLintFramework.podspec @@ -9,6 +9,6 @@ Pod::Spec.new do |s| s.platform = :osx, '10.10' s.source_files = 'Source/SwiftLintFramework/**/*.swift' s.pod_target_xcconfig = { 'APPLICATION_EXTENSION_API_ONLY' => 'YES' } - s.dependency 'SourceKittenFramework', '~> 0.17' + s.dependency 'SourceKittenFramework', '~> 0.18' s.dependency 'Yams', '~> 0.3' end