-
Notifications
You must be signed in to change notification settings - Fork 121
As we start integrating in Packwerk, we are wondering how you report violations to the dev.
Our plan was during CI we'd like to parse the reports to let the devs know there is a package/privacy violation. Even a danger plugin could work as well, but they require a machine readable report.
Has anyone needed this feature before?
Line 119 in 0858c42
All reactions
IIRC packwerk check returns machine readable output by default - should be rubocop compatible. That's the format that the VSCode extension uses.
Replies: 3 comments 5 replies
IIRC packwerk check returns machine readable output by default - should be rubocop compatible. That's the format that the VSCode extension uses.
All reactions
The VSCode plugin uses regular expressions to handle parsing. This is something that I can work with, but ideally I'd like formatters similar to Rubocop formatters.
All reactions
It's not super easy right now, but if you implement your own executable based on Packwerk::Cli you can inject a formatter
Line 35 in 3119c47
This hasn't come up a lot so far, so I'm hesitant to add a mechanism to packwerk for this. What would you like the output to look like?
All reactions
Hey @silasb , Alex here from Gusto's Product Infrastructure team. We created the Packwerk VSCode Extension and as you said, we parse the output using regular expressions. We were also wondering if we can be able to pass in a --json flag to bin/packwerk check. As @exterm suggested, we can do this today by doing something like this:
This executes the CLI
formatter = YourModule::YourFancyFormatter.new style = Packwerk::OutputStyles::Coloured.new Packwerk::Cli.new(style: style, offenses_formatter: formatter)
This is an implementation of YourFancyFormatter
# typed: strict # typed: strict module YourModule module YourFancyFormatter extend T::Sig include Packwerk::OffensesFormatter sig { override.params(offenses: T::Array[T.nilable(Packwerk::Offense)]).returns(String) } def show_offenses(offenses) # Here you can do anything you want! # If you want, you can just go right ahead and modify the offenses output to display in a way # that is useful for the engineers at your company. Note that since we're dealing with in-memory # representations of `Packwerk::Offense`, it's inherently machine readable. # However, you can also serialize the array of `Packwerk::Offense` in a JSON format so that other # systems can parse that however they want end end end end
If we wanted packwerk to output JSON, then we could just implement a new formatter in packwerk that is switched to with the --json flag. I do imagine that could be really useful to have, and perhaps the JSON could just be the same exact interface of Packwerk::Offense (i.e. it moves in lockstep with the currently supported public Ruby API for formatters).
I'm curious though if this solution would work for you in an interim state as we learn more about what the JSON public interface should be. If this doesn't solve things, please share what's missing 🙏
All reactions
Hey @silasb check out https://github.com/BigRails/danger-packwerk! We just released this and I hope it can help you. Would love to hear your feedback!
All reactions
Yessss, this looks awesome. Will give this a try in about 2 weeks when we start migrating more code to Packwerk.
All reactions
Sounds great! Looking forward to your feedback on it.
All reactions
Just wanted to provide an update on this – you can now pass in your own custom offenses formatter without too much funny business!
https://github.com/Shopify/packwerk/blob/main/USAGE.md#custom-offense-formatter
All reactions
-
❤️ 1