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 am trying to upgrade from 0.47.1 to 0.48.0. I am usiing the API to format the code contained in strings (no files). I used to use this for .kts kotlin code:
The script property of Code is false by default. However, both the function above and the Code class is internal. So I don’t know what the proper way is to format .kts code strings since I can’t find a public property or argument for setting script to true any more.
If I am correct you can just provide any filename ending with “.kts”. It is not needed that the file really exists. Problem with having both a filename and script property was that they could be inconsistent, like file “something.kt” with “script = true”.
However in my personal opinion, I think this is not ideal because passing a file path suggests that some IO might occur. In cases like mine where I am just formatting a string snippet of kts code with no associated file or project, this doesn't make sense. The function KtLintRuleEngine.format says '.editorconfig' files on the path are taken into account but this is not desirable for cases where snippets of kotlin code existing outside any file or project are being linted or formated.
The text was updated successfully, but these errors were encountered:
mgroth0
changed the title
Migrating from 0.47.1 to 0.48.0 for formating ".kts" strings (non-files) is confusing
Starting in 0.48.0, the library appears to not fully support the use case of formating kotlin snippets outside of any filesystem
Dec 20, 2022
Copied and pasted from Slack:
I am trying to upgrade from 0.47.1 to 0.48.0. I am usiing the API to format the code contained in strings (no files). I used to use this for .kts kotlin code:
But now that this is deprecated, its unclear how I would format kts code. KtLintRuleEngine.format internally creates a Code instance as seen below:
The script property of Code is false by default. However, both the function above and the Code class is internal. So I don’t know what the proper way is to format .kts code strings since I can’t find a public property or argument for setting script to true any more.
@paul-dingemans on slack answered:
However in my personal opinion, I think this is not ideal because passing a file path suggests that some IO might occur. In cases like mine where I am just formatting a string snippet of
kts
code with no associated file or project, this doesn't make sense. The functionKtLintRuleEngine.format
says'.editorconfig' files on the path are taken into account
but this is not desirable for cases where snippets of kotlin code existing outside any file or project are being linted or formated.The text was updated successfully, but these errors were encountered: