Skip to content

Commit d48e882

Browse files
committed
set up releases
1 parent 6030008 commit d48e882

File tree

9 files changed

+85
-27
lines changed

9 files changed

+85
-27
lines changed

.github/workflows/ci.yml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
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

.github/workflows/release.yml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
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 }}

.scalafmt.conf

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
1-
version = "3.7.15"
2-
runner.dialect = scala213
1+
version = 3.9.2
2+
runner.dialect = scala213
3+
maxColumn = 120

README.md

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff 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
```
1619
scalafix 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
3027
rules = [
3128
# ...
32-
NoFutureTraverse # validate that Future.traverse is not used
29+
NoFutureTraverse
3330
]
3431
35-
# Configuration for the NoFutureTraverse rule
3632
NoFutureTraverse {
37-
isError = true
33+
isError = true # Whether to treat violations as errors (default: true)
3834
}
3935
```
40-
41-

build.sbt

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,14 @@ inThisBuild(
1010
licenses := List(
1111
"Apache-2.0" -> url("http://www.apache.org/licenses/LICENSE-2.0")
1212
),
13-
developers := List()
13+
developers := List(
14+
Developer(
15+
"gmethvin",
16+
"Greg Methvin",
17+
18+
new URL("https://github.com/gmethvin")
19+
)
20+
)
1421
)
1522
)
1623

input/src/main/scala/fix/FutureSequenceTest.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import scala.concurrent.Await
88
import scala.concurrent.ExecutionContext.Implicits.global
99
import scala.concurrent.duration._
1010

11+
/* scalafmt: { newlines.source = fold } */
1112
object FutureSequenceTest {
1213
val futures = List(Future { "hello" }, Future { "world" })
1314
val result = Future.sequence(futures).map(_.mkString) // assert: NoFutureTraverse

input/src/main/scala/fix/FutureTraverseTest.scala

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,9 @@ import scala.concurrent.Await
88
import scala.concurrent.ExecutionContext.Implicits.global
99
import scala.concurrent.duration._
1010

11+
/* scalafmt: { newlines.source = fold } */
1112
object 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
}

project/plugins.sbt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
addSbtPlugin("com.github.sbt" % "sbt-ci-release" % "1.9.2")
22
addSbtPlugin("ch.epfl.scala" % "sbt-scalafix" % "0.13.0")
3+
addSbtPlugin("org.scalameta" % "sbt-scalafmt" % "2.5.4")
34
dependencyOverrides += "ch.epfl.scala" % "scalafix-interfaces" % "0.13.0"

rules/src/main/scala/fix/NoFutureTraverse.scala

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import scalafix.lint._
88
import scalafix.v1._
99

1010
case class NoFutureTraverseConfig(
11-
isError: Boolean = false
11+
isError: Boolean = false
1212
)
1313
object 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 {

0 commit comments

Comments
 (0)