JS代码质量SonarQube常见问题解决

**

JS代码质量SonarQube常见问题及解决思路

**
示例问题:
“i” hides or potentially hides a variable declared in an outer scope at line 10.
Overiding a variable dedlred in an outer scope can strongliy impact th readebliy, and therefore the mantainability,ofa piece fcode. furthr itcoud lad maintines to int oduce bugs because they think they’re using one variable but are really using another.

1、 设置了全局变量i之后,下边所有方法中,例如:init方法参数名不能为i,方法内也不可声明局部变量名称为i,(例如 init方法中var i;),即方法参数名和方法内局部变量名称都不能和全局变量名称一样;

Add curly braces around the nested statement(s) in this “if” block.
2、 if判断格式不标准,
解决方法,if(判断条件){内容};

Refactor this function to reduce itsCognitive Complexity from 49 to the15 allowed.
3、 方法中if判断逻辑太多,逻辑太复杂,if嵌套出现3层以上
解决方法,将单独的,完整的if判断方法拿出来,写成一个独立的函数方法,去调用;
注意:单独抽出的方法中参数传递要准确,有些方法返回值也要准确。

Refactor this code to not nest morethan 3 if/for/while/switch/try statements.
4、for循环中有if判断,
解决方法:根据需求,if判断结束后,是否要终止循环

Add the missing “else” clause.
5、 if-else 判断问题
解决方法:if-else 判断一定要以else结尾,补全else{}即可。

Reduce the number of conditional operators (4) used in the expression (maximum allowed 3).
6、 if()判断中条件超过3个了
解决方法:拆分if判断,if判断条件最多不超过3个

Add a nested comment explaining why this function is empty or complete the implementation.
7、 空的方法,例如 onClick:function(){},onSelect:function(){},没有用到的方法要注释掉或者直接不写。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值