Skip to content

Commit 4611fbe

Browse files
author
arbitrary-dev
authored
Class/Object/Trait constructors styling proposal
1 parent e796e0f commit 4611fbe

File tree

1 file changed

+24
-18
lines changed

1 file changed

+24
-18
lines changed

_style/declarations.md

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -15,38 +15,44 @@ next-page: scaladoc
1515

1616
Class/Object/Trait constructors should be declared all on one line,
1717
unless the line becomes "too long" (about 100 characters). In that case,
18-
put each constructor argument on its own line, indented **four** spaces:
18+
put each constructor argument on its own line with
19+
[trailing commas](https://docs.scala-lang.org/sips/completed/trailing-commas.html#motivation):
1920

2021
class Person(name: String, age: Int) {
22+
2123
}
2224

2325
class Person(
24-
name: String,
25-
age: Int,
26-
birthdate: Date,
27-
astrologicalSign: String,
28-
shoeSize: Int,
29-
favoriteColor: java.awt.Color) {
30-
def firstMethod: Foo = ...
26+
name: String,
27+
age: Int,
28+
birthdate: Date,
29+
astrologicalSign: String,
30+
shoeSize: Int,
31+
favoriteColor: java.awt.Color,
32+
) {
33+
def firstMethod: Foo = …
3134
}
3235

3336
If a class/object/trait extends anything, the same general rule applies,
3437
put it on one line unless it goes over about 100 characters, and then
35-
indent **four** spaces with each item being on its own line and **two**
36-
spaces for extensions; this provides visual separation between
37-
constructor arguments and extensions:
38+
put each item on its own line with
39+
[trailing commas](https://docs.scala-lang.org/sips/completed/trailing-commas.html#motivation);
40+
closing parenthesis provides visual separation between constructor arguments and extensions;
41+
empty line should be added to further separate extensions from class implementation:
3842

3943
class Person(
40-
name: String,
41-
age: Int,
42-
birthdate: Date,
43-
astrologicalSign: String,
44-
shoeSize: Int,
45-
favoriteColor: java.awt.Color)
46-
extends Entity
44+
name: String,
45+
age: Int,
46+
birthdate: Date,
47+
astrologicalSign: String,
48+
shoeSize: Int,
49+
favoriteColor: java.awt.Color,
50+
) extends Entity
4751
with Logging
4852
with Identifiable
4953
with Serializable {
54+
55+
def firstMethod: Foo = …
5056
}
5157

5258
### Ordering Of Class Elements

0 commit comments

Comments
 (0)