Revision 2edf2b26d08b1fe39c25424a7bc993fae1d07480 authored by Jordan Rose on 12 July 2017, 03:39:57 UTC, committed by GitHub on 12 July 2017, 03:39:57 UTC
aa215e7e54 made sure we didn't try to construct Sets and Dictionaries
with a non-Hashable key. However, that commit was a little too
restrictive: there was no handling for imported generic parameters
that were constrained to inherit from NSObject. Fortunately,
recovering that information is fairly straightforward.

rdar://problem/33222646
1 parent d067b63
Raw File
SwiftFormat.md

# Swift-format

## Introduction

Note: This tool is still a work in progress.

swift-format is a tool for automatically format your Swift files according to a
set of rules. It is implemented as another driver kind, like swiftc, the batch
compiler, so swift-format is actually a symbolic link to swift. This tool uses
libIDE to format code, so it can be leveraged from multiple systems and editors.

## Usage

To print all the available options:

     swift-format -help

By default, swift-format will output the formatted file to the standard output:

     swift-format sample.swift

You can either output the result to a separate file:

     swift-format sample.swift -o result.swift

Or you can format in-place (the original file will be overwritten):

     swift-format -in-place sample.swift

If you want to indent using tabs instead of spaces, use the `-use-tabs` option:

     swift-format -use-tabs sample.swift

You can set the number of tabs or spaces using the `-tab-width` and
`-indent-width` options, respectively.

If you want to indent cases in switch statements, use the "-indent-switch-case"
option. The result would be something like this:

    switch aSwitch {
      case .some(let s):
        print(s)

swift-format supports formatting a range of lines from a file:

     swift-format -line-range 2:45 sample.swift

This will format the file from lines 2 to 45, inclusive.

You can format several files, but the `-line-range` option is not supported in
that case.

You can also provide several line ranges by using multiple `-line-range` options:

     swift-format -line-range 2:45 -line-range 100:120 sample.swift
back to top