"no-multi-spaces": 1, //禁止多个空格react
"jsx-quotes": 1, //此规则强制在JSX属性中一导致用双引号或单引号es6
"react/jsx-closing-bracket-location": 1, //有多行属性的话, 新建一行关闭标签,为JSX语法使用下列的对齐方式数组
// bad <Foo superLongParam="bar" anotherSuperLongParam="baz" /> // good <Foo superLongParam="bar" anotherSuperLongParam="baz" /> // 若是组件的属性能够放在一行就保持在当前一行中,(我的以为若是只有一个属性就放在一行) <Foo bar="bar" />
react/jsx-boolean-value": 1,//当属性值等于true的时候,省略该属性的赋值bash
disabled=“true” 改为 disabled
"react/wrap-multilines": 1,使用括号包裹多行JSX标签curl
// bad render() { return <MyComponent className="long body" foo="bar"> <MyChild /> </MyComponent> } // good render() { return ( <MyComponent className="long body" foo="bar"> <MyChild /> </MyComponent> ); } // good, when single line render() { const body = <div>hello</div>; return <MyComponent>{body}</MyComponent>; }
<Form ref="form1"></Form> this.refs.form.validate((valid) => { });
正确方法:函数
<Form ref={ e => { this.form1 = e } }></Form> this.form1.validate((valid) => { });
// bad <Foo className="stuff"></Foo> // good <Foo className="stuff" />
//按照具体规范的React.createClass 的生命周期函数书写代码
// bad import reservationCard from './ReservationCard'; // good import ReservationCard from './ReservationCard'; // bad const ReservationItem = <ReservationCard />; // good const reservationItem = <ReservationCard />;
"quotes": [ 1, "single", { "avoidEscape": true } ],
"beforeStatementContinuationChars": "always"
要求在声明的末尾加分号,若是下一行开头
[
,
(
,
/
,
+
,或
-
。
// bad const Listing = React.createClass({ // ... render() { return <div>{this.state.hello}</div>; } }); // good class Listing extends React.Component { // ... render() { return <div>{this.state.hello}</div>; } }
function MyComponent() { return <div />; } // bad 组件名: MyComponent.js // good 组件名: MyComponent.jsx
//防止在数组中遍历中使用数组key作索引
this
{'TEXT'}