-
Notifications
You must be signed in to change notification settings - Fork 221
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
Cannot invoke plugins from command line #483
Comments
Lucian do you have a pointer to the package plugin you're working with? |
The ones included in swift-format: https://github.com/apple/swift-format/tree/main/Plugins (in the above example, I'm using the linter plugin) |
I see, there are no tests for those in the project. Nice. You can use "swift package edit swift-format" and then go in and add printing to the place where the command is issued, to see what it's actually trying to do. |
My guess is that this thing should not be trying to use |
When invoking the lint command in Xcode the plugin is being passed the project directory, hence the The lint plugin is hardcoded with The default of using |
I'm going to open a PR for the The command plugins operate on a target, currently, not a directory. So you need to tell it what target to lint. For example: This mirrors the behavior of the Xcode plugin, if you want to run |
Maybe I'm misunderstanding the logic I described here, but by my reading it looks like it would seem to work in “normal” projects, but break in unusual projects, e.g. when there are non-target swift files in the same directory as Swift files. I also think you should reconsider whether it's really right to submit whole directories to swift-format. |
I can confirm that adding Does this tool make sense to be run at the directory level? (in any case, I would argue that we need to fix the tool to properly indicate the user the need of specifying a target) |
In the context of using a plugin though the target that is passed is the directory that the target code lives in. It doesn't seem to have any other way of passing a location. It also though only seems to read When running as a standalone tool, |
That's very strange. The plug-in I built gets passed individual files: https://github.com/dabrahams/citron/blob/ecfdaf5db81dcea8c7162f85e6defc5a7052b618/Plugins/CitronParserGenerator/CitronParserGenerator.swift |
Ahh, that helps immensely and I can get the source files now from the target. When using Honestly I don't have a lot of use for the lint command plugin as the warnings don't show up in Xcode as they aren't build warnings. For that we need a BuildPlugin. I'll make a new issue for the removal of For the scope of this particular ticket it seems that calling a Command Plugin without a target specified was the actual issue. I think that can probably be fixed with documentation on how to call a command plugin from the CLI. |
Opened PR #489 for the |
@lucteo @macshome I would suggest the plugin should pick all the targets in the absence of specific targets. Instead of this: we should have this: let targetsToFormat = targetNames.isEmpty ? context.package.targets : try context.package.targets(named: targetNames) |
Default to all targets when plugin `--target` parameter missing. Fix #483
…s-fix-483 Default to all targets when plugin `--target` parameter missing. Fix swiftlang#483
Hi
I'm trying to add swift-format to our project; we aim at being able to run this manually, and from our CI pipeline.
swift-format is added as a dependency in our Package.swift. (in my tests, I'm using
0.50800.0-SNAPSHOT-2022-12-29-a
tag).If I run "Lint Source Code" or "Format Source Code" from XCode, everything works ok.
However, If I try to run it from command line, I get the following errors:
Can you please help me make this work?
Thank you very much
The text was updated successfully, but these errors were encountered: