diff --git a/CHANGELOG.md b/CHANGELOG.md index 241e10e83..dff5a5d2b 100755 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,14 @@ # Change Log +## [0.26.0](https://github.com/nicklockwood/SwiftFormat/releases/tag/0.26.0) (2017-03-13) + +- Added `redundantSelf` rule for removing `self.` prefix for member references in cases where it isn't needed +- Added `--verbose` command-line option for tracking which rules were applied to each file +- Added `--patternlet` command-line option for toggling behavior of the `hoistPatternLet` rule +- Fixed bug where escaped arguments were treated as unused +- Fixed some `unusedArguments` cases +- The `removedBackticks` rule now handles more cases + ## [0.25.2](https://github.com/nicklockwood/SwiftFormat/releases/tag/0.25.2) (2017-03-09) - Fixed bug where `return` keyword could be incorrectly removed inside a conditional statement diff --git a/CommandLineTool/swiftformat b/CommandLineTool/swiftformat index 239ae7d8e..e6d57f4e8 100755 Binary files a/CommandLineTool/swiftformat and b/CommandLineTool/swiftformat differ diff --git a/EditorExtension/Application/Info.plist b/EditorExtension/Application/Info.plist index 05d2517e2..0414bc809 100644 --- a/EditorExtension/Application/Info.plist +++ b/EditorExtension/Application/Info.plist @@ -17,7 +17,7 @@ CFBundlePackageType APPL CFBundleShortVersionString - 0.25.2 + 0.26.0 CFBundleVersion $(CURRENT_PROJECT_VERSION) LSMinimumSystemVersion diff --git a/EditorExtension/Extension/Info.plist b/EditorExtension/Extension/Info.plist index 481b94f84..fd7f56e30 100644 --- a/EditorExtension/Extension/Info.plist +++ b/EditorExtension/Extension/Info.plist @@ -15,7 +15,7 @@ CFBundlePackageType XPC! CFBundleShortVersionString - 0.25.2 + 0.26.0 CFBundleVersion $(CURRENT_PROJECT_VERSION) LSMinimumSystemVersion diff --git a/EditorExtension/SwiftFormat for Xcode.app/Contents/Frameworks/libswiftAppKit.dylib b/EditorExtension/SwiftFormat for Xcode.app/Contents/Frameworks/libswiftAppKit.dylib index 3c71604e6..a85893693 100755 Binary files a/EditorExtension/SwiftFormat for Xcode.app/Contents/Frameworks/libswiftAppKit.dylib and b/EditorExtension/SwiftFormat for Xcode.app/Contents/Frameworks/libswiftAppKit.dylib differ diff --git a/EditorExtension/SwiftFormat for Xcode.app/Contents/Frameworks/libswiftCore.dylib b/EditorExtension/SwiftFormat for Xcode.app/Contents/Frameworks/libswiftCore.dylib index a7926ee46..3d0657744 100755 Binary files a/EditorExtension/SwiftFormat for Xcode.app/Contents/Frameworks/libswiftCore.dylib and b/EditorExtension/SwiftFormat for Xcode.app/Contents/Frameworks/libswiftCore.dylib differ diff --git a/EditorExtension/SwiftFormat for Xcode.app/Contents/Frameworks/libswiftCoreData.dylib b/EditorExtension/SwiftFormat for Xcode.app/Contents/Frameworks/libswiftCoreData.dylib index 476e0ca30..b64015895 100755 Binary files a/EditorExtension/SwiftFormat for Xcode.app/Contents/Frameworks/libswiftCoreData.dylib and b/EditorExtension/SwiftFormat for Xcode.app/Contents/Frameworks/libswiftCoreData.dylib differ diff --git a/EditorExtension/SwiftFormat for Xcode.app/Contents/Frameworks/libswiftCoreGraphics.dylib b/EditorExtension/SwiftFormat for Xcode.app/Contents/Frameworks/libswiftCoreGraphics.dylib index ef40d2a23..ccb849441 100755 Binary files a/EditorExtension/SwiftFormat for Xcode.app/Contents/Frameworks/libswiftCoreGraphics.dylib and b/EditorExtension/SwiftFormat for Xcode.app/Contents/Frameworks/libswiftCoreGraphics.dylib differ diff --git a/EditorExtension/SwiftFormat for Xcode.app/Contents/Frameworks/libswiftCoreImage.dylib b/EditorExtension/SwiftFormat for Xcode.app/Contents/Frameworks/libswiftCoreImage.dylib index 3c74c3a5d..46e9c226f 100755 Binary files a/EditorExtension/SwiftFormat for Xcode.app/Contents/Frameworks/libswiftCoreImage.dylib and b/EditorExtension/SwiftFormat for Xcode.app/Contents/Frameworks/libswiftCoreImage.dylib differ diff --git a/EditorExtension/SwiftFormat for Xcode.app/Contents/Frameworks/libswiftDarwin.dylib b/EditorExtension/SwiftFormat for Xcode.app/Contents/Frameworks/libswiftDarwin.dylib index b7e308fd4..508eef445 100755 Binary files a/EditorExtension/SwiftFormat for Xcode.app/Contents/Frameworks/libswiftDarwin.dylib and b/EditorExtension/SwiftFormat for Xcode.app/Contents/Frameworks/libswiftDarwin.dylib differ diff --git a/EditorExtension/SwiftFormat for Xcode.app/Contents/Frameworks/libswiftDispatch.dylib b/EditorExtension/SwiftFormat for Xcode.app/Contents/Frameworks/libswiftDispatch.dylib index 31e3b4aa6..bec98356b 100755 Binary files a/EditorExtension/SwiftFormat for Xcode.app/Contents/Frameworks/libswiftDispatch.dylib and b/EditorExtension/SwiftFormat for Xcode.app/Contents/Frameworks/libswiftDispatch.dylib differ diff --git a/EditorExtension/SwiftFormat for Xcode.app/Contents/Frameworks/libswiftFoundation.dylib b/EditorExtension/SwiftFormat for Xcode.app/Contents/Frameworks/libswiftFoundation.dylib index 4f03fba48..c51e92c2d 100755 Binary files a/EditorExtension/SwiftFormat for Xcode.app/Contents/Frameworks/libswiftFoundation.dylib and b/EditorExtension/SwiftFormat for Xcode.app/Contents/Frameworks/libswiftFoundation.dylib differ diff --git a/EditorExtension/SwiftFormat for Xcode.app/Contents/Frameworks/libswiftIOKit.dylib b/EditorExtension/SwiftFormat for Xcode.app/Contents/Frameworks/libswiftIOKit.dylib index db8a799a0..5085b8cf7 100755 Binary files a/EditorExtension/SwiftFormat for Xcode.app/Contents/Frameworks/libswiftIOKit.dylib and b/EditorExtension/SwiftFormat for Xcode.app/Contents/Frameworks/libswiftIOKit.dylib differ diff --git a/EditorExtension/SwiftFormat for Xcode.app/Contents/Frameworks/libswiftObjectiveC.dylib b/EditorExtension/SwiftFormat for Xcode.app/Contents/Frameworks/libswiftObjectiveC.dylib index 8976089a6..e8efbf218 100755 Binary files a/EditorExtension/SwiftFormat for Xcode.app/Contents/Frameworks/libswiftObjectiveC.dylib and b/EditorExtension/SwiftFormat for Xcode.app/Contents/Frameworks/libswiftObjectiveC.dylib differ diff --git a/EditorExtension/SwiftFormat for Xcode.app/Contents/Frameworks/libswiftQuartzCore.dylib b/EditorExtension/SwiftFormat for Xcode.app/Contents/Frameworks/libswiftQuartzCore.dylib index 1f3d52627..322de1fa3 100755 Binary files a/EditorExtension/SwiftFormat for Xcode.app/Contents/Frameworks/libswiftQuartzCore.dylib and b/EditorExtension/SwiftFormat for Xcode.app/Contents/Frameworks/libswiftQuartzCore.dylib differ diff --git a/EditorExtension/SwiftFormat for Xcode.app/Contents/Frameworks/libswiftXPC.dylib b/EditorExtension/SwiftFormat for Xcode.app/Contents/Frameworks/libswiftXPC.dylib index 6e304255c..a1318135e 100755 Binary files a/EditorExtension/SwiftFormat for Xcode.app/Contents/Frameworks/libswiftXPC.dylib and b/EditorExtension/SwiftFormat for Xcode.app/Contents/Frameworks/libswiftXPC.dylib differ diff --git a/EditorExtension/SwiftFormat for Xcode.app/Contents/Info.plist b/EditorExtension/SwiftFormat for Xcode.app/Contents/Info.plist index 5510bd2b5..98c4be6a1 100644 --- a/EditorExtension/SwiftFormat for Xcode.app/Contents/Info.plist +++ b/EditorExtension/SwiftFormat for Xcode.app/Contents/Info.plist @@ -17,7 +17,7 @@ CFBundlePackageType APPL CFBundleShortVersionString - 0.25.2 + 0.26.0 CFBundleSupportedPlatforms MacOSX diff --git a/EditorExtension/SwiftFormat for Xcode.app/Contents/MacOS/SwiftFormat for Xcode b/EditorExtension/SwiftFormat for Xcode.app/Contents/MacOS/SwiftFormat for Xcode index f4a107352..ca7b0ba39 100755 Binary files a/EditorExtension/SwiftFormat for Xcode.app/Contents/MacOS/SwiftFormat for Xcode and b/EditorExtension/SwiftFormat for Xcode.app/Contents/MacOS/SwiftFormat for Xcode differ diff --git a/EditorExtension/SwiftFormat for Xcode.app/Contents/PlugIns/SwiftFormat.appex/Contents/Info.plist b/EditorExtension/SwiftFormat for Xcode.app/Contents/PlugIns/SwiftFormat.appex/Contents/Info.plist index 479e4c793..597db5ee7 100644 --- a/EditorExtension/SwiftFormat for Xcode.app/Contents/PlugIns/SwiftFormat.appex/Contents/Info.plist +++ b/EditorExtension/SwiftFormat for Xcode.app/Contents/PlugIns/SwiftFormat.appex/Contents/Info.plist @@ -17,7 +17,7 @@ CFBundlePackageType XPC! CFBundleShortVersionString - 0.25.2 + 0.26.0 CFBundleSupportedPlatforms MacOSX diff --git a/EditorExtension/SwiftFormat for Xcode.app/Contents/PlugIns/SwiftFormat.appex/Contents/MacOS/SwiftFormat b/EditorExtension/SwiftFormat for Xcode.app/Contents/PlugIns/SwiftFormat.appex/Contents/MacOS/SwiftFormat index d12ae3f9b..0bb13222d 100755 Binary files a/EditorExtension/SwiftFormat for Xcode.app/Contents/PlugIns/SwiftFormat.appex/Contents/MacOS/SwiftFormat and b/EditorExtension/SwiftFormat for Xcode.app/Contents/PlugIns/SwiftFormat.appex/Contents/MacOS/SwiftFormat differ diff --git a/EditorExtension/SwiftFormat for Xcode.app/Contents/Resources/Base.lproj/Main.storyboardc/Info.plist b/EditorExtension/SwiftFormat for Xcode.app/Contents/Resources/Base.lproj/Main.storyboardc/Info.plist index e5cfde994..21ffb50cb 100644 Binary files a/EditorExtension/SwiftFormat for Xcode.app/Contents/Resources/Base.lproj/Main.storyboardc/Info.plist and b/EditorExtension/SwiftFormat for Xcode.app/Contents/Resources/Base.lproj/Main.storyboardc/Info.plist differ diff --git a/EditorExtension/SwiftFormat for Xcode.app/Contents/Resources/Base.lproj/Main.storyboardc/MainMenu.nib b/EditorExtension/SwiftFormat for Xcode.app/Contents/Resources/Base.lproj/Main.storyboardc/MainMenu.nib index 078d29656..79ad14142 100644 Binary files a/EditorExtension/SwiftFormat for Xcode.app/Contents/Resources/Base.lproj/Main.storyboardc/MainMenu.nib and b/EditorExtension/SwiftFormat for Xcode.app/Contents/Resources/Base.lproj/Main.storyboardc/MainMenu.nib differ diff --git a/EditorExtension/SwiftFormat for Xcode.app/Contents/Resources/Base.lproj/Main.storyboardc/NSWindowController-B8D-0N-5wS.nib b/EditorExtension/SwiftFormat for Xcode.app/Contents/Resources/Base.lproj/Main.storyboardc/NSWindowController-B8D-0N-5wS.nib index 78d8e4d16..0a5af3dc3 100644 Binary files a/EditorExtension/SwiftFormat for Xcode.app/Contents/Resources/Base.lproj/Main.storyboardc/NSWindowController-B8D-0N-5wS.nib and b/EditorExtension/SwiftFormat for Xcode.app/Contents/Resources/Base.lproj/Main.storyboardc/NSWindowController-B8D-0N-5wS.nib differ diff --git a/EditorExtension/SwiftFormat for Xcode.app/Contents/Resources/Base.lproj/Main.storyboardc/ViewController.nib b/EditorExtension/SwiftFormat for Xcode.app/Contents/Resources/Base.lproj/Main.storyboardc/ViewController.nib index 9ca62dabc..4525ea219 100644 Binary files a/EditorExtension/SwiftFormat for Xcode.app/Contents/Resources/Base.lproj/Main.storyboardc/ViewController.nib and b/EditorExtension/SwiftFormat for Xcode.app/Contents/Resources/Base.lproj/Main.storyboardc/ViewController.nib differ diff --git a/EditorExtension/SwiftFormat for Xcode.app/Contents/Resources/Base.lproj/Main.storyboardc/XfG-lQ-9wD-view-m2S-Jp-Qdl.nib b/EditorExtension/SwiftFormat for Xcode.app/Contents/Resources/Base.lproj/Main.storyboardc/XfG-lQ-9wD-view-m2S-Jp-Qdl.nib index 9edc2362c..53b5aa8f5 100644 Binary files a/EditorExtension/SwiftFormat for Xcode.app/Contents/Resources/Base.lproj/Main.storyboardc/XfG-lQ-9wD-view-m2S-Jp-Qdl.nib and b/EditorExtension/SwiftFormat for Xcode.app/Contents/Resources/Base.lproj/Main.storyboardc/XfG-lQ-9wD-view-m2S-Jp-Qdl.nib differ diff --git a/EditorExtension/SwiftFormat for Xcode.app/Contents/_CodeSignature/CodeResources b/EditorExtension/SwiftFormat for Xcode.app/Contents/_CodeSignature/CodeResources index fdb341703..88e7e3333 100644 --- a/EditorExtension/SwiftFormat for Xcode.app/Contents/_CodeSignature/CodeResources +++ b/EditorExtension/SwiftFormat for Xcode.app/Contents/_CodeSignature/CodeResources @@ -6,23 +6,23 @@ Resources/Base.lproj/Main.storyboardc/Info.plist - Ichh/RsTJt34rImBaFqcrwVWTKc= + KixptwnnpiwOqnhhS2ID2YBOW8k= Resources/Base.lproj/Main.storyboardc/MainMenu.nib - q74jr81D435OlkojDfXZWTCw3jQ= + 3Yz5eLSN1OEoRB+A8ny96pDEnfo= Resources/Base.lproj/Main.storyboardc/NSWindowController-B8D-0N-5wS.nib - yUV83M50eaOyv9yVrN0E3G005Zw= + yRvnt2E5PX5WHq9wnbTKAsleWHo= Resources/Base.lproj/Main.storyboardc/ViewController.nib - Ed+sBPXIkIMOdnq/Fhlts+4ArkI= + b4gbKrJDUpUuVyyWcuLR70JJ9I8= Resources/Base.lproj/Main.storyboardc/XfG-lQ-9wD-view-m2S-Jp-Qdl.nib - fhMVMtZriDHLssbD/R5N+iO9sZA= + yf0o3F7RGoUEj7cXvW+ubxbiRH0= Resources/libswiftRemoteMirror.dylib @@ -143,7 +143,7 @@ cdhash - XaF/zVZ0ZM6PFcPXmIZ7WMv46nE= + SsawMJZeLXYy/3kk8bVI74eWvBA= requirement 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 */ @@ -152,55 +152,55 @@ hash - Ichh/RsTJt34rImBaFqcrwVWTKc= + KixptwnnpiwOqnhhS2ID2YBOW8k= hash2 - A13KlhLJqS9aim9eewBGPpGG0sFsEQ8U7ncS5qR7E1o= + Oj4P8Wz0iWfcLfI7utBFTAmMvJWUwhYsoWbaE271Ge4= Resources/Base.lproj/Main.storyboardc/MainMenu.nib hash - q74jr81D435OlkojDfXZWTCw3jQ= + 3Yz5eLSN1OEoRB+A8ny96pDEnfo= hash2 - VoQcQPfvShCSOByp1GPsFZSShbQh00cdhsJrjAtafQA= + qem232PLvaw44e4oq7rcwIZAvlPVbHEthC/j6Imzq2o= Resources/Base.lproj/Main.storyboardc/NSWindowController-B8D-0N-5wS.nib hash - yUV83M50eaOyv9yVrN0E3G005Zw= + yRvnt2E5PX5WHq9wnbTKAsleWHo= hash2 - sDIoPJuZhyG+I1QFrpqDNQqiJpVNjjiEoBgPY3gBdN8= + g75esuOhc74SIsNYkQ8Vs4KGTqq+gnY6g0pMGUsHYtU= Resources/Base.lproj/Main.storyboardc/ViewController.nib hash - Ed+sBPXIkIMOdnq/Fhlts+4ArkI= + b4gbKrJDUpUuVyyWcuLR70JJ9I8= hash2 - V0E/Brr7jo8v9BkIDwU7O+WdLpZa4Ll3zpUUHBkoAOQ= + a+XAfoyCWUS81a4qlo/zftoM9R9G0alHb05N7uaNBGs= Resources/Base.lproj/Main.storyboardc/XfG-lQ-9wD-view-m2S-Jp-Qdl.nib hash - fhMVMtZriDHLssbD/R5N+iO9sZA= + yf0o3F7RGoUEj7cXvW+ubxbiRH0= hash2 - COmlnUYJCcAZl1PVwC0uLfyxd6cewOoa8lqwttb4yuQ= + FgM6k5uqzX7OlFteLFk2xnJZvFbGfnIMYfZXWcTIJvA= Resources/libswiftRemoteMirror.dylib diff --git a/README.md b/README.md index aa60ee3f9..a7abd7aed 100644 --- a/README.md +++ b/README.md @@ -153,7 +153,9 @@ So what does SwiftFormat actually do? SwiftFormat first converts the source file into tokens, then iteratively applies a set of rules to the tokens to adjust the formatting. The tokens are then converted back into text. -The rules used by SwiftFormat can be displayed using the `--rules` command line argument. You can disable them individually using `--disable` followed by a comma-delimited list of rule names. +The rules used by SwiftFormat can be displayed using the `--rules` command line argument. You can disable them individually using `--disable` followed by a comma-delimited list of rule names, or enable additional rules with `--enable`. + +To see exactly which rules were applied to a given file, you can use the `--verbose` command-line option to force SwiftFormat to print a more detailed log as it applies the formatting. **NOTE:** running in verbose mode is slower than the default mode. Here are all the rules that SwiftFormat currently applies, and what they do: @@ -412,6 +414,14 @@ Here are all the rules that SwiftFormat currently applies, and what they do: let `infix` = bar --> let infix = bar func foo(with `default`: Int) {} --> func foo(with default: Int) {} + +*redundantSelf* - removes the `self.` prefix from instance method and variable references in cases where it isn't needed: + + init(foo: Int, bar: Int) { init(foo: Int, bar: Int) { + self.foo = foo self.foo = foo + self.bar = bar --> self.bar = bar + self.baz = 42 baz = 42 + } } *numberFormatting* - handles case and grouping of number literals @@ -449,7 +459,7 @@ Here are all the rules that SwiftFormat currently applies, and what they do: self.data += data --> self.data += data } } -*hoistPatternLet* - moves `let` or `var` bindings inside patterns or tuples to the start of the expression: +*hoistPatternLet* - moves `let` or `var` bindings inside patterns to the start of the expression, or vice-versa. Use the `--patternlet` command-line option to toggle between hoisted and inline style. (let foo, let bar) = baz() --> let (foo, bar) = baz() @@ -474,7 +484,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. Swift 2.x is no longer actively supported however, and newer rules may not work correctly with Swift 2.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. If you find that SwiftFormat breaks your 2.x codebase, the best solution is probably to revert to an earlier SwiftFormat release, or enable only a subset of rules. *Q. I don't like how SwiftFormat formatted my code* @@ -520,9 +530,9 @@ 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 removing whitespace at the end of a line, or ensuring 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. +> Next, it applies a series of formatting rules to the token array, such as removing whitespace at the end of a line, or ensuring each opening brace appears on the same line as the preceding non-space token. The rules are defined as methods of the `FormatRules` class in `Rules.swift`, and are detected automatically using runtime magic. Each rule is designed to be independent of the others, so they can be enabled or disabled individually. -> Finally, the modified token array is stitched back together to re-generate the source file. +> Rules are applied recursively until no changes are detected. Finally, the modified token array is stitched back together to re-generate the source file. *Q. Why aren't you using regular expressions?* @@ -534,7 +544,7 @@ There haven't been many questions yet, but here's what I'd like to think people > 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 also available as a CocoaPod for easier integration. +> The SwiftFormat framework is also available as a [CocoaPod](https://cocoapods.org/pods/SwiftFormat) for easier integration. Cache diff --git a/Sources/Info.plist b/Sources/Info.plist index 96e123023..00e7cc792 100644 --- a/Sources/Info.plist +++ b/Sources/Info.plist @@ -15,7 +15,7 @@ CFBundlePackageType FMWK CFBundleShortVersionString - 0.25.2 + 0.26.0 CFBundleSignature ???? CFBundleVersion diff --git a/Sources/SwiftFormat.swift b/Sources/SwiftFormat.swift index 2d8a56f96..007248c1c 100644 --- a/Sources/SwiftFormat.swift +++ b/Sources/SwiftFormat.swift @@ -32,7 +32,7 @@ import Foundation /// The current SwiftFormat version -public let version = "0.25.2" +public let version = "0.26.0" /// An enumeration of the types of error that may be thrown by SwiftFormat public enum FormatError: Error, CustomStringConvertible { diff --git a/SwiftFormat.podspec.json b/SwiftFormat.podspec.json index 4eb73c52c..dd14acc4e 100644 --- a/SwiftFormat.podspec.json +++ b/SwiftFormat.podspec.json @@ -1,6 +1,6 @@ { "name": "SwiftFormat", - "version": "0.25.2", + "version": "0.26.0", "license": { "type": "zlib", "file": "LICENCE.md" @@ -10,7 +10,7 @@ "authors": "Nick Lockwood", "source": { "git": "https://github.com/nicklockwood/SwiftFormat.git", - "tag": "0.25.2" + "tag": "0.26.0" }, "default_subspecs": "Core", "subspecs": [ diff --git a/Tests/Info.plist b/Tests/Info.plist index 50c837ea4..f49fa7e83 100644 --- a/Tests/Info.plist +++ b/Tests/Info.plist @@ -15,7 +15,7 @@ CFBundlePackageType BNDL CFBundleShortVersionString - 0.25.2 + 0.26.0 CFBundleSignature ???? CFBundleVersion