Skip to content

Commit

Permalink
Updated for 0.22 release
Browse files Browse the repository at this point in the history
  • Loading branch information
nicklockwood committed Jan 3, 2017
1 parent b002da9 commit d7a6892
Show file tree
Hide file tree
Showing 33 changed files with 81 additions and 49 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
# Change Log

## [0.22](https://github.com/nicklockwood/SwiftFormat/releases/tag/0.22) (2017-01-03)

- Fixed critical bug where `>=` operator was misidentified as end of generic argument list
- Added `redundantRawValues` rule to remove string enum literals that match the associated case name
- Added `redundantVoidReturnType` rule to remove unnecessary `Void` return type from function declarations
- Added `unusedArguments` rule, to replace unused arguments in function declarations with an underscore
- Fixed bug with `--inferoptions` and argument wrapping
- Fixed bug where extra space was added inside empty `TODO:` comments

## [0.21](https://github.com/nicklockwood/SwiftFormat/releases/tag/0.21) (2016-12-19)

- Added `redundantLet` rule to remove unnecessary `let` keyword in statements like `let _ = foo()`
Expand Down
Binary file modified CommandLineTool/swiftformat
Binary file not shown.
2 changes: 1 addition & 1 deletion EditorExtension/Application/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>0.21</string>
<string>0.22</string>
<key>CFBundleVersion</key>
<string>$(CURRENT_PROJECT_VERSION)</string>
<key>LSMinimumSystemVersion</key>
Expand Down
2 changes: 1 addition & 1 deletion EditorExtension/Extension/FormatEntireFileCommand.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import XcodeKit

class FormatEntireFileCommand: NSObject, XCSourceEditorCommand {

func perform(with invocation: XCSourceEditorCommandInvocation, completionHandler: @escaping (Error?) -> Void) -> Void {
func perform(with invocation: XCSourceEditorCommandInvocation, completionHandler: @escaping (Error?) -> Void) {
guard ["public.swift-source", "com.apple.dt.playground"].contains(invocation.buffer.contentUTI) else {
return completionHandler(FormatCommandError.notSwiftLanguage)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ import XcodeKit
class FormatSelectedSourceCommand: NSObject, XCSourceEditorCommand {

func perform(with invocation: XCSourceEditorCommandInvocation,
completionHandler: @escaping (Error?) -> Void) -> Void {
completionHandler: @escaping (Error?) -> Void) {

guard ["public.swift-source", "com.apple.dt.playground"].contains(invocation.buffer.contentUTI) else {
return completionHandler(FormatCommandError.notSwiftLanguage)
Expand Down
2 changes: 1 addition & 1 deletion EditorExtension/Extension/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<key>CFBundlePackageType</key>
<string>XPC!</string>
<key>CFBundleShortVersionString</key>
<string>0.21</string>
<string>0.22</string>
<key>CFBundleVersion</key>
<string>$(CURRENT_PROJECT_VERSION)</string>
<key>LSMinimumSystemVersion</key>
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
8 changes: 4 additions & 4 deletions EditorExtension/SwiftFormat for Xcode.app/Contents/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>0.21</string>
<string>0.22</string>
<key>CFBundleSupportedPlatforms</key>
<array>
<string>MacOSX</string>
Expand All @@ -27,17 +27,17 @@
<key>DTCompiler</key>
<string>com.apple.compilers.llvm.clang.1_0</string>
<key>DTPlatformBuild</key>
<string>8C38</string>
<string>8C1002</string>
<key>DTPlatformVersion</key>
<string>GM</string>
<key>DTSDKBuild</key>
<string>16C58</string>
<key>DTSDKName</key>
<string>macosx10.12</string>
<key>DTXcode</key>
<string>0820</string>
<string>0821</string>
<key>DTXcodeBuild</key>
<string>8C38</string>
<string>8C1002</string>
<key>LSMinimumSystemVersion</key>
<string>10.11</string>
<key>NSHumanReadableCopyright</key>
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<key>CFBundlePackageType</key>
<string>XPC!</string>
<key>CFBundleShortVersionString</key>
<string>0.21</string>
<string>0.22</string>
<key>CFBundleSupportedPlatforms</key>
<array>
<string>MacOSX</string>
Expand All @@ -27,17 +27,17 @@
<key>DTCompiler</key>
<string>com.apple.compilers.llvm.clang.1_0</string>
<key>DTPlatformBuild</key>
<string>8C38</string>
<string>8C1002</string>
<key>DTPlatformVersion</key>
<string>GM</string>
<key>DTSDKBuild</key>
<string>16C58</string>
<key>DTSDKName</key>
<string>macosx10.12</string>
<key>DTXcode</key>
<string>0820</string>
<string>0821</string>
<key>DTXcodeBuild</key>
<string>8C38</string>
<string>8C1002</string>
<key>LSMinimumSystemVersion</key>
<string>10.11</string>
<key>NSExtension</key>
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,23 @@
<dict>
<key>Resources/Base.lproj/Main.storyboardc/Info.plist</key>
<data>
xrn9paFFHBreooEFMaibtN5Awbw=
F+Tjmg2efj+3uT6KvvkJZzaI03s=
</data>
<key>Resources/Base.lproj/Main.storyboardc/MainMenu.nib</key>
<data>
6JRvTcN8aVCvBfleiSj+rKgNAHU=
hjhPmmPPP+rei7SQIrhSfYccMIo=
</data>
<key>Resources/Base.lproj/Main.storyboardc/NSWindowController-B8D-0N-5wS.nib</key>
<data>
IxGRjwoWsAN5/XGgK5DiTUJLCnI=
FiE9NwX3GDUlEZH+LAFkrgHDjLg=
</data>
<key>Resources/Base.lproj/Main.storyboardc/ViewController.nib</key>
<data>
X95tlV+b9f3ROzaXrpCNoIzlQIU=
pOhEs/XDWRX37wKGAoS/eLe8hTQ=
</data>
<key>Resources/Base.lproj/Main.storyboardc/XfG-lQ-9wD-view-m2S-Jp-Qdl.nib</key>
<data>
loBYIyMxogDic3ZfYNPJiZ2he6s=
V5FXmWBTCAajUhhieO//KtDEwEg=
</data>
<key>Resources/libswiftRemoteMirror.dylib</key>
<data>
Expand Down Expand Up @@ -143,7 +143,7 @@
<dict>
<key>cdhash</key>
<data>
gYo+tqwiMPKm36pMe+lu1HnD+0s=
uk8bbV0/ENwpE792prMFaJMqtCc=
</data>
<key>requirement</key>
<string>identifier "com.charcoaldesign.SwiftFormat-for-Xcode.SourceEditorExtension" and anchor apple generic and certificate leaf[subject.CN] = "Mac Developer: Nick Lockwood (XDQ4XJZXHD)" and certificate 1[field.1.2.840.113635.100.6.2.1] /* exists */</string>
Expand All @@ -152,55 +152,55 @@
<dict>
<key>hash</key>
<data>
xrn9paFFHBreooEFMaibtN5Awbw=
F+Tjmg2efj+3uT6KvvkJZzaI03s=
</data>
<key>hash2</key>
<data>
vI24C0+6Eknh86q+kTfUaRHn/3uUbsv9/WdK6VtI4IQ=
YIx8ASHIIxeJLGBrpNQ1C0cM694w0Nmz8zydooUAvQo=
</data>
</dict>
<key>Resources/Base.lproj/Main.storyboardc/MainMenu.nib</key>
<dict>
<key>hash</key>
<data>
6JRvTcN8aVCvBfleiSj+rKgNAHU=
hjhPmmPPP+rei7SQIrhSfYccMIo=
</data>
<key>hash2</key>
<data>
tzbdVlc5v1Yy50PRUjLXICgw6anafaQfYfEsQPE+7Ys=
4j/vfyNen3kWig9Szu0XzCEUHOVvWJHcWDFoIGuDKKU=
</data>
</dict>
<key>Resources/Base.lproj/Main.storyboardc/NSWindowController-B8D-0N-5wS.nib</key>
<dict>
<key>hash</key>
<data>
IxGRjwoWsAN5/XGgK5DiTUJLCnI=
FiE9NwX3GDUlEZH+LAFkrgHDjLg=
</data>
<key>hash2</key>
<data>
5G1tmToHHqGrKejWeoTN0kgYDk/QpKptJdhRz+XZlU4=
70+ENSB9AJCF3kLNDAUek8pW9JyDv3KSvA0v9qWbY+M=
</data>
</dict>
<key>Resources/Base.lproj/Main.storyboardc/ViewController.nib</key>
<dict>
<key>hash</key>
<data>
X95tlV+b9f3ROzaXrpCNoIzlQIU=
pOhEs/XDWRX37wKGAoS/eLe8hTQ=
</data>
<key>hash2</key>
<data>
ed8wEZWTTo7NO7JucIAxKnyVYWgY0t+lW6LQAQqqRqU=
rnEV8OQe6+9zpkmFvTB90HNyngTXuBLoKzI8RQPv8DE=
</data>
</dict>
<key>Resources/Base.lproj/Main.storyboardc/XfG-lQ-9wD-view-m2S-Jp-Qdl.nib</key>
<dict>
<key>hash</key>
<data>
loBYIyMxogDic3ZfYNPJiZ2he6s=
V5FXmWBTCAajUhhieO//KtDEwEg=
</data>
<key>hash2</key>
<data>
00WGDX8i9FLgFx8gdhwQcBik7HYpie8ylchiHqPXOPE=
Z+7AU+d/V+4AFv7+1PgWdZP9vrXmXICyQZDsw1GDaZc=
</data>
</dict>
<key>Resources/libswiftRemoteMirror.dylib</key>
Expand Down
55 changes: 39 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
What is this?
----------------

SwiftFormat is a code library and command line tool for reformatting swift code.
SwiftFormat is a code library and command-line tool for reformatting swift code.

It applies a set of rules to the formatting and space around the code, leaving the meaning intact.

Expand Down Expand Up @@ -383,9 +383,15 @@ Here are all the rules that SwiftFormat currently applies, and what they do:
*redundantRawValues* - removes raw string values from enum cases when they match the case name:

enum Foo { enum Foo {
case bar = "bar" --> case bar
case bar = "bar" --> case bar
case baz = "quux" case baz = "quux"
} }

*redundantVoidReturnType* - removes unnecessary `Void` return type from function declarations:

func foo() -> Void { func foo() {
// returns nothing --> // returns nothing
} }

*hexLiterals* - converts all hex literals to upper- or lower-case, depending on settings:

Expand All @@ -402,11 +408,22 @@ Here are all the rules that SwiftFormat currently applies, and what they do:
...
}

let foo = [bar, let foo = [
baz, --> bar,
quux] baz,
quux
]
let foo = [bar, let foo = [
baz, --> bar,
quux] baz,
quux
]

*unusedArguments* - marks unused arguments in a function with _, to make it clear where they aren't used

func foo(bar: Int, baz: String) { func foo(bar _: Int, baz: String) {
print("Hello \(baz)") --> print("Hello \(baz)")
} }

func foo(_ bar: Int) { func foo(_: Int) {
// no-op --> // no-op
} }


FAQ
-----
Expand All @@ -416,7 +433,7 @@ There haven't been many questions yet, but here's what I'd like to think people

*Q. What versions of Swift are supported?*

> A. The framework requires Swift 3, but it can format programs written in Swift 2.x or 3.x.
> A. The framework requires Swift 3, but it can format programs written in Swift 2.x or 3.x. Swift 2.x is no longer actively supported however, and newer rules may not work correctly with Swift 2.x.

*Q. I don't like how SwiftFormat formatted my code*
Expand All @@ -428,7 +445,7 @@ There haven't been many questions yet, but here's what I'd like to think people

> A. Many configuration options are exposed in the command line interface. You can either set these manually, or use the `--inferoptions` argument to automatically generate the configuration from your existing project.
> If there is a rule that you don't like, and which cannot be disabled via the command line options, you can disable the rule by using the `--disable` argument, followed by the name of the rule. You can display a list of all rules using the `--rules` argument, and their behaviors are documented above this section in the README.
> If there is a rule that you don't like, and which cannot be configured to your liking via the command line options, you can disable the rule by using the `--disable` argument, followed by the name of the rule. You can display a list of all rules using the `--rules` argument, and their behaviors are documented above this section in the README.
> If the options you want aren't exposed, and disabling the rule doesn't solve the problem, the rules are implemented as functions in the file `Rules.swift`, so you can modify them and build a new version of the command line tool. If you think your changes might be generally useful, make a pull request.
Expand Down Expand Up @@ -457,7 +474,7 @@ There haven't been many questions yet, but here's what I'd like to think people

> A. First it loops through the source file character-by-character and breaks it into tokens, such as `number`, `identifier`, `linebreak`, etc. That's handled by the functions in `Tokenizer.swift`.
> Next, it applies a series of formatting rules to the token array, such as "remove whitespace at the end of a line", or "ensure each opening brace appears on the same line as the preceding non-whitespace token". Each rule is designed to be relatively independent of the others, so they can be enabled or disabled individually. The rules are all defined as methods of the `FormatRules` class in `Rules.swift`. The list of rules is then extracted using some runtime magic.
> Next, it applies a series of formatting rules to the token array, such as "remove whitespace at the end of a line", or "ensure each opening brace appears on the same line as the preceding non-space token". Each rule is designed to be independent of the others, so they can be enabled or disabled individually. The rules are defined as methods of the `FormatRules` class in `Rules.swift`, and are executed automatically using runtime magic.
> Finally, the modified token array is stitched back together to re-generate the source file.
Expand All @@ -469,9 +486,9 @@ There haven't been many questions yet, but here's what I'd like to think people

*Q. Can I use the `SwiftFormat.framework` inside another app?*

> A. I only created the framework to facilitate testing, so to be honest I've no idea if it will work in an app, but you're welcome to try. If you need to make adjustments to the public/private flags or namespaces to get it working, open an issue on Github (or even better, a pull request).
> A. I only created the framework to facilitate testing, so to be honest I've no idea if it will work in an app, but you're welcome to try. If you need to make adjustments to the public/private access modifiers or namespaces to get it working, open an issue on Github (or even better, a pull request).
> The SwiftFormat framework is available as a CocoaPod for easier integration.
> The SwiftFormat framework is also available as a CocoaPod for easier integration.

Cache
Expand All @@ -489,11 +506,11 @@ You can specify a custom cache file location by passing a path as the `--cache`
Known issues
---------------

* The formatted file cache is based on file length, so it's possible (though unlikely) that an edited file will have the exact same character count as the previously formatted version, causing SwiftFormat to incorrectly identify it as not having changed, and fail to format it.
* Under rare circumstances, SwiftFormat may misinterpret a generic type followed by an `=` sign as a pair of `<` and `>=` expressions. For example, the following case would be handled incorrectly:

To fix this, you can type an extra space in the file (which SwiftFormat will then remove again when it applies the formatting).

Alternatively, use the command line option `--cache ignore` to force SwiftFormat to ignore the cache for this run.
let foo: Dictionary<String, String>=["Hello": "World"]
To work around this, either manually add a space between the `>` and `=` characters to eliminate the ambiguity, or use add `--disable spaceAroundOperators` to the command-line options.

* If a file begins with a comment, the `stripHeaders` rule will remove it if is followed by a blank line. To avoid this, make sure that the first comment is directly followed by a line of code.

Expand Down Expand Up @@ -538,6 +555,12 @@ Known issues
* }
*
*/

* The formatted file cache is based on file length, so it's possible (though unlikely) that an edited file will have the exact same character count as the previously formatted version, causing SwiftFormat to incorrectly identify it as not having changed, and fail to format it.

To fix this, you can type an extra space in the file (which SwiftFormat will then remove again when it applies the formatting).

Alternatively, use the command line option `--cache ignore` to force SwiftFormat to ignore the cache for this run.


Credits
Expand Down
4 changes: 2 additions & 2 deletions SwiftFormat.podspec.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "SwiftFormat",
"version": "0.21",
"version": "0.22",
"license": {
"type": "zlib",
"file": "LICENCE.md"
Expand All @@ -10,7 +10,7 @@
"authors": "Nick Lockwood",
"source": {
"git": "https://github.com/nicklockwood/SwiftFormat.git",
"tag": "0.21"
"tag": "0.22"
},
"source_files": "SwiftFormat",
"requires_arc": true,
Expand Down
2 changes: 1 addition & 1 deletion SwiftFormat/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<key>CFBundlePackageType</key>
<string>FMWK</string>
<key>CFBundleShortVersionString</key>
<string>0.21</string>
<string>0.22</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
Expand Down
2 changes: 1 addition & 1 deletion SwiftFormat/SwiftFormat.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
import Foundation

/// The current SwiftFormat version
public let version = "0.21"
public let version = "0.22"

/// Errors
public enum FormatError: Error, CustomStringConvertible {
Expand Down
2 changes: 1 addition & 1 deletion SwiftFormatTests/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<key>CFBundlePackageType</key>
<string>BNDL</string>
<key>CFBundleShortVersionString</key>
<string>0.21</string>
<string>0.22</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
Expand Down

0 comments on commit d7a6892

Please sign in to comment.