Skip to content

Commit 94ce795

Browse files
authored
Merge pull request #904 from ahoppen/6.1/merge-main-2024-12-17
Merge `main` into `release/6.1`
2 parents f410c3c + 8c7b261 commit 94ce795

File tree

5 files changed

+186
-96
lines changed

5 files changed

+186
-96
lines changed

.spi.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# This is manifest file for the Swift Package Index for it to
2+
# auto-generate and host DocC documentation.
3+
# For reference see https://swiftpackageindex.com/swiftpackageindex/spimanifest/documentation/spimanifest/commonusecases#Host-DocC-documentation-in-the-Swift-Package-Index.
4+
5+
version: 1
6+
builder:
7+
configs:
8+
- documentation_targets:
9+
# First item in the list is the "landing" (default) target
10+
- SwiftFormat
11+
custom_documentation_parameters: [--experimental-skip-synthesized-symbols]

Documentation/Configuration.md

Lines changed: 169 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -8,97 +8,175 @@ used as a command line tool or as an API.
88
A `swift-format` configuration file is a JSON file with the following
99
top-level keys and values:
1010

11-
* `version` _(number)_: The version of the configuration file. For now, this
12-
should always be `1`.
13-
14-
* `lineLength` _(number)_: The maximum allowed length of a line, in
15-
characters.
16-
17-
* `indentation` _(object)_: The kind and amount of whitespace that should be
18-
added when indenting one level. The object value of this property should
19-
have **exactly one of the following properties:**
20-
21-
* `spaces` _(number)_: One level of indentation is the given number of
22-
spaces.
23-
* `tabs` _(number)_: One level of indentation is the given number of
24-
tabs.
25-
26-
* `tabWidth` _(number)_: The number of spaces that should be considered
27-
equivalent to one tab character. This is used during line length
28-
calculations when tabs are used for indentation.
29-
30-
* `maximumBlankLines` _(number)_: The maximum number of consecutive blank
31-
lines that are allowed to be present in a source file. Any number larger
32-
than this will be collapsed down to the maximum.
33-
34-
* `spacesBeforeEndOfLineComments` _(number)_: The number of spaces between
35-
the last token on a non-empty line and a line comment starting with `//`.
36-
37-
* `respectsExistingLineBreaks` _(boolean)_: Indicates whether or not existing
38-
line breaks in the source code should be honored (if they are valid
39-
according to the style guidelines being enforced). If this settings is
40-
`false`, then the formatter will be more "opinionated" by only inserting
41-
line breaks where absolutely necessary and removing any others, effectively
42-
canonicalizing the output.
43-
44-
* `lineBreakBeforeControlFlowKeywords` _(boolean)_: Determines the
45-
line-breaking behavior for control flow keywords that follow a closing
46-
brace, like `else` and `catch`. If true, a line break will be added before
47-
the keyword, forcing it onto its own line. If false (the default), the
48-
keyword will be placed after the closing brace (separated by a space).
49-
50-
* `lineBreakBeforeEachArgument` _(boolean)_: Determines the line-breaking
51-
behavior for generic arguments and function arguments when a declaration is
52-
wrapped onto multiple lines. If true, a line break will be added before each
53-
argument, forcing the entire argument list to be laid out vertically.
54-
If false (the default), arguments will be laid out horizontally first, with
55-
line breaks only being fired when the line length would be exceeded.
56-
57-
* `lineBreakBeforeEachGenericRequirement` _(boolean)_: Determines the
58-
line-breaking behavior for generic requirements when the requirements list
59-
is wrapped onto multiple lines. If true, a line break will be added before each
60-
requirement, forcing the entire requirements list to be laid out vertically. If false
61-
(the default), requirements will be laid out horizontally first, with line breaks
62-
only being fired when the line length would be exceeded.
63-
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-
71-
* `prioritizeKeepingFunctionOutputTogether` _(boolean)_: Determines if
72-
function-like declaration outputs should be prioritized to be together with the
73-
function signature right (closing) parenthesis. If false (the default), function
74-
output (i.e. throws, return type) is not prioritized to be together with the
75-
signature's right parenthesis, and when the line length would be exceeded,
76-
a line break will be fired after the function signature first, indenting the
77-
declaration output one additional level. If true, A line break will be fired
78-
further up in the function's declaration (e.g. generic parameters,
79-
parameters) before breaking on the function's output.
80-
81-
* `indentConditionalCompilationBlocks` _(boolean)_: Determines if
82-
conditional compilation blocks are indented. If this setting is `false` the body
83-
of `#if`, `#elseif`, and `#else` is not indented. Defaults to `true`.
84-
85-
* `lineBreakAroundMultilineExpressionChainComponents` _(boolean)_: Determines whether
86-
line breaks should be forced before and after multiline components of dot-chained
87-
expressions, such as function calls and subscripts chained together through member
88-
access (i.e. "." expressions). When any component is multiline and this option is
89-
true, a line break is forced before the "." of the component and after the component's
90-
closing delimiter (i.e. right paren, right bracket, right brace, etc.).
91-
92-
* `spacesAroundRangeFormationOperators` _(boolean)_: Determines whether whitespace should be forced
93-
before and after the range formation operators `...` and `..<`.
94-
95-
* `multiElementCollectionTrailingCommas` _(boolean)_: Determines whether multi-element collection literals should have trailing commas.
96-
Defaults to `true`.
97-
98-
* `indentBlankLines` _(boolean)_: Determines whether blank lines should be modified
99-
to match the current indentation. When this setting is true, blank lines will be modified
100-
to match the indentation level, adding indentation whether or not there is existing whitespace.
101-
When false (the default), all whitespace in blank lines will be completely removed.
11+
### `version`
12+
**type:** number
13+
14+
**description:** The version of the configuration file. For now, this should always be `1`.
15+
16+
**default:** `1`
17+
18+
---
19+
20+
### `lineLength`
21+
**type:** number
22+
23+
**description:** The maximum allowed length of a line, in characters.
24+
25+
**default:** `100`
26+
27+
---
28+
29+
### `indentation`
30+
**type:** object
31+
32+
**description:** The kind and amount of whitespace that should be added when indenting one level. The object value of this property should have exactly one of the following properties:
33+
34+
- `spaces` _(number)_: One level of indentation is the given number of spaces.
35+
- `tabs` _(number)_: One level of indentation is the given number of tabs.
36+
37+
**default:** `{ "spaces": 2 }`
38+
39+
---
40+
41+
### `tabWidth`
42+
**type:** number
43+
44+
**description:** The number of spaces that should be considered equivalent to one tab character. This is used during line length calculations when tabs are used for indentation.
45+
46+
**default:** `8`
47+
48+
---
49+
50+
### `maximumBlankLines`
51+
**type:** number
52+
53+
**description:** The maximum number of consecutive blank lines that are allowed to be present in a source file. Any number larger than this will be collapsed down to the maximum.
54+
55+
**default:** `1`
56+
57+
---
58+
59+
### `spacesBeforeEndOfLineComments`
60+
**type:** number
61+
62+
**description:** The number of spaces between the last token on a non-empty line and a line comment starting with `//`.
63+
64+
**default:** `2`
65+
66+
---
67+
68+
### `respectsExistingLineBreaks`
69+
**type:** boolean
70+
71+
**description:** Indicates whether or not existing line breaks in the source code should be honored (if they are valid according to the style guidelines being enforced). If this settings is `false`, then the formatter will be more "opinionated" by only inserting line breaks where absolutely necessary and removing any others, effectively canonicalizing the output.
72+
73+
**default:** `true`
74+
75+
---
76+
77+
### `lineBreakBeforeControlFlowKeywords`
78+
**type:** boolean
79+
80+
**description:** Determines the line-breaking behavior for control flow keywords that follow a closing brace, like `else` and `catch`. If true, a line break will be added before the keyword, forcing it onto its own line. If `false`, the keyword will be placed after the closing brace (separated by a space).
81+
82+
**default:** `false`
83+
84+
---
85+
86+
### `lineBreakBeforeEachArgument`
87+
**type:** boolean
88+
89+
**description:** Determines the line-breaking behavior for generic arguments and function arguments when a declaration is wrapped onto multiple lines. If true, a line break will be added before each argument, forcing the entire argument list to be laid out vertically. If `false`, arguments will be laid out horizontally first, with line breaks only being fired when the line length would be exceeded.
90+
91+
**default:** `false`
92+
93+
---
94+
95+
### `lineBreakBeforeEachGenericRequirement`
96+
**type:** boolean
97+
98+
**description:** Determines the line-breaking behavior for generic requirements when the requirements list is wrapped onto multiple lines. If true, a line break will be added before each requirement, forcing the entire requirements list to be laid out vertically. If `false`, requirements will be laid out horizontally first, with line breaks only being fired when the line length would be exceeded.
99+
100+
**default:** `false`
101+
102+
---
103+
104+
### `lineBreakBetweenDeclarationAttributes`
105+
**type:** boolean
106+
107+
**description:** Determines the line-breaking behavior for adjacent attributes on declarations. If true, a line break will be added between each attribute, forcing the attribute list to be laid out vertically. If `false`, attributes will be laid out horizontally first, with line breaks only being fired when the line length would be exceeded.
108+
109+
**default:** `false`
110+
111+
---
112+
113+
### `prioritizeKeepingFunctionOutputTogether`
114+
**type:** boolean
115+
116+
**description:** Determines if function-like declaration outputs should be prioritized to be together with thefunction signature right (closing) parenthesis. If `false`, function output (i.e. throws, return type) is not prioritized to be together with the signature's right parenthesis, and when the line length would be exceeded,a line break will be fired after the function signature first, indenting the declaration output one additional level. If true, A line break will be fired further up in the function's declaration (e.g. generic parameters, parameters) before breaking on the function's output.
117+
118+
**default:** `false`
119+
120+
---
121+
122+
### `indentConditionalCompilationBlocks`
123+
**type:** boolean
124+
125+
**description:** Determines if conditional compilation blocks are indented. If this setting is `false` the body of `#if`, `#elseif`, and `#else` is not indented.
126+
127+
**default:** `true`
128+
129+
---
130+
131+
### `lineBreakAroundMultilineExpressionChainComponents`
132+
**type:** boolean
133+
134+
**description:** Determines whether line breaks should be forced before and after multiline components of dot-chained expressions, such as function calls and subscripts chained together through member access (i.e. "." expressions). When any component is multiline and this option is true, a line break is forced before the "." of the component and after the component's closing delimiter (i.e. right paren, right bracket, right brace, etc.).
135+
136+
**default:** `false`
137+
138+
---
139+
140+
## FIXME: fileScopedDeclarationPrivacy
141+
142+
---
143+
144+
### FIXME: indentSwitchCaseLabels
145+
146+
---
147+
148+
### `spacesAroundRangeFormationOperators`
149+
**type:** boolean
150+
151+
**description:** Determines whether whitespace should be forced before and after the range formation operators `...` and `..<`.
152+
153+
**default:** `false`
154+
155+
---
156+
157+
### FIXME: noAssignmentInExpressions
158+
159+
---
160+
161+
### `multiElementCollectionTrailingCommas`
162+
**type:** boolean
163+
164+
**description:** Determines whether multi-element collection literals should have trailing commas.
165+
166+
**default:** `true`
167+
168+
---
169+
170+
### FIXME: reflowMultilineStringLiterals
171+
172+
---
173+
174+
### `indentBlankLines`
175+
**type:** boolean
176+
177+
**description:** Determines whether blank lines should be modified to match the current indentation. When this setting is true, blank lines will be modified whitespace. If `false`, all whitespace in blank lines will be completely removed.
178+
179+
**default:** `false`
102180

103181
> TODO: Add support for enabling/disabling specific syntax transformations in
104182
> the pipeline.

Package.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// swift-tools-version:5.6
1+
// swift-tools-version:5.8
22
//===----------------------------------------------------------------------===//
33
//
44
// This source file is part of the Swift.org open source project

Sources/SwiftFormat/API/SwiftFormatter.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public final class SwiftFormatter {
4545
/// This form of the `format` function automatically folds expressions using the default operator
4646
/// set defined in Swift. If you need more control over this—for example, to provide the correct
4747
/// precedence relationships for custom operators—you must parse and fold the syntax tree
48-
/// manually and then call ``format(syntax:assumingFileURL:to:)``.
48+
/// manually and then call ``format(syntax:source:operatorTable:assumingFileURL:selection:to:)``.
4949
///
5050
/// - Parameters:
5151
/// - url: The URL of the file containing the code to format.
@@ -81,7 +81,7 @@ public final class SwiftFormatter {
8181
/// This form of the `format` function automatically folds expressions using the default operator
8282
/// set defined in Swift. If you need more control over this—for example, to provide the correct
8383
/// precedence relationships for custom operators—you must parse and fold the syntax tree
84-
/// manually and then call ``format(syntax:assumingFileURL:to:)``.
84+
/// manually and then call ``format(syntax:source:operatorTable:assumingFileURL:selection:to:)``.
8585
///
8686
/// - Parameters:
8787
/// - source: The Swift source code to be formatted.

Sources/SwiftFormat/API/SwiftLinter.swift

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public final class SwiftLinter {
4545
/// This form of the `lint` function automatically folds expressions using the default operator
4646
/// set defined in Swift. If you need more control over this—for example, to provide the correct
4747
/// precedence relationships for custom operators—you must parse and fold the syntax tree
48-
/// manually and then call ``lint(syntax:assumingFileURL:)``.
48+
/// manually and then call ``lint(syntax:source:operatorTable:assumingFileURL:)``.
4949
///
5050
/// - Parameters:
5151
/// - url: The URL of the file containing the code to format.
@@ -76,7 +76,7 @@ public final class SwiftLinter {
7676
/// This form of the `lint` function automatically folds expressions using the default operator
7777
/// set defined in Swift. If you need more control over this—for example, to provide the correct
7878
/// precedence relationships for custom operators—you must parse and fold the syntax tree
79-
/// manually and then call ``lint(syntax:assumingFileURL:)``.
79+
/// manually and then call ``lint(syntax:source:operatorTable:assumingFileURL:)``.
8080
///
8181
/// - Parameters:
8282
/// - source: The Swift source code to be linted.
@@ -124,6 +124,7 @@ public final class SwiftLinter {
124124
///
125125
/// - Parameters:
126126
/// - syntax: The Swift syntax tree to be converted to be linted.
127+
/// - source: The Swift source code to be linted.
127128
/// - operatorTable: The table that defines the operators and their precedence relationships.
128129
/// This must be the same operator table that was used to fold the expressions in the `syntax`
129130
/// argument.

0 commit comments

Comments
 (0)