Skip to content

Commit

Permalink
allow extra information to be passed for logging
Browse files Browse the repository at this point in the history
  • Loading branch information
mgroth0 committed Dec 24, 2024
1 parent 9d35551 commit 0de1747
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ public class Code private constructor(
filePath?.pathString.orEmpty()
}

public fun filePathOrFileNameOrStdin(): String = filePath?.pathString ?: fileNameOrStdin()

public companion object {
/**
* Create [Code] from a [file] containing valid Kotlin code or script. The '.editorconfig' files on the path to [file] are taken
Expand Down Expand Up @@ -72,15 +74,18 @@ public class Code private constructor(
* The [content] represent a valid piece of Kotlin code or Kotlin script. The '.editorconfig' files on the filesystem are ignored as
* the snippet is not associated with a file path. Use [Code.fromFile] for scanning a file while at the same time respecting the
* '.editorconfig' files on the path to the file.
*
* Use optional parameter [debugFilename] to better identify what is being formatted in various log messages. This does not affect the behavior of the formatter other than logging.
*/
public fun fromSnippet(
content: String,
script: Boolean = false,
debugFilename: String? = null
): Code =
Code(
content = content,
filePath = null,
fileName = null,
fileName = debugFilename,
script = script,
isStdIn = true,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ internal class CodeFormatter(
// Lint violations were found, but the file has not been changed.
LOGGER.warn {
"Format was not able to resolve all violations which (theoretically) can be autocorrected in file " +
code.filePathOrStdin()
code.filePathOrFileNameOrStdin()
}
break
}
Expand All @@ -83,7 +83,7 @@ internal class CodeFormatter(
lintAfterFormat().also {
LOGGER.warn {
"Format was not able to resolve all violations which (theoretically) can be autocorrected in file " +
"${code.filePathOrStdin()} in $maxFormatRunsPerFile consecutive runs of format."
"${code.filePathOrFileNameOrStdin()} in $maxFormatRunsPerFile consecutive runs of format."
}
}
}
Expand Down

0 comments on commit 0de1747

Please sign in to comment.