Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable final new line by default #446

Merged
merged 1 commit into from
Jun 3, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ interface EditorConfig {
val indentSize: Int
val tabWidth: Int
val maxLineLength: Int
val insertFinalNewline: Boolean?

val insertFinalNewline: Boolean
fun get(key: String): String?

companion object {
Expand All @@ -26,7 +25,7 @@ interface EditorConfig {
}
val tabWidth = map["indent_size"]?.toIntOrNull()
val maxLineLength = map["max_line_length"]?.toIntOrNull() ?: -1
val insertFinalNewline = map["insert_final_newline"]?.toBoolean()
val insertFinalNewline = map["insert_final_newline"]?.toBoolean() ?: true
return object : EditorConfig {
override val indentStyle = indentStyle
override val indentSize = indentSize
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class FinalNewlineRule : Rule("final-newline"), Rule.Modifier.RestrictToRoot {
) {
if (node.isRoot()) {
val editorConfig = node.getUserData(KtLint.EDITOR_CONFIG_USER_DATA_KEY)!!
val insertFinalNewline = editorConfig.insertFinalNewline ?: return
val insertFinalNewline = editorConfig.insertFinalNewline
val lastNode = lastChildNodeOf(node)
if (insertFinalNewline) {
if (lastNode !is PsiWhiteSpace || !lastNode.textContains('\n')) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@ class FinalNewlineRuleTest {
@Test
fun testLint() {
// neither true nor false
assertThat(FinalNewlineRule().lint("fun name() {\n}")).isEmpty()
assertThat(FinalNewlineRule().lint("fun name() {\n}")).isEqualTo(
listOf(
LintError(1, 1, "final-newline", "File must end with a newline (\\n)")
)
)
assertThat(FinalNewlineRule().lint("fun name() {\n}\n")).isEmpty()
// true
assertThat(
Expand Down