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

Changing indentation of multiline string works incorrect #811

Closed
kgevorkyan opened this issue Mar 25, 2021 · 1 comment · Fixed by #1364
Closed

Changing indentation of multiline string works incorrect #811

kgevorkyan opened this issue Mar 25, 2021 · 1 comment · Fixed by #1364
Assignees
Labels
autofix Issues related to diktat in autofix mode bug Something isn't working

Comments

@kgevorkyan
Copy link
Member

Describe the bug

Initial code:

    fun `check dummy property`() {
        lintMethod(
                """
                    |// provide your check here
                """.trimMargin(),
                LintError(1, 1, ruleId, "${DUMMY_TEST_WARNING.warnText()} some detailed explanation", true)
        )
    }

Problem: There are extra indentations in lintMethod.

Expected behavior after command mvn diktat:fix@diktat:

    fun `check dummy property`() {
        lintMethod(
            """
                |// provide your check here
            """.trimMargin(),
            LintError(1, 1, ruleId, "${DUMMY_TEST_WARNING.warnText()} some detailed explanation", true)
        )
    }

Observed behavior

    fun `check dummy property`() {
        lintMethod(
            """
                    |// provide your check here
                """.trimMargin(),
            LintError(1, 1, ruleId, "${DUMMY_TEST_WARNING.warnText()} some detailed explanation", true)
        )
    }

So only first and last lines were changed.

Environment information

  • diktat version: 0.4.2
  • build tool (maven/gradle): maven
  • kotlin version: 1.4.31
@kgevorkyan kgevorkyan added the bug Something isn't working label Mar 25, 2021
@petertrr petertrr added the autofix Issues related to diktat in autofix mode label Jul 1, 2021
Arrgentum pushed a commit that referenced this issue Jun 6, 2022
 * 1 new fix test
 * first corrected code

### Issue (#811)
Arrgentum pushed a commit that referenced this issue Jun 6, 2022
    * corrected code StringLiteral
    * added test

### Issue(#811)
@Arrgentum
Copy link
Member

Arrgentum commented Jun 7, 2022

Some part of the error has already been fixed.

Environment information

  • diktat version: 1.1.0
  • DiktatSmokeTest - fix mode
  • kotlin version: 1.6

Test1

Initial code №1:

fun `check dummy property`() {
    lintMethod(
                """
                            |// provide your check here
                        """.trimMargin(),
                LintError(1, 1, ruleId, "${DUMMY_TEST_WARNING.warnText()} some detailed explanation", true)
    )
}

Observed behavior №1:

fun `check dummy property`() {
    lintMethod(
        """
                    |// provide your check here
        """.trimMargin(),
        LintError(1, 1, ruleId, "${DUMMY_TEST_WARNING.warnText()} some detailed explanation", true)
    )
}

Test2

Initial code №2:

fun `check dummy property`() {
    lintMethod(
                """
                            |// provide your check here
                """.trimMargin(),
                LintError(1, 1, ruleId, "${DUMMY_TEST_WARNING.warnText()} some detailed explanation", true)
    )
}

Observed behavior №2:

fun `check dummy property`() {
    lintMethod(
        """
                    |// provide your check here
        """.trimMargin(),
        LintError(1, 1, ruleId, "${DUMMY_TEST_WARNING.warnText()} some detailed explanation", true)
    )
}

Test3

Initial code №3:

fun `check dummy property`() {
    lintMethod(
        """
                                    |// provide your check here
                        """.trimMargin(),
        LintError(1, 1, ruleId, "${DUMMY_TEST_WARNING.warnText()} some detailed explanation", true)
    )
}

Observed behavior №3:

fun `check dummy property`() {
    lintMethod(
        """
                                    |// provide your check here
                        """.trimMargin(),
                        LintError(1, 1, ruleId, "${DUMMY_TEST_WARNING.warnText()} some detailed explanation", true)
    )
}

Expected behavior №3:

fun `check dummy property`() {
    lintMethod(
        """
                    |// provide your check here
        """.trimMargin(),
        LintError(1, 1, ruleId, "${DUMMY_TEST_WARNING.warnText()} some detailed explanation", true)
    )
}

Test4

Initial code №4 (extracted into a separate gh-1347):

fun checkScript() {
    lintMethod(
            """
                        |val A = "aa"
                    """.trimMargin(),
    )
}

Observed behavior №4:

fun checkScript() {
    lintMethod(
        """
                    |val A =            "            aa            "
        """.trimMargin(),
    )
}

Expected behavior №4:

fun checkScript() {
    lintMethod(
        """
                    |val A = "aa"
        """.trimMargin(),
    )
}

Result

Testing showed that in the first two tests, the expected behavior coincides with the result obtained. And in the last two tests, no.
This is due to checking only the beginning of a multiline string and its indentation.
Test error 4 has not been detected yet (07.06.2022 12:04). But checking this test in IndentationRuleFixTest give the same result

Arrgentum pushed a commit that referenced this issue Jun 15, 2022
### Whats added:
 * corrected the logic of checking MultilionString
 * added fix test in IndentationRuleFixTest.kt - MultilionStringExpected.kt, MultilionStringTest.kt
 * run diktat:fix@diktat

  ### Issue (#811)
Arrgentum pushed a commit that referenced this issue Jun 15, 2022
### Whats added:
 * corrected the logic of checking MultilionString
 * added fix test in IndentationRuleFixTest.kt - MultilionStringExpected.kt, MultilionStringTest.kt
 * delete smoke tests
 * run diktat:fix@diktat

  ### Issue (#811)
Arrgentum pushed a commit that referenced this issue Jun 15, 2022
### Whats added:
 * corrected the logic of checking MultilionString
 * added fix test in IndentationRuleFixTest.kt - MultilionStringExpected.kt, MultilionStringTest.kt
 * delete smoke tests
 * run diktat:fix@diktat

  ### Issue (#811)
Arrgentum pushed a commit that referenced this issue Jun 15, 2022
### Whats added:
 * corrected the logic of checking MultilionString
 * added fix test in IndentationRuleFixTest.kt - MultilionStringExpected.kt, MultilionStringTest.kt
 * delete smoke tests
 * run diktat:fix@diktat

  ### Issue (#811)
Arrgentum pushed a commit that referenced this issue Jun 15, 2022
### Whats added:
 * corrected the logic of checking MultilionString
 * added fix test in IndentationRuleFixTest.kt - MultilionStringExpected.kt, MultilionStringTest.kt
 * delete smoke tests

  ### Issue (#811)
Arrgentum pushed a commit that referenced this issue Jun 15, 2022
### Whats added:
 * corrected the logic of checking MultilionString
 * added fix test in IndentationRuleFixTest.kt - MultilionStringExpected.kt, MultilionStringTest.kt
 * delete smoke tests
 * run install
 * mvn fix

  ### Issue (#811)
Arrgentum pushed a commit that referenced this issue Jun 15, 2022
### Whats added:
 * corrected the logic of checking MultilionString
 * added fix test in IndentationRuleFixTest.kt - MultilionStringExpected.kt, MultilionStringTest.kt
 * delete smoke tests
 * run install
 * mvn fix

  ### Issue (#811)
Arrgentum pushed a commit that referenced this issue Jun 15, 2022
### Whats added:
 * corrected the logic of checking MultilionString
 * added fix test in IndentationRuleFixTest.kt - MultilionStringExpected.kt, MultilionStringTest.kt
 * delete smoke tests
 * run install
 * mvn fix

  ### Issue (#811)
0x6675636b796f75676974687562 added a commit that referenced this issue Jul 18, 2022
### What's done:

 * Dead code dropped (originally introduced as a part of #1364).
 * See also 998d0e9.
 * Original issue: #811.
0x6675636b796f75676974687562 added a commit that referenced this issue Jul 18, 2022
### What's done:

 * Dead code dropped (originally introduced as a part of #1364).
 * See also 998d0e9.
 * Original issue: #811.
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
Labels
autofix Issues related to diktat in autofix mode bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants