Cette page n'est pas encore disponible en français, sa traduction est en cours. Si vous avez des questions ou des retours sur notre projet de traduction actuel, n'hésitez pas à nous contacter.
Metadata
ID:kotlin-code-style/statement-wrapping
Language: Kotlin
Severity: Notice
Category: Code Style
Description
When using a multi-line statement with a curly brace, you should always put the contained code on a separate line from the curly brace.
The one exception to this is when using a lambda expression.
fundoTask(){if(enabled){spawn()}}valstringified=when(num){10->"Ten"20->"Twenty"else->"Other"}// Single line block statements are ok
valdouble:(Int)->Int={a->a*2}enumclassStatus{OK,ERROR}classWidget{// Comments are ok
valenabled=truevalkind="mechanical"}durations.filter{d>0}.forEach{total+=d}// It's fine to include params on a lamdba
valadd:(Int,Int)->Int={a,b->a+b}
Seamless integrations. Try Datadog Code Security
Datadog Code Security
Try this rule and analyze your code with Datadog Code Security
How to use this rule
1
2
rulesets:- kotlin-code-style # Rules to enforce Kotlin code style.
Create a static-analysis.datadog.yml with the content above at the root of your repository
Use our free IDE Plugins or add Code Security scans to your CI pipelines