title: How to write custom rules for ktlint in kotlin?
body: <p>I have been trying to write custom rules for ktlint. When I try to execute my custom rule via terminal I get no errors, standard rules of ktlint are executed but my custom rules are ignored. May be somebody has any ideas what I am missing?</p>
  
  <p>My build.gradle:</p>
  
  <pre><code>plugins {
  id 'java-library'
  id 'org.jetbrains.kotlin.jvm' version '1.3.40'
  id 'maven'
  }
  
  group 'com.xxx'
  
  repositories {
      mavenCentral()
      jcenter()
  }
  
  configurations {
      ktlint
  }
  
  
  dependencies {
      compileOnly "com.pinterest.ktlint:ktlint-core:0.32.0"
      testCompile "junit:junit:4.12"
      testCompile "org.assertj:assertj-core:3.10.0"
      testCompile "com.pinterest.ktlint:ktlint-core:0.32.0"
      testCompile "com.pinterest.ktlint:ktlint-test:0.32.0"
  }
  
  task ktlint(type: JavaExec, dependsOn: classes) {
      main = 'com.pinterest.ktlint.Main'
      // adding compiled classes to the classpath so that ktlint would validate project's sources
      // using its own ruleset (in other words to dogfood)
      classpath = configurations.ktlint + sourceSets.main.output
      args '--debug', 'src/**/*.kt'
  }
  
  check.dependsOn ktlint
  </code></pre>
  
  <p>My custom rule class (for testing purposes it is supposed to emit always an lint error):</p>
  
  <pre><code>package com.xxx.ktlint
  
  import com.pinterest.ktlint.core.Rule
  import org.jetbrains.kotlin.com.intellij.lang.ASTNode
  
  class TempRule : Rule("no-var") {
  
      override fun visit(
          node: ASTNode,
          autoCorrect: Boolean,
          emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -&gt; Unit
      ) {
          emit(node.startOffset, "#### TEST: KTLINT ERROR", false)
      }
  }
  </code></pre>
  
  <p>My <code>com.pinterest.ktlint.core.RuleSetProvider</code>:</p>
  
  <pre><code>com.xxx.ktlint.CustomRuleSetProvider
  </code></pre>
  
  <p>I create the jar by executing the gradle task "jar" and then I execute ktlint like this in the terminal:</p>
  
  <pre><code>ktlint -R ../path/to/ktlint-rules.jar "path/to/file/**/file-to-be-checked.kt"
  </code></pre>
  
  <p>I get no errors and ktlint applies to the file that should be checked all the standard rules as expected but my custom rules are just ignored. The jar-file itself does not seem to be ignored since when I put a non existing name in the command I get an error.</p>
  
  <p>Any ideas?</p>