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

Imports: improve blank line detection #4132

Merged
merged 2 commits into from
Aug 2, 2024
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 @@ -386,7 +386,8 @@ object Imports extends RewriteFactory {
var hadLf = false
val slc = new ListBuffer[Token]
ctx.tokenTraverser.findAtOrBefore(ctx.getIndex(tok) - 1) {
case _: Token.AtEOL => if (hadLf) Some(true) else { hadLf = true; None }
case t: Token.AtEOL =>
if (hadLf || t.newlines > 1) Some(true) else { hadLf = true; None }
case t: Token.Comment if TokenOps.isSingleLineIfComment(t) =>
slc.prepend(t); hadLf = false; None
case _: Token.Whitespace => None
Expand Down
14 changes: 14 additions & 0 deletions scalafmt-tests/src/test/resources/rewrite/Imports.source
Original file line number Diff line number Diff line change
Expand Up @@ -973,3 +973,17 @@ import j.collections as collections
>>>
import java as j
import j.collections as collections
<<< comment and blank before import
rewrite.imports.groups = [["qux"]]
===
package foo {
// c1

import bar.baz
}
>>>
package foo {
// c1

import bar.baz
}
Loading