-
Notifications
You must be signed in to change notification settings - Fork 512
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
UTF-8 with BOM results in "Not a valid Kotlin file (expecting a top level declaration)" #272
Comments
Hey @bagage. I can't reproduce. Can you please double-check everything?
|
It's odd: it is working fine on my PC (debian) but not on my working PC (ubuntu 18.04.1). However the ktlint binary is the same, downloaded via $ md5sum ktlint
9f7990328c937b5ef5fb63da88e9b3db ktlint
$ ktlint --version
0.27.0 What in environment could affect ktlint behavior? |
Hmm, after a bit of investigation, I found out that it was caused by the file encoding: $ file /tmp/test-ok.kt # returns C source, ASCII text
$ file /tmp/test-broken.kt # returns C source, UTF-8 Unicode (with BOM) text Here's a link to the broken file in case you want to reproduce the issue. For now I'll convert my files to ASCII instead :). If UTF-8 Unicode files are not valid Kotlin file, it would be great to have a better hint about the error maybe? |
Huh. Apparently, https://github.com/shyiko/ktlint/blob/master/ktlint-core/src/main/kotlin/com/github/shyiko/ktlint/core/KtLint.kt#L140 chokes when BOM is present (UTF-8 without BOM is fine). Thanks for tracking it down, @bagage! |
When running
ktlint
(0.27.0) on some kotlin file, I get this error:Error :
The text was updated successfully, but these errors were encountered: