Skip to content

Commit

Permalink
improvement: Support script files
Browse files Browse the repository at this point in the history
Previously, scripts would not be supported. Now, they should be correctly picked up by Scalafix.

I also tested it in Metals with the organzie imports rule.
  • Loading branch information
tgodzik committed Dec 13, 2023
1 parent f975afd commit e6b6772
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,7 @@ case class Args(

object Args extends TPrintImplicits {
val baseMatcher: PathMatcher =
FileSystems.getDefault.getPathMatcher("glob:**.{scala,sbt}")
FileSystems.getDefault.getPathMatcher("glob:**.{scala,sbt,sc}")
val runtimeScalaVersion: ScalaVersion = ScalaVersion
.from(scala.util.Properties.versionNumberString) // can be empty
.toOption
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ case class ScalafixConfig(

def dialectForFile(path: String): Dialect =
if (path.endsWith(".sbt")) DefaultSbtDialect
else if (path.endsWith(".sc"))
dialect
.withAllowToplevelTerms(true)
else dialect

val reader: ConfDecoder[ScalafixConfig] =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,24 @@ class CliSyntacticSuite extends BaseCliSuite {
expectedExit = ExitStatus.Ok
)

check(
name = "fix script files",
originalLayout = s"""|/a.sc
|def foo { println(1) }
|lazy val bar = project
|""".stripMargin,
args = Array(
"-r",
"ProcedureSyntax",
"a.sc"
),
expectedLayout = s"""|/a.sc
|def foo: Unit = { println(1) }
|lazy val bar = project
|""".stripMargin,
expectedExit = ExitStatus.Ok
)

check(
name = "deprecated name emits warning",
originalLayout = s"""|/a.scala
Expand Down

0 comments on commit e6b6772

Please sign in to comment.