SwiftLint icon indicating copy to clipboard operation
SwiftLint copied to clipboard

SwiftLintCommandPlugin Unknown option '--target'

Open kostasniks opened this issue 1 year ago • 1 comments

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.

kostasniks avatar May 24 '24 11:05 kostasniks

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 avatar Jun 10 '24 20:06 SimplyDanny

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.

valougep avatar Jul 22 '24 15:07 valougep

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

zkline101 avatar Nov 19 '24 18:11 zkline101

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. https://github.com/realm/SwiftLint/pull/5865 addresses that.

SimplyDanny avatar Nov 19 '24 21:11 SimplyDanny

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?

zkline101 avatar Nov 22 '24 17:11 zkline101

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 avatar Nov 24 '24 12:11 SimplyDanny

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

SimplyDanny avatar Nov 25 '24 21:11 SimplyDanny

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.

zkline101 avatar Dec 02 '24 18:12 zkline101

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.

SimplyDanny avatar Dec 07 '24 13:12 SimplyDanny