Skip to content

Commit b56564d

Browse files
committed
Reorder readme
1 parent 45a0307 commit b56564d

File tree

16 files changed

+783
-623
lines changed

16 files changed

+783
-623
lines changed

core/src/main/scala/org/scalafmt/ScalafmtStyle.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ object ScalafmtStyle {
197197
unindentTopLevelOperators = false,
198198
indentOperatorsIncludeFilter = indentOperatorsIncludeDefault,
199199
indentOperatorsExcludeFilter = indentOperatorsExcludeDefault,
200-
alignByArrowEnumeratorGenerator = true,
200+
alignByArrowEnumeratorGenerator = false,
201201
rewriteTokens = Map.empty[String, String],
202202
alignByIfWhileOpenParen = true,
203203
spaceBeforeContextBoundColon = false
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
40 columns |
2+
<<< alignByArrowEnumeratorGenerator
3+
for {
4+
x <- new Integer {
5+
def value = 2
6+
}
7+
y <- Int(2)
8+
} yield x + y
9+
>>>
10+
for {
11+
x <- new Integer {
12+
def value = 2
13+
}
14+
y <- Int(2)
15+
} yield x + y
16+

core/src/test/resources/unit/For.stat

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,3 +158,17 @@ for {
158158
} yield {
159159
thing(i, j)
160160
}
161+
<<< alignByArrowEnumeratorGenerator
162+
for {
163+
x <- new Integer {
164+
def value = 2
165+
}
166+
y <- Int(2)
167+
} yield x + y
168+
>>>
169+
for {
170+
x <- new Integer {
171+
def value = 2
172+
}
173+
y <- Int(2)
174+
} yield x + y

core/src/test/scala/org/scalafmt/util/HasTests.scala

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,10 @@ trait HasTests extends FunSuiteLike with FormatAssertions {
117117
binPackParentConstructors = true,
118118
maxColumn = 40
119119
)
120+
case "alignByArrowEnumeratorGenerator" =>
121+
ScalafmtStyle.unitTest40.copy(
122+
alignByArrowEnumeratorGenerator = true
123+
)
120124
case "noIndentOperators" =>
121125
ScalafmtStyle.unitTest80.copy(
122126
unindentTopLevelOperators = true,

readme/Changelog03.scalatex

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,9 @@
5858
a: Int): Int = {
5959
a + 1
6060
}
61+
@li
62+
The default @code{--alignByArrowEnumeratorGenerator} is now false
63+
instead of true. Refer to @sect.ref{--alignByArrowEnumeratorGenerator}.
6164
@li
6265
Function literals in argument lists can now be single line.
6366
See @issue(323).

readme/Community.scalatex

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
@import Main._
2+
@import org.scalafmt.readme.Readme._
3+
@import org.scalafmt.ScalafmtStyle
4+
@import org.scalafmt.ScalafmtStyle.default
5+
6+
@sect{Community}
7+
@sect{Related projects}
8+
Have a scalafmt related project? Please consider
9+
@lnk("opening a pull request", "https://github.com/olafurpg/scalafmt/blob/master/readme/Readme.scalatex")
10+
to list it here:
11+
@ul
12+
@li
13+
@lnk("scalafmt nix package", "https://github.com/NixOS/nixpkgs/tree/master/pkgs/development/tools/scalafmt"):
14+
package to install scalafmt on nix.
15+
@li
16+
@lnk("whatstyle", "https://github.com/mikr/whatstyle"):
17+
Find a code format style configuration that fits a given source file.
18+
@sect{Adopters}
19+
Are you using scalafmt? Please consider
20+
@lnk("opening a pull request", "https://github.com/olafurpg/scalafmt/blob/master/readme/Adopters.scala#L16")
21+
to list your organization here:
22+
23+
@ul
24+
@org.scalafmt.readme.Adopters.adopters.map(_.bullet)
25+

readme/Configuration.scalatex

Lines changed: 269 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,269 @@
1+
@import Main._
2+
@import org.scalafmt.readme.Readme._
3+
@import org.scalafmt.ScalafmtStyle
4+
@import org.scalafmt.ScalafmtStyle.default
5+
6+
@sect{Configuration}
7+
8+
@p
9+
There are two ways to configure @code("scalafmt").
10+
11+
@ol
12+
@li
13+
As Scala code via the @code("ScalafmtConfig") case class.
14+
This is handy when using scalafmt as a standalone library.
15+
For details, refer to the Scaladoc.
16+
@li
17+
In a plain text file, options are defined as CLI flags.
18+
I recommend you create a file named @code(".scalafmt") and keep it in
19+
the root directory of your project.
20+
21+
@p
22+
Here is an example @code(".scalafmt").
23+
24+
@cliFlags
25+
# Example .scalafmt, comments are supported.
26+
--style defaultWithAlign # For pretty alignment.
27+
--maxColumn 100 # For my wide 30" display.
28+
29+
To experiment with different options, I recommend you use the CLI.
30+
For details, read about the @code("--config") flag in the
31+
@code("--help") page of the CLI.
32+
33+
Here are examples of the most common configuration options.
34+
For a full list of available flags, consult the @code{--help} page of the
35+
CLI or the @lnk("ScalafmtStyle docstring", "https://github.com/olafurpg/scalafmt/blob/master/core/src/main/scala/org/scalafmt/ScalafmtStyle.scala").
36+
37+
@sect{--style}
38+
Option 1: @b{default}
39+
@fmt(ScalafmtStyle.default.copy(maxColumn = 40))
40+
// Column 40 |
41+
// non bin packed parent constructors
42+
object ScalaJsStyle extends Parent with SecondParent with ThirdParent {
43+
// non bin packed arguments
44+
function(argument1, argument2(argument3, argument4))
45+
// No vertical alignment
46+
x match {
47+
case 1 => 1
48+
case 11 => 1
49+
}
50+
}
51+
52+
Option 2: @b{defaultWithAlign}
53+
@fmt(ScalafmtStyle.defaultWithAlign.copy(maxColumn = 40))
54+
// Column 40 |
55+
object ScalaJsStyle extends Parent with SecondParent with ThirdParent {
56+
// vertical alignment
57+
x match {
58+
case 1 => 1 // align me
59+
case 11 => 11 // align me too
60+
61+
case x => // blank line breaks alignment
62+
}
63+
for {
64+
x <- List(1)
65+
xx <- List(1, 2)
66+
} yield x * xx
67+
// A whole bunch of other
68+
// alignment goodies.
69+
// ...
70+
}
71+
72+
Option 3: @b{Scala.js} (experimental)
73+
@fmt(ScalafmtStyle.scalaJs.copy(maxColumn = 40))
74+
// Column 40 |
75+
// bin packed parent constructors
76+
object ScalaJsStyle extends Parent with SecondParent with ThirdParent {
77+
// bin packed arguments
78+
function(argument1, argument2, argument3, argument4)
79+
// Vertical alignment for only =>
80+
x match {
81+
case 1 => 1
82+
case 11 => 1
83+
}
84+
}
85+
86+
@sect{--maxColumn}
87+
Default: @b{80}
88+
89+
@ul
90+
@li
91+
Keep in mind that 80 characters fit perfectly on a split laptop screen
92+
with regular resolution.
93+
@li
94+
Github mobile view only shows 80 characters and sometimes you need
95+
to look at code on your phone.
96+
@li
97+
Consider refactoring your code instead of choosing a value over 100.
98+
99+
@sect{--continuationIndentCallSite}
100+
Default: @b{default.continuationIndentCallSite}
101+
102+
@p
103+
Example:
104+
@hl.scala
105+
function(
106+
argument1 // indented by 2
107+
)
108+
109+
@sect{--continuationIndentDefnSite}
110+
Default: @b{default.continuationIndentDefnSite}
111+
112+
@p
113+
Same as @code{--continuationIndentCallSite} except for definition site.
114+
Example:
115+
@hl.scala
116+
def function(
117+
argument1: Type1): ReturnType // Indented by 4
118+
119+
@sect{--alignTokens}
120+
Default: @b{off}
121+
122+
@p
123+
The style @code("defaultWithAlign") has pre-configured a variety of
124+
tokens that align together nicely.
125+
126+
@exampleAlign
127+
// 40 columns |
128+
object TokenAlignment {
129+
x match {
130+
// Align by => and -> and //
131+
case 1 => 1 -> 2 // first
132+
case 11 => 11 -> 22 // second
133+
134+
// A blank line separates alignment blocks.
135+
case `ignoreMe` => 111 -> 222
136+
}
137+
138+
// Align assignments of similar type.
139+
def name = column[String]("name")
140+
def status = column[Int]("status")
141+
val x = 1
142+
val xx = 22
143+
144+
// Align sbt module IDs.
145+
libraryDependencies ++= Seq(
146+
"org.scala-lang" % "scala-compiler" % scalaVersion.value,
147+
"com.lihaoyi" %% "sourcecode" % "0.1.1"
148+
)
149+
}
150+
151+
If you need more customization, refer to the @code{--help}.
152+
153+
@sect{// format: off}
154+
Disable formatting for specific regions of code by wrapping them in
155+
@code("// format: OFF") blocks:
156+
157+
@example(org.scalafmt.util.FileOps.readFile("readme/matrix.example"))
158+
159+
To disable formatting for a whole file, put the comment at the top of
160+
the file.
161+
162+
@ul
163+
@li
164+
the comment string is case insensitive, you can also write
165+
@code("// format: OFF").
166+
@li
167+
The comments @code("// @formatter:off") and @code("// @formatter:off")
168+
will also work, for compatibility with the IntelliJ formatter.
169+
@li
170+
Scalafmt will do it's best to resume formatting at the correct
171+
indentation level. It's best to enable formatting at the same level as
172+
when it was disabled.
173+
174+
@sect{--assumeStandardLibraryStripMargin}
175+
Default: @default.alignStripMarginStrings
176+
177+
@p
178+
If @b{true}, the margin character @code("|") is aligned with the opening triple
179+
quote @code("\"\"\"") in interpolated and raw string literals.
180+
181+
@example(org.scalafmt.util.FileOps.readFile("readme/stripMargin.example"),
182+
stripMarginStyle)
183+
184+
@note. May cause non-idempotent formatting in rare cases, see @issue(192).
185+
186+
@sect{--javaDocs vs. --scalaDocs}
187+
Default: --scalaDocs
188+
189+
@hl.scala
190+
// --scalaDocs
191+
/** Align by second asterisk.
192+
*
193+
*/
194+
// --javaDocs
195+
/** Align by first asterisk.
196+
*
197+
*/
198+
199+
@sect{--allowNewlineBeforeColonInMassiveReturnTypes}
200+
Default: @default.allowNewlineBeforeColonInMassiveReturnTypes
201+
202+
@hl.scala
203+
// Column limit |
204+
// true
205+
implicit def validatedInstances[E](implicit E: Semigroup[E])
206+
: Traverse[Validated[E, ?]] with ApplicativeError[Validated[E, ?], E] = 2
207+
// false
208+
implicit def validatedInstances[E](implicit E: Semigroup[E]): Traverse[
209+
Validated[E, ?]] with ApplicativeError[Validated[E, ?], E] = 2
210+
211+
@sect{--alignByArrowEnumeratorGenerator}
212+
Default: @default.alignByArrowEnumeratorGenerator
213+
214+
@hl.scala
215+
// false
216+
for {
217+
x <- new Integer {
218+
def value = 2
219+
}
220+
} yield x
221+
222+
// true
223+
for {
224+
x <- new Integer {
225+
def value = 2
226+
}
227+
} yield x
228+
229+
@sect{--binPackParentConstructors}
230+
Default: @default.binPackParentConstructors
231+
232+
@hl.scala
233+
// false
234+
for {
235+
x <- new Integer {
236+
def value = 2
237+
}
238+
} yield x
239+
240+
// true
241+
for {
242+
x <- new Integer {
243+
def value = 2
244+
}
245+
} yield x
246+
@sect{--alignByOpenParenCallSite}
247+
Default: @default.alignByOpenParenCallSite
248+
249+
@hl.scala
250+
// Column limit |
251+
// true
252+
foo(arg1, arg2)
253+
254+
function(arg1, // align by (
255+
arg2,
256+
arg3)
257+
function(
258+
argument1,
259+
argument2)
260+
261+
// false
262+
foo(arg1, arg2)
263+
function( // no align by (
264+
arg1,
265+
arg2,
266+
arg3)
267+
function(
268+
argument1,
269+
argument2)

0 commit comments

Comments
 (0)