You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Add docs for method-declaration-format and type-parameter-format lint rules
Two new pony-lint rules were added in ponylang/ponyc#4892. This adds
the corresponding table entries in the linting overview and detailed
rule reference sections with examples.
Closes#1195
Copy file name to clipboardExpand all lines: docs/use/linting/rule-reference.md
+151Lines changed: 151 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -467,6 +467,87 @@ class Foo
467
467
None
468
468
```
469
469
470
+
## `style/method-declaration-format`
471
+
472
+
**Default:** on
473
+
474
+
Checks formatting of multiline method declarations. When a method's parameters span multiple lines, each parameter must be on its own line. When a method declaration spans multiple lines, the return type `:` must be indented one level (2 spaces) from the method keyword, and the `=>` must align with the method keyword. Single-line declarations are not checked.
475
+
476
+
Applies to `fun`, `new`, and `be` declarations.
477
+
478
+
**Incorrect:**
479
+
480
+
```pony
481
+
class Foo
482
+
fun find(
483
+
value: U32, offset: USize)
484
+
: USize
485
+
=>
486
+
offset
487
+
```
488
+
489
+
Two parameters share a line.
490
+
491
+
```pony
492
+
class Foo
493
+
fun find(
494
+
value: U32,
495
+
offset: USize)
496
+
: USize
497
+
=>
498
+
offset
499
+
```
500
+
501
+
The `:` is indented too far — it should be at the method keyword's column + 2.
502
+
503
+
```pony
504
+
class Foo
505
+
fun find(
506
+
value: U32,
507
+
offset: USize)
508
+
: USize
509
+
=>
510
+
offset
511
+
```
512
+
513
+
The `=>` is indented too far — it should align with `fun`.
514
+
515
+
**Correct:**
516
+
517
+
```pony
518
+
class Foo
519
+
fun find(
520
+
value: U32,
521
+
offset: USize)
522
+
: USize
523
+
=>
524
+
offset
525
+
```
526
+
527
+
```pony
528
+
// Constructor
529
+
class Foo
530
+
let _x: U32
531
+
let _y: U32
532
+
533
+
new create(
534
+
x: U32,
535
+
y: U32)
536
+
=>
537
+
_x = x
538
+
_y = y
539
+
```
540
+
541
+
```pony
542
+
// Behavior
543
+
actor Foo
544
+
be apply(
545
+
x: U32,
546
+
y: U32)
547
+
=>
548
+
None
549
+
```
550
+
470
551
## `style/operator-spacing`
471
552
472
553
**Default:** on
@@ -805,3 +886,73 @@ primitive _MyHelper
805
886
806
887
actor SomeActor
807
888
```
889
+
890
+
## `style/type-parameter-format`
891
+
892
+
**Default:** on
893
+
894
+
Checks formatting of multiline type parameter lists. The opening `[` must always be on the same line as the entity or method name. When type parameters span multiple lines, each type parameter must be on its own line. For entities with a provides clause (`is`), the `is` keyword must be indented one level (2 spaces) from the entity keyword when it appears on its own line. Single-line type parameter lists are not checked (except for the `[` same-line requirement, which always applies).
895
+
896
+
Applies to entities (`class`, `actor`, `primitive`, `struct`, `trait`, `interface`, `type`) and methods (`fun`, `new`, `be`).
897
+
898
+
**Incorrect:**
899
+
900
+
```pony
901
+
class Foo
902
+
[A, B]
903
+
```
904
+
905
+
The `[` is on a different line than the name.
906
+
907
+
```pony
908
+
class Foo[
909
+
A, B,
910
+
C]
911
+
```
912
+
913
+
Two type parameters share a line.
914
+
915
+
```pony
916
+
interface Hashable
917
+
918
+
class Foo[
919
+
A,
920
+
B]
921
+
is Hashable
922
+
```
923
+
924
+
The `is` keyword is indented too far — it should be at the entity keyword's column + 2.
0 commit comments