Comments (11)
@gino-m did you also update the ktfmt-gradle to the newer version (0.18.0)? I suspect the intellij plugin is working correctly but your codebase was formatted incorrectly with the older Gradle plugin
from ktfmt.
@greyhairredbear do you know if this is related to #420?
Unfortunately, not really. My original thought was that this might be because of different ktfmt versions, but according to the original post in the gradle plugin, this doesn't seem to be the case.
I can try if #420 produces the expected results.
UPDATE: @hick209 of course, you are correct, the @interface
is not valid Kotlin... @gino-m are you sure this is a .kt
file you are referencing here?
PS: @gino-m I suppose it would be helpful to also include the versions used in this post.
from ktfmt.
Just FYI: When using #420, the code stays unchanged (regardless of the formatting) due to it not being valid Kotlin. After removing the @interface
-portion, the output is the following:
/**
* Annotates view models to indicate that a single instance should be shared by all fragments in an
* activity. Only one instance of such view models will be created per activity by {@link
* ViewModelFactory#get(Fragment, Class)}.
*/
@Retention(RetentionPolicy.RUNTIME) public SharedViewModel {}
from ktfmt.
@hick209 So sorry, was moving too fast. That was Java - added a Kotlin example .
@greyhairredbear The formatting in the above snippet was produced by Android Studio ktfmt plugin 1.1.0.47, the Gradle plugin com.ncorti.ktfmt.gradle
version 0.17.0. Added these to the updated issue description and shared additional deltas in https://github.com/google/ground-android/pull/2412/files.
from ktfmt.
FYI: Just tried the new version of the plugin released last week and the code you mentioned
@Retention(AnnotationRetention.RUNTIME)
annotation class SharedViewModel
gets reformatted to the code produced by the gradle plugin
@Retention(AnnotationRetention.RUNTIME) annotation class SharedViewModel
Seems to me this is not an issue anymore - probably has been fixed with #420. @gino-m could you verify that also is the case with the code you've mentioned, so we can close this?
from ktfmt.
@greyhairredbear do you know if this is related to #420?
from ktfmt.
I tried to format you code here and it fails due to the @interface
there, as that's not valid Kotlin.
Could you revisit and share a piece of code where we could repro the issue?
from ktfmt.
@gino-m this might be related: cortinico/ktfmt-gradle#277
from ktfmt.
Confirmed, I upgraded to 1.1.0.49 and the outputs for this particular use case now match.
There are still some differences, which I've tried to capture here: https://github.com/google/ground-android/pull/2456/commits
The first run of the latest AS plugin across our codebase introduced many changes, most of which are not modified by running ktfmt via Gradle again. Subsequent commits demonstrate formatting which is changes by both entry points on each run, namely: google/ground-android@b9736a1
from ktfmt.
Good catch. I upgraded ktfmt-gradle to 0.18.0 and reformatted (google/ground-android@9dc9da5).
Reformatting with AS ktfmt 1.1.0.49 still yields several diffs (google/ground-android@e6a4974), but subsequent runs of ktfmt-gradle only modify three files (google/ground-android@ea60727). Two of these changes get undone when running the AS plugin again (google/ground-android@ebe230e).
At this point I would expect the diffs, if any, to be symmetrical, but running ktfmt-gradle again only modifies one file (google/ground-android@81371be). After that, subsequent runs fight over a single delta (google/ground-android@e26f8d9).
Edit: Pasting screenshot here for convenience. Before = ktfmt-gradle 0.180, After = AS ktfmt 1.1.0.49:
![image](https://private-user-images.githubusercontent.com/228050/326838834-74bb678f-fed5-45d1-baee-7e86334d3ce7.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MTc5MjY1MDQsIm5iZiI6MTcxNzkyNjIwNCwicGF0aCI6Ii8yMjgwNTAvMzI2ODM4ODM0LTc0YmI2NzhmLWZlZDUtNDVkMS1iYWVlLTdlODYzMzRkM2NlNy5wbmc_WC1BbXotQWxnb3JpdGhtPUFXUzQtSE1BQy1TSEEyNTYmWC1BbXotQ3JlZGVudGlhbD1BS0lBVkNPRFlMU0E1M1BRSzRaQSUyRjIwMjQwNjA5JTJGdXMtZWFzdC0xJTJGczMlMkZhd3M0X3JlcXVlc3QmWC1BbXotRGF0ZT0yMDI0MDYwOVQwOTQzMjRaJlgtQW16LUV4cGlyZXM9MzAwJlgtQW16LVNpZ25hdHVyZT1iMTVjNGQ0ZjdhY2NiYjI3MTNiODUwY2Y3MGRjZDdhMThhYjBjNzRhZTNhMjg1NmFhOTNlNTZjNzM0YWU0YTAwJlgtQW16LVNpZ25lZEhlYWRlcnM9aG9zdCZhY3Rvcl9pZD0wJmtleV9pZD0wJnJlcG9faWQ9MCJ9.6c3BMPvIcFf6P7T_gIrkhhE171y3nkKzcWUxkh05yRI)
If that delta is resolved the formatting should be stable across both plugins after each is run several times.
from ktfmt.
What is the output of the CLI? I ran ktfmt --google-style Config.kt
locally and got the second output - so it seems the plugin is behaving as expected.
from ktfmt.
Related Issues (20)
- 0.47 trailing comma changes cause class definitions to be formatted weirdly HOT 2
- Formatting isn't idempotent, and repeated invocations produce bad comment formatting HOT 13
- ktfmt version 0.47 incompatible with spotless HOT 2
- Feature request: GraalVM artifacts HOT 1
- add trailing comma support to other non-google styles HOT 7
- Indentation level should be a command-line argument HOT 2
- Treat trailing Elvis operator as part of a call chain HOT 2
- Adding target jar to releases HOT 2
- Weird lambda formatting when wrapping long line HOT 3
- Intellij Plugin set to Google (internal) always removes trailing commas HOT 1
- Lambdas following a statement can be treated as lambda arguments, breaking syntax HOT 1
- No artifacts were released for v0.48 and v0.49 HOT 4
- Trailing comma gets removed if there is only one parameter and it is formatted to be on its own line HOT 2
- ktfmt doesn't seem to work in IJ 2024.1.1 HOT 5
- Is ktfmt used on itself? HOT 5
- Misspelled flags in CLI can cause user data loss HOT 1
- How can I config Intellij plugin? HOT 2
- error: did not generate token "context" HOT 3
- Google style with trailing comma does not use maxWidth correctly HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ktfmt.