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

Allow running scalafmt on generated sources #235

Open
OlegYch opened this issue Jul 1, 2024 · 3 comments
Open

Allow running scalafmt on generated sources #235

OlegYch opened this issue Jul 1, 2024 · 3 comments

Comments

@OlegYch
Copy link

OlegYch commented Jul 1, 2024

I couldn't find a way to hook scalafmt into generated guardrail sources.
Ideally it should run automatically without need for manual configuration, but that's probably sbt or scalafmt responsibility.

@OlegYch
Copy link
Author

OlegYch commented Jul 1, 2024

as a workaround i use Compile / scalafmt / unmanagedSources ++= (Compile / managedSources).value but that breaks caching of generated files

@blast-hardcheese
Copy link
Member

I think there's an opportunity to run the transformation before emission, which would solve the caching issue.

I don't have the time to look into this at the moment, but I'm happy to tend the release were a patch to arrive.

Looking though this, I believe the most sensible thing seems to be to create a new Key, perhaps guardrailFormatter, dereferenced on this line:

      scope / Keys.guardrail := cachedGuardrailTask(SbtKeys.name.value, scope.name, SbtKeys.scalaBinaryVersion.value)(name, _root_.sbt.Keys.streams.value)((scope / Keys.guardrailTasks).value, (scope / SbtKeys.managedSourceDirectories).value),

(Pardon for not directly linking the file, GitHub for mobile is quite limited for stuff like this.)

I'd think it could match whatever the type of sbt-scalafmt's corresponding Task, so we could guardrailFormatter := scalafmt or so, but I'm open to other ideas as well.

@OlegYch
Copy link
Author

OlegYch commented Jul 14, 2024

turns out it was easier, submitted #236

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

No branches or pull requests

2 participants