Skip to content

Class/Object/Trait constructors styling proposal #1284

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 21, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 24 additions & 18 deletions _style/declarations.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,38 +15,44 @@ next-page: scaladoc

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

class Person(name: String, age: Int) {
}

class Person(
name: String,
age: Int,
birthdate: Date,
astrologicalSign: String,
shoeSize: Int,
favoriteColor: java.awt.Color) {
def firstMethod: Foo = ...
name: String,
age: Int,
birthdate: Date,
astrologicalSign: String,
shoeSize: Int,
favoriteColor: java.awt.Color,
) {
def firstMethod: Foo = …
}

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

class Person(
name: String,
age: Int,
birthdate: Date,
astrologicalSign: String,
shoeSize: Int,
favoriteColor: java.awt.Color)
extends Entity
name: String,
age: Int,
birthdate: Date,
astrologicalSign: String,
shoeSize: Int,
favoriteColor: java.awt.Color,
) extends Entity
with Logging
with Identifiable
with Serializable {

def firstMethod: Foo = …
}

### Ordering Of Class Elements
Expand Down