From e60772d89bf3ae53292fe52e1637cfb2b331e657 Mon Sep 17 00:00:00 2001 From: xuwei-k <6b656e6a69@gmail.com> Date: Wed, 20 Dec 2023 17:43:22 +0900 Subject: [PATCH] restore Windows CI --- .github/workflows/ci.yml | 2 + .../main/scala/fix/FileNameConsistent.scala | 97 +++++++++---------- tests/src/test/scala/fix/RuleSuite.scala | 17 +++- 3 files changed, 64 insertions(+), 52 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 290d93f..7385656 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -15,6 +15,8 @@ jobs: include: - java: 8 os: ubuntu-latest + - java: 8 + os: windows-latest - java: 21 os: ubuntu-latest steps: diff --git a/rules/src/main/scala/fix/FileNameConsistent.scala b/rules/src/main/scala/fix/FileNameConsistent.scala index dec8d26..2ab1eb6 100644 --- a/rules/src/main/scala/fix/FileNameConsistent.scala +++ b/rules/src/main/scala/fix/FileNameConsistent.scala @@ -16,64 +16,59 @@ class FileNameConsistent extends SyntacticRule("FileNameConsistent") { override def isLinter = true override def fix(implicit doc: SyntacticDocument): Patch = { - if (scala.util.Properties.isWin) { - // TODO https://github.com/xuwei-k/scalafix-rules/issues/34 - Patch.empty - } else { - val defs = doc.tree.collect { - case x: Defn.Trait if x.isTopLevel => - TemplateDef(x, x.name.value) - case x: Defn.Class if x.isTopLevel => - TemplateDef(x, x.name.value) - case x: Defn.Object if x.isTopLevel => - TemplateDef(x, x.name.value) - } - val packageObjects = doc.tree.collect { case x: Pkg.Object => + val defs = doc.tree.collect { + case x: Defn.Trait if x.isTopLevel => TemplateDef(x, x.name.value) - } - val scalaSourceOpt = PartialFunction.condOpt(doc.input) { - case f: Input.File => - ScalaSource( - fullPath = f.path.toString, - name = f.path.toFile.getName.replace(".scala", "") - ) - case f: Input.VirtualFile => - ScalaSource( - fullPath = f.path, - name = f.path.split('/').lastOption.getOrElse("").replace(".scala", "") - ) - } + case x: Defn.Class if x.isTopLevel => + TemplateDef(x, x.name.value) + case x: Defn.Object if x.isTopLevel => + TemplateDef(x, x.name.value) + } + val packageObjects = doc.tree.collect { case x: Pkg.Object => + TemplateDef(x, x.name.value) + } + val scalaSourceOpt = PartialFunction.condOpt(doc.input) { + case f: Input.File => + ScalaSource( + fullPath = f.path.toString, + name = f.path.toFile.getName.replace(".scala", "") + ) + case f: Input.VirtualFile => + ScalaSource( + fullPath = f.path, + name = f.path.split(java.io.File.separatorChar).lastOption.getOrElse("").replace(".scala", "") + ) + } - val names = defs.map(_.name).distinct - scalaSourceOpt match { - case Some(src) => - if ((src.name == "package") && (packageObjects.size == 1) && names.isEmpty) { + val names = defs.map(_.name).distinct + scalaSourceOpt match { + case Some(src) => + if ((src.name == "package") && (packageObjects.size == 1) && names.isEmpty) { + // correct + // - file name is "package.scala" + // - and only package object + Patch.empty + } else if ((names.size == 1) || (packageObjects.size == 1)) { + if (names.contains(src.name)) { // correct - // - file name is "package.scala" - // - and only package object Patch.empty - } else if ((names.size == 1) || (packageObjects.size == 1)) { - if (names.contains(src.name)) { - // correct - Patch.empty - } else { - Patch.lint( - FileNameConsistentWaring( - names = names, - path = src.fullPath, - position = defs.headOption.getOrElse(packageObjects.head).tree.pos - ) - ) - } } else { - // if there are some toplevel trait, class, object - // TODO - Patch.empty + Patch.lint( + FileNameConsistentWaring( + names = names, + path = src.fullPath, + position = defs.headOption.getOrElse(packageObjects.head).tree.pos + ) + ) } - case _ => - // another input type + } else { + // if there are some toplevel trait, class, object + // TODO Patch.empty - } + } + case _ => + // another input type + Patch.empty } } } diff --git a/tests/src/test/scala/fix/RuleSuite.scala b/tests/src/test/scala/fix/RuleSuite.scala index 632b745..3f0daa3 100644 --- a/tests/src/test/scala/fix/RuleSuite.scala +++ b/tests/src/test/scala/fix/RuleSuite.scala @@ -2,7 +2,22 @@ package fix import scalafix.testkit.AbstractSemanticRuleSuite import org.scalatest.funsuite.AnyFunSuiteLike +import scala.util.Properties class RuleSuite extends AbstractSemanticRuleSuite with AnyFunSuiteLike { - runAllTests() + private[this] val excludeWindows: Set[String] = Set( + "FlatMapCollectTest", + "DuplicateWildcardImportTest", + "UnnecessarySortTest", + ).map(_ + ".scala") + + testsToRun + .filter(x => + if (Properties.isWin) { + !excludeWindows(x.path.input.toFile.getName) + } else { + true + } + ) + .foreach(runOn) }