GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • CodeQL documentation
  • CodeQL overview
  • Writing CodeQL queries
  • CodeQL language guides
  • QL language reference
  • CodeQL standard-libraries
  • CodeQL query help
  • CodeQL repository
  • QL publications
  • CodeQL query help for C and C++
  • CodeQL query help for C#
  • CodeQL query help for GitHub Actions
  • CodeQL query help for Go
  • CodeQL query help for Java and Kotlin

This view

  • Original page
  • New address

GeezerVison is showing codeql.github.com — Useless return in setter — CodeQL query help 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-code-quality.qls
   - 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¶

  • Mozilla Developer Network: Property setters.

  • © GitHub, Inc.
  • Terms
  • Privacy
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.