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

[iOS]Introduce swift-format #801

Closed
wants to merge 8 commits into from
Closed

[iOS]Introduce swift-format #801

wants to merge 8 commits into from

Conversation

KaitoMuraoka
Copy link
Contributor

Issue

Overview (Required)

I'm still unfamiliar with how to incorporate iOS libraries in KMM, so I'm a bit unsure if this is correct... 😥

日本語 - [Swift-format](https://github.com/apple/swift-format) の導入 私はまだKMMにおいて、iOSのライブラリを入れる方法の仕方について知見がないため、この内容で合っているのか少し不安です😥

Links

Screenshot

Before After

@github-actions github-actions bot temporarily deployed to deploygate-distribution August 20, 2023 12:07 Inactive
@github-actions
Copy link

Test Results

122 tests   122 ✔️  8m 4s ⏱️
    9 suites      0 💤
    9 files        0

Results for commit abe25c2.

@@ -20,9 +20,10 @@ var package = Package(
.package(url: "https://github.com/apple/swift-collections.git", from: "1.0.4"),
.package(url: "https://github.com/apple/swift-algorithms.git", from: "1.0.0"),
.package(url: "https://github.com/apple/swift-async-algorithms.git", from: "0.1.0"),
.package(url: "https://github.com/realm/SwiftLint", from: "0.52.4"),
.package(url: "https://github.com/realm/SwiftLint", from: "0.51.0"),
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The following error occurred:

Failed to resolve dependencies Dependencies could not be resolved because root depends on 'swiftlint' 0.52.4..<1.0.0 and root depends on 'swift-format' 508.0.0..<509.0.0.
'swiftlint' is incompatible with 'swift-format'.
'swiftlint' >= 0.52.4 practically depends on 'swift-syntax' 509.0.0-swift-DEVELOPMENT-SNAPSHOT-2023-07-04-a because 'swiftlint' 0.52.4 depends on 'swift-syntax' 509.0.0-swift-DEVELOPMENT-SNAPSHOT-2023-07-04-a and no versions of 'swiftlint' match the requirement 0.52.5..<1.0.0.
'swift-format' >= 508.0.0 practically depends on 'swift-syntax' 508.0.0..<509.0.0 because 'swift-format' 508.0.0 depends on 'swift-syntax' 508.0.0..<509.0.0 and 'swift-format' 508.0.1 depends on 'swift-syntax' 508.0.0..<509.0.0.
'swift-format' {508.0.0, 508.0.2..<509.0.0} practically depends on 'swift-syntax' 508.0.0..<509.0.0 because no versions of 'swift-format' match the requirement 508.0.2..<509.0.0 and 'swift-format' 508.0.0 depends on 'swift-syntax' 508.0.0..<509.0.0.

From this, I belive we either need to upgrade the version of swift-format or downgrade the version of SwiftLint to match the version of swift-syntax.
However, since the current latest version of swift-format is 508.0.1 and cannot be raised any further, I downgraded the SwiftLint version to 51.0.

日本語 以下のようなエラーが発生しました。
Failed to resolve dependencies Dependencies could not be resolved because root depends on 'swiftlint' 0.52.4..<1.0.0 and root depends on 'swift-format' 508.0.0..<509.0.0.
'swiftlint' is incompatible with 'swift-format'.
'swiftlint' >= 0.52.4 practically depends on 'swift-syntax' 509.0.0-swift-DEVELOPMENT-SNAPSHOT-2023-07-04-a because 'swiftlint' 0.52.4 depends on 'swift-syntax' 509.0.0-swift-DEVELOPMENT-SNAPSHOT-2023-07-04-a and no versions of 'swiftlint' match the requirement 0.52.5..<1.0.0.
'swift-format' >= 508.0.0 practically depends on 'swift-syntax' 508.0.0..<509.0.0 because 'swift-format' 508.0.0 depends on 'swift-syntax' 508.0.0..<509.0.0 and 'swift-format' 508.0.1 depends on 'swift-syntax' 508.0.0..<509.0.0.
'swift-format' {508.0.0, 508.0.2..<509.0.0} practically depends on 'swift-syntax' 508.0.0..<509.0.0 because no versions of 'swift-format' match the requirement 508.0.2..<509.0.0 and 'swift-format' 508.0.0 depends on 'swift-syntax' 508.0.0..<509.0.0.

このことから、swift-format のバージョンを上げるか、SwiftLintのバージョンを下げないと、SwiftSyntac のバージョンに合わせることができないと思います。
しかし、swift-format の現在の最新バージョンは 508.0.1 でこれ以上上げることができないので、SwiftLintのバージョンを51.0までバージョンを下げました。

@KaitoMuraoka KaitoMuraoka marked this pull request as ready for review August 21, 2023 14:10
@KaitoMuraoka KaitoMuraoka requested a review from a team as a code owner August 21, 2023 14:10
@@ -209,6 +210,7 @@ package.targets = package.targets.map { target -> Target in
target.plugins = []
}
target.plugins?.append(.plugin(name: "SwiftLintPlugin", package: "SwiftLint"))
target.plugins?.append(.plugin(name: "SwiftFormatPlugin", package: "swift-format"))
Copy link
Member

Choose a reason for hiding this comment

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

SwiftFormatPlugin isn't a correct name 🙏🏼
Please use FormatPlugin 🙏🏼

https://github.com/apple/swift-format/blob/508.0.1/Package.swift#L37

And format or format-lint isn't succeeded. Can you check it? 🙇🏼

@woxtu
Copy link
Contributor

woxtu commented Aug 23, 2023

The current swift-format doesn't seem to provide any build tools, so adding it to targets as a plugin may not work.
FYI: https://qiita.com/maiyama18/items/3d0f7b288c6858b751ce

@KaitoMuraoka
Copy link
Contributor Author

@woxtu
This is the first time I have heard that it is not possible to write files inside Package. Thank you very much 🎉.


As long as SwiftLint is present, the command plugin didn't work either. Below is the error message I received at that time:

error: Dependencies could not be resolved because root depends on 'swiftlint' 0.52.4..<1.0.0 and root depends on 'swift-format' 508.0.1..<509.0.0.
'swift-format' is incompatible with 'swiftlint' because 'swiftlint' 0.52.4 depends on 'swift-syntax' 509.0.0-swift-DEVELOPMENT-SNAPSHOT-2023-07-04-a and no versions of 'swiftlint' match the requirement 0.52.5..<1.0.0.
'swift-format' >= 508.0.1 practically depends on 'swift-syntax' 508.0.0..<509.0.0 because no versions of 'swift-format' match the requirement 508.0.2..<509.0.0 and 'swift-format' 508.0.1 depends on 'swift-syntax' 508.0.0..<509.0.0.

Thus, by removing SwiftLint and introducing it as a command plugin, it worked without any issues.

However, it only formats a portion of the code.
Below are the files it will format:

- Staff Tests
- SessionTests
- ComponentTests
- SponsorTests
- Session
- Navigation
- Component
- ContributorTests
- KMPContainerTests
- StampsTests
- TimetableTests
- FloorMapTests
- ModelTests
- Timetable
- Sponsor
- FloorMap
- AboutTests
日本語 [Package 内へのファイル書き込みができない](https://qiita.com/maiyama18/items/3d0f7b288c6858b751ce#package-%E5%86%85%E3%81%B8%E3%81%AE%E3%83%95%E3%82%A1%E3%82%A4%E3%83%AB%E6%9B%B8%E3%81%8D%E8%BE%BC%E3%81%BF)のは初めて知りました。ありがとうございます🎉

SwiftLintがある以上、コマンドプラグインでも動作しませんでした。以下はその時に出たエラー文です。

error: Dependencies could not be resolved because root depends on 'swiftlint' 0.52.4..<1.0.0 and root depends on 'swift-format' 508.0.1..<509.0.0.
'swift-format' is incompatible with 'swiftlint' because 'swiftlint' 0.52.4 depends on 'swift-syntax' 509.0.0-swift-DEVELOPMENT-SNAPSHOT-2023-07-04-a and no versions of 'swiftlint' match the requirement 0.52.5..<1.0.0.
'swift-format' >= 508.0.1 practically depends on 'swift-syntax' 508.0.0..<509.0.0 because no versions of 'swift-format' match the requirement 508.0.2..<509.0.0 and 'swift-format' 508.0.1 depends on 'swift-syntax' 508.0.0..<509.0.0.

なので、SwiftLintを抜いて、コマンドプラグインとして導入したら問題なく動作しました。

ただ、一部のコードしかformatしてくれないです。
以下はformatしてくれるファイルです。

- Staff Tests
- SessionTests
- ComponentTests
- SponsorTests
- Session
- Navigation
- Component
- ContributorTests
- KMPContainerTests
- StampsTests
- TimetableTests
- FloorMapTests
- ModelTests
- Timetable
- Sponsor
- FloorMap
- AboutTests

@KaitoMuraoka KaitoMuraoka closed this by deleting the head repository Sep 17, 2023
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

Successfully merging this pull request may close these issues.

[iOS] Introduce swift-format
3 participants