[GSoC] Package.swift indentation rules

Hi there!

Before submitting my proposal I came here to ask some important points related to the mechanically edit Package.swift project idea. During my research on this topic I faced with issues that will be better to discuss with you.

Imagine that we have a well-formed manifest file, a good example is the one that exists in the Swift Package Manager repository. It looks very well from the formatting point view. Moreover it has a nice targets list structure, common targets are separated from the test ones.

And now you want to add a new target using the CLI and here we are stuck with some problems:

  • Indentation rules (new lines, spaces and their quantity) which will be applied to the newly created target expression
  • Structure
  • Creation methods

For the case of indentation I see two options:

  • Use indentation rules that are applied to the last target in the list. On my opinion this will work well for the most of the time
  • Create a pre-defined identation rules and use them regardless of the existing manifest file style

A structure is also an interesting topic. If we modify manifest file like the one from Swift PM repository, it will be better to put newly created common target above all test ones to save existing structure. But I think it will be hard to came to some kind of general solution. Anyway I’m glad to hear you thoughts on this.

For creating a target instance we have two options: use a constructor or use a static method. For static method there is a practice to omit Target type name and use an implicit function call. Based on which rule do we select constructor over static method and omit Target type in the method call?

@Aciid @Xi_Ge Hi! It will be cool if you share your minds on this topic

I think we can provide a way for users to customize indentation and formatting rules for a package. This can be stored in some per-package config file. I wouldn’t worry about indentation too much, we can figure that part out later. For initial implementation, we can try to detect the indentation from the manifest file and use a predefined structure for the new code we insert.

1 Like

I agree with @Aciid. I think Package.swift indentation doesn’t differ from any other Swift file indentation. It may have its own indentation rules for sure, but we can certainly use an all-purpose Swift formatter with a customized format setting. A similar idea is being proposed here.