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-positive MULTIPLE_INIT_BLOCKS when properties are assigned in init block using local variables #795

Closed
petertrr opened this issue Mar 10, 2021 · 1 comment
Labels
bug Something isn't working

Comments

@petertrr
Copy link
Member

Describe the bug

class Credentials(auth: String) {
    val gitHubUserName: String
    val gitHubAuthToken: String

    init {
        val splitAuth = auth.split(":")
        if (splitAuth.size != 2) {
            """Incorrect value is passed with 'auth' property.
                    | It should contain user and auth-token separated by a colon (':').
                    | This option is needed to extend the limit of requests.""".trimMargin() logAndExit 8
        }
        gitHubUserName = splitAuth[0]
        gitHubAuthToken = splitAuth[1]
    }
}

Now diktat suggests to move property assignments outside of the init block, but a local variable is used for this assignments, so this refactoring is too complicated. Diktat should not emit a warning in this case.

Environment information

  • diktat version: 0.4.2
@petertrr petertrr added the bug Something isn't working label Mar 10, 2021
@petertrr
Copy link
Member Author

Should be fixed by #967

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant