diff --git a/CommandLineTool/main.swift b/CommandLineTool/main.swift index 0dd4d107..6402d072 100644 --- a/CommandLineTool/main.swift +++ b/CommandLineTool/main.swift @@ -2,7 +2,7 @@ // main.swift // SwiftFormat // -// Version 0.8 +// Version 0.8.1 // // Created by Nick Lockwood on 12/08/2016. // Copyright 2016 Charcoal Design @@ -33,7 +33,7 @@ import Foundation -let version = "0.8" +let version = "0.8.1" func processInput(inputURL: NSURL, andWriteToOutput outputURL: NSURL, withOptions options: FormatOptions) -> Int { let manager = NSFileManager.defaultManager() diff --git a/CommandLineTool/swiftformat b/CommandLineTool/swiftformat index 13b3cd14..afbe04e5 100755 Binary files a/CommandLineTool/swiftformat and b/CommandLineTool/swiftformat differ diff --git a/LICENCE.md b/LICENCE.md index 930d7e3c..aed16e8d 100755 --- a/LICENCE.md +++ b/LICENCE.md @@ -1,6 +1,6 @@ SwiftFormat -Version 0.8, August 31st, 2016 +Version 0.8.1, August 31st, 2016 Copyright (c) 2016 Nick Lockwood diff --git a/README.md b/README.md index 82255d35..e7bf2346 100644 --- a/README.md +++ b/README.md @@ -351,6 +351,10 @@ With a syntax tree in place, it should become possible to add much more sophisti Release notes ---------------- +Version 0.8.1 + +- Fixed formatting of `/*! ... */` and `//!` headerdoc comments, and `/*: ... */` and `//:` Swift Playground comments + Version 0.8 - Added new `ranges` rules that adds or removes the spaces around range operators (e.g. `0 ..< count`, `"a"..."z"`) diff --git a/SwiftFormat/Formatter.swift b/SwiftFormat/Formatter.swift index 1a1c100d..b46f8762 100644 --- a/SwiftFormat/Formatter.swift +++ b/SwiftFormat/Formatter.swift @@ -2,7 +2,7 @@ // Formatter.swift // SwiftFormat // -// Version 0.8 +// Version 0.8.1 // // Created by Nick Lockwood on 12/08/2016. // Copyright 2016 Charcoal Design diff --git a/SwiftFormat/Rules.swift b/SwiftFormat/Rules.swift index ee666d9b..3acfd908 100644 --- a/SwiftFormat/Rules.swift +++ b/SwiftFormat/Rules.swift @@ -2,7 +2,7 @@ // Rules.swift // SwiftFormat // -// Version 0.8 +// Version 0.8.1 // // Created by Nick Lockwood on 12/08/2016. // Copyright 2016 Charcoal Design @@ -432,10 +432,11 @@ public func spaceInsideComments(formatter: Formatter) { guard let nextToken = formatter.tokenAtIndex(i + 1) else { return } if !nextToken.isWhitespaceOrLinebreak { let string = nextToken.string - if string.hasPrefix("*") { + if string.hasPrefix("*") || string.hasPrefix("!") || string.hasPrefix(":") { if !string.hasPrefix("**") && !string.hasPrefix("* ") && !string.hasPrefix("*\t") && !string.hasPrefix("*/") { - let string = "* " + string.substringFromIndex(string.startIndex.advancedBy(1)) + let string = String(string.characters.first!) + " " + + string.substringFromIndex(string.startIndex.advancedBy(1)) formatter.replaceTokenAtIndex(i + 1, with: Token(.CommentBody, string)) } } else { @@ -447,9 +448,10 @@ public func spaceInsideComments(formatter: Formatter) { guard let nextToken = formatter.tokenAtIndex(i + 1) else { return } if !nextToken.isWhitespaceOrLinebreak { let string = nextToken.string - if string.hasPrefix("/") { + if string.hasPrefix("/") || string.hasPrefix("!") || string.hasPrefix(":") { if !string.hasPrefix("/ ") && !string.hasPrefix("/\t") { - let string = "/ " + string.substringFromIndex(string.startIndex.advancedBy(1)) + let string = String(string.characters.first!) + " " + + string.substringFromIndex(string.startIndex.advancedBy(1)) formatter.replaceTokenAtIndex(i + 1, with: Token(.CommentBody, string)) } } else { diff --git a/SwiftFormat/SwiftFormat.h b/SwiftFormat/SwiftFormat.h index 47805f16..021c80c1 100644 --- a/SwiftFormat/SwiftFormat.h +++ b/SwiftFormat/SwiftFormat.h @@ -2,7 +2,7 @@ // SwiftFormat.h // SwiftFormat // -// Version 0.8 +// Version 0.8.1 // // Created by Nick Lockwood on 12/08/2016. // Copyright 2016 Charcoal Design diff --git a/SwiftFormat/SwiftFormat.swift b/SwiftFormat/SwiftFormat.swift index 24d03904..c9dd35e0 100644 --- a/SwiftFormat/SwiftFormat.swift +++ b/SwiftFormat/SwiftFormat.swift @@ -2,7 +2,7 @@ // SwiftFormat.swift // SwiftFormat // -// Version 0.8 +// Version 0.8.1 // // Created by Nick Lockwood on 12/08/2016. // Copyright 2016 Charcoal Design diff --git a/SwiftFormat/Tokenizer.swift b/SwiftFormat/Tokenizer.swift index cce79120..b9170533 100644 --- a/SwiftFormat/Tokenizer.swift +++ b/SwiftFormat/Tokenizer.swift @@ -2,7 +2,7 @@ // Tokenizer.swift // SwiftFormat // -// Version 0.8 +// Version 0.8.1 // // Created by Nick Lockwood on 11/08/2016. // Copyright 2016 Charcoal Design diff --git a/SwiftFormatTests/FormatterTests.swift b/SwiftFormatTests/FormatterTests.swift index 21afd415..dadf2639 100644 --- a/SwiftFormatTests/FormatterTests.swift +++ b/SwiftFormatTests/FormatterTests.swift @@ -2,7 +2,7 @@ // FormatterTests.swift // SwiftFormat // -// Version 0.8 +// Version 0.8.1 // // Created by Nick Lockwood on 30/08/2016. // Copyright 2016 Charcoal Design diff --git a/SwiftFormatTests/RulesTests.swift b/SwiftFormatTests/RulesTests.swift index 745057c7..4498545a 100644 --- a/SwiftFormatTests/RulesTests.swift +++ b/SwiftFormatTests/RulesTests.swift @@ -2,7 +2,7 @@ // RulesTests.swift // SwiftFormat // -// Version 0.8 +// Version 0.8.1 // // Created by Nick Lockwood on 12/08/2016. // Copyright 2016 Charcoal Design @@ -658,6 +658,20 @@ class RulesTests: XCTestCase { XCTAssertEqual(format(input + "\n", rules: defaultRules), output + "\n") } + func testSpaceInsideMultilineHeaderdocCommentType2() { + let input = "/*!foo\n bar*/" + let output = "/*! foo\n bar */" + XCTAssertEqual(format(input, rules: [spaceInsideComments]), output) + XCTAssertEqual(format(input + "\n", rules: defaultRules), output + "\n") + } + + func testSpaceInsideMultilineSwiftPlaygroundDocComment() { + let input = "/*:foo\n bar*/" + let output = "/*: foo\n bar */" + XCTAssertEqual(format(input, rules: [spaceInsideComments]), output) + XCTAssertEqual(format(input + "\n", rules: defaultRules), output + "\n") + } + func testNoExtraSpaceInsideMultilineHeaderdocComment() { let input = "/** foo\n bar */" let output = "/** foo\n bar */" @@ -672,6 +686,20 @@ class RulesTests: XCTestCase { XCTAssertEqual(format(input + "\n", rules: defaultRules), output + "\n") } + func testSpaceInsideSingleLineHeaderdocCommentType2() { + let input = "//!foo" + let output = "//! foo" + XCTAssertEqual(format(input, rules: [spaceInsideComments]), output) + XCTAssertEqual(format(input + "\n", rules: defaultRules), output + "\n") + } + + func testSpaceInsideSingleLineSwiftPlaygroundDocComment() { + let input = "//:foo" + let output = "//: foo" + XCTAssertEqual(format(input, rules: [spaceInsideComments]), output) + XCTAssertEqual(format(input + "\n", rules: defaultRules), output + "\n") + } + func testNoExtraSpaceInsideSingleLineHeaderdocComment() { let input = "/// foo" let output = "/// foo" diff --git a/SwiftFormatTests/SwiftFormatTests.swift b/SwiftFormatTests/SwiftFormatTests.swift index 73d48d12..48ca8655 100644 --- a/SwiftFormatTests/SwiftFormatTests.swift +++ b/SwiftFormatTests/SwiftFormatTests.swift @@ -2,7 +2,7 @@ // SwiftFormatTests.swift // SwiftFormat // -// Version 0.8 +// Version 0.8.1 // // Created by Nick Lockwood on 28/08/2016. // Copyright 2016 Charcoal Design diff --git a/SwiftFormatTests/TokenizerTests.swift b/SwiftFormatTests/TokenizerTests.swift index 7238fbbd..58d277df 100644 --- a/SwiftFormatTests/TokenizerTests.swift +++ b/SwiftFormatTests/TokenizerTests.swift @@ -2,7 +2,7 @@ // TokenizerTests.swift // SwiftFormat // -// Version 0.8 +// Version 0.8.1 // // Created by Nick Lockwood on 12/08/2016. // Copyright 2016 Charcoal Design