Skip to content

Commit 7ecef5d

Browse files
authored
Add info about Swift Package Manager command plugin to README.md (#176)
1 parent 5542090 commit 7ecef5d

File tree

1 file changed

+41
-1
lines changed

1 file changed

+41
-1
lines changed

README.md

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,50 @@ Note that brevity is not a primary goal. Code should be made more concise only i
1717
* This guide is in addition to the official [Swift API Design Guidelines](https://swift.org/documentation/api-design-guidelines/). These rules should not contradict that document.
1818
* These rules should not fight Xcode's <kbd>^</kbd> + <kbd>I</kbd> indentation behavior.
1919
* We strive to make every rule lintable:
20-
* If a rule changes the format of the code, it needs to be able to be reformatted automatically (either using [SwiftLint](https://github.com/realm/SwiftLint) autocorrect or [SwiftFormat](https://github.com/nicklockwood/SwiftFormat)).
20+
* If a rule changes the format of the code, it needs to be able to be reformatted automatically (either using [SwiftFormat](https://github.com/nicklockwood/SwiftFormat) or [SwiftLint](https://github.com/realm/SwiftLint) autocorrect).
2121
* For rules that don't directly change the format of the code, we should have a lint rule that throws a warning.
2222
* Exceptions to these rules should be rare and heavily justified.
2323

24+
## Swift Package Manager command plugin
25+
26+
This repo includes a Swift Package Manager command plugin that you can use to automatically reformat or lint your package according to the style guide. To use this command plugin with your package, all you need to do is add this repo as a dependency:
27+
28+
```swift
29+
dependencies: [
30+
.package(url: "https://github.com/airbnb/swift", from: "1.0.0"),
31+
]
32+
```
33+
34+
and then run the `format` command plugin in your package directory:
35+
36+
```shell
37+
$ swift package format
38+
```
39+
40+
<details>
41+
<summary>Usage guide</summary>
42+
43+
```shell
44+
# Supported in Xcode 14+. Prompts for permission to write to the package directory.
45+
$ swift package format
46+
47+
# When using the Xcode 13 toolchain, or a noninteractive shell, you must use:
48+
$ swift package --allow-writing-to-package-directory format
49+
50+
# To just lint without reformatting, you can use `--lint`:
51+
$ swift package format --lint
52+
53+
# By default the command plugin runs on the entire package directory.
54+
# You can exclude directories using `exclude`:
55+
$ swift package format --exclude Tests
56+
57+
# Alternatively you can explicitly list the set of paths and/or SPM targets:
58+
$ swift package format --paths Sources Tests Package.swift
59+
$ swift package format --targets AirbnbSwiftFormatTool
60+
```
61+
62+
</details>
63+
2464
## Table of Contents
2565

2666
1. [Xcode Formatting](#xcode-formatting)

0 commit comments

Comments
 (0)