pinterest / ktlint

An anti-bikeshedding Kotlin linter with built-in formatter
https://pinterest.github.io/ktlint/
MIT License
6.07k stars 504 forks source link

Prevent exception in `binary-expression-wrapping` rule #2607

Closed paul-dingemans closed 3 months ago

paul-dingemans commented 3 months ago

Description

Prevent exception in binary-expression-wrapping rule in case it is preceded on the same line by a block comment containing a newline character

Function leavesOnLine calls function getFirstLeafOnLineOrSelf which finds the first leaf on the line by looking for newline character. A block comment containing a newline character resulted in considering that block comment to be the first element on the line, even in case it was preceded by other elements on the same line.

Due to this change, the max-line-length rule failed, which has been resolved by refactoring the calculation of the line length.

Closes #2601

Checklist

Before submitting the PR, please check following (checks which are not relevant may be ignored):

Documentation is updated. See difference between snapshot and release documentation