An Xcode formatter plug-in to format your swift code.

Overview

Swimat

Build Status Codacy Badge Awesome

github homebrew-cask

Swimat is an Xcode plug-in to format your Swift code.

Preview

Installation

There are three way to install.

  1. Install via homebrew-cask
# Homebrew previous version
brew cask install swimat
# Homebrew latest version
brew install --cask swimat
  1. Download the App directly.
    https://github.com/Jintin/Swimat/releases/download/1.7.0/Swimat.zip

  2. Clone and archive to Mac App by yourself.

Usage

After installation, you should open the Swimat.app once to make the functionality works.

In the Xcode menu click [Editor] -> [Swimat] -> [Format] then the current active file will reformat.

You can also create a hot-key in [Xcode] -> [Preferences..] -> [Key Bindings], if you don't have any prefernce you can set as + + L.

TroubleShooting

Check [System Preferences] -> [Extensions] -> [Xcode Source Editor] -> [Swimat] is checked.

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/Jintin/Swimat.

License

The module is available as open source under the terms of the MIT License.

Comments
  • inconsistency formatting

    inconsistency formatting

    swipGestureRight = UISwipeGestureRecognizer (target: self , action: Selector("swipViewRight:") ) swipGestureRight = UISwipeGestureRecognizer(target: self, action: Selector("swipViewRight:"))

    the above 2 lines have passed by the formate as valid, it would be a lot better if for the sack of readability the following is adopted. swipGestureRight = UISwipeGestureRecognizer (target: self, action: Selector("swipViewRight:"))

    enhancement 
    opened by Fred-J 42
  • Rethink UI and core design

    Rethink UI and core design

    Please do not merge this; I'm not done with it. This was just to let you check out some of the changes I think we need:

    • Improve the main window's UI
    • Centralize the settings and share it between the app, extension, and CLI
    • Improve parser code
    • Reduce API surface area
    enhancement 
    opened by saagarjha 20
  • Improve preferences management (#2)

    Improve preferences management (#2)

    Share preferences across all targets, improve API consistency, and allow for "testing" configurations that are separate from the user's preferences

    opened by saagarjha 18
  • Function arguments formatting

    Function arguments formatting

    Are there any plans in the future to support the formating for the function arguments?

    Also maybe for dictionaries, arrays, long function call etc,,. Like the clang formatter for Obj-C?

    question 
    opened by dejanskledar 13
  • Swift 3?

    Swift 3?

    Greetings,

    How weary, stale, flat, and unprofitable seem to me all my lines of code since I upgraded to Swift 3 and now have to format them myself.

    To confirm, this plugin does not work for Swift 3, correct? I haven't tried it yet because I am assuming it doesn't.

    Best, Austin

    question 
    opened by awclives 12
  • Regarding the UI changes

    Regarding the UI changes

    I've noticed you've updated the UI, and I had a couple of suggestions:

    1. The new font is monospaced–I'm not convinced this is the best choice. The text is not code, so there's no point in changing the font (which IMHO makes it look uglier). If you were trying to get the list to align properly, there are better ways of doing this (without the many constraints I created).
    2. The background color is gray. I quite liked the white; any reason for the change?
    3. The "Configure" tab can be moved to Swimat > Preferences, which is currently unused.
    4. Make the configuration text field editable, so users can see the effects of their preferences on their own code.
    5. In accordance with the last point, bring back the File and Edit menus for text editing/window management.

    In essence, I'm asking if I can revert the UI to dfa2c98884953f57abbc152c8ac2612a4db319cb and then selectively apply the changes you've made. What do you think; is it worth a shot?

    enhancement 
    opened by saagarjha 11
  • Xcode 12.2 & Big Sur cannot show extension in Editor

    Xcode 12.2 & Big Sur cannot show extension in Editor

    https://developer.apple.com/forums/thread/666434?page=1#647663022

    Source Editor extensions now need to link / embed & sign the XcodeKit framework.

    opened by keyhuihk01 10
  • Remove unnecessary empty lines

    Remove unnecessary empty lines

    Removing unnecessary empty lines

    From:

        class SwimatTest {
            func swimatTest() -> Bool {
                return true
            }
    
    
            func swimatSecondTest() -> Bool {
                return true
            }
    
    
        }
    

    To:

        class SwimatTest {
            func swimatTest() -> Bool {
                return true
            }
    
            func swimatSecondTest() -> Bool {
                return true
            }
        }
    
    enhancement 
    opened by sampayo 10
  • Crash XCode when reformat code

    Crash XCode when reformat code

    I use XCode 7.1.1

    Application Specific Information: Sending doMenuAction to <Swimat: 0x7ff7d6131440> from <NSMenuItem: 0x7ff7d723e7e0 Swimat> ProductBuildVersion: 7B1005 UNCAUGHT EXCEPTION (NSRangeException): -[__NSCFString characterAtIndex:]: Range or index out of bounds UserInfo: (null) Hints: 0: Sending doMenuAction to <Swimat: 0x7ff7d6131440> from <NSMenuItem: 0x7ff7d723e7e0 Swimat> Backtrace: 0 0x00007fff8d69ae1a __exceptionPreprocess (in CoreFoundation) 1 0x0000000103ea0c6e DVTFailureHintExceptionPreprocessor (in DVTFoundation) 2 0x00007fff967eedd4 objc_exception_throw (in libobjc.A.dylib) 3 0x00007fff8d70165d +[NSException raise:format:](in CoreFoundation) 4 0x00007fff8d610de6 -[__NSCFString characterAtIndex:](in CoreFoundation) 5 0x000000010b2ab921 -[SwiftParser transformIndex:] at /Users/buxik/Library/Application Support/Alcatraz/Plug-ins/Swimat/Swimat/SwiftParser.m:99 (in Swimat) 6 0x000000010b2ab4e9 -[SwiftParser formatString:withRange:] at /Users/buxik/Library/Application Support/Alcatraz/Plug-ins/Swimat/Swimat/SwiftParser.m:19 (in Swimat) 7 0x000000010b2aaa09 -[Swimat doMenuAction] at /Users/buxik/Library/Application Support/Alcatraz/Plug-ins/Swimat/Swimat/Swimat.m:43 (in Swimat) 8 0x00007fff93df7082 _os_activity_initiate (in libsystem_trace.dylib) 9 0x00007fff9eb39811 -[NSApplication sendAction:to:from:](in AppKit) 10 0x000000010447aff9 __37-[DVTApplication sendAction:to:from:]_block_invoke (in DVTKit) 11 0x0000000103ea09ac DVTInvokeWithFailureHint (in DVTFoundation) 12 0x000000010434c827 -[DVTApplication sendAction:to:from:](in DVTKit) 13 0x00007fff9eb395ab -[NSMenuItem _corePerformAction](in AppKit) 14 0x00007fff9eb3930b -[NSCarbonMenuImpl performActionWithHighlightingForItemAtIndex:](in AppKit) 15 0x00007fff93df7082 _os_activity_initiate (in libsystem_trace.dylib) 16 0x00007fff9eb381f9 -[NSMenu performKeyEquivalent:](in AppKit) 17 0x00007fff9eb373a0 -[NSApplication _handleKeyEquivalent:](in AppKit) 18 0x00007fff9ea5d1ed -[NSApplication sendEvent:](in AppKit) 19 0x00000001050e3be5 -[IDEApplication sendEvent:](in IDEKit) 20 0x00007fff9e8c3d9a -[NSApplication run](in AppKit) 21 0x00007fff9e88cfbe NSApplicationMain (in AppKit) 22 0x00007fff9a1eb5ad start (in libdyld.dylib)

    Performing @selector(doMenuAction) from sender NSMenuItem 0x7ff7d723e7e0 abort() called

    Application Specific Signatures: NSRangeException

    Application Specific Backtrace 1: 0 CoreFoundation 0x00007fff8d69ae32 __exceptionPreprocess + 178 1 DVTFoundation 0x0000000103ea0c6e DVTFailureHintExceptionPreprocessor + 194 2 libobjc.A.dylib 0x00007fff967eedd4 objc_exception_throw + 48 3 CoreFoundation 0x00007fff8d70165d +[NSException raise:format:] + 205 4 CoreFoundation 0x00007fff8d610de6 -[__NSCFString characterAtIndex:] + 102 5 Swimat 0x000000010b2ab921 -[SwiftParser transformIndex:] + 138 6 Swimat 0x000000010b2ab4e9 -[SwiftParser formatString:withRange:] + 593 7 Swimat 0x000000010b2aaa09 -[Swimat doMenuAction] + 449 8 libsystem_trace.dylib 0x00007fff93df7082 _os_activity_initiate + 75 9 AppKit 0x00007fff9eb39811 -[NSApplication sendAction:to:from:] + 460 10 DVTKit 0x000000010447aff9 __37-[DVTApplication sendAction:to:from:]_block_invoke + 379 11 DVTFoundation 0x0000000103ea09ac DVTInvokeWithFailureHint + 83 12 DVTKit 0x000000010434c827 -[DVTApplication sendAction:to:from:] + 335 13 AppKit 0x00007fff9eb395ab -[NSMenuItem _corePerformAction] + 336 14 AppKit 0x00007fff9eb3930b -[NSCarbonMenuImpl performActionWithHighlightingForItemAtIndex:] + 114 15 libsystem_trace.dylib 0x00007fff93df7082 _os_activity_initiate + 75 16 AppKit 0x00007fff9eb381f9 -[NSMenu performKeyEquivalent:] + 357 17 AppKit 0x00007fff9eb373a0 -[NSApplication _handleKeyEquivalent:] + 920 18 AppKit 0x00007fff9ea5d1ed -[NSApplication sendEvent:] + 4274 19 IDEKit 0x00000001050e3be5 -[IDEApplication sendEvent:] + 739 20 AppKit 0x00007fff9e8c3d9a -[NSApplication run] + 796 21 AppKit 0x00007fff9e88cfbe NSApplicationMain + 1176 22 libdyld.dylib 0x00007fff9a1eb5ad start + 1 23 ??? 0x0000000000000001 0x0 + 1

    bug 
    opened by slawekkrol 10
  • Discuss the indent style about chained closures.

    Discuss the indent style about chained closures.

    My code:

    var someLongExpressionToGetAnArray = [1, 2, 3]
    
    someLongExpressionToGetAnArray
        .sorted { $0 > $1 }
        .map { number in
            number * 2
        }
        .map { number in
            number + 1
        }
    

    After swimat:

    var someLongExpressionToGetAnArray = [1, 2, 3]
    
    someLongExpressionToGetAnArray
        .sorted { $0 > $1 }
        .map { number in
            number * 2
        }
        .map { number in
            number + 1
    }
    

    The last line }

    question 
    opened by PMExtra 9
  • Line end semicolon problem

    Line end semicolon problem

    Hi,

    First of all thanks for great solution for swift development!

    I'm using semicolons at the end of lines, but swimat insert a space between end character and semicolon. Can you remove this, plesase?

    Edit: It insert space only, if there is ')' before ';'

    enhancement 
    opened by larten 9
  • Incorrect format with new Regular expressions (Swift 5.7+)

    Incorrect format with new Regular expressions (Swift 5.7+)

    Swift 5.7+ (New Regular expressions)

    Code example: let search1 = /My name is (.+?) and I'm (\d+) years old./

    After Formatting: let search1 = / My name is (. + ?) and I'm (\d +) years old. /

    Issue: There is a one space between / and the first character and a space between last character and /

    expected: No spaces between / and the first character and between the last character and /

    opened by HassanTaleb90 0
  • Will formatting affect the content in it?

    Will formatting affect the content in it?

    What is the issue

    Expected behavior A clear and concise description of what you expected to happen.

    Desktop (please complete the following information):

    • OS: [e.g. 10.14, 10.15]
    • App Version [e.g. 1.6.2]

    Additional context Add any other context about the problem here.

    opened by phonefixnicole 2
  • SwiftUI modifiers are formatted incorrectly when tabs are set to 2 spaces

    SwiftUI modifiers are formatted incorrectly when tabs are set to 2 spaces

    What is the issue

    Formatting SwiftUI code in a project where both Tab and Indent widths set to 2, results in modifiers code get positioned slightly misaligned.

    Screenshot 2022-05-29 at 5 52 41 PM

    Expected behavior

    Modifiers code should be positioned under the ending curly brace.

    Screenshot 2022-05-29 at 5 52 54 PM

    Desktop (please complete the following information):

    • OS: 12.3.1
    • App Version: 1.7.0

    Additional context Xcode: 12.3.1

    opened by Isuru-Nanayakkara 0
  • Bug With Switch indentation

    Bug With Switch indentation

    Switch indentation is incorrect if there is no line before it

    Expected behavior: Normal indentation

    Screen Shot 2021-07-21 at 12 29 33 PM in the image attached, there is no line before the first switch, so its indentation is incorrect.
    opened by HassanTaleb90 0
  • Curley braces indented incorrectly when formatting spaces.

    Curley braces indented incorrectly when formatting spaces.

    I am using the SwiftParser and all of it's associated classes from a Mac app Xcode project, and am initialising it and passing in the unformatted Swift String, and setting the "autoRemoveChar" and "Indent.paraAlign" from within the init function, for testing purposes. I send an NSTextView.string to the init function, and assign the returned formatted string to the NSTextView.string, all appears to be working well until you send a string with too many and unnecessary spaces, from within a curley brace block or loop or conditional block. I found this out by mistake when accidentally entering to many gaps between code words like this.

    Code 1

    The returned formatted code had closed the gaps as expected, but had indented the Curley braces further than they were already set, and continued to affect any further formatting on new typed or added code .

    Code 2

    At this stage I'm trying to work out if it has something to do with the NSTextView's string, or the formatting by the SwiftParser.

    Any ideas or help as to what might be happening here would be appreciated ? And how it could possibly be resolved ?

    Kind Regards

    Mark

    opened by Mark-FX 0
Releases(1.7.0)
Owner
Jintin
Android GDE, husband and dad. Love to build interesting things to make life easier.
Jintin
A command-line tool and Xcode Extension for formatting Swift code

Table of Contents What? Why? How? Command-line tool Xcode source editor extension Xcode build phase Via Applescript VSCode plugin Sublime Text plugin

Nick Lockwood 6.3k Jan 8, 2023
Measure Swift code metrics and get reports in Xcode, Jenkins and other CI platforms.

Taylor ⚠️ Taylor is DEPRECATED. Use SwiftLint instead. A tool aimed to increase Swift code quality, by checking for conformance to code metrics. Taylo

YOPESO 301 Dec 24, 2022
A tool for Swift code modification intermediating between code generation and formatting.

swift-mod A tool for Swift code modification intermediating between code generation and formatting. Overview swift-mod is a tool for Swift code modifi

Ryo Aoyama 95 Nov 3, 2022
An xcconfig (Xcode configuration) file for easily turning on a boatload of warnings in your project or its targets.

Warnings This is an xcconfig file to make it easy for you to turn on a large suite of useful warnings in your Xcode project. These warnings catch bugs

Peter Hosey 438 Nov 8, 2022
A static source code analysis tool to improve quality and reduce defects for C, C++ and Objective-C

OCLint - https://oclint.org OCLint is a static code analysis tool for improving quality and reducing defects by inspecting C, C++ and Objective-C code

The OCLint Static Code Analysis Tool 3.6k Dec 29, 2022
Asserts on roids, test all your assumptions with ease.

KZAsserts - Asserts on roids, test all your assumptions with ease. There are many ways in which we can improve quality of our code-base, Assertions ar

Krzysztof Zabłocki 101 Jul 1, 2022
Find memory leaks in your iOS app at develop time.

中文介绍 | FAQ中文 MLeaksFinder MLeaksFinder helps you find memory leaks in your iOS apps at develop time. It can automatically find leaks in UIView and UIV

Tencent 5.3k Dec 22, 2022
Find memory issues & leaks in your iOS app without instruments

HeapInspector Find memory issues & leaks in your iOS app HeapInspector is a debug tool that monitors the memory heap with backtrace recording in your

Christian Menschel 1.8k Nov 24, 2022
Find common xib and storyboard-related problems without running your app or writing unit tests.

IBAnalyzer Find common xib and storyboard-related problems without running your app or writing unit tests. Usage Pass a path to your project to ibanal

Arek Holko 955 Oct 15, 2022
decoupling between modules in your iOS Project. iOS模块化过程中模块间解耦方案

DecouplingKit 中文readme Podfile platform :ios, '7.0' pod 'DecouplingKit', '~> 0.0.2' DecouplingKit, decoupling between modules in your iOS Project. D

coderyi 139 Aug 23, 2022
Lint anything by combining the power of Swift & regular expressions.

Installation • Getting Started • Configuration • Xcode Build Script • Donation • Issues • Regex Cheat Sheet • License AnyLint Lint any project in any

Flinesoft 116 Sep 24, 2022
SwiftCop is a validation library fully written in Swift and inspired by the clarity of Ruby On Rails Active Record validations.

SwiftCop is a validation library fully written in Swift and inspired by the clarity of Ruby On Rails Active Record validations. Objective Build a stan

Andres Canal 542 Sep 17, 2022
A tool to enforce Swift style and conventions.

SwiftLint A tool to enforce Swift style and conventions, loosely based on the now archived GitHub Swift Style Guide. SwiftLint enforces the style guid

Realm 16.9k Jan 9, 2023
Cross-platform static analyzer and linter for Swift.

Wiki • Installation • Usage • Features • Developers • License Tailor is a cross-platform static analysis and lint tool for source code written in Appl

Sleekbyte 1.4k Dec 19, 2022
Type-safe observable values and collections in Swift

GlueKit ⚠️ WARNING ⚠️ This project is in a prerelease state. There is active work going on that will result in API changes that can/will break code wh

null 361 Oct 12, 2022
💊 Syntactic sugar for Swift do-try-catch

Fallback Syntactic sugar for Swift do-try-catch. At a Glance value = try fallback( try get("A"), try get("B"), try get("C"), try get("D") ) is

Suyeol Jeon 43 May 25, 2020
A Swift micro-framework to easily deal with weak references to self inside closures

WeakableSelf Context Closures are one of Swift must-have features, and Swift developers are aware of how tricky they can be when they capture the refe

Vincent Pradeilles 72 Sep 1, 2022
Swift-lint-plugin - A SwiftPM plugin that adds a linting command

SwiftLintPlugin This is a SwiftPM plugin that adds a lint command. SwiftPM plugi

null 9 Nov 23, 2022
Aplicação Basica em Swift desenvolvida com o intuito de aplicar os conceitos estudados

Via Cep iOS Sobre - Interface do Usuario - Tecnologias - Requisitos - Autor Projeto ?? FINALIZADO ?? Sobre A Aplicação consiste em fazer buscas usando

Igor Damasceno de Sousa 1 Jun 3, 2022