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've looked into using this tool to format our codebase since we are really not that happy with KtLint because of the issues you mentioned in the README already.
I noticed however that if a class has a property with an annotation that has a use-site target ktfmt errors.
So the class looks like this:
class Something {
@field:[Inject Named("WEB_VIEW")]
internal lateinit var httpClient: OkHttpClient
}
The error is the following one:
error: expected token: '@'; generated internal instead
com.google.googlejavaformat.FormattingError: 71:5: error: expected token: '@'; generated internal instead
at com.google.googlejavaformat.OpsBuilder.token(OpsBuilder.java:315)
at com.facebook.ktfmt.KotlinInputAstVisitor.token(KotlinInputAstVisitor.kt:1689)
at com.facebook.ktfmt.KotlinInputAstVisitor.token$default(KotlinInputAstVisitor.kt:1688)
at com.facebook.ktfmt.KotlinInputAstVisitor.visitKeywordModifiers(KotlinInputAstVisitor.kt:1115)
at com.facebook.ktfmt.KotlinInputAstVisitor.declareOne(KotlinInputAstVisitor.kt:785)
at com.facebook.ktfmt.KotlinInputAstVisitor.visitProperty(KotlinInputAstVisitor.kt:354)
at org.jetbrains.kotlin.psi.KtVisitorVoid.visitProperty(KtVisitorVoid.java:489)
at org.jetbrains.kotlin.psi.KtVisitorVoid.visitProperty(KtVisitorVoid.java:21)
at org.jetbrains.kotlin.psi.KtProperty.accept(KtProperty.java:58)
at org.jetbrains.kotlin.psi.KtElementImplStub.accept(KtElementImplStub.java:59)
at com.facebook.ktfmt.KotlinInputAstVisitor.visitStatements(KotlinInputAstVisitor.kt:347)
at com.facebook.ktfmt.KotlinInputAstVisitor.visitBlockBody(KotlinInputAstVisitor.kt:328)
at com.facebook.ktfmt.KotlinInputAstVisitor.visitClassOrObject(KotlinInputAstVisitor.kt:886)
at org.jetbrains.kotlin.psi.KtVisitorVoid.visitClassOrObject(KtVisitorVoid.java:465)
at org.jetbrains.kotlin.psi.KtVisitorVoid.visitClassOrObject(KtVisitorVoid.java:21)
at org.jetbrains.kotlin.psi.KtVisitor.visitClass(KtVisitor.java:33)
at org.jetbrains.kotlin.psi.KtVisitorVoid.visitClass(KtVisitorVoid.java:33)
at org.jetbrains.kotlin.psi.KtVisitorVoid.visitClass(KtVisitorVoid.java:459)
at org.jetbrains.kotlin.psi.KtVisitorVoid.visitClass(KtVisitorVoid.java:21)
at org.jetbrains.kotlin.psi.KtClass.accept(KtClass.kt:20)
at org.jetbrains.kotlin.psi.KtElementImplStub.accept(KtElementImplStub.java:59)
at com.facebook.ktfmt.KotlinInputAstVisitor.visitKtFile(KotlinInputAstVisitor.kt:1660)
at org.jetbrains.kotlin.psi.KtVisitorVoid.visitKtFile(KtVisitorVoid.java:513)
at org.jetbrains.kotlin.psi.KtVisitorVoid.visitKtFile(KtVisitorVoid.java:21)
at org.jetbrains.kotlin.psi.KtFile.accept(KtFile.kt:242)
at org.jetbrains.kotlin.psi.KtFile.accept(KtFile.kt:229)
at com.facebook.ktfmt.FormatterKt.format(Formatter.kt:79)
at com.facebook.ktfmt.Main.formatFile(Main.kt:82)
at com.facebook.ktfmt.Main.access$formatFile(Main.kt:31)
at com.facebook.ktfmt.Main$run$1.test(Main.kt:63)
at com.facebook.ktfmt.Main$run$1.test(Main.kt:31)
at java.base/java.util.stream.MatchOps$1MatchSink.accept(MatchOps.java:90)
at java.base/java.util.ArrayList$ArrayListSpliterator.tryAdvance(ArrayList.java:1601)
at java.base/java.util.stream.ReferencePipeline.forEachWithCancel(ReferencePipeline.java:127)
at java.base/java.util.stream.AbstractPipeline.copyIntoWithCancel(AbstractPipeline.java:502)
at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:488)
at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:474)
at java.base/java.util.stream.MatchOps$MatchTask.doLeaf(MatchOps.java:306)
at java.base/java.util.stream.MatchOps$MatchTask.doLeaf(MatchOps.java:277)
at java.base/java.util.stream.AbstractShortCircuitTask.compute(AbstractShortCircuitTask.java:115)
at java.base/java.util.concurrent.CountedCompleter.exec(CountedCompleter.java:746)
at java.base/java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:290)
at java.base/java.util.concurrent.ForkJoinPool$WorkQueue.topLevelExec(ForkJoinPool.java:1016)
at java.base/java.util.concurrent.ForkJoinPool.scan(ForkJoinPool.java:1665)
at java.base/java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1598)
at java.base/java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:177)
I would be more than willing to see how I can fix this by making a PR perhaps with some guidance on where to start :).
The text was updated successfully, but these errors were encountered:
Thanks for the report!
Each token in the input must be outputted by our AST visitor, and when we miss things the program crashes. Apologies for that - we'll prioritize fixing this.
I started by adding a test case to FormatterKtTest.kt - thanks for the minimal sample!
It's a bit of a rabbit hole to fix this, but I almost got it working.
Summary:
Release Notes:
* Handle annotations with type arguments (fixes#48)
* Fit annotations in one line when possible
* Handle multi-annotations with use-site targets (fixes#51)
Reviewed By: strulovich
Differential Revision: D22395554
fbshipit-source-id: 4faf371b69edb95431ad244d8fd869a7fa942d4b
Hi there!
I've looked into using this tool to format our codebase since we are really not that happy with KtLint because of the issues you mentioned in the README already.
I noticed however that if a class has a property with an annotation that has a use-site target ktfmt errors.
So the class looks like this:
The error is the following one:
I would be more than willing to see how I can fix this by making a PR perhaps with some guidance on where to start :).
The text was updated successfully, but these errors were encountered: