DSL markers on no-op type positions
| Diagnostic | DSL_MARKER_NOOP_TYPE_POSITION |
| Default severity | Error |
| Gradle property | dslMarkerNoopTypePosition |
| Exemption | none |
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 BranchDslpublic class Branchpublic 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
@TreeDslpublic class Tagpublic 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