-
Notifications
You must be signed in to change notification settings - Fork 1
/
format-code
executable file
·39 lines (36 loc) · 1.22 KB
/
format-code
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
#!/bin/sh
set -e
if ! which swiftformat > /dev/null; then
echo "ERROR: You have to install SwiftFormat first." >&2
echo "This is easy to do using HomeBrew: brew install swiftformat" >&2
echo "Don't have HomeBrew? No problem. Just run the following: " >&2
echo '/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"' >&2
exit 0
fi
get_rules_list() {
cat "${SOURCE_ROOT}/config/${1}-code-format-rules.txt" | egrep -v '^$' | egrep -v '^#' | tr '\n' ','
}
swiftformat \
--swiftversion `swift --version | awk '{print $4}'` \
--tabwidth 4 \
--maxwidth 120 \
--wraparguments before-first \
--wrapparameters before-first \
--wrapcollections before-first \
--closingparen balanced \
--commas always \
--shortoptionals always \
--indent tab \
--linebreaks lf \
--header ignore \
--specifierorder open,public,internal,private,static,weak,unowned,final,convenience,override \
--disable `get_rules_list disabled` \
--enable `get_rules_list enabled` \
`find . -type d -maxdepth 1 -print \
| egrep -v '^\.$' \
| grep -v Pods \
| egrep -v '.*\.xc(workspace|odeproj)' \
| grep -v .git \
| grep -v Carthage \
| egrep -v 'Tests$' \
| tr '\n' ' '`