Skip to content

Commit d45e07b

Browse files
committed
Experimenting with default settings
1 parent a24574a commit d45e07b

File tree

5 files changed

+59
-9
lines changed

5 files changed

+59
-9
lines changed

.swiftpm/xcode/xcshareddata/xcschemes/SwiftFormatterPlugin.xcscheme

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,20 @@
4848
ReferencedContainer = "container:">
4949
</BuildableReference>
5050
</BuildActionEntry>
51+
<BuildActionEntry
52+
buildForTesting = "YES"
53+
buildForRunning = "YES"
54+
buildForProfiling = "YES"
55+
buildForArchiving = "YES"
56+
buildForAnalyzing = "YES">
57+
<BuildableReference
58+
BuildableIdentifier = "primary"
59+
BlueprintIdentifier = "SwiftFormatterPluginDefaults"
60+
BuildableName = "SwiftFormatterPluginDefaults"
61+
BlueprintName = "SwiftFormatterPluginDefaults"
62+
ReferencedContainer = "container:">
63+
</BuildableReference>
64+
</BuildActionEntry>
5165
</BuildActionEntries>
5266
</BuildAction>
5367
<TestAction

Package.swift

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,13 @@ let package = Package(
1414
],
1515

1616
products: [
17+
.library(
18+
name: "SwiftFormatterPluginDefaults",
19+
targets: [
20+
"SwiftFormatterPluginDefaults"
21+
]
22+
),
23+
1724
.plugin(
1825
name: "SwiftFormatterPlugin",
1926
targets: [
@@ -27,9 +34,17 @@ let package = Package(
2734
],
2835

2936
targets: [
37+
.target(
38+
name: "SwiftFormatterPluginDefaults",
39+
40+
resources: [
41+
.copy("Resources/default-config")
42+
]
43+
),
44+
3045
.plugin(
3146
name: "SwiftFormatterPlugin",
32-
47+
3348
capability: .command(
3449
intent: .sourceCodeFormatting(),
3550

@@ -38,7 +53,9 @@ let package = Package(
3853
]
3954
),
4055

56+
4157
dependencies: [
58+
"SwiftFormatterPluginDefaults",
4259
.product(name: "swiftformat", package: "SwiftFormat"),
4360
]
4461
),

Plugins/SwiftFormatterPlugin/SwiftFormatterPlugin.swift

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,26 +5,32 @@
55

66
import Foundation
77
import PackagePlugin
8+
import SwiftFormatterPluginDefaults
89

910
@main
1011
struct FormatterPlugin: CommandPlugin {
1112

1213
func performCommand(context: PluginContext, arguments: [String]) throws {
1314
let swiftFormatTool = try context.tool(named: "swiftformat")
1415
let swiftFormatExec = URL(fileURLWithPath: swiftFormatTool.path.string)
15-
// let configFile = context.package.directory.appending(".swift-format.json")
1616

17+
var baseArguments: [String] = []
18+
let fm = FileManager.default
19+
// let configFile = context.package.directory.appending(".swift-format.json").string
20+
// if fm.fileExists(atPath: configFile) {
21+
// baseArguments.append(contentsOf: ["--config", "\(configFile)"])
22+
// }
23+
24+
1725
for target in context.package.targets {
1826
guard let target = target as? SourceModuleTarget else { continue }
19-
27+
28+
var arguments = baseArguments
29+
arguments.append(target.directory.string)
30+
2031
let process = Process()
2132
process.executableURL = swiftFormatExec
22-
process.arguments = [
23-
// "--configuration", "\(configFile)",
24-
"--in-place",
25-
"--recursive",
26-
"\(target.directory)",
27-
]
33+
process.arguments = arguments
2834
try process.run()
2935
process.waitUntilExit()
3036

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
--indent tab
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
2+
// Created by Sam Deane on 11/07/22.
3+
// All code (c) 2022 - present day, Elegant Chaos Limited.
4+
// -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
5+
6+
import Foundation
7+
8+
public struct SwiftFormatterPluginDefaults {
9+
public static var defaultConfigURL: URL {
10+
return Bundle.module.url(forResource: "default-config", withExtension: nil)!
11+
}
12+
}

0 commit comments

Comments
 (0)