warning/error

1.Identifier xxxxxx is not in camel case.
问题描述:意思就是xxxxxx这个没有用驼峰法命名
举例:<img src={default_logo} alt="图标" />像这里的default_logo
解决:命名改成驼峰法就行<img src={defaultLogo} alt="图标" />

2.xxxxxx is never reassigned. Use const instead.
问题描述:意思就是xxxxxx这个定义了但没有被重新赋值,建议用const去定义
举例:let { dispatch } = this.props;像这里的dispatch
解决:改成用const定义就行const { dispatch } = this.props;

3.Do not nest ternary expressions.
问题描述:意思就是不要嵌套三元表达式
举例:type === 'A' ? '商品类型A' : type === 'B' ? '商品类型B' : '商品类型C'
解决:根据代码逻辑,利用if else 或者switch或者其他方式进行拆分

4.Expected a function expression.
问题描述:意思就是建议用命名函数表达式,而不是函数声明
举例:export function func1() {...函数体}'
解决:改成用命名函数export const func1 = () => {...函数体}

5.Assignment to function parameter xxxxxx
问题描述:意思就是不能直接去赋值参数
举例:export const func1 = (value) => { value = xx}'
解决:尽量不要这么做,要做的可以额外定义多一个变量
export const func1 = (value) => { let newValue = value; newValue = xx}'

6. A function with a name starting with an uppercase letter should only be used as a constructor.
问题描述:意思就是一般建议函数的首字母不要大写
举例:<div>{InputDom()}</div>'像这里的InputDom
解决:改成首字母小写就行

7. Expected to return a value in arrow function.
问题描述:意思就是在这个函数内需要有return,常见于map(),filter()这类方法
举例:arr.map(item => { ...函数体 });
解决:看需求,如果真的是有需要返回值的,就return出去。像map这中只是用来遍历数组的话,可以用forEach代替

8.xxxxxx is assigned a value but never used.
问题描述:意思就是xxxxxx这个变量定义了,但是没有使用
解决:删除这些变量

9. Expected !== and instead saw !=. 和 Expected === and instead saw ==.
问题描述:意思就是使用了!= 和 ==
解决:改成!== 和 ===

10. Using target="_blank" without rel=“noopener noreferrer” is a security risk: see https://mathiasbynens.github.io/rel-noopener
问题描述:意思就是如果在a标签中使用了target="_blank"的话,建议加上rel=“noopener noreferrer”,原因是在新打开的页面中可以通过 window.opener获取到源页面的部分控制权,这样不安全,加上rel=“noopener noreferrer”,通用window.opener获取到的就是null了
解决:加上rel="noopener noreferrer"就ok了

11. eval can be harmful.
问题描述:意思就是不要用eval,因为eval()会执行括号内的js,不安全
解决:可以尝试用自定义的函数去实现想要的效果,或者其他方式改写

12. componentWillReceiveProps is deprecated since React 16.9.0, use UNSAFE_componentWillReceiveProps instead
问题描述:意思就是componentWillReceiveProps这个生命周期被重命名了,建议用UNSAFE_componentWillReceiveProps代替
解决:换成UNSAFE_componentWillReceiveProps就ok了

13. Expected a default case.
问题描述:意思就是没有一个defaule case的情况, 出现场景是在switch case的使用
解决:记得使用switch case要在最后面加上default: break;

————————————————
版权声明:本文为CSDN博主「前端小佬」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/weixin_42436131/article/details/109643210

猜你喜欢

转载自blog.csdn.net/weixin_55572171/article/details/120645798