-
Notifications
You must be signed in to change notification settings - Fork 185
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1217 from taisukeoe/add-on-compile-mode
add --triggered flag to load overlay section in .scalafix.conf
- Loading branch information
Showing
7 changed files
with
152 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
scalafix-cli/src/main/scala/scalafix/internal/v1/ScalafixConfOps.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package scalafix.internal.v1 | ||
|
||
import metaconfig.Conf | ||
import metaconfig.Conf.Obj | ||
import metaconfig.ConfOps | ||
import metaconfig.internal.ConfGet | ||
|
||
object ScalafixConfOps { | ||
def drop(original: Conf, key: String): Conf = | ||
ConfOps.fold(original)(obj = { confObj => | ||
Obj(confObj.values.filterNot(_._1 == key)) | ||
}) | ||
|
||
def overlay(original: Conf, key: String): Conf = { | ||
val child = ConfGet.getKey(original, key :: Nil) | ||
child.fold(original)( | ||
ConfOps.merge(drop(original, key), _) | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
75 changes: 75 additions & 0 deletions
75
scalafix-tests/unit/src/test/scala/scalafix/tests/config/ArgsSuite.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
package scalafix.tests.config | ||
|
||
import metaconfig.Conf | ||
import metaconfig.internal.ConfGet | ||
import scalafix.internal.v1.Args | ||
import metaconfig.typesafeconfig.typesafeConfigMetaconfigParser | ||
import scalafix.internal.config.ScalafixConfig | ||
|
||
class ArgsSuite extends munit.FunSuite { | ||
|
||
private lazy val givenConf = Conf | ||
.parseString( | ||
"ArgsSuite", | ||
""" | ||
|rules = [DisableSyntax, RemoveUnused] | ||
| | ||
|triggered.rules = [DisableSyntax] | ||
| | ||
|DisableSyntax.noVars = true | ||
|DisableSyntax.noThrows = true | ||
| | ||
|triggered = { | ||
| DisableSyntax.noVars = false | ||
|} | ||
| | ||
|triggered.DisableSyntax.noReturns = true | ||
|""".stripMargin | ||
) | ||
.get | ||
|
||
test("ignore triggered section if args.triggered is false") { | ||
val args = Args.default.copy(scalacOptions = "-Ywarn-unused" :: Nil) | ||
val config = ScalafixConfig() | ||
|
||
assert(!args.triggered, "triggered should be false at default.") | ||
|
||
val rulesConfigured = args.configuredRules(givenConf, config).get | ||
|
||
assert( | ||
rulesConfigured.rules | ||
.map(_.name.value) == List("DisableSyntax", "RemoveUnused") | ||
) | ||
|
||
val merged = args.maybeOverlaidConfWithTriggered(givenConf) | ||
|
||
val disableSyntaxRule = ConfGet.getKey(merged, "DisableSyntax" :: Nil).get | ||
|
||
val expected = | ||
Conf.Obj("noVars" -> Conf.Bool(true), "noThrows" -> Conf.Bool(true)) | ||
|
||
assertEquals(disableSyntaxRule, expected) | ||
} | ||
|
||
test("use triggered section if args.triggered is true") { | ||
val args = Args.default.copy(triggered = true) | ||
val config = ScalafixConfig() | ||
|
||
val rulesConfigured = args.configuredRules(givenConf, config).get | ||
|
||
assert(rulesConfigured.rules.map(_.name.value) == List("DisableSyntax")) | ||
|
||
val merged = args.maybeOverlaidConfWithTriggered(givenConf) | ||
|
||
val disableSyntaxRule = ConfGet.getKey(merged, "DisableSyntax" :: Nil).get | ||
|
||
val expected = | ||
Conf.Obj( | ||
"noVars" -> Conf.Bool(false), | ||
"noThrows" -> Conf.Bool(true), | ||
"noReturns" -> Conf.Bool(true) | ||
) | ||
|
||
assertEquals(disableSyntaxRule, expected) | ||
} | ||
} |