Skip to content

Commit

Permalink
Prevent breaking API change in Code class
Browse files Browse the repository at this point in the history
  • Loading branch information
paul-dingemans committed Oct 19, 2024
1 parent d53a62e commit 8f92b3f
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,6 @@ internal class KtlintCommandLine : CliktCommand(name = "ktlint") {
lintStdin(
ktLintRuleEngine,
aggregatedReporter,
stdinPath,
)
} else {
lintFiles(
Expand Down Expand Up @@ -433,17 +432,18 @@ internal class KtlintCommandLine : CliktCommand(name = "ktlint") {
private fun lintStdin(
ktLintRuleEngine: KtLintRuleEngine,
reporter: ReporterV2,
stdinpath: String?,
) {
val expandedStdinPath =
stdinpath
val code =
stdinPath
?.expandTildeToFullPath()
?.let { path -> Paths.get(path) }
?.let { Code.fromStdin(it) }
?: Code.fromStdin()
report(
KtLintRuleEngine.STDIN_FILE,
process(
ktLintRuleEngine = ktLintRuleEngine,
code = Code.fromStdin(expandedStdinPath),
code = code,
baselineLintErrors = emptyList(),
),
reporter,
Expand Down
1 change: 1 addition & 0 deletions ktlint-rule-engine/api/ktlint-rule-engine.api
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public final class com/pinterest/ktlint/rule/engine/api/Code$Companion {
public static synthetic fun fromSnippet$default (Lcom/pinterest/ktlint/rule/engine/api/Code$Companion;Ljava/lang/String;ZILjava/lang/Object;)Lcom/pinterest/ktlint/rule/engine/api/Code;
public final fun fromSnippetWithPath (Ljava/lang/String;Ljava/nio/file/Path;)Lcom/pinterest/ktlint/rule/engine/api/Code;
public static synthetic fun fromSnippetWithPath$default (Lcom/pinterest/ktlint/rule/engine/api/Code$Companion;Ljava/lang/String;Ljava/nio/file/Path;ILjava/lang/Object;)Lcom/pinterest/ktlint/rule/engine/api/Code;
public final fun fromStdin ()Lcom/pinterest/ktlint/rule/engine/api/Code;
public final fun fromStdin (Ljava/nio/file/Path;)Lcom/pinterest/ktlint/rule/engine/api/Code;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,13 @@ public class Code private constructor(
* 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.
*/
public fun fromStdin(stdinPath: Path?): Code = fromSnippetWithPath(String(System.`in`.readBytes()), virtualPath = stdinPath)
public fun fromStdin(): Code = fromSnippetWithPath(String(System.`in`.readBytes()))

/**
* Create [Code] by reading the snippet from 'stdin'. The code snippet is associated with the given path. The actual file does not
* need to exist, neither do the contents of the actual file have to match with the content specified via 'stdin'. The
* '.editorconfig' files on the [virtualPath] are respected.
*/
public fun fromStdin(virtualPath: Path): Code = fromSnippetWithPath(String(System.`in`.readBytes()), virtualPath = virtualPath)
}
}

0 comments on commit 8f92b3f

Please # to comment.