Skip to content

Commit 8c65ea7

Browse files
authored
Add docs for method-declaration-format and type-parameter-format lint rules (#1198)
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
1 parent d2267ee commit 8c65ea7

File tree

2 files changed

+153
-0
lines changed

2 files changed

+153
-0
lines changed

docs/use/linting.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ pony-lint --version
4444
| `style/match-case-indent` | on | Match case `\|` must align with `match` keyword |
4545
| `style/match-no-single-line` | on | Match expressions must span multiple lines |
4646
| `style/member-naming` | on | Member names should be snake_case |
47+
| `style/method-declaration-format` | on | Multiline method declaration formatting (parameter layout, return type and `=>` alignment) |
4748
| `style/operator-spacing` | on | Binary operators need surrounding spaces; no space after unary `-` |
4849
| `style/package-docstring` | on | Package should have a `<package>.pony` file with a docstring |
4950
| `style/package-naming` | off | Package directory name should be snake_case |
@@ -54,6 +55,7 @@ pony-lint --version
5455
| `style/trailing-whitespace` | on | Trailing spaces or tabs |
5556
| `style/type-alias-format` | on | Multiline type alias formatting (paren placement and spacing) |
5657
| `style/type-naming` | on | Type names should be CamelCase |
58+
| `style/type-parameter-format` | on | Multiline type parameter formatting (bracket placement, layout, and `is` alignment) |
5759

5860
See the [Rule Reference](linting/rule-reference.md) for detailed explanations and code examples for each rule.
5961

docs/use/linting/rule-reference.md

Lines changed: 151 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -467,6 +467,87 @@ class Foo
467467
None
468468
```
469469

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+
470551
## `style/operator-spacing`
471552

472553
**Default:** on
@@ -805,3 +886,73 @@ primitive _MyHelper
805886
806887
actor SomeActor
807888
```
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.
925+
926+
**Correct:**
927+
928+
```pony
929+
// Single-line — not checked
930+
class Foo[A, B]
931+
```
932+
933+
```pony
934+
// Multiline class
935+
class Foo[
936+
A,
937+
B]
938+
```
939+
940+
```pony
941+
// Entity with provides clause
942+
interface Hashable
943+
944+
trait Foo[
945+
A,
946+
B]
947+
is Hashable
948+
```
949+
950+
```pony
951+
// Method type parameters
952+
class Foo
953+
fun bar[
954+
A,
955+
B](x: A)
956+
=>
957+
None
958+
```

0 commit comments

Comments
 (0)