Skip to content

Commit 99d5a4d

Browse files
Add documentation for the directory layout and MultiScala
1 parent a62f1da commit 99d5a4d

File tree

3 files changed

+66
-32
lines changed

3 files changed

+66
-32
lines changed

CONTRIBUTING.md

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,11 @@ class toIteratorVsIterator(xs: Iterable[Int]) {
3838
}
3939
~~~
4040

41-
3. Add a corresponding file in the `scalafix/output213/src/main/scala/fix/` directory
41+
3. Add a corresponding file in the `scalafix/output/src/main/scala/fix/` directory
4242
with the same code but using the strawman:
4343

4444
~~~ scala
45-
import strawman.collection.Iterable
45+
import scala.collection.compat._
4646

4747
class toIteratorVsIterator(xs: Iterable[Int]) {
4848
xs.iterator
@@ -75,3 +75,43 @@ Fix the implementation of the rule (in the
7575
`rules/src/main/scala/fix/NewCollections.scala` file) until the
7676
tests are green. You can find more help about the scalafix API in its
7777
[documentation](https://scalacenter.github.io/scalafix/docs/rule-authors/setup).
78+
79+
80+
### Scalafix Teskit Directory Layout
81+
82+
```
83+
.
84+
├── data |
85+
│   └── src |
86+
│   └── main |
87+
│   └── scala | Project to avoid duplicating code between input and output
88+
├── input |
89+
│   └── src |
90+
│   └── main |
91+
│   ├── scala | Input that cross-compile
92+
│   └── scala-2.12 | 2.12 specific input
93+
├── output |
94+
│   └── src |
95+
│   └── main |
96+
│   └── scala | Output that cross-compile
97+
├── output212 |
98+
│   └── src |
99+
│   └── main |
100+
│   └── scala-2.12 | 2.12 specific output
101+
├── output213 |
102+
│   └── src |
103+
│   └── main |
104+
│   └── scala | 2.13 specific output (from a cross-compiled input)
105+
├── output213-failure |
106+
│   └── src |
107+
│   └── main |
108+
│   └── scala | 2.13 specific output that cannot be migrated due to technical limitations
109+
├── rules |
110+
│   └── src |
111+
│   └── main |
112+
│   └── scala | Rule implementations
113+
└── tests |
114+
└── src |
115+
└── test |
116+
└── scala | Scalafix testkit launcher (useful to run a single input file)
117+
```

build.sbt

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,6 @@ lazy val `scalafix-rules` = project
131131
)
132132

133133
// == Scalafix Test Setup ==
134-
135134
lazy val sharedScalafixSettings = Seq(
136135
scalacOptions ++= Seq(
137136
"-deprecation",
@@ -162,7 +161,6 @@ lazy val `scalafix-input` = project
162161
)
163162
.dependsOn(`scalafix-data212`)
164163

165-
166164
val `scalafix-output` = MultiScalaProject("scalafix-output", "scalafix/output",
167165
_.settings(sharedScalafixSettings)
168166
.settings(dontPublish)
@@ -194,16 +192,12 @@ lazy val `scalafix-tests` = project
194192
libraryDependencies += "ch.epfl.scala" % "scalafix-testkit" % scalafixVersion % Test cross CrossVersion.full,
195193
buildInfoPackage := "fix",
196194
buildInfoKeys := Seq[BuildInfoKey](
197-
"inputSourceroot" ->
198-
sourceDirectory.in(`scalafix-input`, Compile).value,
199-
"outputSourceroot" ->
200-
(baseDirectory in ThisBuild).value / "scalafix/output/src/main",
201-
"output212Sourceroot" -> output212.value,
202-
"output213Sourceroot" -> output213.value,
203-
"output213FailureSourceroot" ->
204-
sourceDirectory.in(`scalafix-output213-failure`, Compile).value,
205-
"inputClassdirectory" ->
206-
classDirectory.in(`scalafix-input`, Compile).value
195+
"inputSourceroot" -> sourceDirectory.in(`scalafix-input`, Compile).value,
196+
"outputSourceroot" -> (baseDirectory in ThisBuild).value / "scalafix/output/src/main",
197+
"output212Sourceroot" -> output212.value,
198+
"output213Sourceroot" -> output213.value,
199+
"output213FailureSourceroot" -> sourceDirectory.in(`scalafix-output213-failure`, Compile).value,
200+
"inputClassdirectory" -> classDirectory.in(`scalafix-input`, Compile).value
207201
),
208202
test in Test := (test in Test).dependsOn(
209203
compile in (`scalafix-output211`, Compile),

project/MultiScalaProject.scala

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,24 @@ import scalajscrossproject.ScalaJSCrossPlugin.autoImport._
88

99
import java.io.File
1010

11+
/** MultiScalaCrossProject and MultiScalaProject are an alternative to crossScalaVersion
12+
* it allows you to create a template for a sbt project you can instanciate with a
13+
* specific scala version.
14+
*
15+
* {{{
16+
* // create a project template
17+
* val myProject = MultiScalaProject(
18+
* "name",
19+
* "path/to/dir",
20+
* _.settings(...) // Project => Project (scala version independent configurations)
21+
* )
22+
*
23+
* // instanciate a sbt project
24+
* lazy val myProject211 = myProject("2.11.12", _.settings(...) /* scala version dependent configurations */)
25+
* lazy val myProject212 = myProject("2.12.6" , _.settings(...))
26+
* // ...
27+
* }}}
28+
*/
1129
trait MultiScala {
1230
def majorMinor(in: String): String = {
1331
val Array(major, minor, _) = in.split("\\.")
@@ -101,21 +119,3 @@ class MultiScalaProject(
101119
configurePerScala(configure(resultingProject))
102120
}
103121
}
104-
105-
object TestProject {
106-
private def base(sub: String): String =
107-
s"scalafix/$sub"
108-
109-
def apply(
110-
sub: String,
111-
configure: (Project, String) => Project): MultiScalaProject =
112-
apply(sub, project => configure(project, s"${base(sub)}/src/main"))
113-
114-
def apply(sub: String, configure: Project => Project): MultiScalaProject =
115-
MultiScalaProject(
116-
s"tests${sub.capitalize}",
117-
base(sub),
118-
configure.andThen(_.disablePlugins(scalafix.sbt.ScalafixPlugin))
119-
)
120-
121-
}

0 commit comments

Comments
 (0)