Vikram Kumar
Vikram Kumar

Reputation: 4126

SonarQube is not able to recognize String.prototype method

SonarQube is complaining about following piece of JS code with error

Remove this access to "contains" property, it doesn't exist, as a built-in, on a String.

enter image description here While I have created this method is another JS file as

  String.prototype.contains = function (str, startIndex) {
      return -1 !== this.indexOf(str, startIndex);
    };

The same issue exists with other methods created with prototype. How can I resolve this issue without excluding the files from rule check?

Upvotes: 0

Views: 205

Answers (1)

Elena Vilchik
Elena Vilchik

Reputation: 1090

This rule assumes that no monkey patching is done in the project. If you use monkey patching massively, most probably it's better to disable the rule. Otherwise just mark issue as "won't fix" in SQ UI

Upvotes: 3

Related Questions