Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support sorting array elements, e.g. in Package.swift #1964

Open
simonnickel opened this issue Jan 20, 2025 · 3 comments
Open

Support sorting array elements, e.g. in Package.swift #1964

simonnickel opened this issue Jan 20, 2025 · 3 comments

Comments

@simonnickel
Copy link

simonnickel commented Jan 20, 2025

I have a project with many internal Swift packages inside of it. The rules are properly applied to files in these packages. They are not applied to the Package.swift files of these packages though.

I am trying to sort the list of dependencies in each Package.swift. Using // swiftformat:sort:begin in both places: It works for code files in the package, but not for the Package.swift.

Am I doing something wrong, or is this expected? Is some additional configuration needed to cover these files?

@calda
Copy link
Collaborator

calda commented Jan 20, 2025

Can you share sample code of how you're using the swiftformat:sort:begin directive? The sortDeclaration rule sorts declarations (e.g. properties of types, or top-level global properties) but doesn't support sorting array elements.

@simonnickel
Copy link
Author

An example of a Package.swift file:

Package(
    name: "PackageName",
    products: [
        .library(
            name: "PackageName",
            targets: ["PackageName"]
        ),
    ],
    dependencies: [
        .package(path: "../AnotherPackage"),
        .package(path: "../OtherPackage"),
    ],
    targets: [
        .target(
            name: "PackageName",
            dependencies: [
                "OtherPackage",
                "AnotherPackage",
            ]
        )
    ]
)

The goal is to sort the content of both dependencies arrays.

The sortDeclaration rule sorts declarations (e.g. properties of types, or top-level global properties) but doesn't support sorting array elements.

I guess that's the explanation then. I expected // swiftformat:sort:begin | :end to just sort every line in between.

Is there a way to achieve that?

@calda
Copy link
Collaborator

calda commented Jan 23, 2025

It would definitely be nice to add support for sorting arrays, but that's not implemented currently

@calda calda changed the title Not applied on Package.swift Support sorting array elements, e.g. in Package.swift Jan 23, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants