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

Insert of suppression of condition-wrapping fails #2462

Closed
paul-dingemans opened this issue Dec 23, 2023 · 0 comments · Fixed by #2463
Closed

Insert of suppression of condition-wrapping fails #2462

paul-dingemans opened this issue Dec 23, 2023 · 0 comments · Fixed by #2463
Milestone

Comments

@paul-dingemans
Copy link
Collaborator

Given code below:

fun foo() {
    require(
        true && false ||
            true,
    )
}

This code contains violations below:

src/main/kotlin/Foo.kt:3:17: Newline expected before operand in multiline condition (standard:condition-wrapping)

When suppressing error above with ktlint-intelli-plugin this results in exception below:

java.lang.IllegalStateException: Can not create annotation '@Suppress("ktlint:standard:indent")'
	at com.pinterest.ktlint.rule.engine.internal.KtlintSuppressionKt.createAnnotatedExpression(KtlintSuppression.kt:376)
	at com.pinterest.ktlint.rule.engine.internal.KtlintSuppressionKt.createSuppressAnnotation(KtlintSuppression.kt:281)
	at com.pinterest.ktlint.rule.engine.internal.KtlintSuppressionKt.insertKtlintRuleSuppression(KtlintSuppression.kt:94)
	at com.pinterest.ktlint.rule.engine.internal.KtlintSuppressionKt.insertKtlintRuleSuppression$default(KtlintSuppression.kt:65)
	at com.pinterest.ktlint.rule.engine.api.KtlintRuleEngineSuppressionKt.insertSuppression(KtlintRuleEngineSuppression.kt:30)
	at com.nbadal.ktlint.actions.KtlintRuleSuppressIntention.invoke(KtlintRuleSuppressIntention.kt:66)
	at com.intellij.codeInsight.intention.impl.IntentionActionWithTextCaching$MyIntentionAction.lambda$invoke$0(IntentionActionWithTextCaching.java:229)
	at com.intellij.util.SlowOperations.allowSlowOperations(SlowOperations.java:147)
	at com.intellij.codeInsight.intention.impl.IntentionActionWithTextCaching$MyIntentionAction.invoke(IntentionActionWithTextCaching.java:229)
	at com.intellij.codeInsight.intention.impl.ShowIntentionActionsHandler.lambda$invokeIntention$4(ShowIntentionActionsHandler.java:263)
	at com.intellij.openapi.application.WriteAction.lambda$run$1(WriteAction.java:86)
	at com.intellij.openapi.application.impl.ApplicationImpl.runWriteActionWithClass(ApplicationImpl.java:935)
	at com.intellij.openapi.application.impl.ApplicationImpl.runWriteAction(ApplicationImpl.java:961)
	at com.intellij.openapi.application.WriteAction.run(WriteAction.java:85)
	at com.intellij.codeInsight.intention.impl.ShowIntentionActionsHandler.invokeIntention(ShowIntentionActionsHandler.java:263)
	at com.intellij.codeInsight.intention.impl.ShowIntentionActionsHandler.lambda$chooseActionAndInvoke$3(ShowIntentionActionsHandler.java:239)
	at com.intellij.openapi.command.impl.CoreCommandProcessor.executeCommand(CoreCommandProcessor.java:219)
	at com.intellij.openapi.command.impl.CoreCommandProcessor.executeCommand(CoreCommandProcessor.java:174)
	at com.intellij.openapi.command.impl.CoreCommandProcessor.executeCommand(CoreCommandProcessor.java:164)
	at com.intellij.openapi.command.impl.CoreCommandProcessor.executeCommand(CoreCommandProcessor.java:150)
	at com.intellij.codeInsight.intention.impl.ShowIntentionActionsHandler.chooseActionAndInvoke(ShowIntentionActionsHandler.java:238)
	at com.intellij.codeInsight.intention.impl.IntentionListStep.chooseActionAndInvoke(IntentionListStep.java:134)
	at com.intellij.codeInsight.intention.impl.IntentionListStep.lambda$applyAction$3(IntentionListStep.java:126)
	at com.intellij.openapi.application.TransactionGuardImpl.performUserActivity(TransactionGuardImpl.java:94)
	at com.intellij.ui.popup.AbstractPopup.lambda$dispose$18(AbstractPopup.java:1508)
	at com.intellij.util.ui.EdtInvocationManager.invokeLaterIfNeeded(EdtInvocationManager.java:101)
	at com.intellij.ide.IdeEventQueue.ifFocusEventsInTheQueue(IdeEventQueue.java:186)
	at com.intellij.ide.IdeEventQueue.executeWhenAllFocusEventsLeftTheQueue(IdeEventQueue.java:140)
	at com.intellij.openapi.wm.impl.FocusManagerImpl.doWhenFocusSettlesDown(FocusManagerImpl.java:175)
	at com.intellij.openapi.wm.impl.IdeFocusManagerImpl.doWhenFocusSettlesDown(IdeFocusManagerImpl.java:36)
	at com.intellij.ui.popup.AbstractPopup.dispose(AbstractPopup.java:1505)
	at com.intellij.ui.popup.WizardPopup.dispose(WizardPopup.java:164)
	at com.intellij.ui.popup.list.ListPopupImpl.dispose(ListPopupImpl.java:326)
	at com.intellij.openapi.util.ObjectTree.runWithTrace(ObjectTree.java:136)
	at com.intellij.openapi.util.ObjectTree.executeAll(ObjectTree.java:166)
	at com.intellij.openapi.util.Disposer.dispose(Disposer.java:169)
	at com.intellij.openapi.util.Disposer.dispose(Disposer.java:157)
	at com.intellij.ui.popup.WizardPopup.disposeAllParents(WizardPopup.java:268)
	at com.intellij.ui.popup.list.ListPopupImpl.handleNextStep(ListPopupImpl.java:433)
	at com.intellij.ui.popup.list.ListPopupImpl._handleSelect(ListPopupImpl.java:405)
	at com.intellij.ui.popup.list.ListPopupImpl.handleSelect(ListPopupImpl.java:356)
	at com.intellij.ui.popup.list.ListPopupImpl$1.actionPerformed(ListPopupImpl.java:270)
	at com.intellij.ui.popup.WizardPopup.proceedKeyEvent(WizardPopup.java:380)
	at com.intellij.ui.popup.WizardPopup.dispatch(WizardPopup.java:356)
	at com.intellij.ui.popup.PopupDispatcher.dispatchKeyEvent(PopupDispatcher.java:112)
	at com.intellij.ui.popup.PopupDispatcher.dispatch(PopupDispatcher.java:148)
	at com.intellij.ide.IdePopupManager.dispatch(IdePopupManager.java:101)
	at com.intellij.ide.IdeEventQueue._dispatchEvent(IdeEventQueue.java:724)
	at com.intellij.ide.IdeEventQueue.lambda$dispatchEvent$6(IdeEventQueue.java:447)
	at com.intellij.openapi.progress.impl.CoreProgressManager.computePrioritized(CoreProgressManager.java:818)
	at com.intellij.ide.IdeEventQueue.lambda$dispatchEvent$7(IdeEventQueue.java:446)
	at com.intellij.openapi.application.impl.ApplicationImpl.runIntendedWriteActionOnCurrentThread(ApplicationImpl.java:805)
	at com.intellij.ide.IdeEventQueue.dispatchEvent(IdeEventQueue.java:498)
	at java.desktop/java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:207)
	at java.desktop/java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:128)
	at java.desktop/java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:117)
	at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:113)
	at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:105)
	at java.desktop/java.awt.EventDispatchThread.run(EventDispatchThread.java:92)

Expected behavior:

  • No exception thrown
  • Suppression added as follows:
fun foo() {
    @Suppress("ktlint:standard:condition-wrapping")
    require(
        true && false ||
            true,
    )
}
@paul-dingemans paul-dingemans added this to the 1.1.1 milestone Dec 23, 2023
paul-dingemans added a commit that referenced this issue Dec 23, 2023
… parameter, or type projection in case it is a binary expression

Make creation of the annotation more safe by not using a fake top element in the code which is used to generate the AST.

The 'Suppress' annotation has a parameter, which by default is not allowed to be placed inline (it should start on a new line). Just putting it above the binary expression results in it being applied to the first subexpression only instead of on the entire binary expression.

Closes #2462
paul-dingemans added a commit that referenced this issue Dec 26, 2023
… parameter, or type projection in case it is a binary expression (#2463)

Make creation of the annotation more safe by not using a fake top element in the code which is used to generate the AST.

The 'Suppress' annotation has a parameter, which by default is not allowed to be placed inline (it should start on a new line). Just putting it above the binary expression results in it being applied to the first subexpression only instead of on the entire binary expression.

Closes #2462
paul-dingemans added a commit to Goooler/ktlint that referenced this issue Jan 2, 2024
… parameter, or type projection in case it is a binary expression (pinterest#2463)

Make creation of the annotation more safe by not using a fake top element in the code which is used to generate the AST.

The 'Suppress' annotation has a parameter, which by default is not allowed to be placed inline (it should start on a new line). Just putting it above the binary expression results in it being applied to the first subexpression only instead of on the entire binary expression.

Closes pinterest#2462
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant