Skip to content
Merged
Show file tree
Hide file tree
Changes from 21 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-12
runs-on: macos-13
strategy:
matrix:
xcode_version:
- "14.0.1"
- "15.0.1"
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.7
image: swift:5.9
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-12
runs-on: macos-13
strategy:
matrix:
xcode_version:
- "14.0.1"
- "15.0.1"
env:
DEVELOPER_DIR: /Applications/Xcode_${{ matrix.xcode_version }}.app
steps:
Expand Down
6 changes: 0 additions & 6 deletions .swift-format.json
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed deprecated rules.

Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,16 @@
"indentation": {
"spaces": 4
},
"blankLineBetweenMembers": {
"ignoreSingleLineProperties": true
},
"rules": {
"AllPublicDeclarationsHaveDocumentation": false,
"AlwaysUseLowerCamelCase": true,
"AmbiguousTrailingClosureOverload": true,
"BeginDocumentationCommentWithOneLineSummary": true,
"BlankLineBetweenMembers": true,
"DoNotUseSemicolons": true,
"DontRepeatTypeInStaticProperties": true,
"FullyIndirectEnum": true,
"GroupNumericLiterals": true,
"IdentifiersMustBeASCII": true,
"MultiLineTrailingCommas": true,
"NeverForceUnwrap": false,
"NeverUseForceTry": false,
"NeverUseImplicitlyUnwrappedOptionals": true,
Expand All @@ -43,7 +38,6 @@
"OnlyOneTrailingClosureArgument": true,
"OrderedImports": true,
"ReturnVoidInsteadOfEmptyTuple": true,
"UseEnumForNamespacing": true,
"UseLetInEveryBoundCaseVariable": false,
"UseShorthandTypeNames": true,
"UseSingleLinePropertyGetter": true,
Expand Down
8 changes: 2 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,9 @@ 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.5
DOCKER_IMAGE_NAME := swift:5.9

ifeq ($(shell uname), Darwin)
USE_SWIFT_STATIC_STDLIB := $(shell test -d $$(dirname $$(xcrun --find swift))/../lib/swift_static/macosx && echo use_swift_static_stdlib_flag)
ifeq ($(USE_SWIFT_STATIC_STDLIB), use_swift_static_stdlib_flag)
SWIFT_BUILD_FLAGS += -Xswiftc -static-stdlib
endif
Comment on lines -10 to -13
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We cannot pass -static-stdlib under the Darwin env anymore.
Rev: swiftlang/swift-driver#184

SWIFT_BUILD_FLAGS += --arch arm64 --arch x86_64
endif

Expand Down Expand Up @@ -47,7 +43,7 @@ docker-test:
zip: build
install_name_tool -add_rpath @loader_path -add_rpath $(XCODE_DEFAULT_TOOLCHAIN)/usr/lib/swift/macosx $(TOOL_BIN) 2>/dev/null || true
rm -f $(TOOL_NAME).zip
zip -j $(TOOL_NAME).zip $(TOOL_BIN) $(TOOL_BIN_DIR)/lib_InternalSwiftSyntaxParser.dylib LICENSE
zip -j $(TOOL_NAME).zip $(TOOL_BIN) LICENSE

upload-zip: zip
@[ -n "$(GITHUB_TOKEN)" ] || (echo "\nERROR: Make sure setting environment variable 'GITHUB_TOKEN'." && exit 1)
Expand Down
4 changes: 2 additions & 2 deletions Package.resolved

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

6 changes: 3 additions & 3 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// swift-tools-version:5.6
// swift-tools-version:5.9

import PackageDescription

Expand All @@ -14,8 +14,8 @@ let package = Package(
)
],
dependencies: [
.package(url: "https://github.com/apple/swift-syntax", .upToNextMinor(from: "0.50700.0")),
.package(url: "https://github.com/apple/swift-argument-parser", .upToNextMinor(from: "1.1.2")),
.package(url: "https://github.com/apple/swift-syntax", .upToNextMinor(from: "509.0.1")),
.package(url: "https://github.com/apple/swift-tools-support-core.git", from: "0.2.3"),
.package(url: "https://github.com/jpsim/Yams.git", from: "5.0.0")
],
Expand Down Expand Up @@ -46,7 +46,7 @@ let package = Package(
.target(
name: "SwiftModCore",
dependencies: [
.product(name: "SwiftSyntaxParser", package: "swift-syntax"),
.product(name: "SwiftParser", package: "swift-syntax"),
.product(name: "SwiftToolsSupport-auto", package: "swift-tools-support-core"),
"Yams",
]
Expand Down
4 changes: 2 additions & 2 deletions Sources/SwiftModCommands/Runners/RunCommandRunner.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Foundation
import SwiftModCore
import SwiftParser
import SwiftSyntax
import SwiftSyntaxParser
import TSCBasic
import Yams

Expand Down Expand Up @@ -110,7 +110,7 @@ private extension RunCommandRunner {

do {
source = try self.fileSystem.readFileContents(path).cString
syntax = try Syntax(SyntaxParser.parse(source: source))
syntax = Syntax(Parser.parse(source: source))
modifiedSyntax = pipeline.visit(syntax)
}
catch {
Expand Down
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved from ModifierListSyntaxExtensions. (As ModifierListSyntax is deprecated.)

Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import SwiftSyntax

public extension DeclModifierListSyntax {
var hasFinal: Bool {
contains { $0.name.tokenKind == .keyword(.final) }
}

var hasStatic: Bool {
contains { $0.name.tokenKind == .keyword(.static) }
}

var accessLevelModifier: DeclModifierSyntax? {
first { modifier in
switch modifier.name.tokenKind {
case .keyword(.open),
.keyword(.public),
.keyword(.internal),
.keyword(.fileprivate),
.keyword(.private):
return true

default:
return false
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ public extension IdentifierPatternSyntax {
}

private final class IdentifierBackticksRemover: SyntaxRewriter {
override func visit(_ token: TokenSyntax) -> Syntax {
override func visit(_ token: TokenSyntax) -> TokenSyntax {
guard case .identifier(let text) = token.tokenKind else {
return Syntax(token)
return token
}

return Syntax(token.withKind(.identifier(text.replacingOccurrences(of: "`", with: ""))))
return token.with(\.tokenKind, .identifier(text.replacingOccurrences(of: "`", with: "")))
}
}
2 changes: 1 addition & 1 deletion Sources/SwiftModCore/Extensions/IndentExtensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ public extension Indent {
return .spaces(spaces)

case .tab:
return .tabs(1)
return .tab
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: Replacing with shorter trivia syntaxes like .tab / .space / etc. in this PR.

}
}
}
27 changes: 0 additions & 27 deletions Sources/SwiftModCore/Extensions/ModifierListSyntaxExtensions.swift

This file was deleted.

59 changes: 0 additions & 59 deletions Sources/SwiftModCore/Extensions/SyntaxFactoryExtensions.swift
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Goes to TokenSyntaxExtensions (removing some unnecessary signatures).

This file was deleted.

4 changes: 0 additions & 4 deletions Sources/SwiftModCore/Extensions/TokenKindExtensions.swift
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
import SwiftSyntax

public extension TokenKind {
static let openKeywardText = "open"
static let openKeyward = TokenKind.identifier(openKeywardText)
static let finalKeyward = TokenKind.identifier("final")

var isOptional: Bool {
self == .identifier("Optional")
}
Expand Down
47 changes: 45 additions & 2 deletions Sources/SwiftModCore/Extensions/TokenSyntaxExtensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public extension TokenSyntax {

func withLeadingTrivia(_ leadingTrivia: Trivia, condition: Bool) -> TokenSyntax {
if condition {
return withLeadingTrivia(leadingTrivia)
return with(\.leadingTrivia, leadingTrivia)
}
else {
return self
Expand All @@ -20,10 +20,53 @@ public extension TokenSyntax {

func withTrailingTrivia(_ trailingTrivia: Trivia, condition: Bool) -> TokenSyntax {
if condition {
return withTrailingTrivia(trailingTrivia)
return with(\.trailingTrivia, trailingTrivia)
}
else {
return self
}
}

static func replacingTrivia<S: SyntaxProtocol>(
_ node: S,
for token: TokenSyntax,
leading: Trivia? = nil,
trailing: Trivia? = nil
) -> S {
TriviaReplacer(for: token, leading: leading, trailing: trailing)
.rewrite(Syntax(node))
.as(S.self)!
}

static func movingLeadingTrivia<L: SyntaxProtocol, T: SyntaxProtocol>(
leading: L,
for leadingToken: TokenSyntax,
trailing: T,
for trailingToken: TokenSyntax
) -> (leading: L, trailing: T) {
let leading = replacingTrivia(leading, for: leadingToken, leading: trailingToken.leadingTrivia)
let trailing = replacingTrivia(trailing, for: trailingToken, leading: [])
return (leading, trailing)
}
}

private final class TriviaReplacer: SyntaxRewriter {
let token: TokenSyntax
let leading: Trivia
let trailing: Trivia

init(for token: TokenSyntax, leading: Trivia?, trailing: Trivia?) {
self.token = token
self.leading = leading ?? token.leadingTrivia
self.trailing = trailing ?? token.trailingTrivia
}

override func visit(_ token: TokenSyntax) -> TokenSyntax {
guard token == self.token else { return token }

return
token
.with(\.leadingTrivia, leading)
.with(\.trailingTrivia, trailing)
}
}
2 changes: 1 addition & 1 deletion Sources/SwiftModCore/Extensions/TypeSyntaxExtensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import SwiftSyntax

public extension TypeSyntax {
var isOptional: Bool {
if let identifier = self.as(SimpleTypeIdentifierSyntax.self), identifier.name.tokenKind.isOptional {
if let identifier = self.as(IdentifierTypeSyntax.self), identifier.name.tokenKind.isOptional {
return true
}
else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@ public extension VariableDeclSyntax {
}

var hasAccessor: Bool {
bindings.contains { $0.accessor != nil }
bindings.contains { $0.accessorBlock != nil }
}
}
2 changes: 1 addition & 1 deletion Sources/SwiftModCore/Helpers/RulePipeline.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public struct RulePipeline {

public func visit(_ node: Syntax) -> Syntax {
rules.reduce(node) { node, rule in
rule.rewriter().visit(node)
rule.rewriter().rewrite(node)
}
}
}
4 changes: 2 additions & 2 deletions Sources/SwiftModCore/RuleSyntaxRewriter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ open class RuleSyntaxRewriter<Options: Codable>: SyntaxRewriter, RuleSyntaxRewri

public final override func visitAny(_ node: Syntax) -> Syntax? {
// Whether to extract ignore options from comments
let shouldExtractNode = node.is(MemberDeclListItemSyntax.self) || node.is(CodeBlockItemSyntax.self)
let shouldExtractNode = node.is(MemberBlockItemSyntax.self) || node.is(CodeBlockItemSyntax.self)

guard shouldExtractNode, let leadingTrivia = node.firstToken?.leadingTrivia else {
guard shouldExtractNode, let leadingTrivia = node.firstToken(viewMode: .sourceAccurate)?.leadingTrivia else {
return nil
}

Expand Down
Loading