"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'}