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

WRONG_INDENTATION false-positive: "the same number of indents to the opening and closing quotes was expected" #1490

Closed
petertrr opened this issue Aug 4, 2022 · 1 comment · Fixed by #1501 or #1503
Assignees
Labels
bug Something isn't working good first issue Good for newcomers regression
Milestone

Comments

@petertrr
Copy link
Member

petertrr commented Aug 4, 2022

Describe the bug

I believe, caused by 998d0e9

Observed behavior

https://github.com/saveourtool/save-cli/security/code-scanning/132
https://github.com/saveourtool/save-cli/security/code-scanning/131
Reproducible on diktat-demo with this snippet:

package com.saveourtool.save.reporter.plain

open class PlainTextReporter {
    @Suppress("MAGIC_NUMBER", "MagicNumber")
    override fun afterAll() {
        out.write(
            "$status: $total tests, $passRate%% successful, failed: $failed, skipped: $skipped"
                .encodeToByteArray()
            )
    }
}

Environment information

  • diktat version: 1.2.3
@petertrr petertrr added the bug Something isn't working label Aug 4, 2022
@0x6675636b796f75676974687562
Copy link
Member

0x6675636b796f75676974687562 commented Aug 5, 2022

Originally from [saveourtool/save-cli/security/code-scanning/131] (https://github.com/saveourtool/save-cli/security/code-scanning/131), caused by 998d0e9 as a part of #811/#1364.

The offending fragment is in IndentationRule.kt:248:

            val warnText = if (!difOffsetCloseAndOpenQuote) {
                "the same number of indents to the opening and closing quotes was expected"
            } else {
                "expected $expectedIndent but was ${indentError.actual}"
            }

The minimal repro is

val v = f(
    "text $variable text".isEmpty()
)

Analysis

  1. The sting template should contain an interpolated reference (a SHORT_STRING_TEMPLATE_ENTRY) in the middle of it, i. e. preceded and followed with non-reference text (LITERAL_STRING_TEMPLATE_ENTRY).
  2. The string template should be followed with a dot-qualified (but not a safe-access!) expression.

@0x6675636b796f75676974687562 0x6675636b796f75676974687562 added this to the 1.2.4 milestone Aug 5, 2022
@orchestr7 orchestr7 added the good first issue Good for newcomers label Aug 8, 2022
@0x6675636b796f75676974687562 0x6675636b796f75676974687562 changed the title False-positive Wrong_Indentation: the same number of indents to the opening and closing quotes was expected WRONG_INDENTATION false-positive: "the same number of indents to the opening and closing quotes was expected" Aug 9, 2022
0x6675636b796f75676974687562 added a commit that referenced this issue Aug 15, 2022
### What's done:

 * Fixes the false-positive warnings reported for single-line string templates.
 * Closes #1490.
 * See #811 (the original feature request).
 * See #1364 (the pull request which introduced the regression).
 * See 998d0e9 (the commit which introduced the regression).
0x6675636b796f75676974687562 added a commit that referenced this issue Aug 15, 2022
### What's done:

 * Fixes the false-positive warnings reported for single-line string templates.
 * Closes #1490.
 * See #811 (the original feature request).
 * See #1364 (the pull request which introduced the regression).
 * See 998d0e9 (the commit which introduced the regression).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment