// What an `init` DECLARATION line looks like, for the sweeps that need to find // one (ScaffoldSweepTests). It lived in CapabilityGateSweepTests.swift until that // sweep moved to vitest (scripts/__tests__/swift-sweep-capability-gate.test.ts, // which holds the same rule in TypeScript); keep the two in step. import XCTest enum InitDeclarations { /// An `init` DECLARATION — never `.init(` in an expression, and never /// `SomeType(` that happens to end in those four letters. static func isInitDeclaration(_ line: String) -> Bool { let trimmed = line.trimmingCharacters(in: .whitespaces) guard let range = trimmed.range(of: "init(") else { return false } let before = trimmed[trimmed.startIndex.. = [ "public", "private", "internal", "fileprivate", "package", "required", "convenience", "override", "nonisolated", "@MainActor", ] return before.split(separator: " ").allSatisfy { allowed.contains(String($0)) } } } final class InitDeclarationsTests: XCTestCase { func testReadsAnInitDeclarationAndNotACall() { XCTAssertTrue(InitDeclarations.isInitDeclaration(" public init(core: Core) {")) XCTAssertFalse(InitDeclarations.isInitDeclaration(" let x = Model.init(a: 1)")) XCTAssertFalse(InitDeclarations.isInitDeclaration(" _model = State(initialValue: m)")) } }