Skip to content

Commit cbb9e8a

Browse files
Skip autoformatting in code files containing build headers (#5822)
Preparation for #5820, so we can include single `.java` or `.kt` files in our codebase without their `//|` build headers being mangled by the autoformatter --------- Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
1 parent 4d37738 commit cbb9e8a

File tree

2 files changed

+4
-0
lines changed

2 files changed

+4
-0
lines changed

libs/javalib/src/mill/javalib/palantirformat/PalantirFormatModule.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,9 @@ object PalantirFormatModule extends ExternalModule with PalantirFormatBaseModule
8787
.filter(os.exists(_))
8888
.flatMap(os.walk(_, includeTarget = true))
8989
.filter(os.isFile)
90+
// skip formatting single-file projects since Palantir Format messes up the header block
9091
.filter(_.ext == "java")
92+
.filter(!os.read(_).startsWith("//|"))
9193
.toSeq
9294

9395
if (check) {

libs/kotlinlib/src/mill/kotlinlib/ktlint/KtlintModule.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,9 @@ object KtlintModule extends ExternalModule with KtlintModule with DefaultTaskMod
121121
args ++= configArgument
122122
args ++= formatArgument
123123
args ++= filesToFormat.map(_.path)
124+
// skip formatting single-file projects since Palantir Format messes up the header block
124125
.filter(f => os.exists(f) && (f.ext == "kt" || f.ext == "kts"))
126+
.filter(!os.read(_).startsWith("//|"))
125127
.map(_.toString())
126128

127129
val exitCode = BuildCtx.withFilesystemCheckerDisabled {

0 commit comments

Comments
 (0)