Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Autoformat Java examples #3919

Merged
merged 42 commits into from
Nov 10, 2024
Merged

Autoformat Java examples #3919

merged 42 commits into from
Nov 10, 2024

Conversation

myyk
Copy link
Contributor

@myyk myyk commented Nov 7, 2024

Change 2/3 for #3829

  • I updated the PalantirFormatModule.scala so that it didn't create a ton of noise when there's actually no issues such as no java code changing. I think this is a good thing to do, but I'm not 100% since some users might feel this change in some way.
  • Bugfix: The Github Action now fails on any error instead of only ./mill -i __.fix --check (was using ; instead of &&)
  • Added Palantir formatting into the Github Action
  • Removed a lot of cruft so that the example java modules could use the PalantirFormatModule.

@myyk

This comment was marked as outdated.

@myyk
Copy link
Contributor Author

myyk commented Nov 8, 2024

@lihaoyi I think this one is ready for a review when you get a chance.

Update: I'm not sure how to update the linecounts in the failing tests. I'm having trouble understanding how those are run.

@myyk myyk mentioned this pull request Nov 8, 2024
3 tasks
Copy link
Member

@lihaoyi lihaoyi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great, I think just need to update the test cases and we're good to go

@lihaoyi
Copy link
Member

lihaoyi commented Nov 8, 2024

Looks like a bunch of PalantirFormatModuleTest tests are failing. I'm guessing those expect their test data to be mis-formatted, so we might need to figure out a way to skip those

@lihaoyi
Copy link
Member

lihaoyi commented Nov 9, 2024

So PalantirJavaFormat does not provide any builtin flags to ignore files or folders, instead Mill manages the listing of files to pass to the tool.

args ++=
sources
.iterator
.map(_.path)
.flatMap(os.walk(_, includeTarget = true))
.filter(os.isFile)
.filter(_.ext == "java")
.map(_.toString())

So we likely need to add some logic in Mill to allow PalantirJavaFormatModule to ignore particular globs, and then use that in Mill's own build (after rebootstrapping) to ignore the files and roll out enforcement internally.

To do this, I suggest we overload PalantirFormatModule.formatAll to take an additional optional parameter excludedGlobs: Seq[String]. We can then plumb those through to the java-file-listing above and use it to ignore files matching a glob (may need to find a glob-matching implementation online). We'd need to preserve the current formatAll signature for binary compatibility, but it can be a dumb forwarder to the new implementation

@myyk
Copy link
Contributor Author

myyk commented Nov 9, 2024 via email

@myyk
Copy link
Contributor Author

myyk commented Nov 9, 2024 via email

@lihaoyi
Copy link
Member

lihaoyi commented Nov 9, 2024

Ah I just noticed your skipping code in Mill's own build. Not sure why it's not working

lihaoyi added a commit that referenced this pull request Nov 10, 2024
Noticed this issue when working on
#3919. Added a test case to the
unit tests to cover it
@lihaoyi lihaoyi changed the title Lint java examples Autoformat Java examples Nov 10, 2024
@myyk
Copy link
Contributor Author

myyk commented Nov 10, 2024

Oh interesting. I see you changed the sources in example/build.mill, is that what added a lot more linting to this? That found a lot of files I missed.

@lihaoyi
Copy link
Member

lihaoyi commented Nov 10, 2024

@myyk yeah, previously we only used lintableJavaSources in PalantirFormatModule/, and didnt use it in ScalafmtModule/ so the Scala .mill files were not picked up. Furthermore, sources was pointed at testRepoRoot, which for the javalib/ examples contains a copy of the files and not the original ones so formatting them doesn't do anything.

By re-using the name sources, both PalantirFormatModule/ and ScalafmtModule/ pick up all of them, which is why now the .mill files in the Java folders are being picked up. And I re-targeted sources directly at millSourcePath, so it doesn't get affected by the override of testRepoRoot in ExampleCrossModuleJava

@myyk
Copy link
Contributor Author

myyk commented Nov 10, 2024

That all makes sense. Oh, I think I fixed some of that in the next change #3923 and didn't back port it because I thought it was working enough in this PR. Sorry about that. But also, I wasn't sure about fully redefining sources like that because I'm new to the project. That makes a lot of sense though and I'm glad for the help.

@lihaoyi lihaoyi merged commit 435a721 into com-lihaoyi:main Nov 10, 2024
3 checks passed
@lefou lefou added this to the 0.12.2 milestone Nov 10, 2024
@myyk myyk deleted the lint-java-examples branch November 10, 2024 13:22
lihaoyi added a commit that referenced this pull request Nov 15, 2024
* [x] Needs #3919 as this builds on it
* [x] Update this to use #3961, switching to `KtlintModule`
* [x] Needs #3966 to disable ktlint for some files

Last change I think needed for #3829

Overview:
* Changes `KtfmtModule` to set the error code when there's changes like
is true of the other formatters.
* Some simplifications were made to the `example/package.mill` based on
similarities with Java/Kotlin.
* Files were formatted
* CI was updated

---------

Co-authored-by: Li Haoyi <haoyi.sg@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants