Skip to content

Commit 1c8215f

Browse files
authored
Prefer let for private configurations (#617)
1 parent 76466cc commit 1c8215f

File tree

14 files changed

+41
-41
lines changed

14 files changed

+41
-41
lines changed

Examples/math/Math.swift

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import ArgumentParser
1515
struct Math: ParsableCommand {
1616
// Customize your command's help and subcommands by implementing the
1717
// `configuration` property.
18-
static var configuration = CommandConfiguration(
18+
static let configuration = CommandConfiguration(
1919
// Optional abstracts and discussions are used for help output.
2020
abstract: "A utility for performing maths.",
2121

@@ -50,7 +50,7 @@ extension Math {
5050
}
5151

5252
struct Add: ParsableCommand {
53-
static var configuration =
53+
static let configuration =
5454
CommandConfiguration(abstract: "Print the sum of the values.")
5555

5656
// The `@OptionGroup` attribute includes the flags, options, and
@@ -64,7 +64,7 @@ extension Math {
6464
}
6565

6666
struct Multiply: ParsableCommand {
67-
static var configuration =
67+
static let configuration =
6868
CommandConfiguration(abstract: "Print the product of the values.")
6969

7070
@OptionGroup var options: Options
@@ -79,7 +79,7 @@ extension Math {
7979
// In practice, these nested types could be broken out into different files.
8080
extension Math {
8181
struct Statistics: ParsableCommand {
82-
static var configuration = CommandConfiguration(
82+
static let configuration = CommandConfiguration(
8383
// Command names are automatically generated from the type name
8484
// by default; you can specify an override here.
8585
commandName: "stats",
@@ -90,7 +90,7 @@ extension Math {
9090

9191
extension Math.Statistics {
9292
struct Average: ParsableCommand {
93-
static var configuration = CommandConfiguration(
93+
static let configuration = CommandConfiguration(
9494
abstract: "Print the average of the values.",
9595
version: "1.5.0-alpha")
9696

@@ -160,7 +160,7 @@ extension Math.Statistics {
160160
}
161161

162162
struct StandardDeviation: ParsableCommand {
163-
static var configuration = CommandConfiguration(
163+
static let configuration = CommandConfiguration(
164164
commandName: "stdev",
165165
abstract: "Print the standard deviation of the values.")
166166

@@ -184,7 +184,7 @@ extension Math.Statistics {
184184
}
185185

186186
struct Quantiles: ParsableCommand {
187-
static var configuration = CommandConfiguration(
187+
static let configuration = CommandConfiguration(
188188
abstract: "Print the quantiles of the values (TBD).")
189189

190190
@Argument(completion: .list(["alphabet", "alligator", "branch", "braggart"]))

Sources/ArgumentParser/Documentation.docc/Articles/CommandsAndSubcommands.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ Start by defining the root `Math` command. You can provide a static ``ParsableCo
3939

4040
```swift
4141
struct Math: ParsableCommand {
42-
static var configuration = CommandConfiguration(
42+
static let configuration = CommandConfiguration(
4343
abstract: "A utility for performing maths.",
4444
subcommands: [Add.self, Multiply.self, Statistics.self],
4545
defaultSubcommand: Add.self)
@@ -72,7 +72,7 @@ It's time to define our first two subcommands: `Add` and `Multiply`. Both of the
7272
```swift
7373
extension Math {
7474
struct Add: ParsableCommand {
75-
static var configuration
75+
static let configuration
7676
= CommandConfiguration(abstract: "Print the sum of the values.")
7777

7878
@OptionGroup var options: Math.Options
@@ -84,7 +84,7 @@ extension Math {
8484
}
8585

8686
struct Multiply: ParsableCommand {
87-
static var configuration
87+
static let configuration
8888
= CommandConfiguration(abstract: "Print the product of the values.")
8989

9090
@OptionGroup var options: Math.Options
@@ -102,7 +102,7 @@ Next, we'll define `Statistics`, the third subcommand of `Math`. The `Statistics
102102
```swift
103103
extension Math {
104104
struct Statistics: ParsableCommand {
105-
static var configuration = CommandConfiguration(
105+
static let configuration = CommandConfiguration(
106106
commandName: "stats",
107107
abstract: "Calculate descriptive statistics.",
108108
subcommands: [Average.self, StandardDeviation.self])
@@ -115,7 +115,7 @@ Let's finish our subcommands with the `Average` and `StandardDeviation` types. E
115115
```swift
116116
extension Math.Statistics {
117117
struct Average: ParsableCommand {
118-
static var configuration = CommandConfiguration(
118+
static let configuration = CommandConfiguration(
119119
abstract: "Print the average of the values.")
120120

121121
enum Kind: String, ExpressibleByArgument {
@@ -148,7 +148,7 @@ extension Math.Statistics {
148148
}
149149

150150
struct StandardDeviation: ParsableCommand {
151-
static var configuration = CommandConfiguration(
151+
static let configuration = CommandConfiguration(
152152
commandName: "stdev",
153153
abstract: "Print the standard deviation of the values.")
154154

Sources/ArgumentParser/Documentation.docc/Articles/CustomizingCommandHelp.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ In addition to configuring the command name and subcommands, as described in <do
88

99
```swift
1010
struct Repeat: ParsableCommand {
11-
static var configuration = CommandConfiguration(
11+
static let configuration = CommandConfiguration(
1212
abstract: "Repeats your input phrase.",
1313
usage: """
1414
repeat <phrase>

Sources/ArgumentParser/Usage/HelpCommand.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
//===----------------------------------------------------------------------===//
1111

1212
struct HelpCommand: ParsableCommand {
13-
static var configuration = CommandConfiguration(
13+
static let configuration = CommandConfiguration(
1414
commandName: "help",
1515
abstract: "Show subcommand help information.",
1616
helpNames: [])

Tests/ArgumentParserEndToEndTests/DefaultSubcommandEndToEndTests.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ final class DefaultSubcommandEndToEndTests: XCTestCase {
1919
// MARK: -
2020

2121
private struct Main: ParsableCommand {
22-
static var configuration = CommandConfiguration(
22+
static let configuration = CommandConfiguration(
2323
subcommands: [Default.self, Foo.self, Bar.self],
2424
defaultSubcommand: Default.self
2525
)
@@ -72,7 +72,7 @@ extension DefaultSubcommandEndToEndTests {
7272

7373
extension DefaultSubcommandEndToEndTests {
7474
fileprivate struct MyCommand: ParsableCommand {
75-
static var configuration = CommandConfiguration(
75+
static let configuration = CommandConfiguration(
7676
subcommands: [Plugin.self, NonDefault.self, Other.self],
7777
defaultSubcommand: Plugin.self
7878
)

Tests/ArgumentParserEndToEndTests/DefaultsEndToEndTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -613,7 +613,7 @@ extension DefaultsEndToEndTests {
613613
}
614614

615615
fileprivate struct Main: ParsableCommand {
616-
static var configuration = CommandConfiguration(
616+
static let configuration = CommandConfiguration(
617617
subcommands: [Sub.self],
618618
defaultSubcommand: Sub.self
619619
)

Tests/ArgumentParserEndToEndTests/NestedCommandEndToEndTests.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ final class NestedCommandEndToEndTests: XCTestCase {
1919
// MARK: Single value String
2020

2121
fileprivate struct Foo: ParsableCommand {
22-
static var configuration =
22+
static let configuration =
2323
CommandConfiguration(subcommands: [Build.self, Package.self])
2424

2525
@Flag(name: .short)
@@ -33,7 +33,7 @@ fileprivate struct Foo: ParsableCommand {
3333
}
3434

3535
struct Package: ParsableCommand {
36-
static var configuration =
36+
static let configuration =
3737
CommandConfiguration(subcommands: [Clean.self, Config.self])
3838

3939
@Flag(name: .short)

Tests/ArgumentParserEndToEndTests/SubcommandEndToEndTests.swift

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,22 +19,22 @@ final class SubcommandEndToEndTests: XCTestCase {
1919
// MARK: Single value String
2020

2121
fileprivate struct Foo: ParsableCommand {
22-
static var configuration =
22+
static let configuration =
2323
CommandConfiguration(subcommands: [CommandA.self, CommandB.self])
2424

2525
@Option() var name: String
2626
}
2727

2828
fileprivate struct CommandA: ParsableCommand {
29-
static var configuration = CommandConfiguration(commandName: "a")
29+
static let configuration = CommandConfiguration(commandName: "a")
3030

3131
@OptionGroup() var foo: Foo
3232

3333
@Option() var bar: Int
3434
}
3535

3636
fileprivate struct CommandB: ParsableCommand {
37-
static var configuration = CommandConfiguration(commandName: "b")
37+
static let configuration = CommandConfiguration(commandName: "b")
3838

3939
@OptionGroup() var foo: Foo
4040

@@ -154,7 +154,7 @@ struct BaseCommand: ParsableCommand {
154154

155155
static let baseFlagValue = "base"
156156

157-
static var configuration = CommandConfiguration(
157+
static let configuration = CommandConfiguration(
158158
commandName: "base",
159159
subcommands: [SubCommand.self]
160160
)
@@ -173,7 +173,7 @@ extension BaseCommand {
173173
struct SubCommand : ParsableCommand {
174174
static let subFlagValue = "sub"
175175

176-
static var configuration = CommandConfiguration(
176+
static let configuration = CommandConfiguration(
177177
commandName: "sub",
178178
subcommands: [SubSubCommand.self]
179179
)
@@ -193,7 +193,7 @@ extension BaseCommand.SubCommand {
193193
struct SubSubCommand : ParsableCommand, TestableParsableArguments {
194194
let didValidateExpectation = XCTestExpectation(singleExpectation: "did validate subcommand")
195195

196-
static var configuration = CommandConfiguration(
196+
static let configuration = CommandConfiguration(
197197
commandName: "subsub"
198198
)
199199

@@ -238,7 +238,7 @@ extension SubcommandEndToEndTests {
238238
// MARK: Version flags
239239

240240
private struct A: ParsableCommand {
241-
static var configuration = CommandConfiguration(
241+
static let configuration = CommandConfiguration(
242242
version: "1.0.0",
243243
subcommands: [HasVersionFlag.self, NoVersionFlag.self])
244244

Tests/ArgumentParserPackageManagerTests/HelpTests.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ extension HelpTests {
248248
}
249249

250250
struct SubCommandCustomHelp: ParsableCommand {
251-
static var configuration = CommandConfiguration (
251+
static let configuration = CommandConfiguration (
252252
helpNames: [.customShort("p"), .customLong("parent-help")]
253253
)
254254

@@ -257,7 +257,7 @@ struct SubCommandCustomHelp: ParsableCommand {
257257
}
258258

259259
struct ModifiedHelp: ParsableCommand {
260-
static var configuration = CommandConfiguration (
260+
static let configuration = CommandConfiguration (
261261
helpNames: [.customShort("s"), .customLong("subcommand-help")]
262262
)
263263

Tests/ArgumentParserPackageManagerTests/PackageManager/GenerateXcodeProject.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import ArgumentParser
1414
extension Package {
1515
/// Generates an Xcode project
1616
struct GenerateXcodeProject: ParsableCommand {
17-
static var configuration =
17+
static let configuration =
1818
CommandConfiguration(commandName: "generate-xcodeproj")
1919

2020
@OptionGroup()

Tests/ArgumentParserPackageManagerTests/PackageManager/Options.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,12 +88,12 @@ struct Options: ParsableArguments {
8888
}
8989

9090
struct Package: ParsableCommand {
91-
static var configuration = CommandConfiguration(
91+
static let configuration = CommandConfiguration(
9292
subcommands: [Clean.self, Config.self, Describe.self, GenerateXcodeProject.self, Hidden.self])
9393
}
9494

9595
extension Package {
9696
struct Hidden: ParsableCommand {
97-
static var configuration = CommandConfiguration(shouldDisplay: false)
97+
static let configuration = CommandConfiguration(shouldDisplay: false)
9898
}
9999
}

Tests/ArgumentParserUnitTests/CompletionScriptTests.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ extension CompletionScriptTests {
3434
}
3535

3636
struct Base: ParsableCommand {
37-
static var configuration = CommandConfiguration(
37+
static let configuration = CommandConfiguration(
3838
commandName: "base-test",
3939
subcommands: [SubCommand.self]
4040
)
@@ -55,7 +55,7 @@ extension CompletionScriptTests {
5555
@Option(name: [.short, .long]) var rep2: [String]
5656

5757
struct SubCommand: ParsableCommand {
58-
static var configuration = CommandConfiguration(
58+
static let configuration = CommandConfiguration(
5959
commandName: "sub-command"
6060
)
6161
}
@@ -408,11 +408,11 @@ complete -c base-test -n '_swift_base-test_using_command "base-test" "sub-comman
408408

409409
// MARK: - Test Hidden Subcommand
410410
struct Parent: ParsableCommand {
411-
static var configuration = CommandConfiguration(subcommands: [HiddenChild.self])
411+
static let configuration = CommandConfiguration(subcommands: [HiddenChild.self])
412412
}
413413

414414
struct HiddenChild: ParsableCommand {
415-
static var configuration = CommandConfiguration(shouldDisplay: false)
415+
static let configuration = CommandConfiguration(shouldDisplay: false)
416416
}
417417

418418
extension CompletionScriptTests {

Tests/ArgumentParserUnitTests/ExitCodeTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ extension ExitCodeTests {
2121
struct A: ParsableArguments {}
2222
struct E: Error {}
2323
struct C: ParsableCommand {
24-
static var configuration = CommandConfiguration(version: "v1")
24+
static let configuration = CommandConfiguration(version: "v1")
2525
}
2626

2727
func testExitCodes() {

Tests/ArgumentParserUnitTests/HelpGenerationTests.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@ extension HelpGenerationTests {
304304
@Argument
305305
var argument: String = ""
306306
}
307-
static var configuration = CommandConfiguration(subcommands: [CommandWithVeryLongName.self,ShortCommand.self,AnotherCommandWithVeryLongName.self,AnotherCommand.self])
307+
static let configuration = CommandConfiguration(subcommands: [CommandWithVeryLongName.self,ShortCommand.self,AnotherCommandWithVeryLongName.self,AnotherCommand.self])
308308
}
309309

310310
func testHelpWithSubcommands() {
@@ -342,7 +342,7 @@ extension HelpGenerationTests {
342342
}
343343

344344
struct I: ParsableCommand {
345-
static var configuration = CommandConfiguration(version: "1.0.0")
345+
static let configuration = CommandConfiguration(version: "1.0.0")
346346
}
347347

348348
func testHelpWithVersion() {
@@ -358,7 +358,7 @@ extension HelpGenerationTests {
358358
}
359359

360360
struct J: ParsableCommand {
361-
static var configuration = CommandConfiguration(discussion: "test")
361+
static let configuration = CommandConfiguration(discussion: "test")
362362
}
363363

364364
func testOverviewButNoAbstractSpacing() {
@@ -422,7 +422,7 @@ extension HelpGenerationTests {
422422
struct M: ParsableCommand {
423423
}
424424
struct N: ParsableCommand {
425-
static var configuration = CommandConfiguration(subcommands: [M.self], defaultSubcommand: M.self)
425+
static let configuration = CommandConfiguration(subcommands: [M.self], defaultSubcommand: M.self)
426426
}
427427

428428
func testHelpWithDefaultCommand() {

0 commit comments

Comments
 (0)