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

False positives: incorrectly indented expression body functions with WRONG_INDENTATION inspection #1330

Closed
orchestr7 opened this issue May 30, 2022 · 4 comments · Fixed by #1363 or #1395
Assignees
Labels
bug Something isn't working
Milestone

Comments

@orchestr7
Copy link
Member

orchestr7 commented May 30, 2022

    @Test
    fun `checking that suppression with ignore everything works`() {
        val code =
                """
                    @Suppress("diktat")
                    fun foo() {
                        val a = 1
                    }
                """.trimIndent()
        lintMethod(code)
    }

image

Warn (2:1) [WRONG_INDENTATION] only spaces are allowed for indentation and each indentation should equal to 4 spaces (tabs are not allowed): expected 0 but was 4
Warn (3:1) [WRONG_INDENTATION] only spaces are allowed for indentation and each indentation should equal to 4 spaces (tabs are not allowed): expected 4 but was 8
Warn (10:1) [WRONG_INDENTATION] only spaces are allowed for indentation and each indentation should equal to 4 spaces (tabs are not allowed): expected 4 but was 8
Warn (11:1) [WRONG_INDENTATION] only spaces are allowed for indentation and each indentation should equal to 4 spaces (tabs are not allowed): expected 0 but was 4
Warn (11:5) [WRONG_INDENTATION] only spaces are allowed for indentation and each indentation should equal to 4 spaces (tabs are not allowed): no newline at the end of file demo-1874f666-bfd2-48f0-a471-384a98d6af37.kt

Environment information

  • diktat version: 1.1.0
  • build tool (maven/gradle): maven
  • how is diktat run (CLI, plugin, etc.): plugin
  • kotlin version: 1.6
  • operating system: MAC
@orchestr7 orchestr7 added the bug Something isn't working label May 30, 2022
@orchestr7
Copy link
Member Author

orchestr7 commented May 30, 2022

can be linked with #1312
@0x6675636b796f75676974687562 please check it ASAP

@0x6675636b796f75676974687562 0x6675636b796f75676974687562 added this to the 1.1.1 milestone May 31, 2022
@0x6675636b796f75676974687562 0x6675636b796f75676974687562 changed the title Invalid indenting with WRONG_INDENTATION inspection False positives: incorrectly indented expression body functions with WRONG_INDENTATION inspection May 31, 2022
@0x6675636b796f75676974687562
Copy link
Member

0x6675636b796f75676974687562 commented May 31, 2022

Other examples (from gh-1312), affected by extendedIndentAfterOperators flag (IDEA's code style counterpart is CONTINUATION_INDENT_FOR_EXPRESSION_BODIES):

  1. Correct:

    val currentTime: Time
        get() =
                with(currentDateTime) {
                    Time(hour = hour, minute = minute, second = second)
                }
  2. Correct:

    fun formatDateByPattern(date: String, pattern: String = "ddMMyy"): String =
            DateTimeFormatter.ofPattern(pattern).format(LocalDate.parse(date))
  3. False positive:

    private fun createLayoutParams(): WindowManager.LayoutParams =
            WindowManager.LayoutParams().apply { /* ... */ }
  4. Correct:

    val offsetDelta =
            if (shimmerAnimationType != ShimmerAnimationType.FADE) translateAnim.dp
            else 2000.dp
  5. Correct:

    private fun lerp(start: Float, stop: Float, fraction: Float): Float =
            (1 - fraction) * start + fraction * stop

The problem is spurious, e. g.: if the above examples are concatenated together, no error is reported.

@0x6675636b796f75676974687562 0x6675636b796f75676974687562 changed the title False positives: incorrectly indented expression body functions with WRONG_INDENTATION inspection False positives: incorrectly indented expression body functions with WRONG_INDENTATION inspection Jun 1, 2022
@0x6675636b796f75676974687562
Copy link
Member

0x6675636b796f75676974687562 commented Jun 1, 2022

Also:

fun foo() =
        println()

0x6675636b796f75676974687562 added a commit that referenced this issue Jun 7, 2022
### What's done:

 * Added unit tests for mis-indented expression body functions.
 * See #1330.
0x6675636b796f75676974687562 added a commit that referenced this issue Jun 14, 2022
### What's done:

 * Added unit tests for mis-indented expression body functions.
 * See #1330.
0x6675636b796f75676974687562 added a commit that referenced this issue Jun 14, 2022
### What's done:

 * Added unit tests for mis-indented expression body functions.
 * See #1330.
0x6675636b796f75676974687562 added a commit that referenced this issue Jun 15, 2022
### What's done:

 * Added unit tests for mis-indented expression body functions.
 * See #1330.
0x6675636b796f75676974687562 added a commit that referenced this issue Jun 15, 2022
### What's done:

 * Added unit tests for mis-indented expression body functions.
 * See #1330.
0x6675636b796f75676974687562 added a commit that referenced this issue Jun 15, 2022
### What's done:

 * Added unit tests for mis-indented expression body functions.
 * See #1330.
0x6675636b796f75676974687562 added a commit that referenced this issue Jun 15, 2022
### What's done:

 * Added unit tests for mis-indented expression body functions.
 * See #1330.
0x6675636b796f75676974687562 added a commit that referenced this issue Jun 15, 2022
### What's done:

 * Added unit tests for mis-indented expression body functions.
 * Comparison failures now recognized by IDEA.
 * Content comparison deltas prevented from being wrapped when presented to the user
   (`columnWidth` increased from 80 to `Int.MAX_VALUE`, so deltas will no longer have any inline `<br/>`).
 * Failing tests (caused by #1347, skipped by default) can be re-enabled by running with `-Dtests.can.be.muted=true`
 * See #1330.
@0x6675636b796f75676974687562 0x6675636b796f75676974687562 added the spurious issue An intermittent problem which can't be reliably reproduced label Jun 17, 2022
@0x6675636b796f75676974687562
Copy link
Member

The problem from the original description fixed as #1347.

None of the issues with mis-indented expression bodies (from both this and this comment) was reproduced.

Closing.

@0x6675636b796f75676974687562 0x6675636b796f75676974687562 removed the spurious issue An intermittent problem which can't be reliably reproduced label Jun 22, 2022
0x6675636b796f75676974687562 added a commit that referenced this issue Jun 22, 2022
… flag

### What's done:

 * More complex code fragments which test the behaviour of the
   `extendedIndentAfterOperators` flag have been added.
0x6675636b796f75676974687562 added a commit that referenced this issue Jun 22, 2022
… flag (#1395)

### What's done:

 * More complex code fragments which test the behaviour of the
   `extendedIndentAfterOperators` flag have been added.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment