Skip to content

Commit 3fe9464

Browse files
mkurzmzuehlke
authored andcommitted
Support scala-steward.conf (makes sense in .github and .config folder)
1 parent b83aae5 commit 3fe9464

File tree

4 files changed

+39
-9
lines changed

4 files changed

+39
-9
lines changed

docs/repo-specific-configuration.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Repository-specific configuration
22

3-
You can add a configuration file `.scala-steward.conf` to configure how Scala Steward updates your repository.
4-
The `.scala-steward.conf` configuration file can be located in the root of your repository, in `.github` directory or in `.config` directory (searched in this order).
3+
You can add a configuration file named either `.scala-steward.conf` or `scala-steward.conf` to configure how Scala Steward updates your repository.
4+
The `[.]scala-steward.conf` configuration file can be located in the root of your repository, in `.github` directory or in `.config` directory (searched in this order).
55
If a configuration file exists in more than one location, only the first found file is taken into account.
66

77
```properties

modules/core/src/main/scala/org/scalasteward/core/repoconfig/RepoConfigAlg.scala

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ final class RepoConfigAlg[F[_]](maybeGlobalRepoConfig: Option[RepoConfig])(impli
4343
)(readRepoConfigFromFile(_))
4444
_ <- configParsingResult.fold(
4545
F.unit,
46-
error => logger.info(s"Failed to parse $repoConfigBasename: ${error.getMessage}"),
46+
error => logger.info(s"Failed to parse $activeConfigFile: ${error.getMessage}"),
4747
repoConfig => logger.info(s"Parsed repo config ${repoConfig.show}")
4848
)
4949
} yield configParsingResult
@@ -86,8 +86,10 @@ object RepoConfigAlg {
8686
private def activeConfigFile[F[_]](
8787
repoDir: File
8888
)(implicit fileAlg: FileAlg[F], logger: Logger[F], F: Monad[F]): F[Option[File]] = {
89-
val configFileCandidates: F[List[File]] = repoConfigFileSearchPath
90-
.map(_ :+ repoConfigBasename)
89+
val configFileCandidates: F[List[File]] = (repoConfigFileSearchPath
90+
.map(_ :+ repoConfigBasename) ++
91+
repoConfigFileSearchPath
92+
.map(_ :+ repoConfigBasename.substring(1)))
9193
.map(path => path.foldLeft(repoDir)(_ / _))
9294
.filterA(fileAlg.isRegularFile)
9395

modules/core/src/test/scala/org/scalasteward/core/repoconfig/RepoConfigAlgTest.scala

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ class RepoConfigAlgTest extends FunSuite {
264264
assert(clue(log).contains(startOfErrorMsg))
265265
}
266266

267-
test("config file in .github/") {
267+
test("hidden config file in .github/") {
268268
val repo = Repo("test", "dot-github-config")
269269
val repoDir = workspaceAlg.repoDir(repo).unsafeRunSync()
270270
val rootConfigFile = repoDir / ".scala-steward.conf"
@@ -278,7 +278,21 @@ class RepoConfigAlgTest extends FunSuite {
278278
assert(config.maybeRepoConfig.isDefined)
279279
}
280280

281-
test("config file in .config/") {
281+
test("not hidden config file in .github/") {
282+
val repo = Repo("test", "dot-github-config")
283+
val repoDir = workspaceAlg.repoDir(repo).unsafeRunSync()
284+
val rootConfigFile = repoDir / "scala-steward.conf"
285+
val dotGithubConfigFile = repoDir / ".github" / "scala-steward.conf"
286+
val initialState = MockState.empty.addFiles(dotGithubConfigFile -> "").unsafeRunSync()
287+
val config = repoConfigAlg.readRepoConfig(repo).runA(initialState).unsafeRunSync()
288+
289+
assert(!fileAlg.isRegularFile(rootConfigFile).unsafeRunSync())
290+
assert(fileAlg.isRegularFile(dotGithubConfigFile).unsafeRunSync())
291+
292+
assert(config.maybeRepoConfig.isDefined)
293+
}
294+
295+
test("hidden config file in .config/") {
282296
val repo = Repo("test", "dot-config-config")
283297
val repoDir = workspaceAlg.repoDir(repo).unsafeRunSync()
284298
val rootConfigFile = repoDir / ".scala-steward.conf"
@@ -292,6 +306,20 @@ class RepoConfigAlgTest extends FunSuite {
292306
assert(config.maybeRepoConfig.isDefined)
293307
}
294308

309+
test("not hidden config file in .config/") {
310+
val repo = Repo("test", "dot-config-config")
311+
val repoDir = workspaceAlg.repoDir(repo).unsafeRunSync()
312+
val rootConfigFile = repoDir / "scala-steward.conf"
313+
val dotConfigConfigFile = repoDir / ".config" / "scala-steward.conf"
314+
val initialState = MockState.empty.addFiles(dotConfigConfigFile -> "").unsafeRunSync()
315+
val config = repoConfigAlg.readRepoConfig(repo).runA(initialState).unsafeRunSync()
316+
317+
assert(!fileAlg.isRegularFile(rootConfigFile).unsafeRunSync())
318+
assert(fileAlg.isRegularFile(dotConfigConfigFile).unsafeRunSync())
319+
320+
assert(config.maybeRepoConfig.isDefined)
321+
}
322+
295323
test("log warning on multiple config files") {
296324
val repo = Repo("test", "multiple-config")
297325
val repoDir = workspaceAlg.repoDir(repo).unsafeRunSync()

modules/docs/mdoc/repo-specific-configuration.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Repository-specific configuration
22

3-
You can add a configuration file `.scala-steward.conf` to configure how Scala Steward updates your repository.
4-
The `.scala-steward.conf` configuration file can be located in the root of your repository, in `.github` directory or in `.config` directory (searched in this order).
3+
You can add a configuration file named either `.scala-steward.conf` or `scala-steward.conf` to configure how Scala Steward updates your repository.
4+
The `[.]scala-steward.conf` configuration file can be located in the root of your repository, in `.github` directory or in `.config` directory (searched in this order).
55
If a configuration file exists in more than one location, only the first found file is taken into account.
66

77
```scala mdoc:passthrough

0 commit comments

Comments
 (0)