Skip to content
Merged
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
4 changes: 2 additions & 2 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ on:
jobs:
publish:
name: Publish
runs-on: macos-14
runs-on: macos-15
strategy:
matrix:
xcode_version:
- "15.4"
- "16.4"
env:
DEVELOPER_DIR: /Applications/Xcode_${{ matrix.xcode_version }}.app
steps:
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
name: Test on Linux
runs-on: ubuntu-22.04
container:
image: swift:5.10
image: swift:6.1
steps:
- uses: actions/checkout@v2
- name: Show Environments
Expand All @@ -26,11 +26,11 @@ jobs:
run: make test
macOS:
name: Test on macOS
runs-on: macos-14
runs-on: macos-15
strategy:
matrix:
xcode_version:
- "15.4"
- "16.4"
env:
DEVELOPER_DIR: /Applications/Xcode_${{ matrix.xcode_version }}.app
steps:
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ SWIFT_BUILD_FLAGS := -c release --disable-sandbox
TOOL_NAME := swift-mod
XCODE_DEFAULT_TOOLCHAIN := /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain
GITHUB_REPO := ra1028/$(TOOL_NAME)
DOCKER_IMAGE_NAME := swift:5.10
DOCKER_IMAGE_NAME := swift:6.1

ifeq ($(shell uname), Darwin)
SWIFT_BUILD_FLAGS += --arch arm64 --arch x86_64
Expand Down
18 changes: 9 additions & 9 deletions Package.resolved

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 7 additions & 7 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// swift-tools-version:5.10
// swift-tools-version:6.1

import PackageDescription

Expand All @@ -11,13 +11,13 @@ let package = Package(
.executable(
name: "swift-mod",
targets: ["swift-mod"]
)
),
],
dependencies: [
.package(url: "https://github.com/apple/swift-argument-parser.git", exact: "1.5.0"),
.package(url: "https://github.com/swiftlang/swift-syntax.git", exact: "510.0.3"),
.package(url: "https://github.com/swiftlang/swift-tools-support-core.git", exact: "0.7.1"),
.package(url: "https://github.com/jpsim/Yams.git", exact: "5.1.3")
.package(url: "https://github.com/apple/swift-argument-parser.git", exact: "1.5.1"),
.package(url: "https://github.com/swiftlang/swift-syntax.git", exact: "601.0.1"),
.package(url: "https://github.com/swiftlang/swift-tools-support-core.git", exact: "0.7.3"),
.package(url: "https://github.com/jpsim/Yams.git", exact: "6.0.1")
],
targets: [
.executableTarget(
Expand Down Expand Up @@ -56,5 +56,5 @@ let package = Package(
dependencies: ["SwiftModCore"]
),
],
swiftLanguageVersions: [.v5]
swiftLanguageModes: [.v6]
)
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,7 @@ So you should use swift-mod version that built with compatible version of Swift
|5.8 |0.2.0 |
|5.9 |0.2.0 |
|5.10 |0.2.1 |
|6.1 |0.3.0 |

---

Expand Down
4 changes: 2 additions & 2 deletions Sources/SwiftModCommands/Arguments.swift
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import ArgumentParser
import TSCBasic

public enum Mode: String, CaseIterable, ExpressibleByArgument {
public enum Mode: String, CaseIterable, Sendable, ExpressibleByArgument {
case modify
case dryRun = "dry-run"
case check
}

extension AbsolutePath: ExpressibleByArgument {
extension AbsolutePath: @retroactive ExpressibleByArgument {
public init?(argument: String) {
if let cwd = localFileSystem.currentWorkingDirectory {
try? self.init(validating: argument, relativeTo: cwd)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import SwiftModRules
import TSCBasic

public extension Configuration {
static let template: Configuration = {
nonisolated(unsafe) static let template: Configuration = {
let format = Format(
indent: .spaces(4),
lineBreakBeforeEachArgument: true
Expand Down
2 changes: 1 addition & 1 deletion Sources/SwiftModCommands/InitCommand.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import Foundation
import TSCBasic

public struct InitCommand: ParsableCommand {
public static var configuration = CommandConfiguration(
public static let configuration = CommandConfiguration(
commandName: "init",
abstract: "Generates a modify configuration file."
)
Expand Down
2 changes: 1 addition & 1 deletion Sources/SwiftModCommands/RulesCommand.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import ArgumentParser
import SwiftModCore

public struct RulesCommand: ParsableCommand {
public static var configuration = CommandConfiguration(
public static let configuration = CommandConfiguration(
commandName: "rules",
abstract: "Display the list of rules."
)
Expand Down
2 changes: 1 addition & 1 deletion Sources/SwiftModCommands/RunCommand.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import SwiftModCore
import TSCBasic

public struct RunCommand: ParsableCommand {
public static var configuration = CommandConfiguration(
public static let configuration = CommandConfiguration(
commandName: "run",
abstract: "Runs modification."
)
Expand Down
4 changes: 2 additions & 2 deletions Sources/SwiftModCommands/Runners/RunCommandRunner.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import SwiftSyntax
import TSCBasic
import Yams

internal struct RunCommandRunner {
internal struct RunCommandRunner: @unchecked Sendable {
enum Error: Swift.Error, CustomStringConvertible {
case readOrParseFileFailed(path: AbsolutePath, error: Swift.Error)
case writeFileContentsFailed(path: AbsolutePath, error: Swift.Error)
Expand Down Expand Up @@ -109,7 +109,7 @@ private extension RunCommandRunner {
let modifiedSyntax: Syntax

do {
source = try self.fileSystem.readFileContents(path).cString
source = try fileSystem.readFileContents(path).cString
syntax = Syntax(Parser.parse(source: source))
modifiedSyntax = pipeline.visit(syntax)
}
Expand Down
2 changes: 1 addition & 1 deletion Sources/SwiftModCore/Format.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
public struct Format: Codable, Equatable {
public struct Format: Codable, Equatable, Sendable {
private enum CodingKeys: String, CodingKey {
case indent
case lineBreakBeforeEachArgument
Expand Down
2 changes: 1 addition & 1 deletion Sources/SwiftModCore/Helpers/Atomic.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Foundation

public final class Atomic<Value> {
public final class Atomic<Value>: @unchecked Sendable {
public var value: Value {
get { modify { $0 } }
set { modify { $0 = newValue } }
Expand Down
23 changes: 22 additions & 1 deletion Sources/SwiftModCore/Helpers/InteractiveWriter.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import TSCBasic
@preconcurrency import TSCLibc

public protocol InteractiveWriterProtocol {
func write(_ string: String, inColor color: TerminalController.Color, bold: Bool)
Expand All @@ -10,7 +11,7 @@ public extension InteractiveWriterProtocol {
}
}

public final class InteractiveWriter: InteractiveWriterProtocol {
public final class InteractiveWriter: InteractiveWriterProtocol, @unchecked Sendable {
public static let stdout = InteractiveWriter(stream: stdoutStream)
public static let stderr = InteractiveWriter(stream: stderrStream)

Expand All @@ -33,6 +34,26 @@ public final class InteractiveWriter: InteractiveWriterProtocol {
}
}

private extension InteractiveWriter {
nonisolated(unsafe) static var stdoutStream: ThreadSafeOutputByteStream {
try! ThreadSafeOutputByteStream(
LocalFileOutputByteStream(
filePointer: TSCLibc.stdout,
closeOnDeinit: false
)
)
}

nonisolated(unsafe) static var stderrStream: ThreadSafeOutputByteStream {
try! ThreadSafeOutputByteStream(
LocalFileOutputByteStream(
filePointer: TSCLibc.stderr,
closeOnDeinit: false
)
)
}
}

public final class InMemoryInteractiveWriter: InteractiveWriterProtocol {
public struct Input: Equatable {
public let string: String
Expand Down
2 changes: 1 addition & 1 deletion Sources/SwiftModCore/Helpers/RulePipeline.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import SwiftSyntax

public struct RulePipeline {
public struct RulePipeline: @unchecked Sendable {
private let rules: ContiguousArray<Rule>

public init<S: Sequence>(_ rules: S) where S.Element == Rule {
Expand Down
2 changes: 1 addition & 1 deletion Sources/SwiftModCore/Indent.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
public enum Indent: Codable, Equatable {
public enum Indent: Codable, Equatable, Sendable {
case spaces(Int)
case tab

Expand Down
12 changes: 8 additions & 4 deletions Sources/SwiftModCore/RuleDescription.swift
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
public struct RuleDescription {
public struct RuleDescription: Sendable {
public var name: String
public var priority: RulePriority
public var overview: String
public var exampleOptions: DynamicEncodable
nonisolated(unsafe) public var exampleOptions: DynamicEncodable
public var exampleBefore: String
public var exampleAfter: String

public init<Options: Encodable>(
public init<Options: Sendable & Encodable>(
name: String,
priority: RulePriority,
overview: String,
Expand All @@ -17,7 +17,11 @@ public struct RuleDescription {
self.name = name
self.priority = priority
self.overview = overview
self.exampleOptions = DynamicEncodable(encode: exampleOptions.encode)
self.exampleOptions = DynamicEncodable(
encode: { encoder in
try exampleOptions.encode(to: encoder)
}
)
self.exampleBefore = exampleBefore
self.exampleAfter = exampleAfter
}
Expand Down
2 changes: 1 addition & 1 deletion Sources/SwiftModCore/RulePriority.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
public struct RulePriority: RawRepresentable, Comparable {
public struct RulePriority: RawRepresentable, Comparable, Sendable {
public var rawValue: Int

public static let high = RulePriority(rawValue: 1000)
Expand Down
4 changes: 2 additions & 2 deletions Sources/SwiftModRules/DefaultAccessLevelRule.swift
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,15 @@ public final class DefaultAccessLevelRule: RuleDefinition {
"""
)

public enum AccessLebel: String, Codable {
public enum AccessLebel: String, Codable, Sendable {
case openOrPublic
case `public`
case `internal`
case `fileprivate`
case `private`
}

public struct Options: Codable {
public struct Options: Codable, Sendable {
public var accessLevel: AccessLebel
public var implicitInternal: Bool?

Expand Down
7 changes: 5 additions & 2 deletions Sources/SwiftModRules/DefaultMemberwiseInitializerRule.swift
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public final class DefaultMemberwiseInitializerRule: RuleDefinition {
"""
)

public struct Options: Codable {
public struct Options: Codable, Sendable {
public var implicitInitializer: Bool?
public var implicitInternal: Bool?
public var ignoreClassesWithInheritance: Bool?
Expand Down Expand Up @@ -329,6 +329,8 @@ private extension TypeSyntax {
if self.is(FunctionTypeSyntax.self) {
return TypeSyntax(
AttributedTypeSyntax(
leadingTrivia: nil,
specifiers: [],
attributes: AttributeListSyntax([
.attribute(
AttributeSyntax(
Expand All @@ -338,7 +340,8 @@ private extension TypeSyntax {
)
)
]),
baseType: self
baseType: self,
trailingTrivia: nil
)
)
}
Expand Down
2 changes: 1 addition & 1 deletion Sources/swift-mod/SwiftMod.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import SwiftModCommands

@main
struct SwiftMod: ParsableCommand {
static var configuration = CommandConfiguration(
static let configuration = CommandConfiguration(
commandName: "swift-mod",
abstract: "Modifies Swift source code with rules",
subcommands: [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import SwiftModCore
import XCTest
import Yams

func assertConfigurationCoding(_ configuration: Configuration, file: StaticString = #file, line: UInt = #line) {
func assertConfigurationCoding(_ configuration: Configuration, file: StaticString = #filePath, line: UInt = #line) {
do {
let encoded = try YAMLEncoder().encode(configuration)
let decoded = try YAMLDecoder().decode(Configuration.self, from: encoded)
Expand Down
4 changes: 2 additions & 2 deletions Tests/SwiftModRulesTests/Helpers.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import SwiftModCore
import SwiftParser
import XCTest

func assertRuleDescription(_ rule: AnyRule, file: StaticString = #file, line: UInt = #line) throws {
func assertRuleDescription(_ rule: AnyRule, file: StaticString = #filePath, line: UInt = #line) throws {
let description = type(of: rule).description
let encodedOptions = try? JSONEncoder().encode(description.exampleOptions)
let exampleSyntax = Parser.parse(source: description.exampleBefore)
Expand All @@ -15,7 +15,7 @@ func assertRuleDescription(_ rule: AnyRule, file: StaticString = #file, line: UI
XCTAssertEqual(exampleModified, description.exampleAfter, file: file, line: line)
}

func assertRule(_ rule: AnyRule, source: String, expected: String, file: StaticString = #file, line: UInt = #line) throws {
func assertRule(_ rule: AnyRule, source: String, expected: String, file: StaticString = #filePath, line: UInt = #line) throws {
let syntax = Parser.parse(source: source)
let modified = rule.rewriter().visit(syntax).description
XCTAssertEqual(modified, expected, file: file, line: line)
Expand Down
Loading