File tree Expand file tree Collapse file tree 2 files changed +20
-12
lines changed
Plugins/SwiftFormatterPlugin Expand file tree Collapse file tree 2 files changed +20
-12
lines changed Original file line number Diff line number Diff line change @@ -14,13 +14,6 @@ let package = Package(
1414 ] ,
1515
1616 products: [
17- . library(
18- name: " SwiftFormatterPluginDefaults " ,
19- targets: [
20- " SwiftFormatterPluginDefaults "
21- ]
22- ) ,
23-
2417 . plugin(
2518 name: " SwiftFormatterPlugin " ,
2619 targets: [
Original file line number Diff line number Diff line change @@ -14,11 +14,11 @@ struct FormatterPlugin: CommandPlugin {
1414 let swiftFormatExec = URL ( fileURLWithPath: swiftFormatTool. path. string)
1515
1616 var baseArguments : [ String ] = [ ]
17- // let fm = FileManager.default
18- // let configFile = context.package.directory.appending(".swift-format.json ").string
19- // if fm .fileExists(atPath: configFile) {
20- // baseArguments.append(contentsOf: ["--config", "\(configFile)" ])
21- // }
17+
18+ let configFile = context. package . directory. appending ( " .swiftformat " ) . string
19+ if !FileManager . default . fileExists ( atPath: configFile) {
20+ baseArguments. append ( contentsOf: [ " --config " , defaultConfigPath ] )
21+ }
2222
2323
2424 for target in context. package . targets {
@@ -41,4 +41,19 @@ struct FormatterPlugin: CommandPlugin {
4141 }
4242 }
4343 }
44+
45+ var defaultConfigPath : String {
46+ let path = ( " ~/.swiftformat " as NSString ) . expandingTildeInPath
47+ if !FileManager. default. fileExists ( atPath: path) {
48+ let defaultConfig = """
49+ # Place your default swift-format configuration options here.
50+ # See https://github.com/nicklockwood/SwiftFormat#config-file for more details.
51+
52+ """
53+
54+ try ? defaultConfig. write ( toFile: path, atomically: true , encoding: . utf8)
55+ }
56+
57+ return path
58+ }
4459}
You can’t perform that action at this time.
0 commit comments