Skip to content

Commit adf25bb

Browse files
committed
FileOps: inline getFileMatcher in dynamic
1 parent 2d1d281 commit adf25bb

File tree

2 files changed

+24
-23
lines changed

2 files changed

+24
-23
lines changed

scalafmt-cli/jvm/src/main/scala/org/scalafmt/cli/ScalafmtDynamicRunner.scala

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ object ScalafmtDynamicRunner extends ScalafmtRunner {
2828
val sessionMatcher = session.matchesProjectFilters _
2929
val filterMatcher: Path => Boolean = options.customFilesOpt
3030
.fold(sessionMatcher) { customFiles =>
31-
val customMatcher = FileOps.getFileMatcher(customFiles.map(_.path))
31+
val customMatcher = getFileMatcher(customFiles.map(_.path))
3232
x => customMatcher(x) && sessionMatcher(x)
3333
}
3434
val inputMethods = getInputMethods(options, filterMatcher)
@@ -52,4 +52,27 @@ object ScalafmtDynamicRunner extends ScalafmtRunner {
5252
inputMethod.write(formatResult, input, options)
5353
}
5454

55+
private def getFileMatcher(paths: Seq[Path]): Path => Boolean = {
56+
val dirBuilder = Seq.newBuilder[Path]
57+
val fileBuilder = Set.newBuilder[Path]
58+
paths.foreach(path =>
59+
if (FileOps.isRegularFile(path)) fileBuilder += path
60+
else dirBuilder += path,
61+
)
62+
val dirs = dirBuilder.result()
63+
val files = fileBuilder.result()
64+
x =>
65+
files(x) || {
66+
val filename = x.toString
67+
val sep = x.getFileSystem.getSeparator
68+
dirs.exists { dir =>
69+
val dirname = dir.toString
70+
filename.startsWith(dirname) && {
71+
filename.length == dirname.length ||
72+
filename.startsWith(sep, dirname.length)
73+
}
74+
}
75+
}
76+
}
77+
5578
}

scalafmt-sysops/shared/src/main/scala/org/scalafmt/sysops/FileOps.scala

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -94,26 +94,4 @@ object FileOps {
9494
else if (file.isRegularFile) Some(Success(file.path))
9595
else Some(Failure(new AccessDeniedException(s"Config not a file: $file")))
9696

97-
def getFileMatcher(paths: Seq[Path]): Path => Boolean = {
98-
val dirBuilder = Seq.newBuilder[Path]
99-
val fileBuilder = Set.newBuilder[Path]
100-
paths.foreach(path =>
101-
if (isRegularFile(path)) fileBuilder += path else dirBuilder += path,
102-
)
103-
val dirs = dirBuilder.result()
104-
val files = fileBuilder.result()
105-
x =>
106-
files(x) || {
107-
val filename = x.toString
108-
val sep = x.getFileSystem.getSeparator
109-
dirs.exists { dir =>
110-
val dirname = dir.toString
111-
filename.startsWith(dirname) && {
112-
filename.length == dirname.length ||
113-
filename.startsWith(sep, dirname.length)
114-
}
115-
}
116-
}
117-
}
118-
11997
}

0 commit comments

Comments
 (0)