运行lint命令,可以获得项目中lint检测出错误的语法,比如 bigfish lint
会出现常见的错误和原因, 大概知道原因就知道怎么解决了
CSS 文件
Expected class selector to be kebab-case or lower Camel Case
预期类选择器为短横线命名法 (kebab-case) 或小驼峰命名法 (lower Camel Case)
类名需要使用短横线或者是小驼峰命名
Unexpected duplicate “border-radius”
意外重复的“border-radius”
有重复的css属性
Unexpected empty source
意外的空源
空的样式文件
tsx 文件
‘disabled’ is assigned a value but never used “disabled”
被赋予了一个值,但从未使用过
‘’ is defined but never used '’
已定义但从未使用xxx was used before it was defined xxx
在定义之前被使用
‘xxx’ was used before it was defined
函数在定义前使用
Array.prototype.map() expects a return value from arrow function
使用map执行箭头函数需要返回值 。如果map后面是大括号后面就需要显示的写return, 没有大括号就默认返回
Don’t use
{}
as a type.{}
actually means "any non-nullish value
type MapRelationPropsType = {}; // 不能把{}作为类型Expected an assignment or function call and instead saw an expression
期望的是赋值或函数调用,但却看到了表达式
又有赋值又有三元表达式,比如:a =b > 0 ? ${Math.ceil((b / c) * 100)}% : '-'
还有setState赋值
React Hook “useModel” is called in function “getTableColumns” that is
neither a React function component nor a custom React Hook function.
React component names must start with an uppercase letter. React Hook
names must start with the word “use”
ReactHook“useModel”在函数“getTableColumns”中被调用,该函数既不是 React 函数组件也不是自定义 React
Hook 函数。React 组件名称必须以大写字母开头。React Hook 名称必须以单词“use”开头No duplicate props allowed
不允许重复属性
Unexpected lexical declaration in case block
case 块中的意外词法声明
The body of a for-in should be wrapped in an if statement to filter
unwanted properties from the prototype for-in 的主体应包含在 if
语句中,以从原型中过滤掉不需要的属性