Skip to main content

DSL markers on no-op type positions

DiagnosticDSL_MARKER_NOOP_TYPE_POSITION
Default severityError
Gradle propertydslMarkerNoopTypePosition
Exemptionnone

What it reports​

A DSL marker directly on one of these types:

  • A regular parameter type.
  • A function return type.
  • A property type.
  • A local variable type.
@DslMarker
@Target(
AnnotationTarget.CLASS,
AnnotationTarget.TYPE,
AnnotationTarget.TYPEALIAS,
)
public annotation class BranchDsl
public class Branch
public fun append(branch: @BranchDsl Branch) { }

Rationale​

DSL scope control restricts implicit receivers. A marker on a named value doesn't prevent calls to an outer receiver.

Don't​

public fun configure(block: Tag.() -> Unit): @TreeDsl String = ""

Do​

@TreeDsl
public class Tag
public fun configure(block: Tag.() -> Unit): String = ""

Notes​

The check applies to declarations of any visibility. It skips:

  • Function types with a receiver or context parameters.
  • Receiver and context parameter types, supertypes, type parameter bounds, and type alias expansions.
  • Nested type arguments, such as List<@TreeDsl Tag>.

Configuration​

build.gradle.kts
apiWatchdog {
dslMarkerNoopTypePosition = WatchdogSeverity.ERROR
}

For a direct compiler call:

-P plugin:org.jetbrains.kotlinx.library.api.watchdog:diagnosticSeverity=DSL_MARKER_NOOP_TYPE_POSITION:error

See also​