Skip to content

Adding custom rules to my own project #747

Answered by petertrr
vorobeij asked this question in Q&A
Discussion options

You must be logged in to vote

Hi, @SJOwl !
Yes, you can use diktat-test-framework as a dependency for testing your rules. It's a pretty generic framework that doesn't even depend on ktlint, so you'll need something like our FixTestBase: basically, there are two things:

  • TestComparatorUnit is set up to run ktlint's format method
  • TestComparatorUnit.compareFilesFromResources is called to run and compare output

Alternatively, you can include your rules in diktat itself: diktat uses the same rules format as ktlint, so providing a jar with your rules as a classpath dependency for diktat-gradle-plugin should be enough. To do so you can include it in diktat configuration that is created when applying diktat plugin, like that…

Replies: 2 comments 26 replies

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
26 replies
@akuleshov7
Comment options

@lyharrietbui
Comment options

@lyharrietbui
Comment options

@akuleshov7
Comment options

@lyharrietbui
Comment options

Answer selected by akuleshov7
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
4 participants