File: SwiftIndent.md

package info (click to toggle)
swiftlang 6.0.3-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,519,992 kB
  • sloc: cpp: 9,107,863; ansic: 2,040,022; asm: 1,135,751; python: 296,500; objc: 82,456; f90: 60,502; lisp: 34,951; pascal: 19,946; sh: 18,133; perl: 7,482; ml: 4,937; javascript: 4,117; makefile: 3,840; awk: 3,535; xml: 914; fortran: 619; cs: 573; ruby: 573
file content (56 lines) | stat: -rw-r--r-- 1,637 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56

# Swift-indent

## Introduction

Note: This tool is still a work in progress.

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

## Usage

To print all the available options:

     swift-indent -help

By default, swift-indent will output the indented file to the standard output:

     swift-indent sample.swift

You can either output the result to a separate file:

     swift-indent sample.swift -o result.swift

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

     swift-indent -in-place sample.swift

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

     swift-indent -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-indent supports indenting a range of lines from a file:

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

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

You can indent 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-indent -line-range 2:45 -line-range 100:120 sample.swift