Skip to content

Commit feba87c

Browse files
committed
Merge branch 'main' of https://github.com/apple/swift-format into danthorpe/add_pre_commit_hooks
2 parents 1925645 + 11b7887 commit feba87c

File tree

83 files changed

+3334
-515
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

83 files changed

+3334
-515
lines changed

.swiftci/5_10_ubuntu2204

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
LinuxSwiftPackageJob {
2+
swift_version_tag = "5.10-jammy"
3+
repo = "swift-format"
4+
branch = "main"
5+
}

.swiftci/5_7_ubuntu2204

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
LinuxSwiftPackageJob {
2+
swift_version_tag = "5.7-jammy"
3+
repo = "swift-format"
4+
branch = "main"
5+
}

.swiftci/5_8_ubuntu2204

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
LinuxSwiftPackageJob {
2+
swift_version_tag = "5.8-jammy"
3+
repo = "swift-format"
4+
branch = "main"
5+
}

.swiftci/5_9_ubuntu2204

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
LinuxSwiftPackageJob {
2+
swift_version_tag = "5.9-jammy"
3+
repo = "swift-format"
4+
branch = "main"
5+
}

.swiftci/nightly_6_0_macos

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
macOSSwiftPackageJob {
2+
swift_version = "6.0"
3+
repo = "swift-format"
4+
branch = "main"
5+
}

.swiftci/nightly_6_0_ubuntu2204

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
LinuxSwiftPackageJob {
2+
nightly_docker_tag = "nightly-6.0-jammy"
3+
repo = "swift-format"
4+
branch = "main"
5+
}

.swiftci/nightly_main_macos

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
macOSSwiftPackageJob {
2+
swift_version = "main"
3+
repo = "swift-format"
4+
branch = "main"
5+
}

.swiftci/nightly_main_ubuntu2204

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
LinuxSwiftPackageJob {
2+
nightly_docker_tag = "nightly-jammy"
3+
repo = "swift-format"
4+
branch = "main"
5+
}

.swiftci/nightly_main_windows

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
WindowsSwiftPackageWithDockerImageJob {
2+
docker_image = "swiftlang/swift:nightly-windowsservercore-1809"
3+
repo = "swift-format"
4+
branch = "main"
5+
sub_dir = "swift-format"
6+
label = "windows-server-2019"
7+
}

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ endif()
6868
find_package(SwiftSyntax CONFIG)
6969
if(NOT SwiftSyntax_FOUND)
7070
FetchContent_Declare(Syntax
71-
GIT_REPOSITORY https://github.com/apple/swift-syntax
71+
GIT_REPOSITORY https://github.com/swiftlang/swift-syntax
7272
GIT_TAG main)
7373
list(APPEND _SF_VENDOR_DEPENDENCIES Syntax)
7474
endif()

CODE_OF_CONDUCT.md

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

CONTRIBUTING.md

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

Documentation/Configuration.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ top-level keys and values:
3131
lines that are allowed to be present in a source file. Any number larger
3232
than this will be collapsed down to the maximum.
3333

34+
* `spacesBeforeEndOfLineComments` _(number)_: The number of spaces between
35+
the last token on a non-empty line and a line comment starting with `//`.
36+
3437
* `respectsExistingLineBreaks` _(boolean)_: Indicates whether or not existing
3538
line breaks in the source code should be honored (if they are valid
3639
according to the style guidelines being enforced). If this settings is
@@ -58,6 +61,13 @@ top-level keys and values:
5861
(the default), requirements will be laid out horizontally first, with line breaks
5962
only being fired when the line length would be exceeded.
6063

64+
* `lineBreakBetweenDeclarationAttributes` _(boolean)_: Determines the
65+
line-breaking behavior for adjacent attributes on declarations.
66+
If true, a line break will be added between each attribute, forcing the
67+
attribute list to be laid out vertically. If false (the default),
68+
attributes will be laid out horizontally first, with line breaks only
69+
being fired when the line length would be exceeded.
70+
6171
* `prioritizeKeepingFunctionOutputTogether` _(boolean)_: Determines if
6272
function-like declaration outputs should be prioritized to be together with the
6373
function signature right (closing) parenthesis. If false (the default), function

Documentation/PrettyPrinter.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ if someCondition {
263263
### Token Generation
264264

265265
Token generation begins with the abstract syntax tree (AST) of the Swift source
266-
file, provided by the [SwiftSyntax](https://github.com/apple/swift-syntax)
266+
file, provided by the [SwiftSyntax](https://github.com/swiftlang/swift-syntax)
267267
library. We have overloaded a `visit` method for each of the different kinds of
268268
syntax nodes. Most of these nodes are higher-level, and are composed of other
269269
nodes. For example, `FunctionDeclSyntax` contains

Documentation/RuleDocumentation.md

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
Use the rules below in the `rules` block of your `.swift-format`
66
configuration file, as described in
7-
[Configuration](Documentation/Configuration.md). All of these rules can be
7+
[Configuration](Configuration.md). All of these rules can be
88
applied in the linter, but only some of them can format your source code
99
automatically.
1010

@@ -14,6 +14,7 @@ Here's the list of available rules:
1414
- [AlwaysUseLiteralForEmptyCollectionInit](#AlwaysUseLiteralForEmptyCollectionInit)
1515
- [AlwaysUseLowerCamelCase](#AlwaysUseLowerCamelCase)
1616
- [AmbiguousTrailingClosureOverload](#AmbiguousTrailingClosureOverload)
17+
- [AvoidRetroactiveConformances](#AvoidRetroactiveConformances)
1718
- [BeginDocumentationCommentWithOneLineSummary](#BeginDocumentationCommentWithOneLineSummary)
1819
- [DoNotUseSemicolons](#DoNotUseSemicolons)
1920
- [DontRepeatTypeInStaticProperties](#DontRepeatTypeInStaticProperties)
@@ -28,6 +29,7 @@ Here's the list of available rules:
2829
- [NoAssignmentInExpressions](#NoAssignmentInExpressions)
2930
- [NoBlockComments](#NoBlockComments)
3031
- [NoCasesWithOnlyFallthrough](#NoCasesWithOnlyFallthrough)
32+
- [NoEmptyLinesOpeningClosingBraces](#NoEmptyLinesOpeningClosingBraces)
3133
- [NoEmptyTrailingClosureParentheses](#NoEmptyTrailingClosureParentheses)
3234
- [NoLabelsInCasePatterns](#NoLabelsInCasePatterns)
3335
- [NoLeadingUnderscores](#NoLeadingUnderscores)
@@ -78,6 +80,7 @@ Underscores (except at the beginning of an identifier) are disallowed.
7880

7981
This rule does not apply to test code, defined as code which:
8082
* Contains the line `import XCTest`
83+
* The function is marked with `@Test` attribute
8184

8285
Lint: If an identifier contains underscores or begins with a capital letter, a lint error is
8386
raised.
@@ -93,6 +96,14 @@ Lint: If two overloaded functions with one closure parameter appear in the same
9396

9497
`AmbiguousTrailingClosureOverload` is a linter-only rule.
9598

99+
### AvoidRetroactiveConformances
100+
101+
`@retroactive` conformances are forbidden.
102+
103+
Lint: Using `@retroactive` results in a lint error.
104+
105+
`AvoidRetroactiveConformances` is a linter-only rule.
106+
96107
### BeginDocumentationCommentWithOneLineSummary
97108

98109
All documentation comments must begin with a one-line summary of the declaration.
@@ -179,6 +190,7 @@ Force-unwraps are strongly discouraged and must be documented.
179190

180191
This rule does not apply to test code, defined as code which:
181192
* Contains the line `import XCTest`
193+
* The function is marked with `@Test` attribute
182194

183195
Lint: If a force unwrap is used, a lint warning is raised.
184196

@@ -190,6 +202,7 @@ Force-try (`try!`) is forbidden.
190202

191203
This rule does not apply to test code, defined as code which:
192204
* Contains the line `import XCTest`
205+
* The function is marked with `@Test` attribute
193206

194207
Lint: Using `try!` results in a lint error.
195208

@@ -205,6 +218,7 @@ Certain properties (e.g. `@IBOutlet`) tied to the UI lifecycle are ignored.
205218

206219
This rule does not apply to test code, defined as code which:
207220
* Contains the line `import XCTest`
221+
* The function is marked with `@Test` attribute
208222

209223
TODO: Create exceptions for other UI elements (ex: viewDidLoad)
210224

@@ -258,6 +272,16 @@ Format: The fallthrough `case` is added as a prefix to the next case unless the
258272

259273
`NoCasesWithOnlyFallthrough` rule can format your code automatically.
260274

275+
### NoEmptyLinesOpeningClosingBraces
276+
277+
Empty lines are forbidden after opening braces and before closing braces.
278+
279+
Lint: Empty lines after opening braces and before closing braces yield a lint error.
280+
281+
Format: Empty lines after opening braces and before closing braces will be removed.
282+
283+
`NoEmptyLinesOpeningClosingBraces` rule can format your code automatically.
284+
261285
### NoEmptyTrailingClosureParentheses
262286

263287
Function calls with no arguments and a trailing closure should not have empty parentheses.

Package.swift

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ let package = Package(
4141
dependencies: dependencies,
4242
targets: [
4343
.target(
44-
name: "_SwiftFormatInstructionCounter"
44+
name: "_SwiftFormatInstructionCounter",
45+
exclude: ["CMakeLists.txt"]
4546
),
4647

4748
.target(
@@ -53,7 +54,8 @@ let package = Package(
5354
.product(name: "SwiftOperators", package: "swift-syntax"),
5455
.product(name: "SwiftParser", package: "swift-syntax"),
5556
.product(name: "SwiftParserDiagnostics", package: "swift-syntax"),
56-
]
57+
],
58+
exclude: ["CMakeLists.txt"]
5759
),
5860
.target(
5961
name: "_SwiftFormatTestSupport",
@@ -105,6 +107,7 @@ let package = Package(
105107
.product(name: "SwiftSyntax", package: "swift-syntax"),
106108
.product(name: "SwiftParser", package: "swift-syntax"),
107109
],
110+
exclude: ["CMakeLists.txt"],
108111
linkerSettings: swiftformatLinkSettings
109112
),
110113

@@ -163,7 +166,7 @@ var dependencies: [Package.Dependency] {
163166
return [
164167
.package(url: "https://github.com/apple/swift-argument-parser.git", from: "1.2.2"),
165168
.package(url: "https://github.com/apple/swift-markdown.git", from: "0.2.0"),
166-
.package(url: "https://github.com/apple/swift-syntax.git", branch: "main"),
169+
.package(url: "https://github.com/swiftlang/swift-syntax.git", branch: "main"),
167170
]
168171
}
169172
}

README.md

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# swift-format
22

33
`swift-format` provides the formatting technology for
4-
[SourceKit-LSP](https://github.com/apple/sourcekit-lsp) and the building
4+
[SourceKit-LSP](https://github.com/swiftlang/sourcekit-lsp) and the building
55
blocks for doing code formatting transformations.
66

77
This package can be used as a [command line tool](#command-line-usage)
@@ -18,7 +18,7 @@ invoked via an [API](#api-usage).
1818
### Swift 5.8 and later
1919

2020
As of Swift 5.8, swift-format depends on the version of
21-
[SwiftSyntax](https://github.com/apple/swift-syntax) whose parser has been
21+
[SwiftSyntax](https://github.com/swiftlang/swift-syntax) whose parser has been
2222
rewritten in Swift and no longer has dependencies on libraries in the
2323
Swift toolchain.
2424

@@ -34,7 +34,7 @@ SwiftSyntax; the 5.8 release of swift-format is `508.0.0`, not `0.50800.0`.
3434
### Swift 5.7 and earlier
3535

3636
`swift-format` versions 0.50700.0 and earlier depend on versions of
37-
[SwiftSyntax](https://github.com/apple/swift-syntax) that used a standalone
37+
[SwiftSyntax](https://github.com/swiftlang/swift-syntax) that used a standalone
3838
parsing library distributed as part of the Swift toolchain. When using these
3939
versions, you should check out and build `swift-format` from the release
4040
tag or branch that is compatible with the version of Swift you are using.
@@ -61,8 +61,11 @@ For example, if you are using Xcode 13.3 (Swift 5.6), you will need
6161
## Getting swift-format
6262

6363
If you are mainly interested in using swift-format (rather than developing it),
64-
then you can get swift-format either via [Homebrew](https://brew.sh/) or by checking out the
65-
source and building it.
64+
then you can get it in three different ways:
65+
66+
### Included in Xcode
67+
68+
Xcode 16 and above include swift-format in the toolchain. You can run `swift-format` from anywhere on the system using `swift format` (notice the space instead of dash). To find the path at which `swift-format` is installed, run `xcrun --find swift-format`.
6669

6770
### Installing via Homebrew
6871

@@ -74,7 +77,7 @@ Install `swift-format` using the following commands:
7477

7578
```sh
7679
VERSION=510.1.0 # replace this with the version you need
77-
git clone https://github.com/apple/swift-format.git
80+
git clone https://github.com/swiftlang/swift-format.git
7881
cd swift-format
7982
git checkout "tags/$VERSION"
8083
swift build -c release
@@ -251,3 +254,24 @@ been merged into `main`.
251254

252255
If you are interested in developing `swift-format`, there is additional
253256
documentation about that [here](Documentation/Development.md).
257+
258+
## Contributing
259+
260+
Contributions to Swift are welcomed and encouraged! Please see the
261+
[Contributing to Swift guide](https://swift.org/contributing/).
262+
263+
Before submitting the pull request, please make sure you have [tested your
264+
changes](https://github.com/apple/swift/blob/main/docs/ContinuousIntegration.md)
265+
and that they follow the Swift project [guidelines for contributing
266+
code](https://swift.org/contributing/#contributing-code).
267+
268+
To be a truly great community, [Swift.org](https://swift.org/) needs to welcome
269+
developers from all walks of life, with different backgrounds, and with a wide
270+
range of experience. A diverse and friendly community will have more great
271+
ideas, more unique perspectives, and produce more great code. We will work
272+
diligently to make the Swift community welcoming to everyone.
273+
274+
To give clarity of what is expected of our members, Swift has adopted the
275+
code of conduct defined by the Contributor Covenant. This document is used
276+
across many open source communities, and we think it articulates our values
277+
well. For more, see the [Code of Conduct](https://swift.org/code-of-conduct/).

Sources/SwiftFormat/API/Configuration+Default.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,12 @@ extension Configuration {
2626
self.lineLength = 100
2727
self.tabWidth = 8
2828
self.indentation = .spaces(2)
29+
self.spacesBeforeEndOfLineComments = 2
2930
self.respectsExistingLineBreaks = true
3031
self.lineBreakBeforeControlFlowKeywords = false
3132
self.lineBreakBeforeEachArgument = false
3233
self.lineBreakBeforeEachGenericRequirement = false
34+
self.lineBreakBetweenDeclarationAttributes = false
3335
self.prioritizeKeepingFunctionOutputTogether = false
3436
self.indentConditionalCompilationBlocks = true
3537
self.lineBreakAroundMultilineExpressionChainComponents = false
@@ -38,5 +40,6 @@ extension Configuration {
3840
self.spacesAroundRangeFormationOperators = false
3941
self.noAssignmentInExpressions = NoAssignmentInExpressionsConfiguration()
4042
self.multiElementCollectionTrailingCommas = true
43+
self.reflowMultilineStringLiterals = .never
4144
}
4245
}

0 commit comments

Comments
 (0)