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

Warnings for all unformatted files #27

Merged
merged 2 commits into from Mar 14, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
17 changes: 10 additions & 7 deletions plugin/src/main/scala/org/scalafmt/sbt/ScalafmtPlugin.scala
Expand Up @@ -153,7 +153,7 @@ object ScalafmtPlugin extends AutoPlugin {
cached[Boolean](cacheDirectory, FilesInfo.lastModified) { modified =>
val changed = modified.filter(_.exists)
if (changed.size > 0) {
log.info(s"Formatting ${changed.size} Scala sources...")
log.info(s"Checking ${changed.size} Scala sources...")
Copy link
Member

Choose a reason for hiding this comment

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

Nice 👍

checkSources(changed.toSeq, config, log, writer)
} else {
true
Expand All @@ -167,22 +167,25 @@ object ScalafmtPlugin extends AutoPlugin {
log: Logger,
writer: PrintWriter
): Boolean = {
val res = withFormattedSources(sources, config, log, writer)(
val unformattedCount = withFormattedSources(sources, config, log, writer)(
(file, e) => {
log.err(e.toString)
false
},
(file, input, output) => {
val diff = input != output
if (diff) {
throw new MessageOnlyException(
s"${file.toString} isn't formatted properly!"
)
log.warn(s"${file.toString} isn't formatted properly!")
}
!diff
}
).flatten.forall(x => x)
res
).flatten.count(x => !x)
if (unformattedCount > 0) {
throw new MessageOnlyException(
s"${unformattedCount} files must be formatted"
)
}
unformattedCount == 0
}

private def cached[T](cacheBaseDirectory: File, inStyle: FileInfo.Style)(
Expand Down