Skip to content

Commit

Permalink
Added support for .editorconfig's end_of_line=native (#225)
Browse files Browse the repository at this point in the history
  • Loading branch information
shyiko committed Jul 23, 2018
1 parent 270584d commit 0de89c6
Showing 1 changed file with 8 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -387,8 +387,14 @@ object KtLint {
}
}

private fun determineLineSeparator(fileContent: String, userData: Map<String, String>) =
if (userData["end_of_line"]?.trim()?.toLowerCase() == "crlf" || fileContent.lastIndexOf('\r') != -1) "\r\n" else "\n"
private fun determineLineSeparator(fileContent: String, userData: Map<String, String>): String {
val eol = userData["end_of_line"]?.trim()?.toLowerCase()
return when {
eol == "native" -> System.lineSeparator()
eol == "crlf" || eol != "lf" && fileContent.lastIndexOf('\r') != -1 -> "\r\n"
else -> "\n"
}
}

/**
* @param range zero-based range of lines where lint errors should be suppressed
Expand Down

0 comments on commit 0de89c6

Please sign in to comment.