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 0.47.0 throwing error when using rules with prefix ij_kotlin #1627

Closed
4brunu opened this issue Sep 2, 2022 · 8 comments · Fixed by #1629
Closed

ktlint 0.47.0 throwing error when using rules with prefix ij_kotlin #1627

4brunu opened this issue Sep 2, 2022 · 8 comments · Fixed by #1629
Labels
bug cli ktlint command line interface
Milestone

Comments

@4brunu
Copy link

4brunu commented Sep 2, 2022

Expected Behavior

I updated ktlint from version 0.46.1 to 0.47.0 and when using rules with prefix ij_kotlin it throws errors.

Here is my .editorconfig file.

# http://editorconfig.org
root = true

[*.{kt,kts}]
disabled_rules = filename

ij_kotlin_allow_trailing_comma = true
ij_kotlin_allow_trailing_comma_on_call_site = true

With the previous versions it was working.

I have updated ktlint from version 0.46.1 to 0.47.0 and it started throwing the following exception.
If I downgrade ktlint from version 0.47.0 to 0.46.1 it works again.

./gradlew ktlintFormat --daemon
Configuration on demand is an incubating feature.

> Task :androidprojectliteandroid:ktlintFormat FAILED
Exception in thread "main" java.util.concurrent.ExecutionException: java.lang.ClassCastException: class java.lang.String cannot be cast to class java.lang.Boolean (java.lang.String and java.lang.Boolean are in module java.base of loader 'bootstrap')
        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:605)
        at com.pinterest.ktlint.internal.KtlintCommandLine.parallel$default(KtlintCommandLine.kt:563)
        at com.pinterest.ktlint.internal.KtlintCommandLine.lintFiles(KtlintCommandLine.kt:321)
        at com.pinterest.ktlint.internal.KtlintCommandLine.run(KtlintCommandLine.kt:268)
        at com.pinterest.ktlint.Main.main(Main.kt:27)
Caused by: java.lang.ClassCastException: class java.lang.String cannot be cast to class java.lang.Boolean (java.lang.String and java.lang.Boolean are in module java.base of loader 'bootstrap')
        at com.pinterest.ktlint.ruleset.standard.TrailingCommaOnCallSiteRule.beforeFirstNode(TrailingCommaOnCallSiteRule.kt:56)
        at com.pinterest.ktlint.core.KtLint.executeRule(KtLint.kt:194)
        at com.pinterest.ktlint.core.KtLint.access$executeRule(KtLint.kt:30)
        at com.pinterest.ktlint.core.KtLint$format$1.invoke(KtLint.kt:252)
        at com.pinterest.ktlint.core.KtLint$format$1.invoke(KtLint.kt:251)
        at com.pinterest.ktlint.core.internal.VisitorProvider$visitor$4.invoke(VisitorProvider.kt:82)
        at com.pinterest.ktlint.core.internal.VisitorProvider$visitor$4.invoke(VisitorProvider.kt:80)
        at com.pinterest.ktlint.core.KtLint.format(KtLint.kt:251)
        at com.pinterest.ktlint.internal.FileUtilsKt.formatFile(FileUtils.kt:254)
        at com.pinterest.ktlint.internal.KtlintCommandLine.process(KtlintCommandLine.kt:379)
        at com.pinterest.ktlint.internal.KtlintCommandLine.access$process(KtlintCommandLine.kt:52)
        at com.pinterest.ktlint.internal.KtlintCommandLine$lintFiles$3.invoke$lambda-0(KtlintCommandLine.kt:312)
        at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
        at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136)
        at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
        at java.base/java.lang.Thread.run(Thread.java:833)

> Task :androidprojectandroid:ktlintFormat
Exception in thread "main" java.util.concurrent.ExecutionException: java.lang.ClassCastException: class java.lang.String cannot be cast to class java.lang.Boolean (java.lang.String and java.lang.Boolean are in module java.base of loader 'bootstrap')
        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:605)
        at com.pinterest.ktlint.internal.KtlintCommandLine.parallel$default(KtlintCommandLine.kt:563)
        at com.pinterest.ktlint.internal.KtlintCommandLine.lintFiles(KtlintCommandLine.kt:321)
        at com.pinterest.ktlint.internal.KtlintCommandLine.run(KtlintCommandLine.kt:268)
        at com.pinterest.ktlint.Main.main(Main.kt:27)
Caused by: java.lang.ClassCastException: class java.lang.String cannot be cast to class java.lang.Boolean (java.lang.String and java.lang.Boolean are in module java.base of loader 'bootstrap')
        at com.pinterest.ktlint.ruleset.standard.TrailingCommaOnCallSiteRule.beforeFirstNode(TrailingCommaOnCallSiteRule.kt:56)
        at com.pinterest.ktlint.core.KtLint.executeRule(KtLint.kt:194)
        at com.pinterest.ktlint.core.KtLint.access$executeRule(KtLint.kt:30)
        at com.pinterest.ktlint.core.KtLint$format$1.invoke(KtLint.kt:252)
        at com.pinterest.ktlint.core.KtLint$format$1.invoke(KtLint.kt:251)
        at com.pinterest.ktlint.core.internal.VisitorProvider$visitor$4.invoke(VisitorProvider.kt:82)
        at com.pinterest.ktlint.core.internal.VisitorProvider$visitor$4.invoke(VisitorProvider.kt:80)
        at com.pinterest.ktlint.core.KtLint.format(KtLint.kt:251)
        at com.pinterest.ktlint.internal.FileUtilsKt.formatFile(FileUtils.kt:254)
        at com.pinterest.ktlint.internal.KtlintCommandLine.process(KtlintCommandLine.kt:379)
        at com.pinterest.ktlint.internal.KtlintCommandLine.access$process(KtlintCommandLine.kt:52)
        at com.pinterest.ktlint.internal.KtlintCommandLine$lintFiles$3.invoke$lambda-0(KtlintCommandLine.kt:312)
        at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
        at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136)
        at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
        at java.base/java.lang.Thread.run(Thread.java:833)

> Task :androidprojectandroid:ktlintFormat FAILED

FAILURE: Build completed with 2 failures.

1: Task failed with an exception.
-----------
* What went wrong:
Execution failed for task ':androidprojectliteandroid:ktlintFormat'.
> Process 'command '/Library/Java/JavaVirtualMachines/zulu-17.jdk/Contents/Home/bin/java'' finished with non-zero exit value 1

* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.
==============================================================================

2: Task failed with an exception.
-----------
* What went wrong:
Execution failed for task ':androidprojectandroid:ktlintFormat'.
> Process 'command '/Library/Java/JavaVirtualMachines/zulu-17.jdk/Contents/Home/bin/java'' finished with non-zero exit value 1

* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.
==============================================================================

* Get more help at https://help.gradle.org

Deprecated Gradle features were used in this build, making it incompatible with Gradle 8.0.

You can use '--warning-mode all' to show the individual deprecation warnings and determine if they come from your own scripts or plugins.

See https://docs.gradle.org/7.5/userguide/command_line_interface.html#sec:command_line_warnings

BUILD FAILED in 7s
2 actionable tasks: 2 executed

Observed Behavior

It throws the following exception:

./gradlew ktlintFormat --daemon          
Configuration on demand is an incubating feature.

> Task :androidprojectandroid:ktlintFormat
10:43:31.045 [main] DEBUG com.pinterest.ktlint.internal.KtlintCommandLine - Discovered reporter with "baseline" id.
10:43:31.047 [main] DEBUG com.pinterest.ktlint.internal.KtlintCommandLine - Discovered reporter with "checkstyle" id.
10:43:31.048 [main] DEBUG com.pinterest.ktlint.internal.KtlintCommandLine - Discovered reporter with "json" id.
10:43:31.048 [main] DEBUG com.pinterest.ktlint.internal.KtlintCommandLine - Discovered reporter with "format" id.
10:43:31.048 [main] DEBUG com.pinterest.ktlint.internal.KtlintCommandLine - Discovered reporter with "html" id.
10:43:31.048 [main] DEBUG com.pinterest.ktlint.internal.KtlintCommandLine - Discovered reporter with "plain" id.
10:43:31.048 [main] DEBUG com.pinterest.ktlint.internal.KtlintCommandLine - Discovered reporter with "sarif" id.
10:43:31.049 [main] DEBUG com.pinterest.ktlint.internal.KtlintCommandLine - Initializing "plain" reporter with {verbose=true, color=false, color_name=DARK_GRAY, format=true}
10:43:31.111 [main] DEBUG com.pinterest.ktlint.internal.FileUtils - Start walkFileTree for rootDir: '/Users/user/Developer/MedicineOne/androidprojectAndroid/androidprojectandroid'
   include:
[      - sun.nio.fs.UnixFileSystem$3@1139b2f3]
   exlcude:
[      - sun.nio.fs.UnixFileSystem$3@7a69b07]
10:43:32.055 [main] DEBUG com.pinterest.ktlint.internal.FileUtils - Discovered 627 files to be processed in 944 ms

> Task :androidprojectliteandroid:ktlintFormat FAILED
10:43:31.045 [main] DEBUG com.pinterest.ktlint.internal.KtlintCommandLine - Discovered reporter with "baseline" id.
10:43:31.048 [main] DEBUG com.pinterest.ktlint.internal.KtlintCommandLine - Discovered reporter with "checkstyle" id.
10:43:31.048 [main] DEBUG com.pinterest.ktlint.internal.KtlintCommandLine - Discovered reporter with "json" id.
10:43:31.048 [main] DEBUG com.pinterest.ktlint.internal.KtlintCommandLine - Discovered reporter with "format" id.
10:43:31.048 [main] DEBUG com.pinterest.ktlint.internal.KtlintCommandLine - Discovered reporter with "html" id.
10:43:31.048 [main] DEBUG com.pinterest.ktlint.internal.KtlintCommandLine - Discovered reporter with "plain" id.
10:43:31.048 [main] DEBUG com.pinterest.ktlint.internal.KtlintCommandLine - Discovered reporter with "sarif" id.
10:43:31.049 [main] DEBUG com.pinterest.ktlint.internal.KtlintCommandLine - Initializing "plain" reporter with {verbose=true, color=false, color_name=DARK_GRAY, format=true}
10:43:31.110 [main] DEBUG com.pinterest.ktlint.internal.FileUtils - Start walkFileTree for rootDir: '/Users/user/Developer/MedicineOne/androidprojectAndroid/androidprojectliteandroid'
   include:
[      - sun.nio.fs.UnixFileSystem$3@1139b2f3]
   exlcude:
[      - sun.nio.fs.UnixFileSystem$3@7a69b07]
10:43:31.451 [main] DEBUG com.pinterest.ktlint.internal.FileUtils - Discovered 25 files to be processed in 339 ms
[DEBUG] Rule with id 'standard:indent' should run after the rule with id 'experimental:function-signature'. However, the latter rule is not loaded and is allowed to be ignored. For best results, it is advised load the rule.
[DEBUG] Rules will be executed in order below (unless disabled):
           - standard:annotation, 
           - standard:annotation-spacing, 
           - standard:argument-list-wrapping, 
           - standard:chain-wrapping, 
           - standard:colon-spacing, 
           - standard:comma-spacing, 
           - standard:comment-spacing, 
           - standard:curly-spacing, 
           - standard:dot-spacing, 
           - standard:double-colon-spacing, 
           - standard:enum-entry-name-case, 
           - standard:filename, 
           - standard:final-newline, 
           - standard:import-ordering, 
           - standard:keyword-spacing, 
           - standard:modifier-order, 
           - standard:multiline-if-else, 
           - standard:no-blank-line-before-rbrace, 
           - standard:no-blank-lines-in-chained-method-calls, 
           - standard:no-consecutive-blank-lines, 
           - standard:no-empty-class-body, 
           - standard:no-empty-first-line-in-method-block, 
           - standard:no-line-break-after-else, 
           - standard:no-line-break-before-assignment, 
           - standard:no-multi-spaces, 
           - standard:no-semi, 
           - standard:no-trailing-spaces, 
           - standard:no-unit-return, 
           - standard:no-unused-imports, 
           - standard:no-wildcard-imports, 
           - standard:op-spacing, 
           - standard:package-name, 
           - standard:parameter-list-wrapping, 
           - standard:paren-spacing, 
           - standard:range-spacing, 
           - standard:spacing-around-angle-brackets, 
           - standard:spacing-between-declarations-with-annotations, 
           - standard:spacing-between-declarations-with-comments, 
           - standard:string-template, 
           - standard:unary-op-spacing, 
           - standard:wrapping, 
           - standard:indent, 
           - standard:trailing-comma-on-call-site, 
           - standard:max-line-length, 
           - standard:trailing-comma-on-declaration-site
Exception in thread "main" java.util.concurrent.ExecutionException: java.lang.ClassCastException: class java.lang.String cannot be cast to class java.lang.Boolean (java.lang.String and java.lang.Boolean are in module java.base of loader 'bootstrap')
        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:605)
        at com.pinterest.ktlint.internal.KtlintCommandLine.parallel$default(KtlintCommandLine.kt:563)
        at com.pinterest.ktlint.internal.KtlintCommandLine.lintFiles(KtlintCommandLine.kt:321)
        at com.pinterest.ktlint.internal.KtlintCommandLine.run(KtlintCommandLine.kt:268)
        at com.pinterest.ktlint.Main.main(Main.kt:27)
Caused by: java.lang.ClassCastException: class java.lang.String cannot be cast to class java.lang.Boolean (java.lang.String and java.lang.Boolean are in module java.base of loader 'bootstrap')
        at com.pinterest.ktlint.ruleset.standard.TrailingCommaOnCallSiteRule.beforeFirstNode(TrailingCommaOnCallSiteRule.kt:56)
        at com.pinterest.ktlint.core.KtLint.executeRule(KtLint.kt:194)
        at com.pinterest.ktlint.core.KtLint.access$executeRule(KtLint.kt:30)
        at com.pinterest.ktlint.core.KtLint$format$1.invoke(KtLint.kt:252)
        at com.pinterest.ktlint.core.KtLint$format$1.invoke(KtLint.kt:251)
        at com.pinterest.ktlint.core.internal.VisitorProvider$visitor$4.invoke(VisitorProvider.kt:82)
        at com.pinterest.ktlint.core.internal.VisitorProvider$visitor$4.invoke(VisitorProvider.kt:80)
        at com.pinterest.ktlint.core.KtLint.format(KtLint.kt:251)
        at com.pinterest.ktlint.internal.FileUtilsKt.formatFile(FileUtils.kt:254)
        at com.pinterest.ktlint.internal.KtlintCommandLine.process(KtlintCommandLine.kt:379)
        at com.pinterest.ktlint.internal.KtlintCommandLine.access$process(KtlintCommandLine.kt:52)
        at com.pinterest.ktlint.internal.KtlintCommandLine$lintFiles$3.invoke$lambda-0(KtlintCommandLine.kt:312)
        at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
        at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136)
        at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
        at java.base/java.lang.Thread.run(Thread.java:833)

> Task :androidprojectandroid:ktlintFormat FAILED
[DEBUG] Rule with id 'standard:indent' should run after the rule with id 'experimental:function-signature'. However, the latter rule is not loaded and is allowed to be ignored. For best results, it is advised load the rule.
[DEBUG] Rules will be executed in order below (unless disabled):
           - standard:annotation, 
           - standard:annotation-spacing, 
           - standard:argument-list-wrapping, 
           - standard:chain-wrapping, 
           - standard:colon-spacing, 
           - standard:comma-spacing, 
           - standard:comment-spacing, 
           - standard:curly-spacing, 
           - standard:dot-spacing, 
           - standard:double-colon-spacing, 
           - standard:enum-entry-name-case, 
           - standard:filename, 
           - standard:final-newline, 
           - standard:import-ordering, 
           - standard:keyword-spacing, 
           - standard:modifier-order, 
           - standard:multiline-if-else, 
           - standard:no-blank-line-before-rbrace, 
           - standard:no-blank-lines-in-chained-method-calls, 
           - standard:no-consecutive-blank-lines, 
           - standard:no-empty-class-body, 
           - standard:no-empty-first-line-in-method-block, 
           - standard:no-line-break-after-else, 
           - standard:no-line-break-before-assignment, 
           - standard:no-multi-spaces, 
           - standard:no-semi, 
           - standard:no-trailing-spaces, 
           - standard:no-unit-return, 
           - standard:no-unused-imports, 
           - standard:no-wildcard-imports, 
           - standard:op-spacing, 
           - standard:package-name, 
           - standard:parameter-list-wrapping, 
           - standard:paren-spacing, 
           - standard:range-spacing, 
           - standard:spacing-around-angle-brackets, 
           - standard:spacing-between-declarations-with-annotations, 
           - standard:spacing-between-declarations-with-comments, 
           - standard:string-template, 
           - standard:unary-op-spacing, 
           - standard:wrapping, 
           - standard:indent, 
           - standard:trailing-comma-on-call-site, 
           - standard:max-line-length, 
           - standard:trailing-comma-on-declaration-site
Exception in thread "main" java.util.concurrent.ExecutionException: java.lang.ClassCastException: class java.lang.String cannot be cast to class java.lang.Boolean (java.lang.String and java.lang.Boolean are in module java.base of loader 'bootstrap')
        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:605)
        at com.pinterest.ktlint.internal.KtlintCommandLine.parallel$default(KtlintCommandLine.kt:563)
        at com.pinterest.ktlint.internal.KtlintCommandLine.lintFiles(KtlintCommandLine.kt:321)
        at com.pinterest.ktlint.internal.KtlintCommandLine.run(KtlintCommandLine.kt:268)
        at com.pinterest.ktlint.Main.main(Main.kt:27)
Caused by: java.lang.ClassCastException: class java.lang.String cannot be cast to class java.lang.Boolean (java.lang.String and java.lang.Boolean are in module java.base of loader 'bootstrap')
        at com.pinterest.ktlint.ruleset.standard.TrailingCommaOnCallSiteRule.beforeFirstNode(TrailingCommaOnCallSiteRule.kt:56)
        at com.pinterest.ktlint.core.KtLint.executeRule(KtLint.kt:194)
        at com.pinterest.ktlint.core.KtLint.access$executeRule(KtLint.kt:30)
        at com.pinterest.ktlint.core.KtLint$format$1.invoke(KtLint.kt:252)
        at com.pinterest.ktlint.core.KtLint$format$1.invoke(KtLint.kt:251)
        at com.pinterest.ktlint.core.internal.VisitorProvider$visitor$4.invoke(VisitorProvider.kt:82)
        at com.pinterest.ktlint.core.internal.VisitorProvider$visitor$4.invoke(VisitorProvider.kt:80)
        at com.pinterest.ktlint.core.KtLint.format(KtLint.kt:251)
        at com.pinterest.ktlint.internal.FileUtilsKt.formatFile(FileUtils.kt:254)
        at com.pinterest.ktlint.internal.KtlintCommandLine.process(KtlintCommandLine.kt:379)
        at com.pinterest.ktlint.internal.KtlintCommandLine.access$process(KtlintCommandLine.kt:52)
        at com.pinterest.ktlint.internal.KtlintCommandLine$lintFiles$3.invoke$lambda-0(KtlintCommandLine.kt:312)
        at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
        at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136)
        at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
        at java.base/java.lang.Thread.run(Thread.java:833)

FAILURE: Build completed with 2 failures.

1: Task failed with an exception.
-----------
* What went wrong:
Execution failed for task ':androidprojectliteandroid:ktlintFormat'.
> Process 'command '/Library/Java/JavaVirtualMachines/zulu-17.jdk/Contents/Home/bin/java'' finished with non-zero exit value 1

* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.
==============================================================================

2: Task failed with an exception.
-----------
* What went wrong:
Execution failed for task ':androidprojectandroid:ktlintFormat'.
> Process 'command '/Library/Java/JavaVirtualMachines/zulu-17.jdk/Contents/Home/bin/java'' finished with non-zero exit value 1

* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.
==============================================================================

* Get more help at https://help.gradle.org

Deprecated Gradle features were used in this build, making it incompatible with Gradle 8.0.

You can use '--warning-mode all' to show the individual deprecation warnings and determine if they come from your own scripts or plugins.

See https://docs.gradle.org/7.5/userguide/command_line_interface.html#sec:command_line_warnings

BUILD FAILED in 8s
2 actionable tasks: 2 executed

Steps to Reproduce

Use the following .editorconfig file.

# http://editorconfig.org
root = true

[*.{kt,kts}]
disabled_rules = filename

ij_kotlin_allow_trailing_comma = true
ij_kotlin_allow_trailing_comma_on_call_site = true

Run the following command on the terminal: ./gradlew ktlintFormat --daemon

Your Environment

  • Version of ktlint used: 0.47.0
  • Relevant parts of the .editorconfig settings
# http://editorconfig.org
root = true

[*.{kt,kts}]
disabled_rules = filename

ij_kotlin_allow_trailing_comma = true
ij_kotlin_allow_trailing_comma_on_call_site = true
  • Name and version (or code for custom task) of integration used (Gradle plugin, Maven plugin, command line, custom Gradle task): Gradle plugin
  • Version of Gradle used (if applicable): 7.5
  • Operating System and version: macOS 12.5.1
@paul-dingemans
Copy link
Collaborator

Is it correct that you use the ktlint-gradle plugin? What version are you on?

In this commit the plugin has updated the default ktlint version from 0.42.1 to 0.43.2. As some breaking changes have been introduced in ktlint 0.47.x the communication between the ktlint-gradle plugin and ktlint might no longer work as expected and result in problems. It would be very helpful if you could try to reproduce the problem with the KtLint CLI. If you can reproduce with KtLint CLI than please post a code example and the exact command that you execute.

@4brunu
Copy link
Author

4brunu commented Sep 2, 2022

No, I'm using ktlint directly via gradle.

repositories {
    mavenCentral()
}

configurations {
    ktlint
}

dependencies {
    ktlint("com.pinterest:ktlint:0.46.1") {
        attributes {
            attribute(Bundling.BUNDLING_ATTRIBUTE, getObjects().named(Bundling, Bundling.EXTERNAL))
        }
    }
}

task ktlint(type: JavaExec, group: "verification") {
    description = "Check Kotlin code style."
    mainClass.set("com.pinterest.ktlint.Main")
    classpath = configurations.ktlint
    args "$project.rootDir/**/*.kt", "!**/build/generated/*", "--editorconfig=$qualityDir/ktlint/.editorconfig", "--reporter=html,output=$reportsDir/ktlint/ktlint.html"
    jvmArgs("--add-opens", "java.base/java.lang=ALL-UNNAMED")
    ignoreExitValue = true
}

check.dependsOn 'ktlint'

task ktlintFormat(type: JavaExec, group: "formatting") {
    description = "Fix Kotlin code style deviations."
    mainClass.set("com.pinterest.ktlint.Main")
    classpath = configurations.ktlint
    args "-F", "$project.rootDir/**/*.kt", "!**/build/generated/*", "--editorconfig=$qualityDir/ktlint/.editorconfig"
    jvmArgs("--add-opens", "java.base/java.lang=ALL-UNNAMED")
}

And then I call it via terminal ./gradlew ktlintFormat --daemon

@paul-dingemans
Copy link
Collaborator

There are a few possible causes for the problem. Please run both experiments below:

  1. Refers variable $quality in --editorconfig parameter to an absolute or a relative url? Can you please try to remove the --editorconfig parameter entirely and put the '.editorconfig' file into you project directory?

  2. Remove the globs $project.rootDir/**/*.kt, !**/build/generated/*.

@4brunu
Copy link
Author

4brunu commented Sep 2, 2022

The issue is related to --editorconfig.

I tried to pass the absolute or the relative path of the .editorconfig file to the --editorconfig but it didn't work.

Then I removed the --editorconfig argument, and moved the .editorconfig file to the root project directory and it worked.

Here is my current gradle integration that works.

repositories {
    mavenCentral()
}

configurations {
    ktlint
}

dependencies {
    ktlint("com.pinterest:ktlint:0.47.0") {
        attributes {
            attribute(Bundling.BUNDLING_ATTRIBUTE, getObjects().named(Bundling, Bundling.EXTERNAL))
        }
    }
}

task ktlint(type: JavaExec, group: "verification") {
    description = "Check Kotlin code style."
    mainClass.set("com.pinterest.ktlint.Main")
    classpath = configurations.ktlint
    args "$project.rootDir/**/*.kt", "!**/build/generated/*", "--reporter=html,output=$reportsDir/ktlint/ktlint.html"
    jvmArgs("--add-opens", "java.base/java.lang=ALL-UNNAMED")
    ignoreExitValue = true
}

check.dependsOn 'ktlint'

task ktlintFormat(type: JavaExec, group: "formatting") {
    description = "Fix Kotlin code style deviations."
    mainClass.set("com.pinterest.ktlint.Main")
    classpath = configurations.ktlint
    args "-F", "$project.rootDir/**/*.kt", "!**/build/generated/*"
    jvmArgs("--add-opens", "java.base/java.lang=ALL-UNNAMED")
}

@paul-dingemans
Copy link
Collaborator

Ok cool. Are you working on Windows OS?

@4brunu
Copy link
Author

4brunu commented Sep 2, 2022

No, I'm in macOS

paul-dingemans added a commit to paul-dingemans/ktlint that referenced this issue Sep 3, 2022
@paul-dingemans paul-dingemans added this to the 0.47.1 milestone Sep 3, 2022
@paul-dingemans paul-dingemans added bug cli ktlint command line interface labels Sep 3, 2022
paul-dingemans added a commit that referenced this issue Sep 3, 2022
@paul-dingemans
Copy link
Collaborator

paul-dingemans commented Sep 3, 2022

Would you mind testing the fix with the latest snapshot? See https://pinterest.github.io/ktlint/install/snapshot-build/

@4brunu
Copy link
Author

4brunu commented Sep 5, 2022

Hey, thanks for your help.
I have tested this and can confirm that it fixes the issue. 👍

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
bug cli ktlint command line interface
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants