Skip to content

Commit

Permalink
update for Xcode 7 Beta 6
Browse files Browse the repository at this point in the history
  • Loading branch information
jpsim committed Aug 25, 2015
1 parent e51afd2 commit e1f4ec4
Show file tree
Hide file tree
Showing 18 changed files with 62 additions and 46 deletions.
2 changes: 1 addition & 1 deletion .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
url = https://github.com/Carthage/Commandant.git
[submodule "Carthage/Checkouts/SWXMLHash"]
path = Carthage/Checkouts/SWXMLHash
url = https://github.com/drmohundro/SWXMLHash.git
url = https://github.com/jpsim/SWXMLHash.git
[submodule "Carthage/Checkouts/SourceKitten"]
path = Carthage/Checkouts/SourceKitten
url = https://github.com/jpsim/SourceKitten.git
Expand Down
2 changes: 1 addition & 1 deletion Cartfile
Original file line number Diff line number Diff line change
@@ -1 +1 @@
github "jpsim/SourceKitten" "swift-2.0"
github "jpsim/SourceKitten" "master"
6 changes: 3 additions & 3 deletions Cartfile.resolved
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
github "antitypical/Result" "0.6-beta.1"
github "drmohundro/SWXMLHash" "2203b05b1e093b1dc3e32114953f937a6e7aa5f5"
github "drmohundro/SWXMLHash" "050154bfc56032f04fcca37464693a17f897200a"
github "jpsim/SwiftXPC" "d32e70f1b35cfa833be85fd40e70401f4190f5b0"
github "jspahrsummers/xcconfigs" "0.8.1"
github "Carthage/Commandant" "cc47af4a9e7a7d56bd1202d52762c1c66184c936"
github "jpsim/SourceKitten" "4906120ed45b09d9720718bf666eab1e7ef30b31"
github "Carthage/Commandant" "40f503c33121431dc098adb7c44d9496e3a1de2f"
github "jpsim/SourceKitten" "ace729472170a4ec2996b8f921fc66784e5ef4fe"
1 change: 0 additions & 1 deletion Carthage/Checkouts/LlamaKit
Submodule LlamaKit deleted from e28d7f
2 changes: 1 addition & 1 deletion Carthage/Checkouts/SWXMLHash
6 changes: 4 additions & 2 deletions Source/SwiftLintFramework/Rules/FunctionBodyLengthRule.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,10 @@ public struct FunctionBodyLengthRule: ASTRule, ParameterizedRule {
if let subDict = subItem as? XPCDictionary,
let kindString = subDict["key.kind"] as? String,
let kind = SwiftDeclarationKind(rawValue: kindString) {
violations.extend(self.validateFile(file, dictionary: subDict))
violations.extend(self.validateFile(file, kind: kind, dictionary: subDict))
violations.appendContentsOf(
self.validateFile(file, dictionary: subDict) +
self.validateFile(file, kind: kind, dictionary: subDict)
)
}
return violations
}
Expand Down
8 changes: 5 additions & 3 deletions Source/SwiftLintFramework/Rules/NestingRule.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,10 @@ public struct NestingRule: ASTRule {
if let subDict = subItem as? XPCDictionary,
let kindString = subDict["key.kind"] as? String,
let kind = SwiftDeclarationKind(rawValue: kindString) {
violations.extend(self.validateFile(file, dictionary: subDict))
violations.extend(self.validateFile(file, kind: kind, dictionary: subDict))
violations.appendContentsOf(
self.validateFile(file, dictionary: subDict) +
self.validateFile(file, kind: kind, dictionary: subDict)
)
}
return violations
}
Expand Down Expand Up @@ -67,7 +69,7 @@ public struct NestingRule: ASTRule {
}
}
let substructure = dictionary["key.substructure"] as? XPCArray ?? []
violations.extend(substructure.flatMap { subItem in
violations.appendContentsOf(substructure.flatMap { subItem in
let subDict = subItem as? XPCDictionary
let kindString = subDict?["key.kind"] as? String
let kind = kindString.flatMap { kindString in
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,12 @@ public struct OperatorFunctionWhitespaceRule: Rule {
let operators = ["/", "=", "-", "+", "!", "*", "|", "^", "~", "?", "."].map({"\\\($0)"}) +
["%", "<", ">", "&"]
let zeroOrManySpaces = "(\\s{0}|\\s{2,})"
let pattern1 = "func\\s+[" + "".join(operators) + "]+\(zeroOrManySpaces)(<[A-Z]+>)?\\("
let pattern2 = "func\(zeroOrManySpaces)[" + "".join(operators) + "]+\\s+(<[A-Z]+>)?\\("
let pattern1 = "func\\s+[" +
operators.joinWithSeparator("") +
"]+\(zeroOrManySpaces)(<[A-Z]+>)?\\("
let pattern2 = "func\(zeroOrManySpaces)[" +
operators.joinWithSeparator("") +
"]+\\s+(<[A-Z]+>)?\\("
return file.matchPattern("(\(pattern1)|\(pattern2))").filter { _, syntaxKinds in
return syntaxKinds.first == .Keyword
}.map { range, _ in
Expand Down
2 changes: 1 addition & 1 deletion Source/SwiftLintFramework/Rules/TrailingNewlineRule.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public struct TrailingNewlineRule: Rule {

public func validateFile(file: File) -> [StyleViolation] {
let string = file.contents
let start = advance(string.endIndex, -2, string.startIndex)
let start = string.endIndex.advancedBy(-2, limit: string.startIndex)
let range = Range(start: start, end: string.endIndex)
let substring = string[range].utf16
let newLineSet = NSCharacterSet.newlineCharacterSet()
Expand Down
6 changes: 4 additions & 2 deletions Source/SwiftLintFramework/Rules/TypeBodyLengthRule.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,10 @@ public struct TypeBodyLengthRule: ASTRule, ParameterizedRule {
if let subDict = subItem as? XPCDictionary,
let kindString = subDict["key.kind"] as? String,
let kind = SwiftDeclarationKind(rawValue: kindString) {
violations.extend(self.validateFile(file, dictionary: subDict))
violations.extend(self.validateFile(file, kind: kind, dictionary: subDict))
violations.appendContentsOf(
self.validateFile(file, dictionary: subDict) +
self.validateFile(file, kind: kind, dictionary: subDict)
)
}
return violations
}
Expand Down
6 changes: 4 additions & 2 deletions Source/SwiftLintFramework/Rules/TypeNameRule.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,10 @@ public struct TypeNameRule: ASTRule {
if let subDict = subItem as? XPCDictionary,
let kindString = subDict["key.kind"] as? String,
let kind = SwiftDeclarationKind(rawValue: kindString) {
violations.extend(self.validateFile(file, dictionary: subDict))
violations.extend(self.validateFile(file, kind: kind, dictionary: subDict))
violations.appendContentsOf(
self.validateFile(file, dictionary: subDict) +
self.validateFile(file, kind: kind, dictionary: subDict)
)
}
return violations
}
Expand Down
6 changes: 4 additions & 2 deletions Source/SwiftLintFramework/Rules/VariableNameRule.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,10 @@ public struct VariableNameRule: ASTRule {
if let subDict = subItem as? XPCDictionary,
let kindString = subDict["key.kind"] as? String,
let kind = SwiftDeclarationKind(rawValue: kindString) {
violations.extend(self.validateFile(file, dictionary: subDict))
violations.extend(self.validateFile(file, kind: kind, dictionary: subDict))
violations.appendContentsOf(
self.validateFile(file, dictionary: subDict) +
self.validateFile(file, kind: kind, dictionary: subDict)
)
}
return violations
}
Expand Down
12 changes: 6 additions & 6 deletions Source/SwiftLintFrameworkTests/ASTRuleTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class ASTRuleTests: XCTestCase {
severity: .Medium,
reason: "Type name should be between 3 and 40 characters in length: 'Ab'")])

let longName = "".join(Array(count: 40, repeatedValue: "A"))
let longName = Repeat(count: 40, repeatedValue: "A").joinWithSeparator("")
XCTAssertEqual(violations("\(kind) \(longName) {}\n"), [])
let longerName = longName + "A"
XCTAssertEqual(violations("\(kind) \(longerName) {}\n"), [
Expand Down Expand Up @@ -82,7 +82,7 @@ class ASTRuleTests: XCTestCase {
"'de'")
])

let longName = "".join(Array(count: 40, repeatedValue: "d"))
let longName = Repeat(count: 40, repeatedValue: "d").joinWithSeparator("")
XCTAssertEqual(violations("\(kind) Abc { \(varType) \(longName): Void }\n"), [])
let longerName = longName + "d"
XCTAssertEqual(violations("\(kind) Abc { \(varType) \(longerName): Void }\n"), [
Expand All @@ -98,11 +98,11 @@ class ASTRuleTests: XCTestCase {

func testFunctionBodyLengths() {
let longFunctionBody = "func abc() {" +
"".join(Array(count: 40, repeatedValue: "\n")) +
Repeat(count: 40, repeatedValue: "\n").joinWithSeparator("") +
"}\n"
XCTAssertEqual(violations(longFunctionBody), [])
let longerFunctionBody = "func abc() {" +
"".join(Array(count: 41, repeatedValue: "\n")) +
Repeat(count: 41, repeatedValue: "\n").joinWithSeparator("") +
"}\n"
XCTAssertEqual(violations(longerFunctionBody), [StyleViolation(type: .Length,
location: Location(file: nil, line: 1, character: 1),
Expand All @@ -113,11 +113,11 @@ class ASTRuleTests: XCTestCase {
func testTypeBodyLengths() {
for kind in ["class", "struct", "enum"] {
let longTypeBody = "\(kind) Abc {" +
"".join(Array(count: 200, repeatedValue: "\n")) +
Repeat(count: 200, repeatedValue: "\n").joinWithSeparator("") +
"}\n"
XCTAssertEqual(violations(longTypeBody), [])
let longerTypeBody = "\(kind) Abc {" +
"".join(Array(count: 201, repeatedValue: "\n")) +
Repeat(count: 201, repeatedValue: "\n").joinWithSeparator("") +
"}\n"
XCTAssertEqual(violations(longerTypeBody), [StyleViolation(type: .Length,
location: Location(file: nil, line: 1, character: 1),
Expand Down
25 changes: 14 additions & 11 deletions Source/SwiftLintFrameworkTests/StringRuleTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ import XCTest

class StringRuleTests: XCTestCase {
func testLineLengths() {
let longLine = "".join(Array(count: 100, repeatedValue: "/")) + "\n"
let longLine = Repeat(count: 100, repeatedValue: "/").joinWithSeparator("") + "\n"
XCTAssertEqual(violations(longLine), [])
let testCases: [(String, Int, ViolationSeverity)] = [
("/", 101, .VeryLow),
("".join(Array(count: 21, repeatedValue: "/")), 121, .Low),
("".join(Array(count: 51, repeatedValue: "/")), 151, .Medium),
("".join(Array(count: 101, repeatedValue: "/")), 201, .High),
("".join(Array(count: 151, repeatedValue: "/")), 251, .VeryHigh)
(Repeat(count: 21, repeatedValue: "/").joinWithSeparator(""), 121, .Low),
(Repeat(count: 51, repeatedValue: "/").joinWithSeparator(""), 151, .Medium),
(Repeat(count: 101, repeatedValue: "/").joinWithSeparator(""), 201, .High),
(Repeat(count: 151, repeatedValue: "/").joinWithSeparator(""), 251, .VeryHigh)
]
for testCase in testCases {
XCTAssertEqual(violations(testCase.0 + longLine), [StyleViolation(type: .Length,
Expand All @@ -42,13 +42,16 @@ class StringRuleTests: XCTestCase {
}

func testFileLengths() {
XCTAssertEqual(violations("".join(Array(count: 400, repeatedValue: "//\n"))), [])
XCTAssertEqual(
violations(Repeat(count: 400, repeatedValue: "//\n").joinWithSeparator("")),
[]
)
let testCases: [(String, Int, ViolationSeverity)] = [
("".join(Array(count: 401, repeatedValue: "//\n")), 401, .VeryLow),
("".join(Array(count: 501, repeatedValue: "//\n")), 501, .Low),
("".join(Array(count: 751, repeatedValue: "//\n")), 751, .Medium),
("".join(Array(count: 1001, repeatedValue: "//\n")), 1001, .High),
("".join(Array(count: 2001, repeatedValue: "//\n")), 2001, .VeryHigh)
(Repeat(count: 401, repeatedValue: "//\n").joinWithSeparator(""), 401, .VeryLow),
(Repeat(count: 501, repeatedValue: "//\n").joinWithSeparator(""), 501, .Low),
(Repeat(count: 751, repeatedValue: "//\n").joinWithSeparator(""), 751, .Medium),
(Repeat(count: 1001, repeatedValue: "//\n").joinWithSeparator(""), 1001, .High),
(Repeat(count: 2001, repeatedValue: "//\n").joinWithSeparator(""), 2001, .VeryHigh)
]
for testCase in testCases {
XCTAssertEqual(violations(testCase.0), [StyleViolation(type: .Length,
Expand Down
2 changes: 1 addition & 1 deletion Source/swiftlint/LintCommand.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ struct LintCommand: CommandType {
let stdinNSString = NSString(data: stdinData, encoding: NSUTF8StringEncoding)
if let stdinString = stdinNSString as? String {
let violations = Linter(file: File(contents: stdinString)).styleViolations
print("\n".join(violations.map { $0.description }))
print(violations.map({ $0.description }).joinWithSeparator("\n"))
return .Success()
}
return .Failure(CommandantError<()>.CommandError())
Expand Down
10 changes: 5 additions & 5 deletions Source/swiftlint/StructuredText.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ enum StructuredText {
var markdown: String {
switch self {
case let .Header(level, t):
return "".join(Array(count: level, repeatedValue: "#")) + " \(t)"
return String(Repeat(count: level, repeatedValue: "#")) + " \(t)"
case .Paragraph(let t):
return t
case .List(let items):
return "\n".join(items.map { "* " + $0.markdown })
return items.map({ "* " + $0.markdown }).joinWithSeparator("\n")
case .Joined(let items):
return "\n\n".join(items.map { $0.markdown } )
return items.map({ $0.markdown }).joinWithSeparator("\n\n")
}
}

Expand All @@ -34,8 +34,8 @@ enum StructuredText {
case .Header(1, let t): return t.uppercaseString
case .Header(_, let t): return t
case .Paragraph(let t): return t
case .List(let items): return "\n".join(items.map { "* " + $0.ansi })
case .Joined(let items): return "\n\n".join(items.map { $0.ansi } )
case .List(let items): return items.map({ "* " + $0.ansi }).joinWithSeparator("\n")
case .Joined(let items): return items.map({ $0.ansi } ).joinWithSeparator("\n\n")
}
}
}

0 comments on commit e1f4ec4

Please sign in to comment.