nicklockwood / SwiftFormat

A command-line tool and Xcode Extension for formatting Swift code
MIT License
7.9k stars 639 forks source link

blank-lines option for indent rule. #513

Open r-plus opened 4 years ago

r-plus commented 4 years ago

@nicklockwood Hi, I won't remove white spaces of blank lines by indent rule. What do you think of --blank-lines option? (e.g. remove (default) and ignore)

class A {
....  <- I won't remove this space
....var a: String?
}
nicklockwood commented 4 years ago

@r-plus You can use --disable blankLinesAtStartOfScope to disable the rule that does this.

r-plus commented 4 years ago

@nicklockwood thanks for your response.

sorry, my sample is not good. I have mixed code that have space having blank line and no-space blank line. In this case, indent rule will remove all of the spaces from blank lines.

sample

before format code.

class A {
....
....var a: String?
[empty-line]
....var b: String?
....
}

after the format by $ swiftformat --rules indent --swiftversion 5.1 test.swift

class A {
[empty-line]
....var a: String?
[empty-line]
....var b: String?
[empty-line]
}

I'm won't format about blank lines in this case.

NOTE: swiftformat version 0.42.0

nicklockwood commented 4 years ago

@r-plus you can add the --trimwhitespace nonblank-lines option if you don't want the whitespace in empty lines to be trimmed.

r-plus commented 4 years ago

@nicklockwood with that rule and option by following command

$ swiftformat --rules indent --rules trailingSpace --trimwhitespace nonblank-lines --swiftversion 5.1 test.swift

file will be formatted to

class A {
....
....var a: String?
....  <- changed
....var b: String?
....
}

I won't format about blank lines. So i wanting ignore able option for indent rule for blank lines. How about?

nicklockwood commented 4 years ago

Hmm, this is a pretty obscure use-case. Why do you want the inconsistent whitespace in blank lines to be preserved - is it just to avoid noise in the commit?

r-plus commented 4 years ago

yes, i'm thinking changes of blank lines are not meaningful change for code readability.

ivan-gaydamakin commented 3 years ago

same problem