From 5a2d659edf13e106b74770b1dc8309d04df1f45e Mon Sep 17 00:00:00 2001 From: Jordan Gensler Date: Sun, 13 Dec 2015 18:36:25 -0800 Subject: [PATCH] Cleaning up the react styleguide. Adding additional info in props. --- packages/eslint-config-airbnb/rules/react.js | 3 + react/README.md | 117 +++++++++++++++++-- 2 files changed, 110 insertions(+), 10 deletions(-) diff --git a/packages/eslint-config-airbnb/rules/react.js b/packages/eslint-config-airbnb/rules/react.js index d5c82c7949..5d37894147 100644 --- a/packages/eslint-config-airbnb/rules/react.js +++ b/packages/eslint-config-airbnb/rules/react.js @@ -21,6 +21,9 @@ module.exports = { // Validate props indentation in JSX // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-indent-props.md 'react/jsx-indent-props': [2, 2], + // Prevent usage of .bind() and arrow functions in JSX props + // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-no-bind.md + 'react/jsx-no-bind': 2, // Prevent duplicate props in JSX // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-no-duplicate-props.md 'react/jsx-no-duplicate-props': 0, diff --git a/react/README.md b/react/README.md index dde064c58c..8b3aa85358 100644 --- a/react/README.md +++ b/react/README.md @@ -24,7 +24,7 @@ ## Class vs React.createClass - - Use class extends React.Component unless you have a very good reason to use mixins. + - Use `class extends React.Component` unless you have a very good reason to use mixins. eslint rules: [`react/prefer-es6-class`](https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/prefer-es6-class.md). @@ -54,10 +54,10 @@ ```javascript // bad - const reservationCard = require('./ReservationCard'); + import reservationCard from './ReservationCard'; // good - const ReservationCard = require('./ReservationCard'); + import ReservationCard from './ReservationCard'; // bad const ReservationItem = ; @@ -69,13 +69,13 @@ **Component Naming**: Use the filename as the component name. For example, `ReservationCard.jsx` should have a reference name of `ReservationCard`. However, for root components of a directory, use `index.jsx` as the filename and use the directory name as the component name: ```javascript // bad - const Footer = require('./Footer/Footer.jsx') + import Footer from './Footer/Footer.jsx'; // bad - const Footer = require('./Footer/index.jsx') + import Footer from './Footer/index.jsx'; // good - const Footer = require('./Footer') + import Footer from './Footer'; ``` @@ -177,13 +177,29 @@ /> ``` + - Omit the value of the prop when it is explicitly `true`. + + eslint rules: [`react/jsx-boolean-value`](https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-boolean-value.md). + + ```javascript + // bad +