Skip to content

Commit d72cf2f

Browse files
committed
feat: Use nicklockwood/swiftformat
1 parent cf86c3c commit d72cf2f

File tree

6 files changed

+112
-71
lines changed

6 files changed

+112
-71
lines changed

.github/workflows/Format.yml

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,12 @@ on:
44
push:
55
branches:
66
- main
7-
- experimental/swift-format
87

98
jobs:
109
swift_format:
1110
if: |
12-
!startsWith(github.event.head_commit.message, '[ci skip]') &&
13-
!startsWith(github.event.head_commit.message, '[ci skip format]') &&
14-
!startsWith(github.event.head_commit.message, '[ci skip swift_format]')
11+
!contains(github.event.head_commit.message, '[ci skip]') &&
12+
!contains(github.event.head_commit.message, '[ci skip format]')
1513
name: swift-format
1614
runs-on: macos-12
1715
steps:
@@ -22,7 +20,7 @@ jobs:
2220
run: make format
2321
- uses: stefanzweifel/git-auto-commit-action@v4
2422
with:
25-
commit_message: 'ci: swift-format'
23+
commit_message: 'style(ci): run swiftformat'
2624
branch: 'main'
2725
env:
2826
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.swift-format

Lines changed: 0 additions & 56 deletions
This file was deleted.

.swiftformat

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
--acronyms ID,URL,URI,UUID,ULID,SPM,XML,YAML,JSON,IDFA
2+
--allman false
3+
--assetliterals visual-width
4+
--binarygrouping none
5+
--categorymark "MARK: %c"
6+
--classthreshold 0
7+
--closingparen balanced
8+
--closurevoid remove
9+
--commas always
10+
--conflictmarkers reject
11+
--decimalgrouping none
12+
--elseposition same-line
13+
--emptybraces no-space
14+
--enumnamespaces always
15+
--enumthreshold 0
16+
--exponentcase lowercase
17+
--exponentgrouping disabled
18+
--extensionacl on-declarations
19+
--extensionlength 0
20+
--extensionmark "MARK: - %t + %c"
21+
--fractiongrouping disabled
22+
--fragment false
23+
--funcattributes preserve
24+
--generictypes
25+
--groupedextension "MARK: %c"
26+
--guardelse auto
27+
--header ignore
28+
--hexgrouping none
29+
--hexliteralcase uppercase
30+
--ifdef indent
31+
--importgrouping alpha
32+
--indent 2
33+
--indentcase false
34+
--indentstrings false
35+
--lifecycle
36+
--lineaftermarks true
37+
--linebreaks lf
38+
--markcategories true
39+
--markextensions always
40+
--marktypes always
41+
--maxwidth none
42+
--modifierorder
43+
--nevertrailing
44+
--nospaceoperators
45+
--nowrapoperators
46+
--octalgrouping none
47+
--operatorfunc spaced
48+
--organizetypes actor,class,enum,struct
49+
--patternlet hoist
50+
--ranges spaced
51+
--redundanttype infer-locals-only
52+
--self init-only
53+
--selfrequired
54+
--semicolons never
55+
--shortoptionals always
56+
--smarttabs enabled
57+
--someAny true
58+
--stripunusedargs always
59+
--structthreshold 0
60+
--tabwidth unspecified
61+
--trailingclosures
62+
--trimwhitespace always
63+
--typeattributes preserve
64+
--typeblanklines remove
65+
--typemark "MARK: - %t"
66+
--varattributes preserve
67+
--voidtype void
68+
--wraparguments before-first
69+
--wrapcollections before-first
70+
--wrapconditions preserve
71+
--wrapparameters before-first
72+
--wrapreturntype preserve
73+
--wrapternary default
74+
--wraptypealiases preserve
75+
--xcodeindentation disabled
76+
--yodaswap always

Makefile

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,13 @@ install_formatter:
22
@chmod +x ./scripts/install_swift-format.sh
33
@./scripts/install_swift-format.sh
44

5+
update_formatter:
6+
@rm ./scripts/.bin/swift-format
7+
@make install_formatter
8+
59
format:
6-
./scripts/.bin/swift-format \
7-
--in-place --recursive \
8-
./Package.swift ./Sources ./Tests
10+
@chmod +x ./scripts/format.sh
11+
@./scripts/format.sh
912

1013
test:
11-
swift test --enable-test-discovery
14+
@swift test --enable-test-discovery

Scripts/format.sh

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#!/bin/bash
2+
3+
_get_parent_dir_abs_path() {
4+
echo "$(cd "$(dirname "$1")" && pwd)"
5+
}
6+
7+
# ––––––––––––––––––––––––– Constants ––––––––––––––––––––––––––
8+
9+
SCRIPT_DIR=$(_get_parent_dir_abs_path $0)
10+
TOOLS_DIR="${SCRIPT_DIR}/.bin/"
11+
TOOL_NAME="swiftformat"
12+
TOOL="${TOOLS_DIR}/${TOOL_NAME}"
13+
14+
# ––––––––––––––––––––––––––– Script –––––––––––––––––––––––––––
15+
16+
cd ${SCRIPT_DIR}
17+
cd ..
18+
19+
${TOOL} . \
20+
--config .swiftformat

Scripts/install_swift-format.sh

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ _get_parent_dir_abs_path() {
66

77
# ––––––––––––––––––––––––––– Config –––––––––––––––––––––––––––
88

9-
TOOL_NAME="swift-format"
10-
TOOL_OWNER="CaptureContext"
11-
TOOL_VERSION="0.50600.1"
9+
TOOL_NAME="swiftformat"
10+
TOOL_OWNER="nicklockwood"
11+
TOOL_VERSION="0.50.5"
1212

1313
# ––––––––––––––––––––––––– Constants ––––––––––––––––––––––––––
1414

@@ -19,8 +19,8 @@ TOOL_DOWNLOAD_DIR="${TOOLS_INSTALL_PATH}/_${TOOL_NAME}"
1919

2020
TOOL=${TOOL_INSTALL_PATH}
2121
TOOL_REPO="https://github.com/${TOOL_OWNER}/${TOOL_NAME}"
22-
ARCHIVE_NAME="x86_64"
23-
ARCHIVE_URL="${TOOL_REPO}/releases/download/0.50600.1/${ARCHIVE_NAME}.zip" # todo: support other archs
22+
ARCHIVE_NAME="${TOOL_NAME}.artifactbundle"
23+
ARCHIVE_URL="${TOOL_REPO}/releases/download/${TOOL_VERSION}/${ARCHIVE_NAME}.zip"
2424

2525
# ––––––––––––––––––––––––––– Steps ––––––––––––––––––––––––––––
2626

@@ -33,7 +33,7 @@ tool_extract() {
3333
}
3434

3535
tool_install() {
36-
install "${TOOL_DOWNLOAD_DIR}/${ARCHIVE_NAME}/${TOOL_NAME}" "${TOOLS_INSTALL_PATH}"
36+
install "${TOOL_DOWNLOAD_DIR}/${ARCHIVE_NAME}/${TOOL_NAME}-${TOOL_VERSION}-macos/bin/${TOOL_NAME}" "${TOOLS_INSTALL_PATH}"
3737
}
3838

3939
# ––––––––––––––––––––––––––– Script –––––––––––––––––––––––––––

0 commit comments

Comments
 (0)