Skip to content

Commit

Permalink
FinalNewlineRule: don't report for empty files
Browse files Browse the repository at this point in the history
  • Loading branch information
t-kameyama committed May 13, 2020
1 parent cb0595b commit 63a7432
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class FinalNewlineRule : Rule("final-newline"), Rule.Modifier.RestrictToRoot {
emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> Unit
) {
if (node.isRoot()) {
if (node.textLength == 0) return
val editorConfig = node.getUserData(KtLint.EDITOR_CONFIG_USER_DATA_KEY)!!
val insertFinalNewline = editorConfig.insertFinalNewline
val lastNode = lastChildNodeOf(node)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,7 @@ class FinalNewlineRuleTest {
"",
mapOf("insert_final_newline" to "true")
)
).isEqualTo(
listOf(
LintError(1, 1, "final-newline", "File must end with a newline (\\n)")
)
)
).isEmpty()
assertThat(
FinalNewlineRule().lint(
"fun name() {\n}",
Expand All @@ -52,6 +48,12 @@ class FinalNewlineRuleTest {
)
).isEmpty()
// false
assertThat(
FinalNewlineRule().lint(
"",
mapOf("insert_final_newline" to "false")
)
).isEmpty()
assertThat(
FinalNewlineRule().lint(
"fun name() {\n}",
Expand Down

0 comments on commit 63a7432

Please # to comment.