swiftlang / swift-format

Formatting technology for Swift source code
Apache License 2.0
2.54k stars 229 forks source link

Suggestion: Add configuration init with data instead of url #810

Open doozMen opened 1 month ago

doozMen commented 1 month ago

Hei I'm using, and loving, the formatting tool inside my code generator. I embed the config json file into the code as it is a cli tool that runs on linux. This means in my package manifest i use resources: [.embedInCode(swift_format.json)] which would not produce a url but data.

As the let config = try Configuration(contentsOf: url) only accepts an url would it be ok to make a PR and add an init that accepts data?

My current workaround is to create a temporary file but that seams like inefficient.


  let tempFile = try Folder.temporary
    .createFile(
      named: "swift_format.json",
      contents: Data(PackageResources.swift_format_json))
ahoppen commented 1 month ago

Synced to Apple’s issue tracker as rdar://136347689

andre-richter commented 1 month ago

This could also serve as an enabler for the command-line tool for getting a future extension to pass the config as a string inline, like clang-format's --style="{key: value, ...}" 👍

allevato commented 1 month ago

Which version of the swift-format package are you using? This was added in https://github.com/swiftlang/swift-format/pull/634, so it should be available in the 6.0 release.

This could also serve as an enabler for the command-line tool for getting a future extension to pass the config as a string inline, like clang-format's --style="{key: value, ...}" 👍

The PR above also added this. We should probably update the README to reflect that, instead of just the argument help text.