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

Bugfix. NPE in indentation rule(#555) #596

Merged
merged 6 commits into from
Dec 3, 2020
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 @@ -59,8 +59,8 @@ import org.jetbrains.kotlin.psi.psiUtil.siblings
*/
internal class AssignmentOperatorChecker(configuration: IndentationConfig) : CustomIndentationChecker(configuration) {
override fun checkNode(whiteSpace: PsiWhiteSpace, indentError: IndentationError): CheckResult? {
val prevNode = whiteSpace.prevSibling.node
if (prevNode.elementType == EQ && prevNode.treeNext.let { it.elementType == WHITE_SPACE && it.textContains('\n') }) {
val prevNode = whiteSpace.prevSibling?.node
if (prevNode?.elementType == EQ && prevNode.treeNext.let { it.elementType == WHITE_SPACE && it.textContains('\n') }) {
return CheckResult.from(indentError.actual, (whiteSpace.parentIndent()
?: indentError.expected) + (if (configuration.extendedIndentAfterOperators) 2 else 1) * configuration.indentationSize, true)
}
Expand Down Expand Up @@ -256,8 +256,8 @@ internal class CustomGettersAndSettersChecker(config: IndentationConfig) : Custo
*/
internal class ArrowInWhenChecker(configuration: IndentationConfig) : CustomIndentationChecker(configuration) {
override fun checkNode(whiteSpace: PsiWhiteSpace, indentError: IndentationError): CheckResult? {
val prevNode = whiteSpace.prevSibling.node
if (prevNode.elementType == ARROW && whiteSpace.parent is KtWhenEntry) {
val prevNode = whiteSpace.prevSibling?.node
if (prevNode?.elementType == ARROW && whiteSpace.parent is KtWhenEntry) {
return CheckResult.from(indentError.actual, (whiteSpace.parentIndent()
?: indentError.expected) + configuration.indentationSize, true)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,12 @@ httpClient.doRequest()

fun setDefaultUrl(httpClient: HttpClient) {
httpClient.url = "http://example.com"
}

fun foo() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would add check tests too

val diktatExtension = project.extensions.create(DIKTAT_EXTENSION, DiktatExtension::class.java).apply {
inputs = project.fileTree("src").apply {
include("**/*.kt")
}
reporter = PlainReporter(System.out)}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,12 @@ httpClient.doRequest()

fun setDefaultUrl(httpClient: HttpClient) {
httpClient.url = "http://example.com"
}

fun foo() {
val diktatExtension = project.extensions.create(DIKTAT_EXTENSION, DiktatExtension::class.java)
diktatExtension.inputs = project.fileTree("src").apply {
include("**/*.kt")
}
diktatExtension.reporter = PlainReporter(System.out)
}