Skip to content

CastToNullableType: highlights too much #5346

@TWiStErRob

Description

@TWiStErRob

Expected Behavior

Highlight either the as keyword or the nullable type, maybe even just the question-mark.

Observed Behavior

Whole expression on the left of the cast is highlighted.
image

Steps to Reproduce

Any expression really, but it shows most when the casted thing is a chain of functional code

listOf("fieldName").map {
	// very long code
	String::class.java.getDeclaredField(it).get(null)
}.first() as String?

Context

Pretty much the same as #5316, but a different rule.

Your Environment

  • Version of detekt used: 1.21.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions