Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Placing // ktlint-disable at top of file crashes ktlint #1029

Closed
AndrewReitz opened this issue Dec 23, 2020 · 6 comments · Fixed by #1487
Closed

Placing // ktlint-disable at top of file crashes ktlint #1029

AndrewReitz opened this issue Dec 23, 2020 · 6 comments · Fixed by #1487
Labels
Milestone

Comments

@AndrewReitz
Copy link

AndrewReitz commented Dec 23, 2020

Step to Reproduce
Pick any kotlin file add at the very top add // ktlint-disable
Run ktlint lint

Following Stacktrace will be printed out

com.pinterest.ktlint.core.RuleExecutionException: kotlin.UninitializedPropertyAccessException: lateinit property importSorter has not been initialized
        at com.pinterest.ktlint.core.KtLint$lint$1.invoke(KtLint.kt:93)
        at com.pinterest.ktlint.core.KtLint$lint$1.invoke(KtLint.kt:23)
        at com.pinterest.ktlint.core.KtLint$visitor$2$1.invoke(KtLint.kt:206)
        at com.pinterest.ktlint.core.KtLint$visitor$2$1.invoke(KtLint.kt:23)
        at com.pinterest.ktlint.core.ast.PackageKt.visit(package.kt:224)
        at com.pinterest.ktlint.core.ast.PackageKt.visit(package.kt:225)
        at com.pinterest.ktlint.core.KtLint$visitor$2.invoke(KtLint.kt:204)
        at com.pinterest.ktlint.core.KtLint$visitor$2.invoke(KtLint.kt:23)
        at com.pinterest.ktlint.core.KtLint.lint(KtLint.kt:74)
        at org.jmailen.gradle.kotlinter.tasks.lint.LintWorkerAction.lint(LintWorkerAction.kt:71)
        at org.jmailen.gradle.kotlinter.tasks.lint.LintWorkerAction.lintKt(LintWorkerAction.kt:65)
        at org.jmailen.gradle.kotlinter.tasks.lint.LintWorkerAction.access$lintKt(LintWorkerAction.kt:19)
        at org.jmailen.gradle.kotlinter.tasks.lint.LintWorkerAction$execute$2$lintFunc$1.invoke(LintWorkerAction.kt:40)
        at org.jmailen.gradle.kotlinter.tasks.lint.LintWorkerAction$execute$2$lintFunc$1.invoke(LintWorkerAction.kt:19)
        at org.jmailen.gradle.kotlinter.tasks.lint.LintWorkerAction.execute(LintWorkerAction.kt:47)
        at org.gradle.workers.internal.DefaultWorkerServer.execute(DefaultWorkerServer.java:63)
        at org.gradle.workers.internal.NoIsolationWorkerFactory$1$1.create(NoIsolationWorkerFactory.java:67)
        at org.gradle.workers.internal.NoIsolationWorkerFactory$1$1.create(NoIsolationWorkerFactory.java:63)
        at org.gradle.internal.classloader.ClassLoaderUtils.executeInClassloader(ClassLoaderUtils.java:97)
        at org.gradle.workers.internal.NoIsolationWorkerFactory$1.lambda$execute$0(NoIsolationWorkerFactory.java:63)
        at org.gradle.workers.internal.AbstractWorker$1.call(AbstractWorker.java:44)
        at org.gradle.workers.internal.AbstractWorker$1.call(AbstractWorker.java:41)
        at org.gradle.internal.operations.DefaultBuildOperationRunner$CallableBuildOperationWorker.execute(DefaultBuildOperationRunner.java:200)
        at org.gradle.internal.operations.DefaultBuildOperationRunner$CallableBuildOperationWorker.execute(DefaultBuildOperationRunner.java:195)
        at org.gradle.internal.operations.DefaultBuildOperationRunner$3.execute(DefaultBuildOperationRunner.java:75)
        at org.gradle.internal.operations.DefaultBuildOperationRunner$3.execute(DefaultBuildOperationRunner.java:68)
        at org.gradle.internal.operations.DefaultBuildOperationRunner.execute(DefaultBuildOperationRunner.java:153)
        at org.gradle.internal.operations.DefaultBuildOperationRunner.execute(DefaultBuildOperationRunner.java:68)
        at org.gradle.internal.operations.DefaultBuildOperationRunner.call(DefaultBuildOperationRunner.java:62)
        at org.gradle.internal.operations.DefaultBuildOperationExecutor.lambda$call$2(DefaultBuildOperationExecutor.java:76)
        at org.gradle.internal.operations.UnmanagedBuildOperationWrapper.callWithUnmanagedSupport(UnmanagedBuildOperationWrapper.java:54)
        at org.gradle.internal.operations.DefaultBuildOperationExecutor.call(DefaultBuildOperationExecutor.java:76)
        at org.gradle.workers.internal.AbstractWorker.executeWrappedInBuildOperation(AbstractWorker.java:41)
        at org.gradle.workers.internal.NoIsolationWorkerFactory$1.execute(NoIsolationWorkerFactory.java:60)
        at org.gradle.workers.internal.DefaultWorkerExecutor.lambda$submitWork$2(DefaultWorkerExecutor.java:200)
        at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
        at org.gradle.internal.work.DefaultConditionalExecutionQueue$ExecutionRunner.runExecution(DefaultConditionalExecutionQueue.java:215)
        at org.gradle.internal.work.DefaultConditionalExecutionQueue$ExecutionRunner.runBatch(DefaultConditionalExecutionQueue.java:164)
        at org.gradle.internal.work.DefaultConditionalExecutionQueue$ExecutionRunner.run(DefaultConditionalExecutionQueue.java:131)
        at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515)
        at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
        at org.gradle.internal.concurrent.ExecutorPolicy$CatchAndRecordFailures.onExecute(ExecutorPolicy.java:64)
        at org.gradle.internal.concurrent.ManagedExecutorImpl$1.run(ManagedExecutorImpl.java:48)
        at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
        at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
        at org.gradle.internal.concurrent.ThreadFactoryImpl$ManagedThreadRunnable.run(ThreadFactoryImpl.java:56)
        at java.base/java.lang.Thread.run(Thread.java:834)
Caused by: kotlin.UninitializedPropertyAccessException: lateinit property importSorter has not been initialized
        at com.pinterest.ktlint.ruleset.standard.ImportOrderingRule.visit(ImportOrderingRule.kt:95)
        at com.pinterest.ktlint.core.KtLint$lint$1.invoke(KtLint.kt:81)
        ... 46 more
@Tapchicoma
Copy link
Collaborator

I could not reproduce it neither with build from master nor from 0.40.0 tag using following test file:

// ktlint-disable

fun test() {}

Have you tried to run ktlint CLI over failing file (maybe it is a bug in Gradle plugin)? Could you provide more information?

@AndrewReitz
Copy link
Author

AndrewReitz commented Dec 27, 2020

I think it must be the package statement.

// ktlint-disable
package ktlint.test

import kotlin.math.sqrt

fun test() {
    
}

fails for me on 0.40.0 with

test.kt:4:1: Internal Error (import-ordering). Please create a ticket at https://github.com/pinterest/ktlint/issues (if possible, provide the source code that triggered an error) (cannot be auto-corrected)

@Tapchicoma
Copy link
Collaborator

Yes, with package I could reproduce it 👍

@Tapchicoma Tapchicoma added this to the 0.41.0 milestone Dec 27, 2020
@Tapchicoma
Copy link
Collaborator

Seems not a package here, but import is important.

@paul-dingemans
Copy link
Collaborator

According to the documentation, the directive should be placed as EOL comment after the package statement. That also resulted in a problem, but has been fixed in this PR.

@paul-dingemans
Copy link
Collaborator

The statement // ktlint-disable at the top of the file is really ambiguous to disable all rules for the entire file.

Use below to suppress all rules in the entire file:

@file:Suppress("ktlint")

or provide a named list of rules to suppress in the entire file:

@file:Suppress("ktlint:no-foo-identifier-standard", "ktlint:custom:no-foo-identifier")

@paul-dingemans paul-dingemans added this to the 0.46.0 milestone Jun 4, 2022
paul-dingemans added a commit that referenced this issue Jun 7, 2022
Disable all rules or a list of specific rules in the entire file (#1029)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants