Skip to content

Commit d907980

Browse files
authored
Migrate from SwiftFormat to swift-format (#248)
* Disable VSCode automatic generation of launch configuration * Add .swift-format configuration file * Remove SwiftFormat configuration * Set file association for .swift-format * Configure swiftlang.swift-vscode as default formatter * Update format checking workflow to use swift-format * Fix ValidateDocumentationComments linter error * Fix ReplaceForEachWithForLoop linter error * Fix NoBlockComments linter errors * Consolidate format and unit-tests workflows into single CI workflow * Remove vknabel.vscode-swiftformat from recommended extensions * swift format -i --recursive .
1 parent 33d45a2 commit d907980

38 files changed

+404
-477
lines changed

.github/workflows/ci.yml

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
name: Unit Tests
2+
3+
on:
4+
# This runs in the context of the base of the pull request,
5+
# rather than in the context of the merge commit.
6+
# Maintainers must approve and we tighten permissions below.
7+
pull_request_target:
8+
types: [opened, synchronize, reopened]
9+
10+
permissions:
11+
contents: read
12+
13+
jobs:
14+
build-and-test:
15+
uses: huggingface/hf-workflows/.github/workflows/swift_transformers_unit_tests.yml@main
16+
with:
17+
# Use the PR merge ref, not the head.
18+
pr_number: ${{ github.event.pull_request.number }}
19+
secrets: inherit
20+
21+
lint:
22+
name: Lint
23+
runs-on: macos-latest
24+
25+
steps:
26+
- uses: actions/checkout@v4
27+
28+
- run: |
29+
swift format lint --recursive .
30+
31+
- name: Suggest fixes (if check fails)
32+
if: failure()
33+
run: |
34+
echo "### Here's how to fix the formatting locally:" >> $GITHUB_STEP_SUMMARY
35+
echo "" >> $GITHUB_STEP_SUMMARY
36+
echo "```bash" >> $GITHUB_STEP_SUMMARY
37+
echo "# Format all Swift files" >> $GITHUB_STEP_SUMMARY
38+
echo 'swift format -i --recursive .' >> $GITHUB_STEP_SUMMARY
39+
echo '```' >> $GITHUB_STEP_SUMMARY

.github/workflows/format.yml

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

.github/workflows/unit-tests.yml

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

.swift-format

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
{
2+
"fileScopedDeclarationPrivacy": {
3+
"accessLevel": "private"
4+
},
5+
"indentConditionalCompilationBlocks": false,
6+
"indentSwitchCaseLabels": false,
7+
"indentation": {
8+
"spaces": 4
9+
},
10+
"lineBreakAroundMultilineExpressionChainComponents": false,
11+
"lineBreakBeforeControlFlowKeywords": false,
12+
"lineBreakBeforeEachArgument": false,
13+
"lineBreakBeforeEachGenericRequirement": false,
14+
"lineBreakBetweenDeclarationAttributes": false,
15+
"lineLength": 10000,
16+
"maximumBlankLines": 1,
17+
"multiElementCollectionTrailingCommas": true,
18+
"noAssignmentInExpressions": {
19+
"allowedFunctions": [
20+
"XCTAssertNoThrow"
21+
]
22+
},
23+
"prioritizeKeepingFunctionOutputTogether": false,
24+
"reflowMultilineStringLiterals": {
25+
"never": {}
26+
},
27+
"respectsExistingLineBreaks": true,
28+
"rules": {
29+
"AllPublicDeclarationsHaveDocumentation": false,
30+
"AlwaysUseLiteralForEmptyCollectionInit": false,
31+
"AlwaysUseLowerCamelCase": false,
32+
"AmbiguousTrailingClosureOverload": true,
33+
"AvoidRetroactiveConformances": true,
34+
"BeginDocumentationCommentWithOneLineSummary": false,
35+
"DoNotUseSemicolons": false,
36+
"DontRepeatTypeInStaticProperties": true,
37+
"FileScopedDeclarationPrivacy": true,
38+
"FullyIndirectEnum": true,
39+
"GroupNumericLiterals": false,
40+
"IdentifiersMustBeASCII": true,
41+
"NeverForceUnwrap": false,
42+
"NeverUseForceTry": false,
43+
"NeverUseImplicitlyUnwrappedOptionals": false,
44+
"NoAccessLevelOnExtensionDeclaration": false,
45+
"NoAssignmentInExpressions": true,
46+
"NoBlockComments": true,
47+
"NoCasesWithOnlyFallthrough": true,
48+
"NoEmptyLinesOpeningClosingBraces": false,
49+
"NoEmptyTrailingClosureParentheses": true,
50+
"NoLabelsInCasePatterns": true,
51+
"NoLeadingUnderscores": false,
52+
"NoParensAroundConditions": true,
53+
"NoPlaygroundLiterals": true,
54+
"NoVoidReturnOnFunctionSignature": true,
55+
"OmitExplicitReturns": false,
56+
"OneCasePerLine": true,
57+
"OneVariableDeclarationPerLine": true,
58+
"OnlyOneTrailingClosureArgument": true,
59+
"OrderedImports": true,
60+
"ReplaceForEachWithForLoop": true,
61+
"ReturnVoidInsteadOfEmptyTuple": true,
62+
"TypeNamesShouldBeCapitalized": true,
63+
"UseEarlyExits": false,
64+
"UseExplicitNilCheckInConditions": true,
65+
"UseLetInEveryBoundCaseVariable": false,
66+
"UseShorthandTypeNames": true,
67+
"UseSingleLinePropertyGetter": true,
68+
"UseSynthesizedInitializer": true,
69+
"UseTripleSlashForDocumentationComments": false,
70+
"UseWhereClausesInForLoops": false,
71+
"ValidateDocumentationComments": true
72+
},
73+
"spacesAroundRangeFormationOperators": false,
74+
"spacesBeforeEndOfLineComments": 1,
75+
"tabWidth": 8,
76+
"version": 1
77+
}

.swiftformat

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

.vscode/extensions.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
{
22
"recommendations": [
33
"swiftlang.swift-vscode",
4-
"vknabel.vscode-swiftformat"
54
]
6-
}
5+
}

.vscode/settings.json

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
11
{
2-
// SwiftFormat configuration to match CI
3-
"swiftformat.configSearchPaths": [
4-
".swiftformat"
5-
],
62
// Swift language settings
73
"swift.path": "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin",
84
"swift.buildPath": ".build",
@@ -15,12 +11,13 @@
1511
"editor.trimAutoWhitespace": true,
1612
// File associations
1713
"files.associations": {
14+
".swift-format": "json",
1815
"*.swift": "swift"
1916
},
2017
// Format on save for Swift files
2118
"[swift]": {
2219
"editor.formatOnSave": true,
23-
"editor.defaultFormatter": "vknabel.vscode-swiftformat"
20+
"editor.defaultFormatter": "swiftlang.swift-vscode"
2421
},
2522
// Exclude build artifacts from search
2623
"search.exclude": {
@@ -35,6 +32,6 @@
3532
"swift.swiftEnvironmentVariables": {
3633
"DEVELOPER_DIR": "/Applications/Xcode.app"
3734
},
38-
// Disable automatic generation of launch `launch.json`
35+
// Disable automatic generation of launch configuration (`launch.json`)
3936
"swift.autoGenerateLaunchConfigurations": false
4037
}

Package.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,17 @@ import PackageDescription
55

66
/// Define the strict concurrency settings to be applied to all targets.
77
let swiftSettings: [SwiftSetting] = [
8-
.enableExperimentalFeature("StrictConcurrency"),
8+
.enableExperimentalFeature("StrictConcurrency")
99
]
1010

1111
let package = Package(
1212
name: "swift-transformers",
1313
platforms: [.iOS(.v16), .macOS(.v13)],
1414
products: [
15-
.library(name: "Transformers", targets: ["Tokenizers", "Generation", "Models"]),
15+
.library(name: "Transformers", targets: ["Tokenizers", "Generation", "Models"])
1616
],
1717
dependencies: [
18-
.package(url: "https://github.com/johnmai-dev/Jinja", .upToNextMinor(from: "1.3.0")),
18+
.package(url: "https://github.com/johnmai-dev/Jinja", .upToNextMinor(from: "1.3.0"))
1919
],
2020
targets: [
2121
.target(name: "Generation", dependencies: ["Tokenizers"]),

Sources/Generation/GenerationConfig.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,4 +55,4 @@ public extension GenerationConfig {
5555
}
5656
}
5757

58-
extension GenerationConfig: Decodable { }
58+
extension GenerationConfig: Decodable {}

Sources/Generation/Math.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import Foundation
1919
public enum Math {
2020
/**
2121
Returns the index and value of the largest element in the array.
22-
22+
2323
- Parameters:
2424
- ptr: Pointer to the first element in memory.
2525
- count: How many elements to look at.

0 commit comments

Comments
 (0)