Skip to content

Instantly share code, notes, and snippets.

View TakuSemba's full-sized avatar

TakuSemba TakuSemba

View GitHub Profile
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()) {
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())
configurations {
ktlint
}
dependencies {
ktlint "com.github.shyiko:ktlint:$KTLINT_VERSION"
}
check.dependsOn ktlint
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'
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() {
class CustomReporterProvider : ReporterProvider {
override val id: String = “custom-ktlint-reporter"
override fun get(
out: PrintStream,
opt: Map<String, String>
): Reporter = CustomReporter(out)
}
// disable specific rule
import package.* // ktlint-disable no-wildcard-imports
// disable the whole rule
import package.* // ktlint-disable
[*.{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
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)
}
// NG
fun add(a: Int, b: Int) = a + b
// OK
fun add(a: Int, b: Int): Int = a + b