swiftlang / swift-syntax

A set of Swift libraries for parsing, inspecting, generating, and transforming Swift source code.
Apache License 2.0
3.24k stars 414 forks source link

One Script to rule them all #2066

Closed Matejkob closed 9 months ago

Matejkob commented 1 year ago

Description

If one is making changes to Swift syntax by updating CodeGeneration (or in any other way), and one wants to ensure that all changes have been implemented correctly, all tests are passing, and none of the packages are throwing warnings or errors, has to follow these steps:

Only after completing all these steps, one can be sure that the newly added changes don't impact other parts of the repository.

I find it beneficial to prepare a Swift script that will automate these actions, eliminating the need to remember them all. Running such a script might take a while, so it's probably more useful to do a final check before submitting a PR rather than running it after every change but still I believe it would be cool to have something to rule them all ๐Ÿ˜‡

Matejkob commented 1 year ago

Let me know what you think about this idea.

By the way, if the title is inappropriate, feel free to change it. I couldn't resist using this reference ๐Ÿ™ˆ

ahoppen commented 1 year ago

Tracked in Appleโ€™s issue tracker as rdar://113920485

ahoppen commented 1 year ago

I think adding such an action to the new SwiftSyntaxDevUtils package would be a very good idea.

natikgadzhi commented 1 year ago

Some (hopefully relevant) context that I've learned about how we currently do soundness check in Swift opensource projects:

In https://github.com/apple/swift-nio/pull/2242, @FranzBusch prototyped a Swift Package Manager plugin that would implement a soundness.sh that checks licensing and formatting for SwiftNIO.

SwiftNIO has soundness.sh that's pretty consistent with other SSWG projects, but sometimes there are one-off changes, like the one I made in https://github.com/apple/swift-metrics/pull/134 in swift-metrics because the original soundness.sh fails silently with exit code 0 if swiftformat was not installed. It also does not enforce a specific version of swiftformat.

The formatting that we're using in swift-syntax is different from what SSWG projects use: both the configuration (2 spaces indentation instead of 4), and the tool (SSWG uses SwiftFormat, swift-syntax uses apple/swift-format).

I love the idea of having the checks consolidated in a single script or a SwiftPM plugin (that's perfect!) in a single repository instead of being copied over. But it looks like for SSWG projects, it's not clear where exactly to put the script, and who will then own and maintain it. Obviously, I'm missing a lot of context about this, being a beginner contributor.

I'm also not sure if there is a long-term plan to switch all SSWG repositories to use swift-format.

But, I would love to keep an eye on this and participate in this work โ€”ย @Matejkob, please let me know if I can help you in any way. Perhaps we could prototype it for swift-syntax first, and see how to pitch that to other projects?

Matejkob commented 1 year ago

@natikgadzhi, thank you for your input on this issue. I'm not sure if I've fully conveyed the idea I have in mind in the issue description. So perhaps it would be best if I drafted a PR, and we could continue the discussion there. Personally, I find it much easier to discuss things through code rather than just words. ๐Ÿ˜„

@kimdv, would you mind assigning me to this issue?

Matejkob commented 1 year ago

Blocked by #2063 and #2022