CodeQL documentation

Useless return in setter

ID: js/setter-return
Kind: problem
Security severity: 
Severity: warning
Precision: very-high
Tags:
   - quality
   - maintainability
   - useless-code
   - language-features
Query suites:
   - javascript-security-and-quality.qls

Click to see the query in the CodeQL repository

Returning a value from a property setter function is useless, since it will always be ignored.

Recommendation

Remove the return statement altogether, or replace it with a simple return; statement that does not return a value.

Example

The following example shows a constructor function Point that uses property accessors on x and y to ensure that they are only set to integer values. It returns the new values for x and y from their setters, but these return values will simply be ignored.

function Point(x, y) {
	return {
		get x() { return x; },
		set x(_x) { x = _x|0; return x; },
		get y() { return y; },
		set y(_y) { y = _y|0; return y; }
	};
}

It would be clearer to omit the return statements:

function Point(x, y) {
	return {
		get x() { return x; },
		set x(_x) { x = _x|0; },
		get y() { return y; },
		set y(_y) { y = _y|0; }
	};
}

References

  • © GitHub, Inc.
  • Terms
  • Privacy
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy