Skip to content

Commit

Permalink
ScalafmtRunner: always allow top-level terms
Browse files Browse the repository at this point in the history
The formatter's job is not to validate code but to format it.
  • Loading branch information
kitbellew committed Oct 30, 2022
1 parent 69bad29 commit e536486
Showing 1 changed file with 2 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,6 @@ case class ScalafmtRunner(
}
@inline private[scalafmt] def getParser = parser.parse

@inline private def topLevelDialect = dialect.copy(
dialect = getDialect
.withAllowToplevelTerms(true)
.withToplevelSeparator("")
)

@inline
private[scalafmt] def withDialect(dialect: NamedDialect): ScalafmtRunner =
copy(dialect = dialect)
Expand All @@ -48,11 +42,10 @@ case class ScalafmtRunner(
private[scalafmt] def withParser(parser: ScalafmtParser): ScalafmtRunner =
copy(parser = parser)

def forSbt: ScalafmtRunner = withDialect(topLevelDialect)
def forSbt: ScalafmtRunner = this

private[scalafmt] def forCodeBlock: ScalafmtRunner = copy(
debug = false,
dialect = topLevelDialect,
eventCallback = null,
parser = ScalafmtParser.Source
)
Expand All @@ -64,7 +57,7 @@ case class ScalafmtRunner(
if (null != eventCallback) evts.foreach(eventCallback)

def parse(input: meta.inputs.Input): Parsed[_ <: Tree] =
getParser(input, getDialect)
getParser(input, getDialect.withAllowToplevelTerms(true))

@inline def isDefaultDialect = dialect.name == NamedDialect.defaultName

Expand Down

0 comments on commit e536486

Please sign in to comment.