File tree Expand file tree Collapse file tree 8 files changed +77
-26
lines changed Expand file tree Collapse file tree 8 files changed +77
-26
lines changed Original file line number Diff line number Diff line change 1+ name : CI
2+ on :
3+ push :
4+ pull_request :
5+ jobs :
6+ build :
7+ runs-on : ubuntu-latest
8+ steps :
9+ - uses : actions/checkout@v4
10+ - uses : actions/setup-java@v4
11+ with :
12+ distribution : temurin
13+ java-version : 8
14+ cache : sbt
15+ - uses : sbt/setup-sbt@v1
16+ - run : sbt +test
17+ format :
18+ runs-on : ubuntu-latest
19+ steps :
20+ - uses : actions/checkout@v4
21+ - uses : actions/setup-java@v4
22+ with :
23+ distribution : temurin
24+ java-version : 8
25+ - uses : sbt/setup-sbt@v1
26+ - run : sbt scalafmtSbtCheck +scalafmtCheckAll
Original file line number Diff line number Diff line change 1+ name : Release
2+ on :
3+ push :
4+ branches : [main]
5+ tags : ["*"]
6+ jobs :
7+ publish :
8+ runs-on : ubuntu-latest
9+ steps :
10+ - uses : actions/checkout@v4
11+ with :
12+ fetch-depth : 0
13+ - uses : actions/setup-java@v4
14+ with :
15+ distribution : temurin
16+ java-version : 8
17+ cache : sbt
18+ - uses : sbt/setup-sbt@v1
19+ - run : sbt ci-release
20+ env :
21+ PGP_PASSPHRASE : ${{ secrets.PGP_PASSPHRASE }}
22+ PGP_SECRET : ${{ secrets.PGP_SECRET }}
23+ SONATYPE_PASSWORD : ${{ secrets.SONATYPE_PASSWORD }}
24+ SONATYPE_USERNAME : ${{ secrets.SONATYPE_USERNAME }}
Original file line number Diff line number Diff line change 1- version = "3.7.15"
2- runner.dialect = scala213
1+ version = 3.9 .2
2+ runner.dialect = scala213
3+ maxColumn = 120
Original file line number Diff line number Diff line change @@ -4,38 +4,32 @@ Repository of custom scalafix rules for Iterable projects.
44
55## Usage
66
7- This library is not published anywhere yet, so you'll first need to build and publish locally with:
8- ```
9- sbt publishLocal
7+ See the tags on this repo to find the the latest version or the version you want to use. You can use the rules in your project by adding a dependency to the ` scalafix-rules ` artifact:
8+
9+ ``` scala
10+ ThisBuild / libraryDependencies += " com.iterable" %% " scalafix-rules" % " 0.1.0" % ScalafixConfig
1011```
11- Then you can reference the published library version in your project.
1212
13- For example, you can run version ` 0.1.0 ` of ` NoFutureTraverse ` dynamically in the ` sbt ` console:
13+ This will make the rules available to reference in your ` .scalafix.conf ` file.
14+
15+ You can also run directly from the sbt console without including it in your build.
16+ For example, to run version ` 0.1.0 ` of ` NoFutureTraverse ` dynamically in the ` sbt ` console:
1417
1518```
1619scalafix dependency:[email protected] ::scalafix-rules:0.1.0 1720```
1821
19- Replace the version ` 0.1.0 ` with the version you published.
20-
21- To run the rules by default with ` scalafix ` or ` scalafixAll ` , you'll need to add a library dependency in ` build.sbt ` :
22+ ### NoFutureTraverse
2223
23- ``` scala
24- ThisBuild / libraryDependencies += " com.iterable" %% " scalafix-rules" % " 0.1.0" % ScalafixConfig
25- ```
26-
27- Then you can add the rules in your ` .scalafix.conf ` file, e.g.:
24+ Disallows the use of ` Future.traverse ` in your Scala code, to prevent a potentially unbounded number of concurrent tasks from being run at once.
2825
2926``` hocon
3027rules = [
3128 # ...
32- NoFutureTraverse # validate that Future.traverse is not used
29+ NoFutureTraverse
3330]
3431
35- # Configuration for the NoFutureTraverse rule
3632NoFutureTraverse {
37- isError = true
33+ isError = true # Whether to treat violations as errors (default: true)
3834}
3935```
40-
41-
Original file line number Diff line number Diff line change @@ -8,6 +8,7 @@ import scala.concurrent.Await
88import scala .concurrent .ExecutionContext .Implicits .global
99import scala .concurrent .duration ._
1010
11+ /* scalafmt: { newlines.source = fold } */
1112object FutureSequenceTest {
1213 val futures = List (Future { " hello" }, Future { " world" })
1314 val result = Future .sequence(futures).map(_.mkString) // assert: NoFutureTraverse
Original file line number Diff line number Diff line change @@ -8,8 +8,9 @@ import scala.concurrent.Await
88import scala .concurrent .ExecutionContext .Implicits .global
99import scala .concurrent .duration ._
1010
11+ /* scalafmt: { newlines.source = fold } */
1112object FutureTraverseTest {
1213 val items = List (" hello" , " world" )
13- val result = Future .traverse(items)(item => Future (item.length)).map(_.sum) // assert: NoFutureTraverse
14- println(Await .result(result , 1 .second))
14+ val sum = Future .traverse(items)(item => Future (item.length)).map(_.sum) // assert: NoFutureTraverse
15+ println(Await .result(sum , 1 .second))
1516}
Original file line number Diff line number Diff line change 11addSbtPlugin(" com.github.sbt" % " sbt-ci-release" % " 1.9.2" )
22addSbtPlugin(" ch.epfl.scala" % " sbt-scalafix" % " 0.13.0" )
3+ addSbtPlugin(" org.scalameta" % " sbt-scalafmt" % " 2.5.4" )
34dependencyOverrides += " ch.epfl.scala" % " scalafix-interfaces" % " 0.13.0"
Original file line number Diff line number Diff line change @@ -8,7 +8,7 @@ import scalafix.lint._
88import scalafix .v1 ._
99
1010case class NoFutureTraverseConfig (
11- isError : Boolean = false
11+ isError : Boolean = false
1212)
1313object NoFutureTraverseConfig {
1414 implicit val surface : Surface [NoFutureTraverseConfig ] =
@@ -21,7 +21,8 @@ class NoFutureTraverse(config: NoFutureTraverseConfig) extends SemanticRule("NoF
2121
2222 case class Deprecation (position : Position , name : String ) extends Diagnostic {
2323 override def message = s " $name is deprecated "
24- override def severity = if (config.isError) LintSeverity .Error else LintSeverity .Warning
24+ override def severity =
25+ if (config.isError) LintSeverity .Error else LintSeverity .Warning
2526 }
2627
2728 def this () = this (NoFutureTraverseConfig ())
@@ -31,8 +32,10 @@ class NoFutureTraverse(config: NoFutureTraverseConfig) extends SemanticRule("NoF
3132 .getOrElse(" NoFutureTraverse" )(this .config)
3233 .map(c => new NoFutureTraverse (c))
3334
34- val futureTraverse = SymbolMatcher .normalized(" scala.concurrent.Future.traverse" )
35- val futureSequence = SymbolMatcher .normalized(" scala.concurrent.Future.sequence" )
35+ val futureTraverse =
36+ SymbolMatcher .normalized(" scala.concurrent.Future.traverse" )
37+ val futureSequence =
38+ SymbolMatcher .normalized(" scala.concurrent.Future.sequence" )
3639
3740 override def fix (implicit doc : SemanticDocument ): Patch = {
3841 doc.tree.collect {
You can’t perform that action at this time.
0 commit comments