From 33969c5f9ab5d09e137ec881d2373d4bc8bea9ed Mon Sep 17 00:00:00 2001 From: Toshiaki Kameyama Date: Tue, 4 Aug 2020 08:37:32 +0200 Subject: [PATCH] Redundant semicolon: fix false negative on start of line ^KT-40704 Fixed --- .../idea/inspections/RedundantSemicolonInspection.kt | 3 +++ .../inspectionsLocal/redundantSemicolon/startOfLine.kt | 6 ++++++ .../redundantSemicolon/startOfLine.kt.after | 6 ++++++ .../redundantSemicolon/startOfLine2.kt | 6 ++++++ .../redundantSemicolon/startOfLine2.kt.after | 6 ++++++ .../idea/inspections/LocalInspectionTestGenerated.java | 10 ++++++++++ 6 files changed, 37 insertions(+) create mode 100644 idea/testData/inspectionsLocal/redundantSemicolon/startOfLine.kt create mode 100644 idea/testData/inspectionsLocal/redundantSemicolon/startOfLine.kt.after create mode 100644 idea/testData/inspectionsLocal/redundantSemicolon/startOfLine2.kt create mode 100644 idea/testData/inspectionsLocal/redundantSemicolon/startOfLine2.kt.after diff --git a/idea/src/org/jetbrains/kotlin/idea/inspections/RedundantSemicolonInspection.kt b/idea/src/org/jetbrains/kotlin/idea/inspections/RedundantSemicolonInspection.kt index d978ffbe003..48146edd1f4 100644 --- a/idea/src/org/jetbrains/kotlin/idea/inspections/RedundantSemicolonInspection.kt +++ b/idea/src/org/jetbrains/kotlin/idea/inspections/RedundantSemicolonInspection.kt @@ -49,6 +49,9 @@ class RedundantSemicolonInspection : AbstractKotlinInspection(), CleanupLocalIns if (semicolon.parent is KtPackageDirective && (nextLeaf as? KtImportList)?.imports?.isEmpty() == true) { return true } + if (semicolon.prevLeaf { it !is PsiWhiteSpace && it !is PsiComment || it.isLineBreak() } is PsiWhiteSpace) { + return true + } return false } diff --git a/idea/testData/inspectionsLocal/redundantSemicolon/startOfLine.kt b/idea/testData/inspectionsLocal/redundantSemicolon/startOfLine.kt new file mode 100644 index 00000000000..07921c6ab67 --- /dev/null +++ b/idea/testData/inspectionsLocal/redundantSemicolon/startOfLine.kt @@ -0,0 +1,6 @@ +fun test() { + foo() + ;foo() +} + +fun foo() {} \ No newline at end of file diff --git a/idea/testData/inspectionsLocal/redundantSemicolon/startOfLine.kt.after b/idea/testData/inspectionsLocal/redundantSemicolon/startOfLine.kt.after new file mode 100644 index 00000000000..60859d218dd --- /dev/null +++ b/idea/testData/inspectionsLocal/redundantSemicolon/startOfLine.kt.after @@ -0,0 +1,6 @@ +fun test() { + foo() + foo() +} + +fun foo() {} \ No newline at end of file diff --git a/idea/testData/inspectionsLocal/redundantSemicolon/startOfLine2.kt b/idea/testData/inspectionsLocal/redundantSemicolon/startOfLine2.kt new file mode 100644 index 00000000000..30dd46104e6 --- /dev/null +++ b/idea/testData/inspectionsLocal/redundantSemicolon/startOfLine2.kt @@ -0,0 +1,6 @@ +fun test() { + foo() + /* comment */;foo() +} + +fun foo() {} \ No newline at end of file diff --git a/idea/testData/inspectionsLocal/redundantSemicolon/startOfLine2.kt.after b/idea/testData/inspectionsLocal/redundantSemicolon/startOfLine2.kt.after new file mode 100644 index 00000000000..190634eaaed --- /dev/null +++ b/idea/testData/inspectionsLocal/redundantSemicolon/startOfLine2.kt.after @@ -0,0 +1,6 @@ +fun test() { + foo() + /* comment */foo() +} + +fun foo() {} \ No newline at end of file diff --git a/idea/tests/org/jetbrains/kotlin/idea/inspections/LocalInspectionTestGenerated.java b/idea/tests/org/jetbrains/kotlin/idea/inspections/LocalInspectionTestGenerated.java index ad60217f1e6..cd28e4eac7b 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/inspections/LocalInspectionTestGenerated.java +++ b/idea/tests/org/jetbrains/kotlin/idea/inspections/LocalInspectionTestGenerated.java @@ -8890,6 +8890,16 @@ public class LocalInspectionTestGenerated extends AbstractLocalInspectionTest { public void testIfElse() throws Exception { runTest("idea/testData/inspectionsLocal/redundantSemicolon/ifElse.kt"); } + + @TestMetadata("startOfLine.kt") + public void testStartOfLine() throws Exception { + runTest("idea/testData/inspectionsLocal/redundantSemicolon/startOfLine.kt"); + } + + @TestMetadata("startOfLine2.kt") + public void testStartOfLine2() throws Exception { + runTest("idea/testData/inspectionsLocal/redundantSemicolon/startOfLine2.kt"); + } } @TestMetadata("idea/testData/inspectionsLocal/redundantSetter")