Skip to content

Commit

Permalink
Move explicitReturnTypes config to top-level.
Browse files Browse the repository at this point in the history
This rewrite is quite important for scalafix so it deserves to be
promoted into the main configuration object.

Fixes #267.
  • Loading branch information
olafurpg committed Aug 11, 2017
1 parent 1b93be6 commit 905bb6a
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 9 deletions.
13 changes: 13 additions & 0 deletions readme/Rewrites.scalatex
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,19 @@
give fine-grained control on how the rewrite works, see
@lnk("ExplicitReturnTypesConfig",
"https://github.com/scalacenter/scalafix/blob/db6152304aaef19c4a8ba4fc77b732264bf52fec/scalafix-core/src/main/scala/scalafix/config/ExplicitReturnTypesConfig.scala").
Example configuration:
@config
explicitReturnTypes {
memberKind = [
Def
Var
Val
]
memberVisibility = [
Public
Protected
]
}


@sect(RemoveUnusedImports.toString)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ case class ScalafixConfig(
// Custom configuration for rewrites.
// Feel free to read data from here if your custom rewrite needs
// configuration from the user.
x: Conf = Conf.Obj()
x: Conf = Conf.Obj(),
explicitReturnTypes: ExplicitReturnTypesConfig = ExplicitReturnTypesConfig()
) {
def getRewriteConfig[T: ConfDecoder](key: String, default: T): T = {
x.getOrElse[T](key)(default).get
Expand All @@ -32,15 +33,17 @@ case class ScalafixConfig(
getOrElse("reporter")(reporter) |@|
getOrElse("patches")(patches)(patches.reader) |@|
getOrElse("dialect")(dialect) |@|
getOrElse("x")(x)
getOrElse("x")(x) |@|
getOrElse("explicitReturnTypes")(explicitReturnTypes)
).map {
case ((((a, b), c), d), e) =>
case (((((a, b), c), d), e), f) =>
copy(
fatalWarnings = a,
reporter = b,
patches = c,
dialect = d,
x = e
x = e,
explicitReturnTypes = f
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,7 @@ case class ExplicitReturnTypes(mirror: SemanticCtx)
defn: D,
mods: Traversable[Mod],
body: Term)(implicit ev: Extract[D, Mod]): Boolean = {
val config = ctx.config
.getRewriteConfig("explicitReturnTypes", ExplicitReturnTypesConfig())
import config._
import ctx.config.explicitReturnTypes._

def matchesMemberVisibility(): Boolean =
memberVisibility.contains(visibility(mods))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
rewrites = ExplicitReturnTypes
x.explicitReturnTypes.memberKind = [Val, Def, Var]
x.explicitReturnTypes.memberVisibility = [Public, Protected]
explicitReturnTypes.memberKind = [Val, Def, Var]
explicitReturnTypes.memberVisibility = [Public, Protected]
*/
package test

Expand Down

0 comments on commit 905bb6a

Please sign in to comment.