GHGHGHKO / memes-api

Get memes api
0 stars 0 forks source link

bug: sonarlint "Unused local variables should be removed" is broken #2

Open GHGHGHKO opened 1 year ago

GHGHGHKO commented 1 year ago
    fun signIn(signInRequestDto: SignInRequestDto): SignInResponseDto {
        val user: UserMaster = userMasterRepository.findByEmail(signInRequestDto.email)
            ?: throw UserNotFoundExceptionCustom()

        if (!passwordEncoder.matches(signInRequestDto.password, user.password)) {
            throw EmailSignInFailedExceptionCustom()
        }

        val jwtInfo = jwtTokenProvider.createToken(user.id.toString(), user.roles)

        return SignInResponseDto(
            jwtInfo.token, jwtInfo.expirationDate
        )
    }

user variable is Unused local variables should be removed

https://community.sonarsource.com/t/unused-local-variables-should-be-removed-is-broken/78750

GHGHGHKO commented 1 year ago

Hi,

Welcome to the community!

It looks like SonarLint 6.8 has some age on it at this point. Could you upgrade to the current version, 7.2.1.58118, and see if this is replicable?

Thx, Ann

Hi, G Ann Campbell!

Thank you for your reply

Updated from version 6.8 to version 7.2.1.58118 See this issue is replicated Is it because didn’t return a variable? image

GHGHGHKO commented 1 year ago

Hi,

Thanks for trying with the updated version. Unfortunately, I can’t answer your question, so I’ve flagged this for more expert eyes.

Ann

GHGHGHKO commented 1 year ago

Hi, Thanks for trying with the updated version. Unfortunately, I can’t answer your question, so I’ve flagged this for more expert eyes. Ann

Margarita Nedzelska SonarSourcer 6d Hello @GHGHGHKO,

Thanks for your report. I was able to reproduce this issue when analyzing the single file. However, when I analyze the whole project, this issue disappears. This means that the problem is that SonarLint wasn’t able to locate the .class files of your project correctly. And without semantics, the analyzer is not able to resolve variables, types, and bindings correctly, which leads to the incorrect result.

For now, I can suggest you build your project with Gradle (either from the IDE or command line), make sure that the build folder is generated, and then run the analysis. The issue should disappear.

Meanwhile, I created a ticket to not report FPs in case of incomplete semantics:

https://sonarsource.atlassian.net/browse/SONARKT-269 2

Kind regards, Margarita