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
Copy file name to clipboardExpand all lines: CODINGSTYLE.md
+3-43Lines changed: 3 additions & 43 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -3,9 +3,10 @@
3
3
The Scala.js project has a strict policy regarding coding style.
4
4
This is one of the cornerstones that has allowed Scala.js to maintain a clean, consistent and maintainable codebase.
5
5
6
-
This document tries to document the style in use as much as possible to make it easier for everyone to contribute.
6
+
Most coding style rules can be applied automatically by scalafmt. It is recommended that you configure your editor to reformat on save; see the [scalafmt instructions](https://scalameta.org/scalafmt/docs/installation.html)for how to configure this.
7
7
8
-
A *few* of these rules are checked automatically using Scalastyle, but most of them are too complex to teach to an automated tool.
8
+
While most rules are checked automatically by scalafmt and Scalastyle, but there are also a few rules that are too complex to teach to an automated tool.
9
+
This document tries to document the manually enforced rules as much as possible to make it easier for everyone to contribute.
9
10
10
11
The Scala.js core team has decided to designate a single developer to drive and "maintain" the project's coding style.
11
12
This allows us to maintain a consistent, yet flexible style.
@@ -32,10 +33,6 @@ In some cases, if breaking a line makes it significantly less readable, it can g
32
33
Rationale: when reviewing on GitHub, only 120 characters are visible; when reviewing on a mobile phone, only 80 characters are visible.
33
34
And we do review on mobile phone quite a lot.
34
35
35
-
#### Where to break a line
36
-
37
-
A line can be broken after either a `,` or a `(`, or possibly after a binary operator in a long expression.
38
-
39
36
### Indentation
40
37
41
38
In general, indentation is 2 spaces, except continuation lines, which are indented 4 spaces.
@@ -113,26 +110,6 @@ def abs(x: Int): Int =
113
110
-x
114
111
```
115
112
116
-
#### Long expressions with binary operators
117
-
118
-
Very long expressions consisting of binary operators at their "top-level" can be broken *without indentation* if they are alone in their brace-delimited block or their actual parameter.
119
-
This happens mostly for long chains of `&&`s, `||`s, or string concatenations.
120
-
Here is an example:
121
-
122
-
```scala
123
-
valisValidIdent= {
124
-
ident !=""&&
125
-
ident.charAt(0).isUnicodeIdentifierStart &&
126
-
ident.tail.forall(_.isUnicodeIdentifierPart)
127
-
}
128
-
129
-
if (!isValidIdent) {
130
-
reportError(
131
-
"This string is very long and will "+
132
-
"span several lines.")
133
-
}
134
-
```
135
-
136
113
#### Braces in lambdas
137
114
138
115
In lambdas (anonymous functions), the opening brace must be placed before the formal arguments, and not after the `=>`:
@@ -160,21 +137,6 @@ val f = (x: Int) => body
160
137
valys= xs.map(x => x +1)
161
138
```
162
139
163
-
### Spaces
164
-
165
-
There must not be any space before the following tokens: `:``,``;``)`
166
-
167
-
There must be exactly one space after the following tokens: `:``,``;``if``for``while`
168
-
169
-
There must be exactly one space before the tokens `=` and `=>`, and either exactly one space or a new line after them.
170
-
Exception: `=>` may be vertically aligned instead in some scenarios: see [the "Pattern matching" section](#pattern-matching).
171
-
172
-
There must be exactly one space before and after `{` and `}`.
173
-
With the exception of partial import, where there is no space on either side.
174
-
175
-
Binary operators must have a single space on both sides.
176
-
Unary operators must not be followed by a space.
177
-
178
140
### Method call style
179
141
180
142
Usually, parentheses should be used for actual parameters to a method call.
@@ -214,8 +176,6 @@ Procedure syntax must not be used.
214
176
Side-effect-free methods without formal parameters should be declared without `()`, unless either a) it overrides a method defined with `()` (such as `toString()`) or b) it implements a Java method in the Java libraries.
215
177
216
178
The signature of a method is technically a single line, and hence, if it has to be broken due to line length reasons, subsequent lines should be indented 4 spaces.
217
-
As a reminder, the line can be broken right after a `,` or a `(` (and not, for example, after `implicit` or `:`).
218
-
You should avoid breaking the line between the last parameter and the result type; going over the 80 characters limit is preferred in that case.
0 commit comments