-
Notifications
You must be signed in to change notification settings - Fork 186
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow configuring the dialect in Scalafix #1373
Changes from all commits
4f93c8e
0b530b8
0fa1b89
cf30a3f
f1d4472
b56ec7f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,10 @@ | ||
package scala.meta.internal.scalafix | ||
|
||
import scala.meta.Dialect | ||
import scala.meta.Tree | ||
import scala.meta.dialects | ||
import scala.meta.internal.semanticdb.Scala.Names | ||
import scala.meta.internal.trees.Origin | ||
|
||
object ScalafixScalametaHacks { | ||
def dialect(language: String): Dialect = | ||
if (language == "Scala") dialects.Scala212 | ||
else if (language.isEmpty) dialects.Scala212 | ||
else Dialect.standards(language) | ||
def resetOrigin(tree: Tree): Tree = tree.withOrigin(Origin.None) | ||
def encode(name: String): String = Names.encode(name) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1 @@ | ||
package scalafix.internal.config | ||
|
||
import java.nio.file.FileSystems | ||
import java.nio.file.PathMatcher | ||
|
||
import scala.meta.Dialect | ||
|
||
import metaconfig._ | ||
|
||
case class ParserConfig( | ||
literalTypes: Boolean = true, | ||
trailingCommas: Boolean = true, | ||
inlineKeyword: Boolean = false | ||
) { | ||
|
||
private val dialect = scala.meta.dialects.Scala213.copy( | ||
allowLiteralTypes = literalTypes, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. already true in 2.12 |
||
allowTrailingCommas = trailingCommas, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. already true in 2.12 |
||
allowInlineMods = inlineKeyword, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we set allowInlineMods to false, and it's true in scala3 |
||
allowInlineIdents = !inlineKeyword | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. allowInlineIdent is true since 2.10 |
||
) | ||
private val sbtDialect = dialect.copy(allowToplevelTerms = true) | ||
|
||
def dialectForFile(path: String): Dialect = | ||
if (path.endsWith(".sbt")) sbtDialect | ||
else dialect | ||
|
||
} | ||
|
||
object ParserConfig { | ||
val sbtMatcher: PathMatcher = | ||
FileSystems.getDefault.getPathMatcher("glob:*.sbt") | ||
implicit val surface: generic.Surface[ParserConfig] = | ||
generic.deriveSurface | ||
implicit val codec: ConfCodec[ParserConfig] = | ||
generic.deriveCodec(ParserConfig()) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't see the point of writing our own definition of dialect. this one is not correct.
implicit val Scala213 = Scala212
.withAllowImplicitByNameParameters(true)
.withAllowLiteralTypes(true)
.withAllowNumericLiteralUnderscoreSeparators(true)
.withAllowTryWithAnyExpr(true)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not sure either - does it make sense to keep
ParserConfig
at all?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IIRC, the motivation for the custom dialect was to allow as much as possible of Scala 3 syntax without introducing regressions for Scala 2 users. Some Scala 3 syntax can be enabled safely while other syntax like significant indent may change the parsed structure of Scala 2 programs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, thanks! I understand better! Clever idea.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, thanks! I understand better! Clever idea.