forked from ktlint/ktlint.github.io
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
809 lines (703 loc) · 35.3 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="description" content="An anti-bikeshedding Kotlin linter with built-in formatter.">
<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0">
<title>ktlint</title>
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto:regular,bold,thin,light,black,medium&lang=en">
<link rel="stylesheet" href="https://fonts.googleapis.com/icon?family=Material+Icons">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/prism/1.6.0/themes/prism.min.css">
<link rel="stylesheet" href="https://code.getmdl.io/1.3.0/material.min.css">
<link rel="stylesheet" href="index.css">
</head>
<body>
<div class="mdl-layout mdl-js-layout mdl-layout--fixed-header docs-layout mdl-layout--no-desktop-drawer-button">
<!-- header -->
<div class="ktlint-header mdl-layout__header mdl-layout__header--waterfall mdl-layout__header--waterfall-hide-top">
<div class="mdl-layout__header-row">
<span class="ktlint-pn ktlint-title mdl-layout-title">ktlint</span>
<div class="ktlint-header-spacer mdl-layout-spacer"></div>
<div class="ktlint-navigation-container">
<nav class="ktlint-navigation mdl-navigation">
<a class="mdl-navigation__link mdl-typography--text-uppercase" href="#getting-started">Getting Started</a>
<a class="mdl-navigation__link mdl-typography--text-uppercase" href="#rules">Rules</a>
<a class="mdl-navigation__link mdl-typography--text-uppercase" href="#faq">FAQ</a>
<a class="mdl-navigation__link mdl-typography--text-uppercase" href="https://github.com/pinterest/ktlint">GitHub</a>
</nav>
</div>
</div>
</div>
<!-- header/drawer -->
<div class="ktlint-drawer mdl-layout__drawer">
<nav class="mdl-navigation">
<a class="mdl-navigation__link" href="#getting-started">Getting Started</a>
<a class="mdl-navigation__link" href="#rules">Rules</a>
<a class="mdl-navigation__link" href="#faq">FAQ</a>
<a class="mdl-navigation__link" href="https://github.com/pinterest/ktlint">GitHub</a>
</nav>
</div>
<!-- welcome -->
<div class="mdl-layout__content">
<a name="top"></a>
<div class="ktlint-be-together-section mdl-typography--text-center">
<div class="logo-font ktlint-slogan">
<span class="ktlint-pn ktlint-slogn--box">ktlint</span>
</div>
<div class="logo-font ktlint-sub-slogan">An anti-bikeshedding Kotlin linter with built-in formatter.</div>
</div>
<!-- survey -->
<div id="getting-started" class="ktlint-screen-section getting-started-section mdl-typography--text-center">
<div class="mdl-typography--display-1-color-contrast ktlint-category">User survey</div>
<div class="ktlint-content">
<p>Interested in providing your feedback about ktlint? Fill out our <a href="https://forms.gle/FPv2VkHyDsMJDvPG7">2019 user survey.</a></p>
</div>
</div>
<!-- getting-started -->
<div id="getting-started" class="ktlint-screen-section getting-started-section mdl-typography--text-center">
<div class="mdl-typography--display-1-color-contrast ktlint-category">Getting Started</div>
<div class="ktlint-content">
<div class="mdl-tabs mdl-js-tabs mdl-js-ripple-effect">
<!-- getting-started/tabs -->
<div class="mdl-tabs__tab-bar ktlint-getting-started">
<a href="#command-line" class="mdl-tabs__tab is-active">Command Line</a>
<a href="#maven" class="mdl-tabs__tab">Maven</a>
<a href="#gradle" class="mdl-tabs__tab">Gradle</a>
</div>
<!-- getting-started/command-line tab -->
<div class="mdl-tabs__panel is-active mdl-typography--text-left" id="command-line">
<h2 class="mdl-typography--headline mdl-typography--subhead">Installation</h2>
<div class="snippet-code">
<pre><code class=" language-bash">curl -sSLO https://github.com/pinterest/ktlint/releases/download/0.34.2/ktlint && chmod a+x ktlint
# you can also download ktlint manually from https://github.com/pinterest/ktlint/releases
# another option is "brew install ktlint"
# verify PGP signature (optional but recommended)
curl -sS https://keybase.io/pinterestandroid/pgp_keys.asc | gpg --import
curl -sSLO https://github.com/pinterest/ktlint/releases/download/0.34.2/ktlint.asc
gpg --verify ktlint.asc</code></pre>
</div>
<h2 class="mdl-typography--headline mdl-typography--subhead">Usage</h2>
<div class="snippet-code">
<pre><code class=" language-bash"># check the style of all Kotlin files inside the current dir (recursively)
# (hidden folders will be skipped)
$ ktlint
src/main/kotlin/Main.kt:10:10: Unused import
# check only certain locations (prepend ! to negate the pattern)
$ ktlint "src/**/*.kt" "!src/**/*Test.kt"
# auto-correct style violations
# (if some errors cannot be fixed automatically they will be printed to stderr)
$ ktlint -F "src/**/*.kt"
# print style violations grouped by file
$ ktlint --reporter=plain?group_by_file
# print style violations as usual + create report in checkstyle format
$ ktlint --reporter=plain --reporter=checkstyle,output=ktlint-report-in-checkstyle-format.xml
# install git hook to automatically check files for style violations on commit
$ ktlint --install-git-pre-commit-hook</code></pre>
</div>
</div>
<!-- getting-started/maven tab -->
<div class="mdl-tabs__panel mdl-typography--text-left" id="maven">
<h2 class="mdl-typography--headline mdl-typography--subhead">Integration</h2>
<p>Add the following snippet to pom.xml (inside <span style="color: slategray"><build><plugins>...</plugins></build></span>)
<div class="snippet-code">
<pre><code class=" language-markup"><plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.7</version>
<executions>
<execution>
<id>ktlint</id>
<phase>verify</phase>
<configuration>
<target name="ktlint">
<java taskname="ktlint" dir="${basedir}" fork="true" failonerror="true"
classname="com.pinterest.ktlint.Main" classpathref="maven.plugin.classpath">
<arg value="src/**/*.kt"/>
<!-- to generate report in checkstyle format prepend following args: -->
<!--
<arg value="--reporter=plain"/>
<arg value="--reporter=checkstyle,output=${project.build.directory}/ktlint.xml"/>
-->
<!-- see https://github.com/pinterest/ktlint#usage for more -->
</java>
</target>
</configuration>
<goals><goal>run</goal></goals>
</execution>
<execution>
<id>ktlint-format</id>
<configuration>
<target name="ktlint">
<java taskname="ktlint" dir="${basedir}" fork="true" failonerror="true"
classname="com.pinterest.ktlint.Main" classpathref="maven.plugin.classpath">
<arg value="-F"/>
<arg value="src/**/*.kt"/>
</java>
</target>
</configuration>
<goals><goal>run</goal></goals>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>com.pinterest</groupId>
<artifactId>ktlint</artifactId>
<version>0.34.2</version>
</dependency>
<!-- additional 3rd party ruleset(s) can be specified here -->
</dependencies>
</plugin></code></pre>
</div>
<h2 class="mdl-typography--headline mdl-typography--subhead">Usage</h2>
<div class="snippet-code">
<pre><code class=" language-bash"># check code style (it's also bound to "mvn verify")
$ mvn antrun:run@ktlint
src/main/kotlin/Main.kt:10:10: Unused import
# fix code style deviations (runs built-in formatter)
$ mvn antrun:run@ktlint-format</code></pre>
</div>
</div>
<!-- getting-started/gradle tab -->
<div class="mdl-tabs__panel mdl-typography--text-left" id="gradle">
<h2 class="mdl-typography--headline mdl-typography--subhead">Integration</h2>
<h2 class="mdl-typography--headline mdl-typography--subhead">Plugins (Recommended)</h2>
<p>There are few community-driven plugins (in order of appearance):
<ul class="mdl-list gradle-thirdparty-list">
<li class="mdl-list__item mdl-list__item--two-line">
<span class="mdl-list__item-primary-content">
<span><a href="https://github.com/jlleitschuh/ktlint-gradle">jlleitschuh/ktlint-gradle</a></span>
<span class="mdl-list__item-sub-title">
Gradle plugin that automatically creates check and format tasks for project Kotlin sources,
supports different kotlin plugins and Gradle build caching.
</span>
</span>
</li>
<li class="mdl-list__item mdl-list__item--two-line">
<span class="mdl-list__item-primary-content">
<span><a href="https://github.com/jeremymailen/kotlinter-gradle">jeremymailen/kotlinter-gradle</a></span>
<span class="mdl-list__item-sub-title">
Gradle plugin featuring incremental build support, file reports, .kt & .kts source support.
</span>
</span>
</li>
<li class="mdl-list__item mdl-list__item--two-line">
<span class="mdl-list__item-primary-content">
<span><a href="https://github.com/diffplug/spotless/tree/master/plugin-gradle#applying-ktlint-to-kotlin-files">diffplug/spotless</a></span>
<span class="mdl-list__item-sub-title">
Spotless is not really a plugin, it's a standalone project that happens to have a built-in ktlint support.
In addition to linting/formatting kotlin code it allows you to keep license headers, markdown documentation, etc. in check.
</span>
</span>
</li>
</ul>
<h2 class="mdl-typography--headline mdl-typography--subhead">Without Plugins</h2>
<p>Add the following snippet to build.gradle
<div class="snippet-code">
<pre><code class=" language-groovy">apply plugin: "java"
repositories {
jcenter()
}
configurations {
ktlint
}
dependencies {
ktlint "com.pinterest:ktlint:0.34.2"
// additional 3rd party ruleset(s) can be specified here
// just add them to the classpath (ktlint 'groupId:artifactId:version') and
// ktlint will pick them up
}
task ktlint(type: JavaExec, group: "verification") {
description = "Check Kotlin code style."
main = "com.pinterest.ktlint.Main"
classpath = configurations.ktlint
args "src/**/*.kt"
// to generate report in checkstyle format prepend following args:
// "--reporter=plain", "--reporter=checkstyle,output=${buildDir}/ktlint.xml"
// see https://github.com/pinterest/ktlint#usage for more
}
check.dependsOn ktlint
task ktlintFormat(type: JavaExec, group: "formatting") {
description = "Fix Kotlin code style deviations."
main = "com.pinterest.ktlint.Main"
classpath = configurations.ktlint
args "-F", "src/**/*.kt"
}</code></pre>
</div>
<h4 class="mdl-typography--headline mdl-typography--subhead">Usage</h4>
<div class="snippet-code">
<pre><code class=" language-bash"># check code style (it's also bound to "gradle check")
$ gradle ktlint
src/main/kotlin/Main.kt:10:10: Unused import
# fix code style deviations (runs built-in formatter)
$ gradle ktlintFormat</code></pre>
</div>
</div>
</div>
</div>
</div>
<!-- rules -->
<div id="rules" class="ktlint-screen-section">
<div class="mdl-typography--display-1-color-contrast mdl-typography--text-center ktlint-category">Rules</div>
<div class="ktlint-content">
<section id="rule-indentation">
<div class="mdl-grid">
<div class="mdl-cell mdl-cell--2-col mdl-cell--12-col-phone">
<h3><a href="#rule-indentation">4 spaces for indentation*.</a></h3>
</div>
<div class="mdl-cell mdl-cell--10-col mdl-cell--12-col-phone">
<div class="snippet-header snippet-good">
<div class="snippet-captions">
<div class="snippet-caption">
<span class="snippet-hint">Do.</span>
</div>
</div>
</div>
<div class="snippet-code snipper-code-good">
<pre><code class="language-kotlin">data class C(
val a: Any,
val b: Any = 0,
val c: Any
) {}
</code></pre>
</div>
<div class="snippet-header snippet-bad">
<div class="snippet-captions">
<div class="snippet-caption">
<span class="snippet-hint">Don't.</span>
</div>
</div>
</div>
<div class="snippet-code snipper-code-bad">
<pre><code class="language-kotlin">data class C(val a: Any,
val b: Any = 0,
val c: Any) {
}</code></pre>
</div>
<p style="font-size: 14px; text-align: left; color: slategray;">
* Starting from <a href="https://github.com/shyiko/ktlint/releases/tag/0.8.0">0.8.0</a> value of indent_size specified under
[*{kt,kts}] section in <a href="http://editorconfig.org/">.editorconfig</a> takes precedence (if any).
Official recommendation is to use 4 spaces, though. (see <a href="https://github.com/shyiko/ktlint/issues/43#issuecomment-304953280">#43</a> for details)
</p>
</div>
</div>
</section>
<section id="rule-semi">
<div class="mdl-grid">
<div class="mdl-cell mdl-cell--2-col mdl-cell--12-col-phone">
<h3><a href="#rule-semi">No semicolons.</a></h3>
</div>
<div class="mdl-cell mdl-cell--10-col mdl-cell--12-col-phone">
<div class="snippet-header snippet-good">
<div class="snippet-captions">
<div class="snippet-caption">
<span class="snippet-hint">Do.</span>
</div>
</div>
</div>
<div class="snippet-code snipper-code-good">
<pre><code class="language-kotlin">val v = ""
println(v)
// semicolons used to separate multiple statements on the same line are OK
// try avoid though
fn({ v -> println(v); v * 10 })</code></pre>
</div>
<div class="snippet-header snippet-bad">
<div class="snippet-captions">
<div class="snippet-caption">
<span class="snippet-hint">Don't.</span>
</div>
</div>
</div>
<div class="snippet-code snipper-code-bad">
<pre><code class="language-kotlin">val v = "";
println(v);</code></pre>
</div>
</div>
</div>
</section>
<section id="rule-import">
<div class="mdl-grid">
<div class="mdl-cell mdl-cell--2-col mdl-cell--12-col-phone">
<h3><a href="#rule-import">No wildcard / unused imports.</a></h3>
</div>
<div class="mdl-cell mdl-cell--10-col mdl-cell--12-col-phone">
<div class="snippet-header snippet-good">
<div class="snippet-captions">
<div class="snippet-caption">
<span class="snippet-hint">Do.</span>
</div>
</div>
</div>
<div class="snippet-code snipper-code-good">
<pre><code class="language-kotlin">import io.vertx.core.Vertx
import com.google.Guice
import com.google.Injector</code></pre>
</div>
<div class="snippet-header snippet-bad">
<div class="snippet-captions">
<div class="snippet-caption">
<span class="snippet-hint">Don't.</span>
</div>
</div>
</div>
<div class="snippet-code snipper-code-bad">
<pre><code class="language-kotlin">import io.vertx.core.*
import com.google.inject.*
import pkg.UnusedClass
</code></pre>
</div>
</div>
</div>
</section>
<section id="rule-blank">
<div class="mdl-grid">
<div class="mdl-cell mdl-cell--2-col mdl-cell--12-col-phone">
<h3><a href="#rule-blank">No consecutive blank lines.</a></h3>
</div>
<div class="mdl-cell mdl-cell--10-col mdl-cell--12-col-phone">
<div class="snippet-header snippet-good">
<div class="snippet-captions">
<div class="snippet-caption">
<span class="snippet-hint">Do.</span>
</div>
</div>
</div>
<div class="snippet-code snipper-code-good">
<pre><code class="language-kotlin">class A {}
class B {}
</code></pre>
</div>
<div class="snippet-header snippet-bad">
<div class="snippet-captions">
<div class="snippet-caption">
<span class="snippet-hint">Don't.</span>
</div>
</div>
</div>
<div class="snippet-code snipper-code-bad">
<pre><code class="language-kotlin">// this in not a Python and you are not in PEP 8 realm
class A {}
class B {}
</code></pre>
</div>
</div>
</div>
</section>
<section id="rule-trailing-whitespaces">
<div class="mdl-grid">
<div class="mdl-cell mdl-cell--2-col mdl-cell--12-col-phone">
<h3><a href="#rule-trailing-whitespaces">No trailing whitespaces.</a></h3>
</div>
<div class="mdl-cell mdl-cell--10-col mdl-cell--12-col-phone">
<div class="snippet-header snippet-good">
<div class="snippet-captions">
<div class="snippet-caption">
<span class="snippet-hint">Do.</span>
</div>
</div>
</div>
<div class="snippet-code snipper-code-good">
<pre><code class="language-kotlin">class A {}
class B {}</code></pre>
</div>
<div class="snippet-header snippet-bad">
<div class="snippet-captions">
<div class="snippet-caption">
<span class="snippet-hint">Don't.</span>
</div>
</div>
</div>
<div class="snippet-code snipper-code-bad">
<pre><code class="language-kotlin">class A {}⋅⋅⋅
class B {}⋅</code></pre>
</div>
<p style="font-size: 14px; text-align: left; color: slategray;">
* If you don't use <a href="http://editorconfig.org/#download">EditorConfig</a> it's a good time to start.
</p>
</div>
</div>
</section>
<section id="rule-unit-return">
<div class="mdl-grid">
<div class="mdl-cell mdl-cell--2-col mdl-cell--12-col-phone">
<h3><a href="#rule-unit-return">No Unit returns.</a></h3>
</div>
<div class="mdl-cell mdl-cell--10-col mdl-cell--12-col-phone">
<div class="snippet-header snippet-good">
<div class="snippet-captions">
<div class="snippet-caption">
<span class="snippet-hint">Do.</span>
</div>
</div>
</div>
<div class="snippet-code snipper-code-good">
<pre><code class="language-kotlin">fun f() {}</code></pre>
</div>
<div class="snippet-header snippet-bad">
<div class="snippet-captions">
<div class="snippet-caption">
<span class="snippet-hint">Don't.</span>
</div>
</div>
</div>
<div class="snippet-code snipper-code-bad">
<pre><code class="language-kotlin">fun f(): Unit {}</code></pre>
</div>
</div>
</div>
</section>
<section id="rule-unit-return">
<div class="mdl-grid">
<div class="mdl-cell mdl-cell--2-col mdl-cell--12-col-phone">
<h3><a href="#rule-empty-class-body">No empty class bodies.</a></h3>
</div>
<div class="mdl-cell mdl-cell--10-col mdl-cell--12-col-phone">
<div class="snippet-header snippet-good">
<div class="snippet-captions">
<div class="snippet-caption">
<span class="snippet-hint">Do.</span>
</div>
</div>
</div>
<div class="snippet-code snipper-code-good">
<pre><code class="language-kotlin">class A
interface B</code></pre>
</div>
<div class="snippet-header snippet-bad">
<div class="snippet-captions">
<div class="snippet-caption">
<span class="snippet-hint">Don't.</span>
</div>
</div>
</div>
<div class="snippet-code snipper-code-bad">
<pre><code class="language-kotlin">class A {}
interface B {}</code></pre>
</div>
</div>
</div>
</section>
<section id="rule-unit-return">
<div class="mdl-grid">
<div class="mdl-cell mdl-cell--2-col mdl-cell--12-col-phone">
<h3><a href="#rule-string-template">Consistent string templates.</a></h3>
</div>
<div class="mdl-cell mdl-cell--10-col mdl-cell--12-col-phone">
<div class="snippet-header snippet-good">
<div class="snippet-captions">
<div class="snippet-caption">
<span class="snippet-hint">Do.</span>
</div>
</div>
</div>
<div class="snippet-code snipper-code-good">
<pre><code class="language-kotlin">val a = "class = ${String::class}"
val b = "not $a"</code></pre>
</div>
<div class="snippet-header snippet-bad">
<div class="snippet-captions">
<div class="snippet-caption">
<span class="snippet-hint">Don't.</span>
</div>
</div>
</div>
<div class="snippet-code snipper-code-bad">
<pre><code class="language-kotlin">val a = "class = ${String::class.toString()}"
val b = "not ${a}"</code></pre>
</div>
</div>
</div>
</section>
<section id="rule-modifier-order">
<div class="mdl-grid">
<div class="mdl-cell mdl-cell--2-col mdl-cell--12-col-phone">
<h3><a href="#rule-modifier-order">Consistent order of modifiers.</a></h3>
</div>
<div class="mdl-cell mdl-cell--10-col mdl-cell--12-col-phone">
<div class="snippet-header snippet-good">
<div class="snippet-captions">
<div class="snippet-caption">
<span class="snippet-hint">Do.</span>
</div>
</div>
</div>
<div class="snippet-code snipper-code-good">
<pre><code class="language-kotlin">internal abstract class A {
protected open val v = ""
internal open suspend fun f(v: Any): Any = ""
public lateinit var lv: String
abstract tailrec fun findFixPoint(x: Double = 1.0): Double
}
class B : A() {
public override val v = ""
suspend override fun f(v: Any): Any = ""
tailrec override fun findFixPoint(x: Double): Double
= if (x == Math.cos(x)) x else findFixPoint(Math.cos(x))
}</code></pre>
</div>
<div class="snippet-header snippet-bad">
<div class="snippet-captions">
<div class="snippet-caption">
<span class="snippet-hint">Don't.</span>
</div>
</div>
</div>
<div class="snippet-code snipper-code-bad">
<pre><code class="language-kotlin">abstract internal class A {
open protected val v = ""
open suspend internal fun f(v: Any): Any = ""
lateinit public var lv: String
tailrec abstract fun findFixPoint(x: Double = 1.0): Double
}
class B : A() {
override public val v = ""
override suspend fun f(v: Any): Any = ""
override tailrec fun findFixPoint(x: Double): Double
= if (x == Math.cos(x)) x else findFixPoint(Math.cos(x))
}</code></pre>
</div>
</div>
</div>
</section>
<section id="rule-spacing">
<div class="mdl-grid">
<div class="mdl-cell mdl-cell--2-col mdl-cell--12-col-phone">
<h3><a href="#rule-spacing">Consistent spacing.</a></h3>
</div>
<div class="mdl-cell mdl-cell--10-col mdl-cell--12-col-phone">
<div class="snippet-header snippet-good">
<div class="snippet-captions">
<div class="snippet-caption">
<span class="snippet-hint">Do.</span>
</div>
</div>
</div>
<div class="snippet-code snipper-code-good">
<pre><code class="language-kotlin">val short = ""
val long = ""
val v = a - b * c
class A : B, C {}
if (true) {}
@file:JvmName("Main")
class A : B
call(object : C() {})
fun fn(@field:F a: Any, b: Any, c: Any): Any
val v: String = str()
if (ok) { /* .. */ }
fn({ v -> f(v) * g(v) })
emptyList<String>().find { true }!!.hashCode()
find { it.default ?: false }?.phone</code></pre>
</div>
<div class="snippet-header snippet-bad">
<div class="snippet-captions">
<div class="snippet-caption">
<span class="snippet-hint">Don't.</span>
</div>
</div>
</div>
<div class="snippet-code snipper-code-bad">
<pre><code class="language-kotlin">// multiple spaces after "val long" for vertical alignment
val short = ""
val long = ""
// no spacing around operators
val v=a-b*c
// no space after the comma
class A : B,C {}
// no spacing after keyword ("if" in this case)
if(true) {}
// incorrect spacing around ":"
@file: JvmName("Main")
class A:B
call(object: C() {})
fun fn(@field: F a:Any, b:Any, c:Any):Any
val v:String = str()
// missing spacing around "{" and before "}"
if (true){/* .. */}
// missing spacing after "{" and before "}"
fn({v -> f(v) * g(v)}!!)
// unnecessary space after "}"
emptyList<String>().find { true } !!.hashCode()
find { it.default ?: false } ?.phone</code></pre>
</div>
</div>
</div>
</section>
</div>
</div>
<!-- faq -->
<div id="faq" class="ktlint-screen-section faq-section">
<div class="mdl-typography--display-1-color-contrast mdl-typography--text-center ktlint-category">FAQ</div>
<div class="ktlint-content">
<!-- faq/why -->
<h2 id="faq-why" class="faq-q mdl-typography--headline mdl-typography--subhead"><i class="material-icons faq-icon">fiber_manual_record</i><a class="faq-q--link" href="#faq-why">Why should I use ktlint?</a></h2>
<div class="faq-a">
<p>
<strong>Simplicity</strong>.
<p>Spending time on configuration (& maintenance down the road) of hundred-line long style config file(s) is counter-productive.
Instead of wasting your energy on something that has no business value - focus on what really matters (not debating whether to use
tabs or spaces).
<p>By using ktlint you put the importance of code clarity and community conventions over personal preferences.
This makes things easier for people reading your code as well as frees you from having to document &
explain what style potential contributor(s) have to follow.
<p>ktlint is a single binary with both linter & formatter included. All you need is to drop it in (no need to
get <a href="https://en.wikipedia.org/wiki/decision_fatigue">overwhelmed</a> while choosing
among <a href="http://checkstyle.sourceforge.net/checks.html">dozens of code style options</a>).
</div>
<!-- faq/ruleset -->
<h2 id="faq-ruleset" class="faq-q mdl-typography--headline mdl-typography--subhead"><i class="material-icons faq-icon">fiber_manual_record</i><a class="faq-q--link" href="#faq-ruleset">Can I have my own rules on top of ktlint?</a></h2>
<div class="faq-a">
<p>Absolutely, "no configuration" doesn't mean "no extensibility". You can add your own ruleset(s) to discover potential bugs, check for anti-patterns, etc.
<p>See <a href="https://github.com/pinterest/ktlint#creating-a-ruleset">Creating A Ruleset</a> on GitHub.
</div>
<!-- faq/error-suppression -->
<h2 id="faq-error-suppression" class="faq-q mdl-typography--headline mdl-typography--subhead"><i class="material-icons faq-icon">fiber_manual_record</i><a class="faq-q--link" href="#faq-error-suppression">How do I suppress an error?</a></h2>
<div class="faq-a">
<p style="color: slategray;">
This is meant primarily as an escape latch for the rare cases when ktlint is not able to produce the correct result (please report any such instances using <a href="https://github.com/pinterest/ktlint/issues">GitHub Issues</a>).
<p>To disable a specific rule you'll need to turn on the verbose mode (ktlint --verbose ...). At the end of each line you'll see an error code. Use it as an argument for ktlint-disable directive (shown below).
<div class="snippet-code">
<pre><code class="language-kotlin">import package.* // ktlint-disable no-wildcard-imports
/* ktlint-disable no-wildcard-imports */
import package.a.*
import package.b.*
/* ktlint-enable no-wildcard-imports */</code></pre>
</div>
<p>To disable all checks:
<div class="snippet-code">
<pre><code class="language-kotlin">import package.* // ktlint-disable</code></pre>
</div>
</div>
<!-- faq/globally-disable -->
<h2 id="faq-/globally-disable" class="faq-q mdl-typography--headline mdl-typography--subhead"><i class="material-icons faq-icon">fiber_manual_record</i><a class="faq-q--link" href="#faq-globally-disable">How do I globally disable a rule?</a></h2>
<div class="faq-a">
<p>See the <a href="https://github.com/pinterest/ktlint#editorconfig">EditorConfig</a> section on GitHub. You may also use the --disabled_rules command line flag.
</div>
</div>
</div>
<footer class="mdl-mini-footer ktlint-footer">
<div class="mdl-mini-footer__left-section">
<div class="mdl-logo"><i class="material-icons">favorite</i></div>
<!--<ul class="mdl-mini-footer__link-list">
<li><a href="#">Help</a></li>
<li><a href="#">Privacy & Terms</a></li>
</ul>-->
</div>
</footer>
</div>
<script src="https://code.getmdl.io/1.3.0/material.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/prism/1.6.0/prism.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/prism/1.6.0/components/prism-bash.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/prism/1.6.0/components/prism-kotlin.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/prism/1.6.0/components/prism-markup.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/prism/1.6.0/components/prism-groovy.min.js"></script>
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','https://www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-35914342-6', 'auto');
ga('send', 'pageview');
</script>
</body>
</html>