Skip to content

Commit

Permalink
wip DirectoryAndPackageName
Browse files Browse the repository at this point in the history
  • Loading branch information
xuwei-k committed Jan 9, 2024
1 parent 32e43b3 commit c07968d
Show file tree
Hide file tree
Showing 11 changed files with 24 additions and 10 deletions.
20 changes: 10 additions & 10 deletions rules/src/main/scala/fix/DirectoryAndPackageName.scala
Original file line number Diff line number Diff line change
Expand Up @@ -152,12 +152,6 @@ class DirectoryAndPackageName(config: DirectoryAndPackageNameConfig) extends Syn
{
for {
path <- scalaSourceOpt
dirOpt = config.baseDirectory.find { dir =>
path.contains(dir)
}.map { dir =>
path.split(dir).last.split('/').init.mkString("/")
}
dir <- dirOpt
if packages.nonEmpty // TODO check if empty package
packageName = {
val x = packages
Expand All @@ -166,20 +160,26 @@ class DirectoryAndPackageName(config: DirectoryAndPackageNameConfig) extends Syn
if (keywords(p)) { p.replace("`", "") }
else p
)
.mkString("/")
packageObjectOpt match {
case Some(value) =>
x + "/" + value.name.value
x :+ value.name.value
case None =>
x
}
}
if packageName != dir
if config.baseDirectory.find { dir =>
path.contains(dir)
}.exists { fullDir =>
val splitedDir = path.split(fullDir).last.split('/').init.toList
packageName != splitedDir
} || {
path.split('/').init.toList.takeRight(packageName.size) != packageName
}
} yield {
Patch.lint(
Diagnostic(
id = "",
message = s"inconsistent package and directory\n${path}\n${packageName}",
message = s"inconsistent package and directory\n${path}\n${packageName.mkString("/")}",
position = packages.last.pos,
severity = config.severity
)
Expand Down
File renamed without changes.
5 changes: 5 additions & 0 deletions sbt-test/DirectoryAndPackageName/test-2/.scalafix.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
rules = [
DirectoryAndPackageName
]

DirectoryAndPackageName.severity = error
3 changes: 3 additions & 0 deletions sbt-test/DirectoryAndPackageName/test-2/build.sbt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
ThisBuild / scalafixDependencies += "com.github.xuwei-k" %% "scalafix-rules" % sys.props("scalafix-rules.version")

Compile / unmanagedSourceDirectories += baseDirectory.value / "my-src-dir"
3 changes: 3 additions & 0 deletions sbt-test/DirectoryAndPackageName/test-2/my-src-dir/a/X.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package b

class X
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
addSbtPlugin("ch.epfl.scala" % "sbt-scalafix" % sys.props("scalafix.version"))
2 changes: 2 additions & 0 deletions sbt-test/DirectoryAndPackageName/test-2/test
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
> Test/compile
-> scalafixAll

0 comments on commit c07968d

Please sign in to comment.