Skip to content

Commit

Permalink
Fix internal error on "no-multi-spaces" rule (#817)
Browse files Browse the repository at this point in the history
* fixed "no-multi-spaces" rule to correctly handle multiple spaces in the beginning of the file (#803)

* simplified null check on a KDoc node verification to avoid extra method creation (#803)

Co-authored-by: sasha <[email protected]>
  • Loading branch information
lazysasha and sasha authored Jul 20, 2020
1 parent 427e2ae commit f697547
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class NoMultipleSpacesRule : Rule("no-multi-spaces") {
// allow multiple spaces in KDoc in case of KDOC_TAG for alignment, e.g.
// @param foo stuff
// @param foobar stuff2
!(node.treePrev.elementType == KDOC_MARKDOWN_LINK && node.treeParent.elementType == KDOC_TAG)
!(node.treePrev?.elementType == KDOC_MARKDOWN_LINK && node.treeParent?.elementType == KDOC_TAG)
) {
emit(node.startOffset + 1, "Unnecessary space(s)", true)
if (autoCorrect) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,14 @@ class NoMultipleSpacesRuleTest {
""".trimIndent()
assertThat(NoMultipleSpacesRule().format(code)).isEqualTo(code)
}

@Test
fun `test multiple spaces in the beginning of the file`() {
assertThat(NoMultipleSpacesRule().lint(" package my.company.android"))
.isEqualTo(
listOf(
LintError(1, 2, "no-multi-spaces", "Unnecessary space(s)")
)
)
}
}

0 comments on commit f697547

Please sign in to comment.