javascript - SonarQube 无法识别 String.prototype 方法

标签 javascript sonarqube sonarlint sonarjs

SonarQube 提示以下 JS 代码有错误

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

enter image description here 虽然我创建了这个方法,但它是另一个 JS 文件

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

使用原型(prototype)创建的其他方法也存在同样的问题。如何解决此问题而不从规则检查中排除文件?

最佳答案

此规则假设项目中未进行猴子修补。如果您大量使用猴子修补,很可能最好禁用该规则。否则,只需在 SQ UI 中将问题标记为“无法修复”

关于javascript - SonarQube 无法识别 String.prototype 方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49384342/

相关文章:

javascript - 如何以 Angular 动态添加新行

javascript - 使用 truncate.js chop 多行 html 文本

javascript - 删除列表项时 Magnific Popup 关闭

jenkins - 无法在网络浏览器中打开 SonarQube

java - SonarLint 针对 java :S1206 issue but hashCode and equals are implemented 发出警报

java - SonarLint:返回空集合而不是 null

java - Java代码中方法签名后禁止括号

javascript - 在 javascript 中创建和解析 3D 数组?

powershell - 配置 Elasticsearch

c# - 修改SonarQube中的默认参数规则