Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 38 additions & 4 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
// swift-tools-version: 5.9
// swift-tools-version: 6.0
//===----------------------------------------------------------------------===//
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2019 Apple Inc. and the Swift project authors
// Copyright (c) 2014 - 2025 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See https://swift.org/LICENSE.txt for license information
Expand Down Expand Up @@ -47,7 +47,11 @@ var targets: [Target] = [
+ swiftSyntaxDependencies([
"SwiftOperators", "SwiftParser", "SwiftParserDiagnostics", "SwiftSyntax", "SwiftSyntaxBuilder",
]),
exclude: ["CMakeLists.txt"]
exclude: ["CMakeLists.txt"],
swiftSettings: [
// TODO: Does not compile with Swift 6 in Swift 6 mode due to Swift concurrency bugs. Remove once swift-tools-version is bumped to 6.1.
.swiftLanguageMode(.v5)
]
),
.target(
name: "_SwiftFormatTestSupport",
Expand Down Expand Up @@ -121,6 +125,34 @@ var targets: [Target] = [
),
]

// Apply global Swift settings to targets.
do {
var globalSwiftSettings: [SwiftSetting] = [
// Swift 7 mode upcoming features. These must be compatible with 'swift-tools-version'.
.enableUpcomingFeature("ExistentialAny"),
.enableUpcomingFeature("InternalImportsByDefault"),
.enableUpcomingFeature("MemberImportVisibility"),
.enableUpcomingFeature("NonisolatedNonsendingByDefault"),
]

#if compiler(>=6.1)
globalSwiftSettings.append(
.unsafeFlags(["-Werror", "ExistentialAny"])
)
#endif

globalSwiftSettings += [] // avoid unused warning

for target in targets where target.type != .plugin {
if let swiftSettings = target.swiftSettings {
// Target-specific settings should come last.
target.swiftSettings = globalSwiftSettings + swiftSettings
} else {
target.swiftSettings = globalSwiftSettings
}
}
}

if buildOnlyTests {
products = []
let allowedNames: Set<String> = ["_SwiftFormatTestSupport", "_GenerateSwiftFormat"]
Expand All @@ -146,9 +178,11 @@ let package = Package(
],
products: products,
dependencies: dependencies,
targets: targets
targets: targets,
swiftLanguageModes: [.v5, .v6]
)

@MainActor
func swiftSyntaxDependencies(_ names: [String]) -> [Target.Dependency] {
if buildDynamicSwiftSyntaxLibrary {
return [.product(name: "_SwiftSyntaxDynamic", package: "swift-syntax")]
Expand Down
22 changes: 11 additions & 11 deletions Sources/SwiftFormat/API/Configuration.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2023 Apple Inc. and the Swift project authors
// Copyright (c) 2014 - 2025 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See https://swift.org/LICENSE.txt for license information
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
//
//===----------------------------------------------------------------------===//

import Foundation
public import Foundation

/// A version number that can be specified in the configuration file, which allows us to change the
/// format in the future if desired and still support older files.
Expand All @@ -22,7 +22,7 @@ import Foundation
internal let highestSupportedConfigurationVersion = 1

/// Holds the complete set of configured values and defaults.
public struct Configuration: Codable, Equatable {
public struct Configuration: Codable, Equatable, Sendable {

private enum CodingKeys: CodingKey {
case version
Expand Down Expand Up @@ -176,7 +176,7 @@ public struct Configuration: Codable, Equatable {
public var noAssignmentInExpressions: NoAssignmentInExpressionsConfiguration

/// Determines how trailing commas in comma-separated lists should be handled during formatting.
public enum MultilineTrailingCommaBehavior: String, Codable {
public enum MultilineTrailingCommaBehavior: String, Codable, Sendable {
case alwaysUsed
case neverUsed
case keptAsWritten
Expand Down Expand Up @@ -215,7 +215,7 @@ public struct Configuration: Codable, Equatable {
public var multiElementCollectionTrailingCommas: Bool

/// Determines how multiline string literals should reflow when formatted.
public enum MultilineStringReflowBehavior: String, Codable {
public enum MultilineStringReflowBehavior: String, Codable, Sendable {
/// Never reflow multiline string literals.
case never
/// Reflow lines in string literal that exceed the maximum line length. For example with a line length of 10:
Expand Down Expand Up @@ -320,7 +320,7 @@ public struct Configuration: Codable, Equatable {
self = try jsonDecoder.decode(Configuration.self, from: data)
}

public init(from decoder: Decoder) throws {
public init(from decoder: any Decoder) throws {
let container = try decoder.container(keyedBy: CodingKeys.self)

// If the version number is not present, assume it is 1.
Expand Down Expand Up @@ -463,7 +463,7 @@ public struct Configuration: Codable, Equatable {
?? defaults.rules
}

public func encode(to encoder: Encoder) throws {
public func encode(to encoder: any Encoder) throws {
var container = encoder.container(keyedBy: CodingKeys.self)

try container.encode(version, forKey: .version)
Expand Down Expand Up @@ -524,8 +524,8 @@ public struct Configuration: Codable, Equatable {
}

/// Configuration for the `FileScopedDeclarationPrivacy` rule.
public struct FileScopedDeclarationPrivacyConfiguration: Codable, Equatable {
public enum AccessLevel: String, Codable {
public struct FileScopedDeclarationPrivacyConfiguration: Codable, Equatable, Sendable {
public enum AccessLevel: String, Codable, Sendable {
/// Private file-scoped declarations should be declared `private`.
///
/// If a file-scoped declaration is declared `fileprivate`, it will be diagnosed (in lint mode)
Expand All @@ -547,7 +547,7 @@ public struct FileScopedDeclarationPrivacyConfiguration: Codable, Equatable {
}

/// Configuration for the `NoAssignmentInExpressions` rule.
public struct NoAssignmentInExpressionsConfiguration: Codable, Equatable {
public struct NoAssignmentInExpressionsConfiguration: Codable, Equatable, Sendable {
/// A list of function names where assignments are allowed to be embedded in expressions that are
/// passed as parameters to that function.
public var allowedFunctions: [String] = [
Expand All @@ -561,7 +561,7 @@ public struct NoAssignmentInExpressionsConfiguration: Codable, Equatable {
}

/// Configuration for the `OrderedImports` rule.
public struct OrderedImportsConfiguration: Codable, Equatable {
public struct OrderedImportsConfiguration: Codable, Equatable, Sendable {
/// Determines whether imports within conditional compilation blocks should be ordered.
public var includeConditionalImports: Bool = false

Expand Down
4 changes: 2 additions & 2 deletions Sources/SwiftFormat/API/DebugOptions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2019 Apple Inc. and the Swift project authors
// Copyright (c) 2014 - 2025 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See https://swift.org/LICENSE.txt for license information
Expand All @@ -12,7 +12,7 @@

/// Advanced options that are useful when debugging and developing the formatter, but are otherwise
/// not meant for general use.
public struct DebugOptions: OptionSet {
public struct DebugOptions: OptionSet, Sendable {

/// Disables the pretty-printer pass entirely, executing only the syntax-transforming rules in the
/// pipeline.
Expand Down
8 changes: 4 additions & 4 deletions Sources/SwiftFormat/API/Finding.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2021 Apple Inc. and the Swift project authors
// Copyright (c) 2014 - 2025 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See https://swift.org/LICENSE.txt for license information
Expand Down Expand Up @@ -39,7 +39,7 @@ public struct Finding {
/// an `extension` of the `Finding.Message` type and add `static` properties or functions of type
/// `Finding.Message`; these can be initialized using string literals or string interpolations.
public struct Message:
CustomStringConvertible, ExpressibleByStringLiteral, ExpressibleByStringInterpolation
CustomStringConvertible, ExpressibleByStringLiteral, ExpressibleByStringInterpolation, Sendable
{
/// The message text of the diagnostic.
public var text: String
Expand Down Expand Up @@ -71,7 +71,7 @@ public struct Finding {
}

/// The category associated with the finding.
public let category: FindingCategorizing
public let category: any FindingCategorizing

/// The finding's message.
public let message: Message
Expand All @@ -85,7 +85,7 @@ public struct Finding {
/// Creates a new finding with the given category, message, optional location, and
/// notes.
init(
category: FindingCategorizing,
category: any FindingCategorizing,
message: Message,
location: Location? = nil,
notes: [Note] = []
Expand Down
8 changes: 4 additions & 4 deletions Sources/SwiftFormat/API/Indent.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2019 Apple Inc. and the Swift project authors
// Copyright (c) 2014 - 2025 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See https://swift.org/LICENSE.txt for license information
Expand All @@ -11,7 +11,7 @@
//===----------------------------------------------------------------------===//

/// Represents an indentation unit that is applied to lines that are pretty-printed.
public enum Indent: Hashable, Codable {
public enum Indent: Hashable, Codable, Sendable {

/// An indentation unit equal to the given number of tab characters.
///
Expand All @@ -27,7 +27,7 @@ public enum Indent: Hashable, Codable {
case spaces
}

public init(from decoder: Decoder) throws {
public init(from decoder: any Decoder) throws {
let container = try decoder.container(keyedBy: CodingKeys.self)
let spacesCount = try container.decodeIfPresent(Int.self, forKey: .spaces)
let tabsCount = try container.decodeIfPresent(Int.self, forKey: .tabs)
Expand Down Expand Up @@ -57,7 +57,7 @@ public enum Indent: Hashable, Codable {
)
}

public func encode(to encoder: Encoder) throws {
public func encode(to encoder: any Encoder) throws {
var container = encoder.container(keyedBy: CodingKeys.self)
switch self {
case .tabs(let count):
Expand Down
6 changes: 3 additions & 3 deletions Sources/SwiftFormat/API/Selection.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2024 Apple Inc. and the Swift project authors
// Copyright (c) 2024 - 2025 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See https://swift.org/LICENSE.txt for license information
Expand All @@ -11,10 +11,10 @@
//===----------------------------------------------------------------------===//

import Foundation
import SwiftSyntax
public import SwiftSyntax

/// The selection as given on the command line - an array of offets and lengths
public enum Selection {
public enum Selection: Sendable {
case infinite
case ranges([Range<AbsolutePosition>])

Expand Down
4 changes: 2 additions & 2 deletions Sources/SwiftFormat/API/SwiftFormatError.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2019 Apple Inc. and the Swift project authors
// Copyright (c) 2014 - 2025 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See https://swift.org/LICENSE.txt for license information
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
//
//===----------------------------------------------------------------------===//

import Foundation
public import Foundation
import SwiftSyntax

/// Errors that can be thrown by the `SwiftFormatter` and `SwiftLinter` APIs.
Expand Down
10 changes: 5 additions & 5 deletions Sources/SwiftFormat/API/SwiftFormatter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2024 Apple Inc. and the Swift project authors
// Copyright (c) 2014 - 2025 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See https://swift.org/LICENSE.txt for license information
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
//
//===----------------------------------------------------------------------===//

import Foundation
import SwiftDiagnostics
import SwiftOperators
import SwiftSyntax
public import Foundation
public import SwiftDiagnostics
public import SwiftOperators
public import SwiftSyntax

/// Formats Swift source code or syntax trees according to the Swift style guidelines.
public final class SwiftFormatter {
Expand Down
10 changes: 5 additions & 5 deletions Sources/SwiftFormat/API/SwiftLinter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2019 Apple Inc. and the Swift project authors
// Copyright (c) 2014 - 2025 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See https://swift.org/LICENSE.txt for license information
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
//
//===----------------------------------------------------------------------===//

import Foundation
import SwiftDiagnostics
import SwiftOperators
import SwiftSyntax
public import Foundation
public import SwiftDiagnostics
public import SwiftOperators
public import SwiftSyntax

/// Diagnoses and reports problems in Swift source code or syntax trees according to the Swift style
/// guidelines.
Expand Down
8 changes: 4 additions & 4 deletions Sources/SwiftFormat/Core/Context.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2024 Apple Inc. and the Swift project authors
// Copyright (c) 2014 - 2025 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See https://swift.org/LICENSE.txt for license information
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
//
//===----------------------------------------------------------------------===//

import Foundation
import SwiftOperators
public import Foundation
public import SwiftOperators
import SwiftParser
import SwiftSyntax
public import SwiftSyntax

/// Context contains the bits that each formatter and linter will need access to.
///
Expand Down
Loading
Loading