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

SwiftLintCommandPlugin Unknown option '--target' #5603

Closed
kostasniks opened this issue May 24, 2024 · 9 comments · Fixed by #5696 or #5865
Closed

SwiftLintCommandPlugin Unknown option '--target' #5603

kostasniks opened this issue May 24, 2024 · 9 comments · Fixed by #5696 or #5865
Assignees
Labels
enhancement Ideas for improvements of existing features and rules. integration Issues related to integration of SwiftLint into toolchains.

Comments

@kostasniks
Copy link

kostasniks commented May 24, 2024

Describe the bug

Greetings 👋 ,
I used the new CommandPlugin but for some reason when I am running it in one of my packages it results to the following error:

CleanShot 2024-05-24 at 14 34 59
CleanShot 2024-05-24 at 14 35 19
CleanShot 2024-05-24 at 14 32 41

My package.swift looks like this:

// MARK: Networking
        .target(
            name: "Networking",
            dependencies: [],
            plugins: [.plugin(name: "SwiftLintCommandPlugin", package: "SwiftLint")]
        ),

Environment

  • SwiftLint version: 0.55.1
  • Installation method used: Homebrew
  • Paste your configuration file: The default one.
@SimplyDanny
Copy link
Collaborator

The plugin itself doesn't add the --target option, so it must come from Xcode constructing the call. Can you provide the complete commend that Xcode runs?

@SimplyDanny SimplyDanny added the integration Issues related to integration of SwiftLint into toolchains. label Jun 10, 2024
@SimplyDanny SimplyDanny added the repro-needed Issues that cannot be reproduced or miss proper descriptive examples. label Jun 25, 2024
@valougep
Copy link

valougep commented Jul 22, 2024

Hello, Apple's documentation about Plugins says This is commonly used in order to narrow down the application of a command to one or more targets, through the convention of one or more occurrences of a --target option with the name of the target(s) Apple's official documentation.
In your implementation you do not iterate over the targets like Apple does in its code example.
Also in the same documentation it is written: If any targets are chosen in the Xcode user interface, Xcode passes their names as --target arguments to the plugin. So when launching the command from Xcode with a specific target this leads the --target myTarget is added by Xcode as a parameter to the SwiftLint executable and this last is unable to recognize it. Thus the error shown above.
Can you add the target based behavior to the swiftLint exec ? It seems that when getting the target in the plugin the accessortarget.directory returns the path of the files' target which is an easy way to pass which files are needed.

@SimplyDanny SimplyDanny added enhancement Ideas for improvements of existing features and rules. and removed repro-needed Issues that cannot be reproduced or miss proper descriptive examples. labels Jul 24, 2024
@SimplyDanny SimplyDanny self-assigned this Jul 24, 2024
@zkline101
Copy link

I'm using SwiftLintPlugins version 0.56.1 (I also tried 0.57.0) and I am still seeing this problem when using the command plugin:
Screenshot 2024-11-19 at 10 56 07 AM

@SimplyDanny
Copy link
Collaborator

I'm using SwiftLintPlugins version 0.56.1 (I also tried 0.57.0) and I am still seeing this problem when using the command plugin: Screenshot 2024-11-19 at 10 56 07 AM

You're right. The current solution still passes the original list of arguments to the swiftlint command. However, it should only pass the remaining arguments without the --target parameters. #5865 addresses that.

@zkline101
Copy link

Thanks! That helps get rid of the error. I ran the command plugin from within Xcode and didn't see any linter warnings when there should have been. But based on this doc:

The command plugin enables running SwiftLint from the command line

It sounds like the command plugin is only supported from the command line and not from within Xcode. Is that correct?

@SimplyDanny
Copy link
Collaborator

Thanks! That helps get rid of the error. I ran the command plugin from within Xcode and didn't see any linter warnings when there should have been. But based on this doc:

The command plugin enables running SwiftLint from the command line

It sounds like the command plugin is only supported from the command line and not from within Xcode. Is that correct?

That's correct at present. You can, however, run it in a build phase.

@SimplyDanny
Copy link
Collaborator

@zkline101: In case you are interested, with #5867 SwiftLint would be available as an Xcode command plugin as well.

@zkline101
Copy link

Thank you for working on that. I tested it out and I can see the linter warnings in the plug-in command log. Is it possible to get those warnings to show up as they would if you were using the build command? Where the warnings should up as normal warnings would in Xcode.

@SimplyDanny
Copy link
Collaborator

Thank you for working on that. I tested it out and I can see the linter warnings in the plug-in command log. Is it possible to get those warnings to show up as they would if you were using the build command? Where the warnings should up as normal warnings would in Xcode.

The output of both plugin variants should be exactly the same. Might be a problem with Xcode not respecting printed warnings from Xcode Commands Plugins. I don't know if that's intended. In terms of SwiftLint, it doesn't seem like we can do anything about it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Ideas for improvements of existing features and rules. integration Issues related to integration of SwiftLint into toolchains.
Projects
None yet
4 participants