react eslint解决方案整理

eslint 解决方案整理
最近在处理react项目中报的warning,进行了以下整理

参考文档
http://eslint.cn/docs/rules/
项目中遇到warning的解决
$ xxx is defined but never used no-unused-vars

禁止出现未使用过的变量删除
$ Expected '===' and instead saw '==' eqeqeq

要求使用 === 和 !====变===
$ img elements must have an alt prop, either with meaningful text, or an empty string for decorative images jsx-a11y/alt-text

img标签添加alt=""属性
$ Expected a default case default-case

switch 添加default:break;
$ Expected a conditional expression and instead saw an assignment no-cond-assign

禁止在条件语句中出现赋值操作符if判断里=边===
$ Script URL is a form of eval no-script-url

禁用 Script URL 使用 href="###" e.preventDefault();阻止
$ Expected to return a value in arrow function array-callback-return

强制数组方法的回调函数中有 return 语句 添加return true;
$ Useless constructor no-useless-constructor

禁用不必要的构造函数 删除constructor函数;
$ Unexpected mix of '&&' and '||' no-mixed-operators

禁止混合使用不同的操作符 &&的优先级大于|| 例如:type && type.flag || false改为(type && type.flag) || false;
$ Unreachable code no-unreachable

禁止在return、throw、continue 和 break 语句之后出现不可达代码 删除;
$ Unexpected string concatenation of literals no-useless-concat

禁止不必要的字符串字面量或模板字面量的连接 详见:http://eslint.cn/docs/rules/no-useless-concat;
$ 'ws' is already defined no-redeclare

禁止多次声明同一变量 去掉var;
$ Style prop value must be an object react/style-prop-object

React框架的JSX编码格式要求,style必须是一个对象 详见:https://blog.csdn.net/sinat_17775997/article/details/66967829
$ Missing radix parameter radix

强制在parseInt()使用基数参数 详见:https://blog.csdn.net/katecatecake/article/details/78817019
$ Do not mutate state directly. Use setState() react/no-direct-mutation-state

React中不能直接更改state的值 进行拷贝,然后赋值
$ The array literal notation [] is preferrable no-array-constructor

禁用 Array 构造函数 例如:let clickX = new Array();改let clickX = [];
$ No duplicate props allowed react/jsx-no-duplicate-props

禁止重复定义删除一个;
$ The element img has an implicit role of presentation. Defining this explicitly is redundant and should be avoided jsx-a11y/no-redundant-roles

删除role="presentation"属性;
$ Block is redundant no-lone-blocks

禁用不必要的嵌套块 删除注释;
$ Block is redundant no-lone-blocks

禁用不必要的嵌套块 删除break;
$ Unexpected use of comma operator no-sequences

禁用逗号操作符 ,号变;;
$ iframe elements must have a unique title property jsx-a11y/iframe-has-title

添加title="navigation";
$ Unnecessary escape character: \. no-useless-escape

禁用不必要的转义字符;
$ Duplicate key 'uploadType' no-dupe-keys

禁止对象字面量中出现重复的 key;

 

来源:https://blog.csdn.net/zcfzfc123456789/article/details/87899298

  • 2
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值