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

type_contents_order false positive when using custom availability macro in Swift Package #5999

Open
2 tasks done
jarrodrobins opened this issue Feb 13, 2025 · 0 comments
Open
2 tasks done

Comments

@jarrodrobins
Copy link

New Issue Checklist

Bug Description

I have noticed that I am receiving a false positive for type_contents_order when using a custom availability macro in a Swift Package. When I don't use the custom availability macro and just use Apple's built in ones, SwiftLint does not throw a false positive at all.

Here is my Package.swift file defining the availability macro -

// swift-tools-version: 6.0
// The swift-tools-version declares the minimum version of Swift required to build this package.

import PackageDescription

let package = Package(
    name: "SwiftLintRegression",
    platforms: [.iOS(.v15)],
    products: [
        .library(
            name: "SwiftLintRegression",
            targets: ["SwiftLintRegression"]),
    ],
    dependencies: [
        .package(url: "https://github.com/SimplyDanny/SwiftLintPlugins", exact: "0.58.2")
    ],
    targets: [
        .target(
            name: "SwiftLintRegression",
            swiftSettings: [
                .enableExperimentalFeature(
                    "AvailabilityMacro=SwiftUI_v5:iOS 17.0, macOS 14.0, tvOS 17.0, watchOS 10.0, visionOS 1.0" // https://github.com/swiftlang/swift/pull/65218
                )
            ],
            plugins: [.plugin(name: "SwiftLintBuildToolPlugin", package: "SwiftLintPlugins")]
        ),

    ]
)

And here is my sample view which throws the error -

import SwiftUI

struct ContentView: View {
    // type_contents_order violation thrown here
    @available(SwiftUI_v5, *)
    var v5Body: some View {
        EmptyView()
    }

    var body: some View {
        EmptyView()
    }
}

Swapping around the vars does not solve the issue.

If I replace it with the following, the error isn't thrown.

struct ContentView: View {
    @available(iOS 17.0, macOS 14.0, tvOS 17.0, watchOS 10.0, visionOS 1.0, *)
    var v5Body: some View {
        EmptyView()
    }

    var body: some View {
        EmptyView()
    }
}

Environment

  • SwiftLint version: 0.58.2
  • Xcode version: 16.2
  • Installation method used: I have tested both Swift Package Manager and Mint
  • Configuration file:
opt_in_rules:
  - type_contents_order

Are you using nested configurations? If so, paste their
relative paths and respective contents.
N/A

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant