Skip to content

Navigation Menu

Sign in
Sign up

How do you report violations to devs? #184

Answered by exterm
silasb asked this question in Ideas
Discussion options

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?

def output_result(result)
seems like the critical section to export these reports as machine readable?
You must be logged in to vote

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

Comment options

IIRC packwerk check returns machine readable output by default - should be rubocop compatible. That's the format that the VSCode extension uses.

You must be logged in to vote
2 replies
Comment options

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.

Comment options

It's not super easy right now, but if you implement your own executable based on Packwerk::Cli you can inject a formatter

@offenses_formatter = T.let(offenses_formatter || Formatters::OffensesFormatter.new(style: @style),

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?

Answer selected by silasb
Comment options

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 🙏

You must be logged in to vote
3 replies
Comment options

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!

Comment options

Yessss, this looks awesome. Will give this a try in about 2 weeks when we start migrating more code to Packwerk.

Comment options

Sounds great! Looking forward to your feedback on it.

Comment options

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

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Ideas
Labels
None yet

AltStyle によって変換されたページ (->オリジナル) /