You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I expect ktlint to handle build.gradle.kts files over standard in.
$ <build.gradle.kts ktlint --stdin
Observed Behavior
$ <build.gradle.kts ktlint --log-level=info --stdin
10:37:16.772 [main] INFO com.pinterest.ktlint.internal.KtlintCommandLine - Enable default patterns [**/*.kt, **/*.kts]
<stdin>:1:1: Not a valid Kotlin file (1:1 expecting a top level declaration) (cannot be auto-corrected) ()
Summary error count (descending) by rule:
Not a valid Kotlin file: 1
Steps to Reproduce
Pass a build.gradle.kts file over standard input.
Your Environment
Version of ktlint used: 0.48.2
Relevant parts of the .editorconfig settings: n/a
Name and version (or code for custom task) of integration used (Gradle plugin, Maven plugin, command line, custom Gradle task): n/a
Version of Gradle used (if applicable): 8.0.1
Operating System and version: macOS Ventura 13.2.1
The text was updated successfully, but these errors were encountered:
Given the command you specified, ktlint can not determine whether the code snippet is to be treated as kotlin (.kt) or as kotlin script (.kts).
The first log line is misleading in this case. It actually tells you which patterns will be recognized when scanning files. However when reading from stdin no files are scanned, only stdin is read.
10:37:16.772 [main] INFO com.pinterest.ktlint.internal.KtlintCommandLine - Enable default patterns [**/*.kt, **/*.kts]
Ktlint needs to run the embedded kotlin compiler with a file with either .kt or a .kts extension and it chooses .kt by default. As a result the pre-compiler throws the error:
<stdin>:1:1: Not a valid Kotlin file (1:1 expecting a top level declaration) (cannot be auto-corrected) ()
Possible solutions to be investigated:
For extension to be specified explicitly when reading from stdin. Either use the current patterns parameter of add a new parameter which indicates that stdin has to be treated as kotlin script
In case reading from stdin then retry compilation automatically as .kts file in case initial compilation with .kt fails.
When reading from stdin send the same snippet both as .kt and .kts file to the processing pipeline. Exactly one of the files is expected to raise an compilation error and could be ignored.
Expected Behavior
I expect ktlint to handle build.gradle.kts files over standard in.
$ <build.gradle.kts ktlint --stdin
Observed Behavior
Steps to Reproduce
Pass a build.gradle.kts file over standard input.
Your Environment
.editorconfig
settings: n/aThe text was updated successfully, but these errors were encountered: