All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.sonar.l10n.javascript.rules.javascript.S3827.html Maven / Gradle / Ivy

There is a newer version: 10.17.0.28100
Show newest version

Why is this an issue?

When a non-existent variable is referenced a ReferenceError is raised.

Due to the dynamic nature of JavaScript this can happen in a number of scenarios:

  • When typo was made in a symbol’s name.
  • When using variable declared with let or const before declaration (unlike var-declarations, they are not hoisted to the top of the scope).
  • Due to confusion with scopes of let- and const-declarations (they have block scope, unlike var-declarations, having function scope).
  • When accessing a property in the wrong scope (e.g. forgetting to specify this.).

This rule does not raise issues on global variables which are defined with sonar.javascript.globals and sonar.javascript.environments properties.

Noncompliant code example

var john = {
  firstName: "john",
  show: function() { console.log(firstName); } // Noncompliant: firstName is not defined
}
john.show();

Compliant solution

var john = {
  firstName: "john",
  show: function() { console.log(this.firstName); }
}
john.show();




© 2015 - 2024 Weber Informatics LLC | Privacy Policy