DSL markers with no-op targets
| Diagnostic | DSL_MARKER_NOOP_TARGET |
| Default severity | Error |
| Gradle property | dslMarkerNoopTarget |
| Exemption | @IntentionallyWrongDslMarkerTargetsForBackwardsCompatibility |
What it reports
Each explicit @Target entry on a @DslMarker annotation outside this set:
CLASS.ANNOTATION_CLASS.TYPE.TYPEALIAS.
@DslMarker@Target(AnnotationTarget.CLASS, AnnotationTarget.FUNCTION)public annotation class MyDsl
Rationale
DSL scope control ignores markers on functions and properties. Such targets let callers apply markers that don't restrict outer receivers.
Don't
// This is the shape that broke Ktor's @KtorDsl (KTOR-8901).@DslMarker@Target(AnnotationTarget.CLASS,AnnotationTarget.TYPEALIAS,AnnotationTarget.TYPE,AnnotationTarget.FUNCTION,)public annotation class KtorDsl
Do
@DslMarker@Target(AnnotationTarget.CLASS,AnnotationTarget.TYPE,AnnotationTarget.TYPEALIAS,)public annotation class KtorDsl
Notes
- The check applies to markers of any visibility.
- For missing or empty targets, DSL markers without explicit targets applies.
Exemption
If this is intended, apply
@IntentionallyWrongDslMarkerTargetsForBackwardsCompatibility to the DSL marker.
Use the exemption if a narrower target set on a published marker rejects existing user code:
@IntentionallyWrongDslMarkerTargetsForBackwardsCompatibility@DslMarker@Target(AnnotationTarget.CLASS, AnnotationTarget.FUNCTION)public annotation class KtorDsl
The annotation doesn't have a reason parameter. Its description is optional.
Configuration
build.gradle.kts
apiWatchdog {dslMarkerNoopTarget = WatchdogSeverity.ERROR}
For a direct compiler call:
-P plugin:org.jetbrains.kotlinx.library.api.watchdog:diagnosticSeverity=DSL_MARKER_NOOP_TARGET:error