-
Notifications
You must be signed in to change notification settings - Fork 44
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
add detailed error config (#71) #142
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -62,6 +62,8 @@ object ScalafmtPlugin extends AutoPlugin { | |||||
"Execute the scalafmtCheck task for all configurations in which it is enabled. " + | ||||||
"(By default this means the Compile and Test configurations.)" | ||||||
) | ||||||
val scalafmtDetailedError = | ||||||
settingKey[Boolean]("Log detailed error with stack trace, off by default") | ||||||
} | ||||||
|
||||||
import autoImport._ | ||||||
|
@@ -100,11 +102,12 @@ object ScalafmtPlugin extends AutoPlugin { | |||||
config: Path, | ||||||
log: Logger, | ||||||
writer: OutputStreamWriter, | ||||||
resolvers: Seq[Resolver] | ||||||
resolvers: Seq[Resolver], | ||||||
isDetailedError: Boolean | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
more understandable name |
||||||
)( | ||||||
onFormat: (File, Input, Output) => T | ||||||
): Seq[Option[T]] = { | ||||||
val reporter = new ScalafmtSbtReporter(log, writer) | ||||||
val reporter = new ScalafmtSbtReporter(log, writer, isDetailedError) | ||||||
val repositories = resolvers.collect { | ||||||
case r: MavenRepository => r.root | ||||||
} | ||||||
|
@@ -147,7 +150,8 @@ object ScalafmtPlugin extends AutoPlugin { | |||||
config: Path, | ||||||
log: Logger, | ||||||
writer: OutputStreamWriter, | ||||||
resolvers: Seq[Resolver] | ||||||
resolvers: Seq[Resolver], | ||||||
isDetailedError: Boolean | ||||||
): Unit = { | ||||||
trackSourcesAndConfig(cacheStoreFactory, sources, config) { | ||||||
(outDiff, configChanged, prev) => | ||||||
|
@@ -162,7 +166,14 @@ object ScalafmtPlugin extends AutoPlugin { | |||||
} | ||||||
if (filesToFormat.nonEmpty) { | ||||||
log.info(s"Formatting ${filesToFormat.size} Scala sources...") | ||||||
formatSources(filesToFormat, config, log, writer, resolvers) | ||||||
formatSources( | ||||||
filesToFormat, | ||||||
config, | ||||||
log, | ||||||
writer, | ||||||
resolvers, | ||||||
isDetailedError | ||||||
) | ||||||
} | ||||||
ScalafmtAnalysis(Set.empty) | ||||||
} | ||||||
|
@@ -173,10 +184,18 @@ object ScalafmtPlugin extends AutoPlugin { | |||||
config: Path, | ||||||
log: Logger, | ||||||
writer: OutputStreamWriter, | ||||||
resolvers: Seq[Resolver] | ||||||
resolvers: Seq[Resolver], | ||||||
isDetailedError: Boolean | ||||||
): Unit = { | ||||||
val cnt = | ||||||
withFormattedSources(sources.toSeq, config, log, writer, resolvers)( | ||||||
withFormattedSources( | ||||||
sources.toSeq, | ||||||
config, | ||||||
log, | ||||||
writer, | ||||||
resolvers, | ||||||
isDetailedError | ||||||
)( | ||||||
(file, input, output) => { | ||||||
if (input != output) { | ||||||
IO.write(file, output) | ||||||
|
@@ -199,7 +218,8 @@ object ScalafmtPlugin extends AutoPlugin { | |||||
config: Path, | ||||||
log: Logger, | ||||||
writer: OutputStreamWriter, | ||||||
resolvers: Seq[Resolver] | ||||||
resolvers: Seq[Resolver], | ||||||
isDetailedError: Boolean | ||||||
): ScalafmtAnalysis = { | ||||||
trackSourcesAndConfig(cacheStoreFactory, sources, config) { | ||||||
(outDiff, configChanged, prev) => | ||||||
|
@@ -213,7 +233,14 @@ object ScalafmtPlugin extends AutoPlugin { | |||||
else prev.failedScalafmtCheck & outDiff.unmodified | ||||||
prevFailed foreach { warnBadFormat(_, log) } | ||||||
val result = | ||||||
checkSources(filesToCheck.toSeq, config, log, writer, resolvers) | ||||||
checkSources( | ||||||
filesToCheck.toSeq, | ||||||
config, | ||||||
log, | ||||||
writer, | ||||||
resolvers, | ||||||
isDetailedError | ||||||
) | ||||||
prev.copy( | ||||||
failedScalafmtCheck = result.failedScalafmtCheck | prevFailed | ||||||
) | ||||||
|
@@ -239,13 +266,21 @@ object ScalafmtPlugin extends AutoPlugin { | |||||
config: Path, | ||||||
log: Logger, | ||||||
writer: OutputStreamWriter, | ||||||
resolvers: Seq[Resolver] | ||||||
resolvers: Seq[Resolver], | ||||||
isDetailedError: Boolean | ||||||
): ScalafmtAnalysis = { | ||||||
if (sources.nonEmpty) { | ||||||
log.info(s"Checking ${sources.size} Scala sources...") | ||||||
} | ||||||
val unformatted = | ||||||
withFormattedSources(sources, config, log, writer, resolvers)( | ||||||
withFormattedSources( | ||||||
sources, | ||||||
config, | ||||||
log, | ||||||
writer, | ||||||
resolvers, | ||||||
isDetailedError | ||||||
)( | ||||||
(file, input, output) => { | ||||||
val diff = input != output | ||||||
if (diff) { | ||||||
|
@@ -323,14 +358,15 @@ object ScalafmtPlugin extends AutoPlugin { | |||||
} | ||||||
|
||||||
private def scalafmtTask = | ||||||
Def.task { | ||||||
Def.task { //TODO implement from here | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What does this comment means? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It was a reminder for myself. Sorry that I failed to check it before sending the commit. I'll remove it and send it with other changes. |
||||||
formatSources( | ||||||
streams.value.cacheStoreFactory, | ||||||
(unmanagedSources in scalafmt).value, | ||||||
scalaConfig.value, | ||||||
streams.value.log, | ||||||
outputStreamWriter(streams.value), | ||||||
fullResolvers.value | ||||||
fullResolvers.value, | ||||||
scalafmtDetailedError.value | ||||||
) | ||||||
} tag (ScalafmtTagPack: _*) | ||||||
|
||||||
|
@@ -341,14 +377,16 @@ object ScalafmtPlugin extends AutoPlugin { | |||||
sbtConfig.value, | ||||||
streams.value.log, | ||||||
outputStreamWriter(streams.value), | ||||||
fullResolvers.value | ||||||
fullResolvers.value, | ||||||
scalafmtDetailedError.value | ||||||
) | ||||||
formatSources( | ||||||
metabuildSources.value.toSet, | ||||||
scalaConfig.value, | ||||||
streams.value.log, | ||||||
outputStreamWriter(streams.value), | ||||||
fullResolvers.value | ||||||
fullResolvers.value, | ||||||
scalafmtDetailedError.value | ||||||
) | ||||||
} tag (ScalafmtTagPack: _*) | ||||||
|
||||||
|
@@ -360,7 +398,8 @@ object ScalafmtPlugin extends AutoPlugin { | |||||
scalaConfig.value, | ||||||
streams.value.log, | ||||||
outputStreamWriter(streams.value), | ||||||
fullResolvers.value | ||||||
fullResolvers.value, | ||||||
scalafmtDetailedError.value | ||||||
) | ||||||
trueOrBoom(analysis) | ||||||
} tag (ScalafmtTagPack: _*) | ||||||
|
@@ -373,7 +412,8 @@ object ScalafmtPlugin extends AutoPlugin { | |||||
sbtConfig.value, | ||||||
streams.value.log, | ||||||
outputStreamWriter(streams.value), | ||||||
fullResolvers.value | ||||||
fullResolvers.value, | ||||||
scalafmtDetailedError.value | ||||||
) | ||||||
) | ||||||
trueOrBoom( | ||||||
|
@@ -382,13 +422,14 @@ object ScalafmtPlugin extends AutoPlugin { | |||||
scalaConfig.value, | ||||||
streams.value.log, | ||||||
outputStreamWriter(streams.value), | ||||||
fullResolvers.value | ||||||
fullResolvers.value, | ||||||
scalafmtDetailedError.value | ||||||
) | ||||||
) | ||||||
} tag (ScalafmtTagPack: _*) | ||||||
|
||||||
lazy val scalafmtConfigSettings: Seq[Def.Setting[_]] = Seq( | ||||||
scalafmt := scalafmtTask.value, | ||||||
scalafmt := scalafmtTask, | ||||||
scalafmtIncremental := scalafmt.value, | ||||||
scalafmtSbt := scalafmtSbtTask.value, | ||||||
scalafmtCheck := scalafmtCheckTask.value, | ||||||
|
@@ -420,7 +461,8 @@ object ScalafmtPlugin extends AutoPlugin { | |||||
scalaConfig.value, | ||||||
streams.value.log, | ||||||
outputStreamWriter(streams.value), | ||||||
fullResolvers.value | ||||||
fullResolvers.value, | ||||||
scalafmtDetailedError.value | ||||||
) | ||||||
} | ||||||
) | ||||||
|
@@ -446,7 +488,8 @@ object ScalafmtPlugin extends AutoPlugin { | |||||
|
||||||
override def globalSettings: Seq[Def.Setting[_]] = | ||||||
Seq( | ||||||
scalafmtOnCompile := false | ||||||
scalafmtOnCompile := false, | ||||||
scalafmtDetailedError := false | ||||||
) | ||||||
|
||||||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure about English grammar :)
May be
Enables logging of detailed errors with stacktraces, disabled by default
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It sounds better :)