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

SwiftLint plugin for SPM doesn't seem to be discoverable #4542

Closed
2 tasks done
jbehrens94 opened this issue Nov 10, 2022 · 9 comments
Closed
2 tasks done

SwiftLint plugin for SPM doesn't seem to be discoverable #4542

jbehrens94 opened this issue Nov 10, 2022 · 9 comments
Labels
help Questions or user problems that require more explanation rather than code changes.

Comments

@jbehrens94
Copy link

New Issue Checklist

Describe the bug

SwiftLint's plugin is not discoverable by SPM through swift package plugin --list. When running the aforementioned command, the swiftlint plugin is not listed.

I added .package(url: "https://github.com/realm/SwiftLint.git", branch: "main") to my SPM dependencies, because 0.50.0-rc.4 gives another error:

Failed to resolve dependencies Dependencies could not be resolved because package 'swiftlint' is required using a stable-version but 'swiftlint' depends on an unstable-version package 'swift-syntax' and root depends on 'swiftlint' 0.50.0-rc.4.

Environment

  • Which Xcode version are you using (check xcodebuild -version)?
xcodebuild -version
Xcode 14.1
Build version 14B47b
swift package --version
Swift Package Manager - Swift 5.7.1
swift --version
swift-driver version: 1.62.15 Apple Swift version 5.7.1 (swiftlang-5.7.1.135.3 clang-1400.0.29.51)
Target: x86_64-apple-macosx13.0
@RemiRodriguesLM
Copy link

Hello, you can target 0.50.0-rc4 using revision :

.package(
    url: "https://github.com/realm/SwiftLint",
    revision: "0e6d19b4c1906e6fbf396172e9a0a22acdf6f86c"
),

However it seems this version don't implement yet CommandBuild to use SwiftLint using command line :

swift package plugin swiftlint

For example, SwiftGen has implemented this command :

swift package plugin generate-code-for-resources

SwiftGen CommandPlugin here : https://github.com/SwiftGen/SwiftGenPlugin/blob/stable/Plugins/SwiftGen-Generate/Plugin.swift

@jbehrens94
Copy link
Author

Oh, so, currently it's only an Xcode plugin?

@RemiRodriguesLM
Copy link

I think yes, CommandPlugin protocol must be implemented to run SwiftLint in command line (useful for CI)

@jpsim
Copy link
Collaborator

jpsim commented Nov 25, 2022

I believe this is the same issue as #4558? Closing as a duplicate, but please let me know if I'm missing something.

@jpsim jpsim closed this as completed Nov 25, 2022
@jpsim jpsim added the help Questions or user problems that require more explanation rather than code changes. label Nov 25, 2022
@jbehrens94
Copy link
Author

There's overlap in the issue with regard to versioning. However, independent of versioning (when I checkout development as branch in SPM) swift package plugin --list doesn't detect SwiftLint as a CLI plugin. I'm guessing that besides an Xcode plugin, there's extra work needed for that.

@jpsim
Copy link
Collaborator

jpsim commented Nov 26, 2022

@technocidal since you added the plugins in #4176, perhaps you're more familiar with what's happening here? And in general, if you wanted to help with plugin-related inbound issues, I'd really appreciate it.

@technocidal
Copy link
Contributor

@jpsim @jbehrens94

I agree with @RemiRodriguesLM. This is due to the missing support to run SwiftLint as a Command Plug-in. Implementing that shouldn't be too hard. I'll try to take a look tomorrow and update this thread with some findings.

@technocidal
Copy link
Contributor

@jpsim @jbehrens94

After a week of some personal stuff I had some time to look into this. You can find my current progress here.

I’ll use many of the improvements that were made to the original Build Tool Plugin implementation like the automatic configuration file discovery etc.

Command Tool Plugins give users the option to provide additional arguments so we’re not that dependent on automatic behavior, but it’s nice to have more sensible defaults.

They also come with their own challenges that I’m currently trying to understand/need feedback.

  • Command Plugins aren’t linked to a specific target like Build Tool Plugins are. Instead they present the user with a list of all targets in your current project/package and let you select as many as you want. This means that it gets a little bit complicated. If we ignore this selection and just use the config files we disregard a users choice which leads to confusion.
  • Additionally Xcode only allows for one instance/configuration of a Command to be configured and doesn’t save any user input in between runs. This means that you can’t create one for your root level configuration and one command for your tests with all the arguments you might want to use. This is a clear argument for doing just some basic target and configuration matching and not parse any additional arguments. This presents some challenges if a target doesn’t have its own config but we might be able to explain that.
  • In contrast to Build Tool Plugins which are wrapped in a shell script and executed directly by Xcode, Command Plugins expect you to do all the necessary work inside the performCommand(context: XcodePluginContext, arguments: [String]) throws function. We're able to get the path to the swiftlint executable but we’ll still need to use the Process API to actually call it. We could also build a “dumbed down" version of swiftlint inside the plugin which would allow us a bit more control. I’m unsure which way would be better.

This is all the stuff that I found until now. I’ll continue working on this throughout the week as I’ve some long-distance train journeys.

@technocidal
Copy link
Contributor

@jpsim @jbehrens94

I've not made any significant progress on this as I was looking into the other more pressing issues with plugins. I don't see an easy way out here and I'm starting to agree with @jpsim that it might be easier to condense our findings into some more documentation and remove the official first-party plugin. It seems like the implementation on Xcode/Swift Package side is not really ready for primetime yet.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help Questions or user problems that require more explanation rather than code changes.
Projects
None yet
Development

No branches or pull requests

4 participants