Skip to content

Add scalafmtAll hook#15

Merged
adamw merged 6 commits into
softwaremill:masterfrom
gumaz:master
Mar 21, 2025
Merged

Add scalafmtAll hook#15
adamw merged 6 commits into
softwaremill:masterfrom
gumaz:master

Conversation

@gumaz
Copy link
Copy Markdown
Contributor

@gumaz gumaz commented Jan 27, 2025

What

  • Add scalafmtAll hook to apply formatting rather than just check
  • Add function to stage modified file so that scalafmtAll does not appear as failed

Why

Git pre-commit hook is failing when sbt scalafmtAll modifies files, even though the command itself exits successfully (exit code 0). This likely happens because git expects the working directory to be clean after the pre-commit hook runs. If scalafmtAll modifies any files, git sees uncommitted changes and fails the commit.
So I added a function to also run git add -u to stage tracked files that may have been modified by the formatter.

Test

image

@gumaz
Copy link
Copy Markdown
Contributor Author

gumaz commented Mar 18, 2025

Hello @adamw, any chance to get this merged?

Comment thread README.adoc Outdated
- `sbt-unused-imports` - as above, but also adds the "unused imports" warning.
- `sbt-scalafmt` - runs `scalafmtCheckAll`.
- `sbt-wartremover` - runs the wartremover plugin.
- `sbt-scalafmt-apply` - runs `scalafmtAll`.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

shouldn't we add some more information here, on how this differs from sbt-scalafmt?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Sure. Just done, keeping the coincise style of the other commands. Let me know if looks good or you want to add some more information

@adamw
Copy link
Copy Markdown
Member

adamw commented Mar 19, 2025

@gumaz sure! sorry, for some reason I didn't have notifications turned on for this repo

@adamw adamw merged commit 4e10e9a into softwaremill:master Mar 21, 2025
@adamw
Copy link
Copy Markdown
Member

adamw commented Mar 21, 2025

Thanks :)

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.

2 participants