This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.io.File | |
import java.nio.file.Files.isDirectory | |
fun removeHederTemplate(directoryName: String) { | |
var files = mutableListOf<File>() | |
File(directoryName).listFiles() | |
.forEach { file -> | |
if (file.isFile()) { | |
files.add(file) | |
} else if (file.isDirectory()) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.io.File | |
fun breakLines(directoryName: String) { | |
var files = mutableListOf<File>() | |
File(directoryName).listFiles() | |
.forEach { file -> | |
if (file.isFile()) { | |
files.add(file) | |
} else if (file.isDirectory()) { | |
breakLines(file.getAbsolutePath()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
configurations { | |
ktlint | |
} | |
dependencies { | |
ktlint "com.github.shyiko:ktlint:$KTLINT_VERSION" | |
} | |
check.dependsOn ktlint |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
task ktlint(type: JavaExec, group: "kotlin verification") { | |
description = 'Check Kotlin code style.' | |
args 'src/**/*.kt' | |
main = 'com.github.shyiko.ktlint.Main' | |
classpath = configurations.ktlint + sourceSets.main.output | |
} | |
task ktFormat(type: JavaExec, group: "kotlin Formatting") { | |
description = 'Fix Kotlin code style deviations.' | |
args '-F', 'src/**/*.kt' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class CustomReporter(private val out: PrintStream) : Reporter { | |
private val errors = ArrayList<LintError>() | |
override fun onLintError( | |
file: String, | |
err: LintError, | |
corrected: Boolean) { | |
errors.add(err) | |
} | |
override fun afterAll() { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class CustomReporterProvider : ReporterProvider { | |
override val id: String = “custom-ktlint-reporter" | |
override fun get( | |
out: PrintStream, | |
opt: Map<String, String> | |
): Reporter = CustomReporter(out) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// disable specific rule | |
import package.* // ktlint-disable no-wildcard-imports | |
// disable the whole rule | |
import package.* // ktlint-disable |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[*.{kt,kts}] | |
# possible values: number (e.g. 2), "unset" (makes ktlint ignore indentation completely) | |
indent_size=4 | |
# possible values: number (e.g. 2), "unset" | |
continuation_indent_size=4 | |
# true (recommended) / false | |
insert_final_newline=unset | |
# possible values: number (e.g. 120) (package name, imports & comments are ignored), "off" | |
# it's automatically set to 100 on `ktlint --android ...` (per Android Kotlin Style Guide) | |
max_line_length=off |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class CustomRule : Rule("custom-rule") { | |
override fun visit( | |
node: ASTNode, | |
autoCorrect: Boolean, | |
emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> Unit | |
) { | |
if (isLintError) { | |
emit(node.startOffset, "Lint Error Found!!!", false) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// NG | |
fun add(a: Int, b: Int) = a + b | |
// OK | |
fun add(a: Int, b: Int): Int = a + b |