danger-ruby-swiftlint icon indicating copy to clipboard operation
danger-ruby-swiftlint copied to clipboard

[Question] Add danger-ruby-swift-lint as dependency in other gem

Open wellavelino opened this issue 5 years ago • 2 comments

I was just wondering if it's possible to wrap your plug-in inside another one. I'm trying to call the functions inside a common Ruby file (not sure if it's possible, I'm not too familiar with the danger structure)

It's something like this.

def lint(path) swiftlint.config_file path end

But I couldn't make it work looks like the DSL isn't available in that context only on Dangerfiles.

wellavelino avatar Oct 11 '19 13:10 wellavelino

Great question! What we'd need to do is move most of the logic from danger_plugin.rb into a different file, let's call it swiftlint.rb. The way we'd decide what goes where is this:

  • danger_plugin.rb
    • Extracts all the necessary context from the Danger DSL.
    • Calls function(s) in swiftlint.rb and receives all the violations.
    • Based on violations, make calls to warn, fail, etc.
  • swiftlint.rb
    • Gets passed in all the files specified from the Danger DSL (or, your new plugin 😉).
    • Does the config file and directory setup stuff.
    • Runs swiftlint and returns the violations.

While you work on this refactor, it will be helpful to keep the unit tests alone. It will be helpful for you to have a set of tests that make sure things are still working, as you refactor the code into two files. Afterward, in a separate commit, you could refactor the unit tests (or open an issue to work on them later, since small PRs are better than big ones).

If you're new to Ruby, this might seem a little challenging. But it's also a great way to learn about the language, and I'm here to answer any questions you have. Good luck!

ashfurrow avatar Oct 11 '19 13:10 ashfurrow

Hey @ashfurrow again, thanks for taking the time to answer me. I'll create a branch and start the refactor, I'll keep a PR opened as WIP so I can receive some feedbacks.

👍

wellavelino avatar Oct 14 '19 12:10 wellavelino