Skip to content
New issue

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

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

Already on GitHub? # to your account

Bumping from 2.4.4 to 2.4.5, scalafmtCheckAll ignores badly formatted files if git is not setup and config says otherwise #189

Closed
daddykotex opened this issue Dec 15, 2021 · 5 comments · Fixed by #195

Comments

@daddykotex
Copy link

Hi,

Thanks for sbt-scalafmt. We use it extensively. I create this issue mostly for documentation purposes because I guess we won't be the only to have this issue. We have an in-house sbt plugin that uses sbt-scalafmt. Bumping from 2.4.4 to 2.4.5, one of our test started to fail.

The test contains one source file that is badly formatted. When sbt runs the test, it copies everything into a new directory, where git is not setup. I understand that's why scalafmtCheckAll does not fail anymore: git is not setup, but our config says git is.

Looking at the changelog, I can see #172 could have an effect on this.

I have a solution and it's fine for me.

@daddykotex daddykotex changed the title Bumping from 2.4.4 to 2.4.5, scalafmtCheckAll ignores badly formatted files if unchanged Bumping from 2.4.4 to 2.4.5, scalafmtCheckAll ignores badly formatted files if git is not setup and config says otherwise Dec 15, 2021
@kitbellew
Copy link
Contributor

@daddykotex should you remove project.git = true if git is not set up and thus not used? the only purpose of that setting is use git to determine which files should be formatted.

@daddykotex
Copy link
Author

daddykotex commented Dec 16, 2021 via email

@kitbellew
Copy link
Contributor

@daddykotex understood, thank you. is there a recommended solution?

@kitbellew
Copy link
Contributor

also, it's possible that the next version will work. in #183, git is within Try and falls back to no filtering.

@daddykotex
Copy link
Author

@daddykotex understood, thank you. is there a recommended solution?

We have a sbt-test, that runs in a layout like this:

.
├── build.sbt
├── p1
│   └── src
│       └── main
│           └── scala
│               └── Hello.scala # this file is not formatted properly
├── project
│   ├── build.properties
│   ├── plugins.sbt
│   └── project
└── test

I updated the test file with the following diff:

diff --git a/src/sbt-test/sbt-company/tools/test b/src/sbt-test/sbt-company/tools/test
index 1047a45..6f9d5c7 100644
--- a/src/sbt-test/sbt-company/tools/test
+++ b/src/sbt-test/sbt-company/tools/test
@@ -4,6 +4,12 @@
 > generateScalafmtConf
 $ exists .scalafmt.conf

+# we set up git, and commit all the files
+# otherwise, scalafmt wont check them (starting 2.4.5)
+# if project.git = true
+$ exec git init -b main
+$ exec git add .
+$ exec git commit -m "init commit"
+
 # fails because the formatting is in error
 -> p1/scalafmtCheckAll

If the generated config did not contain project.git = true, I assume no problem would have happened. But the configuration contains it because all of our project are on git. So instead of adding logic to update the config, I made sure that, during this particular test, we setup git before running scalafmt.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants