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

S2583: FP with multiple if-else clauses involving NaN #618

Closed
kamushkin opened this issue Jul 3, 2017 · 3 comments
Closed

S2583: FP with multiple if-else clauses involving NaN #618

kamushkin opened this issue Jul 3, 2017 · 3 comments
Labels
type: false positive Issue is reported when it should NOT be

Comments

@kamushkin
Copy link

RSPEC-2583 - the following code triggers FP on the third condition -

function compare1(a, b){
	return a < b ? -1 : a > b ? 1 : a >= b ? 0 : NaN;
}

https://sonarcloud.io/project/issues?id=kamushkin%3Asonarqube-tests&issues=AV0H2uTRI1Qj-tYTbHFX&open=AV0H2uTRI1Qj-tYTbHFX

Same when the code is written as if-else statements -

function compare2(a, b){

	if (a < b){
		return -1;
	}
	else if (a > b){
		return 1;
	}
	else if (a >= b){
		return 0;
	}
	else {
		return NaN;
	}
}

https://sonarcloud.io/project/issues?id=kamushkin%3Asonarqube-tests&issues=AV0H2uTTI1Qj-tYTbHFY&open=AV0H2uTTI1Qj-tYTbHFY

original source -
https://sonarcloud.io/project/issues?id=d3&open=AVcREIlyzjiM7eGZNOsO&resolved=false&types=BUG

The FP is not triggered when the third comparison is ==, so probably a bug.

@inverno
Copy link
Contributor

inverno commented Jul 3, 2017

@kamushkin thanks, yes, it's likely a bug

@inverno inverno added the type: bug Exceptions and blocking issues during analysis label Jul 3, 2017
@fmallet fmallet added type: false positive Issue is reported when it should NOT be and removed type: bug Exceptions and blocking issues during analysis labels Jul 4, 2017
@Nisgrak
Copy link

Nisgrak commented May 11, 2020

This issue hasn't been resolved yet
Any case, I don't know if my error is relationed

compare2(a) {
	a.forEach(b => {
		if (typeof b == "object") {
			return "aaa";
		} else if (Array.isArray(b)) { // This line is marked as error sonarlint(javascript:S2583)
			return "bbbb";
		} else {
			return 0;
		}
	});
}

@vilchik-elena
Copy link
Contributor

This rule is deprecated as it's based on the Symbolic Execution engine we plan to drop soon. So updating the SonarLint plugin should disable the rule (but not in VSCode yet, but it should be the case soon).

So I closing this issue as won't fix, as rule will be dropped eventually.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: false positive Issue is reported when it should NOT be
Projects
None yet
Development

No branches or pull requests

5 participants