Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

ktlint_code_style = android not working #1559

Closed
junhanRyu opened this issue Jul 28, 2022 · 4 comments · Fixed by #1564
Closed

ktlint_code_style = android not working #1559

junhanRyu opened this issue Jul 28, 2022 · 4 comments · Fixed by #1564
Labels
Milestone

Comments

@junhanRyu
Copy link

Expected Behavior

ktlint_code_style should be applied. but when run gradle task of ktlint, exception occurred

Observed Behavior

ClassCastException occurred

when I see the document in https://pinterest.github.io/ktlint/rules/configuration/
we can configure the code style to android. but the property is not working...

Exception in thread "main" java.util.concurrent.ExecutionException: java.lang.ClassCastException: class java.lang.String cannot be cast to class com.pinterest.ktlint.core.api.DefaultEditorConfigProperties$CodeStyleValue (java.lang.String is in module java.base of loader 'bootstrap'; com.pinterest.ktlint.core.api.DefaultEditorConfigProperties$CodeStyleValue is in unnamed module of loader 'app')
	at java.base/java.util.concurrent.FutureTask.report(FutureTask.java:122)
	at java.base/java.util.concurrent.FutureTask.get(FutureTask.java:191)
	at com.pinterest.ktlint.internal.KtlintCommandLine.parallel(KtlintCommandLine.kt:578)
	at com.pinterest.ktlint.internal.KtlintCommandLine.parallel$default(KtlintCommandLine.kt:536)
	at com.pinterest.ktlint.internal.KtlintCommandLine.lintFiles(KtlintCommandLine.kt:283)
	at com.pinterest.ktlint.internal.KtlintCommandLine.run(KtlintCommandLine.kt:235)
	at com.pinterest.ktlint.Main.main(Main.kt:31)
Caused by: java.lang.ClassCastException: class java.lang.String cannot be cast to class com.pinterest.ktlint.core.api.DefaultEditorConfigProperties$CodeStyleValue (java.lang.String is in module java.base of loader 'bootstrap'; com.pinterest.ktlint.core.api.DefaultEditorConfigProperties$CodeStyleValue is in unnamed module of loader 'app')
	at com.pinterest.ktlint.core.api.UsesEditorConfigProperties$DefaultImpls.getEditorConfigValue(UsesEditorConfigProperties.kt:50)
	at com.pinterest.ktlint.core.internal.VisitorProvider.getEditorConfigValue(VisitorProvider.kt:17)
	at com.pinterest.ktlint.core.internal.VisitorProvider.isNotDisabled(VisitorProvider.kt:132)
	at com.pinterest.ktlint.core.internal.VisitorProvider.visitor$ktlint_core(VisitorProvider.kt:43)
Caused by: java.lang.ClassCastException: class java.lang.String cannot be cast to class com.pinterest.ktlint.core.api.DefaultEditorConfigProperties$CodeStyleValue (java.lang.String is in module java.base of loader 'bootstrap'; com.pinterest.ktlint.core.api.DefaultEditorConfigProperties$CodeStyleValue is in unnamed module of loader 'app')

	at com.pinterest.ktlint.core.internal.VisitorProvider.visitor$ktlint_core$default(VisitorProvider.kt:37)
	at com.pinterest.ktlint.core.KtLint.lint(KtLint.kt:140)
	at com.pinterest.ktlint.internal.FileUtilsKt.lintFile(FileUtils.kt:174)
	at com.pinterest.ktlint.internal.KtlintCommandLine.process(KtlintCommandLine.kt:384)
	at com.pinterest.ktlint.internal.KtlintCommandLine.access$process(KtlintCommandLine.kt:48)
	at com.pinterest.ktlint.internal.KtlintCommandLine$lintFiles$3.invoke$lambda-1(KtlintCommandLine.kt:274)
	at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
	at java.base/java.lang.Thread.run(Thread.java:829)

Steps to Reproduce

add "ktlint_code_style = official" to project or module level .editorconfig

Your Environment

  • Version of ktlint used: 0.46.1
  • Relevant parts of the .editorconfig settings "ktlint_code_style"
  • Name and version (or code for custom task) of integration used (Gradle plugin, Maven plugin, command line, custom Gradle task): gradle plugin ( android )
  • Version of Gradle used (if applicable):
  • Operating System and version: macOs 11.6.2
@paul-dingemans
Copy link
Collaborator

Please provide more details on how to reproduce. Include a code sample, entire .editorconfig, etc.

@junhanRyu
Copy link
Author

module level .editorconfig is like below

[*.{kt, kts}]
ij_kotlin_allow_trailing_comma = true
ij_kotlin_allow_trailing_comma_on_call_site = true
ktlint_code_style = android

task difinition like below.

task localKtlint(type: JavaExec, group: "verification") {
    description = "..."
    mainClass.set("com.pinterest.ktlint.Main")
    classpath = configurations.ktlintPinterest
    ....
}

if I remove the line "ktlint_code_style = android" in .editorconfig file, task runs well. but I add the line, Exception occurs

@junhanRyu
Copy link
Author

I have question. what is the difference of between "official" and "android" for ktlint_code_style property. the "android" code style is for https://developer.android.com/kotlin/style-guide#formatting right?

@paul-dingemans
Copy link
Collaborator

Yes it is. But as far as I know this property only affects the default values of some other properties. For example, android codestyle uses a default max line length of 100 while official does not have a default set.

I am not aware of rules that apply different formatting implementations for Android vs official.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants