Skip to content

Commit 6794036

Browse files
authored
Update scalafmt-core to 3.0.0
1 parent 97204b6 commit 6794036

18 files changed

+882
-961
lines changed

.scalafmt.conf

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
version=2.7.5
1+
version=3.0.0
22
style = defaultWithAlign
33
maxColumn = 100
44

@@ -15,9 +15,9 @@ align {
1515
openParenDefnSite = false
1616
}
1717

18-
docstrings = JavaDoc
18+
docstrings.style = Asterisk
1919

2020
rewrite {
2121
rules = [SortImports, RedundantBraces]
2222
redundantBraces.maxLines = 1
23-
}
23+
}

build.sbt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import com.jsuereth.sbtpgp.PgpKeys.publishSigned
22

3-
ThisBuild / organization := "org.scala-exercises"
3+
ThisBuild / organization := "org.scala-exercises"
44
ThisBuild / githubOrganization := "47degrees"
5-
ThisBuild / scalaVersion := "2.13.3"
5+
ThisBuild / scalaVersion := "2.13.3"
66

77
// This is required by the exercises compiler:
8-
publishLocal := (publishLocal dependsOn compile).value
8+
publishLocal := (publishLocal dependsOn compile).value
99
publishSigned := (publishSigned dependsOn compile).value
1010

1111
addCommandAlias("ci-test", "scalafmtCheckAll; scalafmtSbtCheck; test")

src/main/scala/scalatutorial/ScalaTutorial.scala

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,11 @@ import org.scalaexercises.definitions.Library
2121
import sections._
2222

2323
/**
24-
* Quickly learn Scala through an interactive tutorial based on the first two courses of the Scala MOOCs.
24+
* Quickly learn Scala through an interactive tutorial based on the first two courses of the Scala
25+
* MOOCs.
2526
*
26-
* @param name scala_tutorial
27+
* @param name
28+
* scala_tutorial
2729
*/
2830
object ScalaTutorial extends Library {
2931
val owner = "scala-exercises"

src/main/scala/scalatutorial/sections/ClassesVsCaseClasses.scala

Lines changed: 33 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -19,20 +19,19 @@ package scalatutorial.sections
1919
import scalatutorial.utils.{BankAccount, Note}
2020

2121
/**
22-
* @param name classes_vs_case_classes
22+
* @param name
23+
* classes_vs_case_classes
2324
*/
2425
object ClassesVsCaseClasses extends ScalaTutorialSection {
2526

2627
/**
27-
* In the previous sections we have seen how case classes could be
28-
* used to achieve information aggregation, and also how classes
29-
* could be used to achieve data abstraction or to define stateful
30-
* objects.
28+
* In the previous sections we have seen how case classes could be used to achieve information
29+
* aggregation, and also how classes could be used to achieve data abstraction or to define
30+
* stateful objects.
3131
*
32-
* What are the relationship between classes and case classes? How
33-
* do they differ?
32+
* What are the relationship between classes and case classes? How do they differ?
3433
*
35-
* = Creation and Manipulation =
34+
* =Creation and Manipulation=
3635
*
3736
* Remember the class definition of `BankAccount`:
3837
*
@@ -69,21 +68,20 @@ object ClassesVsCaseClasses extends ScalaTutorialSection {
6968
}
7069

7170
/**
72-
* We see that creating a class instance requires the keyword `new`, whereas
73-
* this is not required for case classes.
71+
* We see that creating a class instance requires the keyword `new`, whereas this is not required
72+
* for case classes.
7473
*
75-
* Also, we see that the case class constructor parameters are promoted to
76-
* members, whereas this is not true for regular classes: the parameters
77-
* will remain private.
74+
* Also, we see that the case class constructor parameters are promoted to members, whereas this
75+
* is not true for regular classes: the parameters will remain private.
7876
*
7977
* {{{
80-
* class MyClass(x: Int) { def doubledX = x * 2 }
81-
* val myInstance = new MyClass(5)
82-
* myInstance.doubledX // returns 10
83-
* myInstance.x // error: value x is not a member of MyClass
78+
* class MyClass(x: Int) { def doubledX = x * 2 }
79+
* val myInstance = new MyClass(5)
80+
* myInstance.doubledX // returns 10
81+
* myInstance.x // error: value x is not a member of MyClass
8482
* }}}
8583
*
86-
* = Equality =
84+
* =Equality=
8785
*/
8886
def equality(res0: Boolean, res1: Boolean): Unit = {
8987
val aliceAccount = new BankAccount
@@ -98,18 +96,17 @@ object ClassesVsCaseClasses extends ScalaTutorialSection {
9896
}
9997

10098
/**
101-
* In the above example, the same definitions of bank accounts lead to different
102-
* values, whereas the same definitions of notes lead to equal values.
99+
* In the above example, the same definitions of bank accounts lead to different values, whereas
100+
* the same definitions of notes lead to equal values.
103101
*
104102
* As we have seen in the previous sections, stateful classes introduce a notion of ''identity''
105-
* that does not exist in case classes. Indeed, the value of `BankAccount` can change over
106-
* time whereas the value of a `Note` is immutable.
103+
* that does not exist in case classes. Indeed, the value of `BankAccount` can change over time
104+
* whereas the value of a `Note` is immutable.
107105
*
108-
* In Scala, by default, comparing objects will compare their identity, but in the
109-
* case of case class instances, the equality is redefined to compare the values of
110-
* the aggregated information.
106+
* In Scala, by default, comparing objects will compare their identity, but in the case of case
107+
* class instances, the equality is redefined to compare the values of the aggregated information.
111108
*
112-
* = Pattern Matching =
109+
* =Pattern Matching=
113110
*
114111
* We saw how pattern matching can be used to extract information from a case class instance:
115112
*
@@ -121,24 +118,23 @@ object ClassesVsCaseClasses extends ScalaTutorialSection {
121118
*
122119
* By default, pattern matching does not work with regular classes.
123120
*
124-
* = Extensibility =
121+
* =Extensibility=
125122
*
126-
* A class can extend another class, whereas a case class can not extend
127-
* another case class (because it would not be possible to correctly
128-
* implement their equality).
123+
* A class can extend another class, whereas a case class can not extend another case class
124+
* (because it would not be possible to correctly implement their equality).
129125
*
130-
* = Case Classes Encoding =
126+
* =Case Classes Encoding=
131127
*
132128
* We saw the main differences between classes and case classes.
133129
*
134-
* It turns out that case classes are just a special case of classes,
135-
* whose purpose is to aggregate several values into a single value.
130+
* It turns out that case classes are just a special case of classes, whose purpose is to
131+
* aggregate several values into a single value.
136132
*
137-
* The Scala language provides explicit support for this use case
138-
* because it is very common in practice.
133+
* The Scala language provides explicit support for this use case because it is very common in
134+
* practice.
139135
*
140-
* So, when we define a case class, the Scala compiler defines a class
141-
* enhanced with some more methods and a companion object.
136+
* So, when we define a case class, the Scala compiler defines a class enhanced with some more
137+
* methods and a companion object.
142138
*
143139
* For instance, the following case class definition:
144140
*

src/main/scala/scalatutorial/sections/DefinitionsAndEvaluation.scala

Lines changed: 45 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -17,22 +17,22 @@
1717
package scalatutorial.sections
1818

1919
/**
20-
* @param name definitions_and_evaluation
20+
* @param name
21+
* definitions_and_evaluation
2122
*/
2223
object DefinitionsAndEvaluation extends ScalaTutorialSection {
2324

2425
/**
25-
* = Naming Things =
26+
* =Naming Things=
2627
*
27-
* Consider the following program that computes the area of a disc
28-
* whose radius is `10`:
28+
* Consider the following program that computes the area of a disc whose radius is `10`:
2929
*
3030
* {{{
3131
* 3.14159 * 10 * 10
3232
* }}}
3333
*
34-
* To make complex expressions more readable we can give meaningful names to
35-
* intermediate expressions:
34+
* To make complex expressions more readable we can give meaningful names to intermediate
35+
* expressions:
3636
*
3737
* {{{
3838
* val radius = 10
@@ -41,14 +41,14 @@ object DefinitionsAndEvaluation extends ScalaTutorialSection {
4141
* pi * radius * radius
4242
* }}}
4343
*
44-
* Besides making the last expression more readable it also allows us to
45-
* not repeat the actual value of the radius.
44+
* Besides making the last expression more readable it also allows us to not repeat the actual
45+
* value of the radius.
4646
*
47-
* = Evaluation =
47+
* =Evaluation=
4848
*
4949
* A name is evaluated by replacing it with the right hand side of its definition
5050
*
51-
* == Example ==
51+
* ==Example==
5252
*
5353
* Here are the evaluation steps of the above expression:
5454
*
@@ -61,7 +61,7 @@ object DefinitionsAndEvaluation extends ScalaTutorialSection {
6161
* 314.159
6262
* }}}
6363
*
64-
* = Methods =
64+
* =Methods=
6565
*
6666
* Definitions can have parameters. For instance:
6767
*/
@@ -83,15 +83,15 @@ object DefinitionsAndEvaluation extends ScalaTutorialSection {
8383
}
8484

8585
/**
86-
* = Multiple Parameters =
86+
* =Multiple Parameters=
8787
*
8888
* Separate several parameters with commas:
8989
*
9090
* {{{
9191
* def sumOfSquares(x: Double, y: Double) = square(x) + square(y)
9292
* }}}
9393
*
94-
* = Parameters and Return Types =
94+
* =Parameters and Return Types=
9595
*
9696
* Function parameters come with their type, which is given after a colon
9797
*
@@ -101,12 +101,12 @@ object DefinitionsAndEvaluation extends ScalaTutorialSection {
101101
*
102102
* If a return type is given, it follows the parameter list.
103103
*
104-
* = Val vs Def =
104+
* =Val vs Def=
105105
*
106106
* The right hand side of a `def` definition is evaluated on each use.
107107
*
108-
* The right hand side of a `val` definition is evaluated at the point of the definition
109-
* itself. Afterwards, the name refers to the value.
108+
* The right hand side of a `val` definition is evaluated at the point of the definition itself.
109+
* Afterwards, the name refers to the value.
110110
*
111111
* {{{
112112
* val x = 2
@@ -115,16 +115,15 @@ object DefinitionsAndEvaluation extends ScalaTutorialSection {
115115
*
116116
* For instance, `y` above refers to `4`, not `square(2)`.
117117
*
118-
* = Evaluation of Function Applications =
118+
* =Evaluation of Function Applications=
119119
*
120-
* Applications of parametrized functions are evaluated in a similar way as
121-
* operators:
120+
* Applications of parametrized functions are evaluated in a similar way as operators:
122121
*
123-
* 1. Evaluate all function arguments, from left to right
124-
* 1. Replace the function application by the function's right-hand side, and, at the same time
125-
* 1. Replace the formal parameters of the function by the actual arguments.
122+
* 1. Evaluate all function arguments, from left to right
123+
* 1. Replace the function application by the function's right-hand side, and, at the same time
124+
* 1. Replace the formal parameters of the function by the actual arguments.
126125
*
127-
* == Example ==
126+
* ==Example==
128127
*
129128
* {{{
130129
* sumOfSquares(3, 2+2)
@@ -137,19 +136,19 @@ object DefinitionsAndEvaluation extends ScalaTutorialSection {
137136
* 25
138137
* }}}
139138
*
140-
* = The substitution model =
139+
* =The substitution model=
141140
*
142141
* This scheme of expression evaluation is called the ''substitution model''.
143142
*
144-
* The idea underlying this model is that all evaluation does is ''reduce
145-
* an expression to a value''.
143+
* The idea underlying this model is that all evaluation does is ''reduce an expression to a
144+
* value''.
146145
*
147146
* It can be applied to all expressions, as long as they have no side effects.
148147
*
149-
* The substitution model is formalized in the λ-calculus, which gives
150-
* a foundation for functional programming.
148+
* The substitution model is formalized in the λ-calculus, which gives a foundation for functional
149+
* programming.
151150
*
152-
* = Termination =
151+
* =Termination=
153152
*
154153
* Does every expression reduce to a value (in a finite number of steps)?
155154
*
@@ -161,10 +160,10 @@ object DefinitionsAndEvaluation extends ScalaTutorialSection {
161160
* loop
162161
* }}}
163162
*
164-
* = Value Definitions and Termination =
163+
* =Value Definitions and Termination=
165164
*
166-
* The difference between `val` and `def` becomes apparent when the right
167-
* hand side does not terminate. Given
165+
* The difference between `val` and `def` becomes apparent when the right hand side does not
166+
* terminate. Given
168167
*
169168
* {{{
170169
* def loop: Int = loop
@@ -184,10 +183,9 @@ object DefinitionsAndEvaluation extends ScalaTutorialSection {
184183
*
185184
* will lead to an infinite loop.
186185
*
187-
* = Changing the evaluation strategy =
186+
* =Changing the evaluation strategy=
188187
*
189-
* The interpreter reduces function arguments to values before rewriting the
190-
* function application.
188+
* The interpreter reduces function arguments to values before rewriting the function application.
191189
*
192190
* One could alternatively apply the function to unreduced arguments.
193191
*
@@ -204,30 +202,27 @@ object DefinitionsAndEvaluation extends ScalaTutorialSection {
204202
* 25
205203
* }}}
206204
*
207-
* = Call-by-name and call-by-value =
205+
* =Call-by-name and call-by-value=
208206
*
209-
* The first evaluation strategy is known as ''call-by-value'',
210-
* the second is known as ''call-by-name''.
207+
* The first evaluation strategy is known as ''call-by-value'', the second is known as
208+
* ''call-by-name''.
211209
*
212-
* Both strategies reduce to the same final values
213-
* as long as
210+
* Both strategies reduce to the same final values as long as
214211
*
215-
* - the reduced expression consists of pure functions, and
216-
* - both evaluations terminate.
212+
* - the reduced expression consists of pure functions, and
213+
* - both evaluations terminate.
217214
*
218-
* Call-by-value has the advantage that it evaluates every function argument
219-
* only once.
215+
* Call-by-value has the advantage that it evaluates every function argument only once.
220216
*
221-
* Call-by-name has the advantage that a function argument is not evaluated if the
222-
* corresponding parameter is unused in the evaluation of the function body.
217+
* Call-by-name has the advantage that a function argument is not evaluated if the corresponding
218+
* parameter is unused in the evaluation of the function body.
223219
*
224220
* Scala normally uses call-by-value.
225221
*
226-
* = Exercise =
222+
* =Exercise=
227223
*
228-
* Complete the following definition of the `triangleArea` function,
229-
* which takes a triangle base and height as parameters and returns
230-
* its area:
224+
* Complete the following definition of the `triangleArea` function, which takes a triangle base
225+
* and height as parameters and returns its area:
231226
*/
232227
def triangleAreaExercise(res0: Double, res1: Double): Unit = {
233228
def triangleArea(base: Double, height: Double): Double =

0 commit comments

Comments
 (0)