diff --git a/README.md b/README.md index f5bf352603..8dae16d297 100644 --- a/README.md +++ b/README.md @@ -33,7 +33,7 @@ Add `plugins` section and specify ESLint-plugin-React as a plugin. You can also specify some settings that will be shared across all the plugin rules. -```js +```json { "settings": { "react": { @@ -152,7 +152,7 @@ This plugin exports a `recommended` configuration that enforce React good practi To enable this configuration use the `extends` property in your `.eslintrc` config file: -```js +```json { "extends": ["eslint:recommended", "plugin:react/recommended"] } @@ -182,7 +182,7 @@ The rules enabled in this configuration are: This plugin also exports an `all` configuration that includes every available rule. This pairs well with the `eslint:all` rule. -```js +```json { "plugins": [ "react" diff --git a/docs/rules/display-name.md b/docs/rules/display-name.md index 24f500c5f6..49cfcf3c9d 100644 --- a/docs/rules/display-name.md +++ b/docs/rules/display-name.md @@ -6,7 +6,7 @@ DisplayName allows you to name your component. This name is used by React in deb The following patterns are considered warnings: -```js +```jsx var Hello = React.createClass({ render: function() { return
Hello {this.props.name}
; @@ -16,7 +16,7 @@ var Hello = React.createClass({ The following patterns are not considered warnings: -```js +```jsx var Hello = React.createClass({ displayName: 'Hello', render: function() { @@ -39,7 +39,7 @@ When `true` the rule will ignore the name set by the transpiler and require a `d The following patterns are considered okay and do not cause warnings: -```js +```jsx var Hello = React.createClass({ displayName: 'Hello', @@ -50,7 +50,7 @@ var Hello = React.createClass({ module.exports = Hello; ``` -```js +```jsx export default class Hello extends React.Component { render() { return
Hello {this.props.name}
; @@ -59,7 +59,7 @@ export default class Hello extends React.Component { Hello.displayName = 'Hello'; ``` -```js +```jsx export default function Hello({ name }) { return
Hello {name}
; } @@ -68,7 +68,7 @@ Hello.displayName = 'Hello'; The following patterns will cause warnings: -```js +```jsx var Hello = React.createClass({ render: function() { return
Hello {this.props.name}
; @@ -77,7 +77,7 @@ var Hello = React.createClass({ module.exports = Hello; ``` -```js +```jsx export default class Hello extends React.Component { render() { return
Hello {this.props.name}
; @@ -85,7 +85,7 @@ export default class Hello extends React.Component { } ``` -```js +```jsx module.exports = React.createClass({ render: function() { return
Hello {this.props.name}
; @@ -93,7 +93,7 @@ module.exports = React.createClass({ }); ``` -```js +```jsx export default class extends React.Component { render() { return
Hello {this.props.name}
; @@ -101,7 +101,7 @@ export default class extends React.Component { } ``` -```js +```jsx function HelloComponent() { return React.createClass({ render: function() { diff --git a/docs/rules/forbid-prop-types.md b/docs/rules/forbid-prop-types.md index c8ee957dc4..adf3a34c31 100644 --- a/docs/rules/forbid-prop-types.md +++ b/docs/rules/forbid-prop-types.md @@ -9,7 +9,7 @@ This rule is off by default. The following patterns are considered warnings: -```js +```jsx var Component = React.createClass({ propTypes: { a: React.PropTypes.any, diff --git a/docs/rules/jsx-boolean-value.md b/docs/rules/jsx-boolean-value.md index e06fd91841..c3ad2ec677 100644 --- a/docs/rules/jsx-boolean-value.md +++ b/docs/rules/jsx-boolean-value.md @@ -10,25 +10,25 @@ This rule takes one argument. If it is `"always"` then it warns whenever an attr The following patterns are considered warnings when configured `"never"`: -```js +```jsx var Hello = ; ``` The following patterns are not considered warnings when configured `"never"`: -```js +```jsx var Hello = ; ``` The following patterns are considered warnings when configured `"always"`: -```js +```jsx var Hello = ; ``` The following patterns are not considered warnings when configured `"always"`: -```js +```jsx var Hello = ; ``` diff --git a/docs/rules/jsx-curly-spacing.md b/docs/rules/jsx-curly-spacing.md index fbbde0597f..3f5b2761f1 100644 --- a/docs/rules/jsx-curly-spacing.md +++ b/docs/rules/jsx-curly-spacing.md @@ -27,7 +27,7 @@ Depending on your coding conventions, you can choose either option by specifying When `"never"` is set, the following patterns are considered warnings: -```js +```jsx ; ; ; @@ -35,7 +35,7 @@ When `"never"` is set, the following patterns are considered warnings: The following patterns are not warnings: -```js +```jsx ; ; ; ; ; @@ -55,7 +55,7 @@ When `"always"` is used, the following patterns are considered warnings: The following patterns are not warnings: -```js +```jsx ; ; ; ; ; @@ -84,14 +84,14 @@ When `"never"` is used and `allowMultiline` is `false`, the following patterns a The following patterns are not warnings: -```js +```jsx ; ; ``` When `"always"` is used and `allowMultiline` is `false`, the following patterns are considered warnings: -```js +```jsx ; ; ; @@ -102,7 +102,7 @@ When `"always"` is used and `allowMultiline` is `false`, the following patterns The following patterns are not warnings: -```js +```jsx ; ; ``` @@ -123,13 +123,13 @@ All spacing options accept either the string `"always"` or the string `"never"`. When `"always"` is used but `objectLiterals` is `"never"`, the following pattern is not considered a warning: -```js +```jsx ; ``` When `"never"` is used and `objectLiterals` is `"always"`, the following pattern is not considered a warning: -```js +```jsx ; ``` diff --git a/docs/rules/jsx-equals-spacing.md b/docs/rules/jsx-equals-spacing.md index d32d7ef89e..a07ea54aa6 100644 --- a/docs/rules/jsx-equals-spacing.md +++ b/docs/rules/jsx-equals-spacing.md @@ -25,7 +25,7 @@ Depending on your coding conventions, you can choose either option by specifying When `"never"` is set, the following patterns are considered warnings: -```js +```jsx ; ; ; @@ -33,7 +33,7 @@ When `"never"` is set, the following patterns are considered warnings: The following patterns are not warnings: -```js +```jsx ; ; ; @@ -43,7 +43,7 @@ The following patterns are not warnings: When `"always"` is used, the following patterns are considered warnings: -```js +```jsx ; ; ; @@ -51,7 +51,7 @@ When `"always"` is used, the following patterns are considered warnings: The following patterns are not warnings: -```js +```jsx ; ; ; diff --git a/docs/rules/jsx-handler-names.md b/docs/rules/jsx-handler-names.md index f9c26fc186..ef6aa192ae 100644 --- a/docs/rules/jsx-handler-names.md +++ b/docs/rules/jsx-handler-names.md @@ -6,21 +6,21 @@ Ensures that any component or prop methods used to handle events are correctly p The following patterns are considered warnings: -```js +```jsx ``` -```js +```jsx ``` The following patterns are not considered warnings: -```js +```jsx ``` -```js +```jsx ``` @@ -40,4 +40,4 @@ The following patterns are not considered warnings: ## When Not To Use It -If you are not using JSX, or if you don't want to enforce specific naming conventions for event handlers. \ No newline at end of file +If you are not using JSX, or if you don't want to enforce specific naming conventions for event handlers. diff --git a/docs/rules/jsx-no-bind.md b/docs/rules/jsx-no-bind.md index 412f03dc24..3baa143c47 100644 --- a/docs/rules/jsx-no-bind.md +++ b/docs/rules/jsx-no-bind.md @@ -6,15 +6,15 @@ A `bind` call or [arrow function](https://developer.mozilla.org/en-US/docs/Web/J The following patterns are considered warnings: -```js +```jsx
``` -```js +```jsx
console.log('Hello!'))}>
``` The following patterns are not considered warnings: -```js +```jsx
``` @@ -59,7 +59,7 @@ When `true` the following is not considered a warning: A common use case of `bind` in render is when rendering a list, to have a separate callback per list item: -```js +```jsx var List = React.createClass({ render() { return ( @@ -77,7 +77,7 @@ var List = React.createClass({ Rather than doing it this way, pull the repeated section into its own component: -```js +```jsx var List = React.createClass({ render() { return ( @@ -110,7 +110,7 @@ This will speed up rendering, as it avoids the need to create new functions (thr Unfortunately [React ES6 classes](https://facebook.github.io/react/blog/2015/01/27/react-v0.13.0-beta-1.html#es6-classes) do not autobind their methods like components created with the older `React.createClass` syntax. There are several approaches to binding methods for ES6 classes. A basic approach is to just manually bind the methods in the constructor: -```js +```jsx class Foo extends React.Component { constructor() { super(); diff --git a/docs/rules/jsx-no-comment-textnodes.md b/docs/rules/jsx-no-comment-textnodes.md index 9dfd339ce5..68a4969a28 100644 --- a/docs/rules/jsx-no-comment-textnodes.md +++ b/docs/rules/jsx-no-comment-textnodes.md @@ -7,7 +7,7 @@ injected as a text node in JSX statements. The following patterns are considered warnings: -```js +```jsx var Hello = React.createClass({ render: function() { return ( @@ -29,7 +29,7 @@ var Hello = React.createClass({ The following patterns are not considered warnings: -```js +```jsx var Hello = React.createClass({ displayName: 'Hello', render: function() { @@ -57,7 +57,7 @@ var Hello = React.createClass({ It's possible you may want to legitimately output comment start characters (`//` or `/*`) in a JSX text node. In which case, you can do the following: -```js +```jsx var Hello = React.createClass({ render: function() { return ( diff --git a/docs/rules/jsx-no-duplicate-props.md b/docs/rules/jsx-no-duplicate-props.md index 022ac9e42d..729ad39f57 100644 --- a/docs/rules/jsx-no-duplicate-props.md +++ b/docs/rules/jsx-no-duplicate-props.md @@ -6,13 +6,13 @@ Creating JSX elements with duplicate props can cause unexpected behavior in your The following patterns are considered warnings: -```js +```jsx ; ``` The following patterns are not considered warnings: -```js +```jsx ; ``` diff --git a/docs/rules/jsx-no-literals.md b/docs/rules/jsx-no-literals.md index 2051175cce..3c23c1fd64 100644 --- a/docs/rules/jsx-no-literals.md +++ b/docs/rules/jsx-no-literals.md @@ -8,13 +8,13 @@ Prevents any odd artifacts of highlighters if your unwrapped string contains an The following patterns are considered warnings: -```javascript +```jsx var Hello =
test
; ``` The following patterns are not considered warnings: -```javascript +```jsx var Hello =
{'test'}
; ``` diff --git a/docs/rules/jsx-no-undef.md b/docs/rules/jsx-no-undef.md index cd423f79bf..00cae519d5 100644 --- a/docs/rules/jsx-no-undef.md +++ b/docs/rules/jsx-no-undef.md @@ -6,13 +6,13 @@ This rule helps locate potential ReferenceErrors resulting from misspellings or The following patterns are considered warnings: -```js +```jsx ; ``` The following patterns are not considered warnings: -```js +```jsx var Hello = require('./Hello'); ; diff --git a/docs/rules/jsx-pascal-case.md b/docs/rules/jsx-pascal-case.md index 0544f45095..077378018a 100644 --- a/docs/rules/jsx-pascal-case.md +++ b/docs/rules/jsx-pascal-case.md @@ -8,31 +8,31 @@ Note that since React's JSX uses the upper vs. lower case convention to distingu The following patterns are considered warnings: -```js +```jsx ``` -```js +```jsx ``` The following patterns are not considered warnings: -```js +```jsx
``` -```js +```jsx ``` -```js +```jsx
``` -```js +```jsx ``` diff --git a/docs/rules/jsx-sort-props.md b/docs/rules/jsx-sort-props.md index 63b5dd6e1e..81d1a7bfdf 100644 --- a/docs/rules/jsx-sort-props.md +++ b/docs/rules/jsx-sort-props.md @@ -8,13 +8,13 @@ This rule checks all JSX components and verifies that all props are sorted alpha The following patterns are considered warnings: -```js +```jsx ; ``` The following patterns are considered okay and do not cause warnings: -```js +```jsx ; ; ``` @@ -39,7 +39,7 @@ When `true` the rule ignores the case-sensitivity of the props order. The following patterns are considered okay and do not cause warnings: -```js +```jsx ; ``` @@ -47,7 +47,7 @@ The following patterns are considered okay and do not cause warnings: When `true`, callbacks must be listed after all other props, even if `shorthandLast` is set : -```js +```jsx ``` @@ -55,7 +55,7 @@ When `true`, callbacks must be listed after all other props, even if `shorthandL When `true`, short hand props must be listed before all other props, but still respecting the alphabetical order: -```js +```jsx ``` @@ -63,7 +63,7 @@ When `true`, short hand props must be listed before all other props, but still r When `true`, short hand props must be listed after all other props (unless `callbacksLast` is set), but still respecting the alphabetical order: -```js +```jsx ``` @@ -71,7 +71,7 @@ When `true`, short hand props must be listed after all other props (unless `call When `true`, alphabetical order is not enforced: -```js +```jsx ``` diff --git a/docs/rules/jsx-space-before-closing.md b/docs/rules/jsx-space-before-closing.md index a58096d092..6d5cd640c1 100644 --- a/docs/rules/jsx-space-before-closing.md +++ b/docs/rules/jsx-space-before-closing.md @@ -12,14 +12,14 @@ This rule takes one argument. If it is `"always"` then it warns whenever a space The following patterns are considered warnings when configured `"always"`: -```js +```jsx ``` The following patterns are not considered warnings when configured `"always"`: -```js +```jsx ``` The following patterns are not considered warnings when configured `"never"`: -```js +```jsx Hello {this.props.name}
; The following patterns are not considered warnings: -```js +```jsx var React = require('react'); var Hello =
Hello {this.props.name}
; ``` -```js +```jsx /** @jsx Foo */ var Foo = require('foo'); diff --git a/docs/rules/jsx-uses-vars.md b/docs/rules/jsx-uses-vars.md index f320a5e415..d60dab4e46 100644 --- a/docs/rules/jsx-uses-vars.md +++ b/docs/rules/jsx-uses-vars.md @@ -14,7 +14,7 @@ var Hello = require('./Hello'); The following patterns are not considered warnings: -```js +```jsx var Hello = require('./Hello'); ; diff --git a/docs/rules/jsx-wrap-multilines.md b/docs/rules/jsx-wrap-multilines.md index 3179f8cca3..7de409d3e7 100644 --- a/docs/rules/jsx-wrap-multilines.md +++ b/docs/rules/jsx-wrap-multilines.md @@ -8,7 +8,7 @@ Wrapping multiline JSX in parentheses can improve readability and/or convenience The following patterns are considered warnings: -```js +```jsx var Hello = React.createClass({ render: function() { return
@@ -20,7 +20,7 @@ var Hello = React.createClass({ The following patterns are not considered warnings: -```js +```jsx var singleLineJSX =

Hello

var Hello = React.createClass({ diff --git a/docs/rules/no-danger.md b/docs/rules/no-danger.md index 3a9aa6f2fd..0e8c382afa 100644 --- a/docs/rules/no-danger.md +++ b/docs/rules/no-danger.md @@ -8,7 +8,7 @@ See https://facebook.github.io/react/tips/dangerously-set-inner-html.html The following patterns are considered warnings: -```js +```jsx var React = require('react'); var Hello =
; @@ -16,7 +16,7 @@ var Hello =
; The following patterns are not considered warnings: -```js +```jsx var React = require('react'); var Hello =
Hello World
; diff --git a/docs/rules/no-deprecated.md b/docs/rules/no-deprecated.md index 333664a51a..2ca554168a 100644 --- a/docs/rules/no-deprecated.md +++ b/docs/rules/no-deprecated.md @@ -6,7 +6,7 @@ Several methods are deprecated between React versions. This rule will warn you i The following patterns are considered warnings: -```js +```jsx React.render(, root); React.unmountComponentAtNode(root); @@ -20,7 +20,7 @@ React.renderToStaticMarkup(); The following patterns are not considered warnings: -```js +```jsx ReactDOM.render(, root); // When [1, {"react": "0.13.0"}] diff --git a/docs/rules/no-did-mount-set-state.md b/docs/rules/no-did-mount-set-state.md index 7af9e6320e..ce6f78b9a8 100644 --- a/docs/rules/no-did-mount-set-state.md +++ b/docs/rules/no-did-mount-set-state.md @@ -8,7 +8,7 @@ This rule is aimed to forbid the use of `this.setState` in `componentDidMount` o The following patterns are considered warnings: -```js +```jsx var Hello = React.createClass({ componentDidMount: function() { this.setState({ @@ -23,7 +23,7 @@ var Hello = React.createClass({ The following patterns are not considered warnings: -```js +```jsx var Hello = React.createClass({ componentDidMount: function() { this.onMount(function callback(newName) { @@ -38,7 +38,7 @@ var Hello = React.createClass({ }); ``` -```js +```jsx var Hello = React.createClass({ componentDidMount: function() { this.props.onMount(); @@ -63,7 +63,7 @@ By default this rule forbids any call to `this.setState` in `componentDidMount` The following patterns are considered warnings: -```js +```jsx var Hello = React.createClass({ componentDidMount: function() { this.setState({ @@ -76,7 +76,7 @@ var Hello = React.createClass({ }); ``` -```js +```jsx var Hello = React.createClass({ componentDidMount: function() { this.onMount(function callback(newName) { diff --git a/docs/rules/no-did-update-set-state.md b/docs/rules/no-did-update-set-state.md index 60d398e818..fb40e34637 100644 --- a/docs/rules/no-did-update-set-state.md +++ b/docs/rules/no-did-update-set-state.md @@ -6,7 +6,7 @@ Updating the state after a component update will trigger a second `render()` cal The following patterns are considered warnings: -```js +```jsx var Hello = React.createClass({ componentDidUpdate: function() { this.setState({ @@ -21,7 +21,7 @@ var Hello = React.createClass({ The following patterns are not considered warnings: -```js +```jsx var Hello = React.createClass({ componentDidUpdate: function() { this.props.onUpdate(); @@ -32,7 +32,7 @@ var Hello = React.createClass({ }); ``` -```js +```jsx var Hello = React.createClass({ componentDidUpdate: function() { this.onUpdate(function callback(newName) { @@ -61,7 +61,7 @@ By default this rule forbids any call to `this.setState` in `componentDidUpdate` The following patterns are considered warnings: -```js +```jsx var Hello = React.createClass({ componentDidUpdate: function() { this.setState({ @@ -74,7 +74,7 @@ var Hello = React.createClass({ }); ``` -```js +```jsx var Hello = React.createClass({ componentDidUpdate: function() { this.onUpdate(function callback(newName) { diff --git a/docs/rules/no-direct-mutation-state.md b/docs/rules/no-direct-mutation-state.md index f42d86c011..b260190fc9 100644 --- a/docs/rules/no-direct-mutation-state.md +++ b/docs/rules/no-direct-mutation-state.md @@ -9,7 +9,7 @@ This rule is aimed to forbid the use of mutating `this.state` directly. The following patterns are considered warnings: -```js +```jsx var Hello = React.createClass({ componentDidMount: function() { this.state.name = this.props.name.toUpperCase(); @@ -23,7 +23,7 @@ var Hello = React.createClass({ The following patterns are not considered warnings: -```js +```jsx var Hello = React.createClass({ componentDidMount: function() { this.setState({ diff --git a/docs/rules/no-find-dom-node.md b/docs/rules/no-find-dom-node.md index f981c00319..e962db0667 100644 --- a/docs/rules/no-find-dom-node.md +++ b/docs/rules/no-find-dom-node.md @@ -8,7 +8,7 @@ It is recommended to use callback refs instead. See [Dan Abramov comments and ex The following patterns are considered warnings: -```js +```jsx class MyComponent extends Component { componentDidMount() { findDOMNode(this).scrollIntoView(); @@ -21,7 +21,7 @@ class MyComponent extends Component { The following patterns are not considered warnings: -```js +```jsx class MyComponent extends Component { componentDidMount() { this.node.scrollIntoView(); diff --git a/docs/rules/no-is-mounted.md b/docs/rules/no-is-mounted.md index 1fd3b4ee16..201ca82ca7 100644 --- a/docs/rules/no-is-mounted.md +++ b/docs/rules/no-is-mounted.md @@ -8,7 +8,7 @@ The following patterns are considered warnings: -```js +```jsx var Hello = React.createClass({ handleClick: function() { setTimeout(function() { @@ -25,7 +25,7 @@ var Hello = React.createClass({ The following patterns are not considered warnings: -```js +```jsx var Hello = React.createClass({ render: function() { return
Hello
; diff --git a/docs/rules/no-multi-comp.md b/docs/rules/no-multi-comp.md index 5108402759..6122dc602c 100644 --- a/docs/rules/no-multi-comp.md +++ b/docs/rules/no-multi-comp.md @@ -6,7 +6,7 @@ Declaring only one component per file improves readability and reusability of co The following patterns are considered warnings: -```js +```jsx var Hello = React.createClass({ render: function() { return
Hello {this.props.name}
; @@ -22,7 +22,7 @@ var HelloJohn = React.createClass({ The following patterns are not considered warnings: -```js +```jsx var Hello = require('./components/Hello'); var HelloJohn = React.createClass({ @@ -46,7 +46,7 @@ When `true` the rule will ignore stateless components and will allow you to have The following patterns are considered okay and do not cause warnings: -```js +```jsx function Hello(props) { return
Hello {props.name}
; } @@ -55,7 +55,7 @@ function HelloAgain(props) { } ``` -```js +```jsx function Hello(props) { return
Hello {props.name}
; } diff --git a/docs/rules/no-render-return-value.md b/docs/rules/no-render-return-value.md index 0337962368..a0575c259c 100644 --- a/docs/rules/no-render-return-value.md +++ b/docs/rules/no-render-return-value.md @@ -10,14 +10,14 @@ This rule will warn you if you try to use the `ReactDOM.render()` return value. The following pattern is considered a warning: -```js +```jsx const inst = ReactDOM.render(, document.body); doSomethingWithInst(inst); ``` The following patterns are not considered warnings: -```js +```jsx ReactDOM.render(, document.body); ReactDOM.render(, document.body, doSomethingWithInst); diff --git a/docs/rules/no-set-state.md b/docs/rules/no-set-state.md index 7693ce5bc2..c30283a905 100644 --- a/docs/rules/no-set-state.md +++ b/docs/rules/no-set-state.md @@ -6,7 +6,7 @@ When using an architecture that separates your application state from your UI co The following patterns are considered warnings: -```js +```jsx var Hello = React.createClass({ getInitialState: function() { return { @@ -26,7 +26,7 @@ var Hello = React.createClass({ The following patterns are not considered warnings: -```js +```jsx var Hello = React.createClass({ render: function() { return
Hello {this.props.name}
; diff --git a/docs/rules/no-string-refs.md b/docs/rules/no-string-refs.md index ebcd9c9189..1965bc7d3d 100644 --- a/docs/rules/no-string-refs.md +++ b/docs/rules/no-string-refs.md @@ -6,7 +6,7 @@ Currently, two ways are supported by React to refer to components. The first one Invalid: -```js +```jsx var Hello = React.createClass({ render: function() { return
Hello, world.
; @@ -14,7 +14,7 @@ var Hello = React.createClass({ }); ``` -```js +```jsx var Hello = React.createClass({ componentDidMount: function() { var component = this.refs.hello; @@ -28,7 +28,7 @@ var Hello = React.createClass({ Valid: -```js +```jsx var Hello = React.createClass({ componentDidMount: function() { var component = this.hello; diff --git a/docs/rules/no-unknown-property.md b/docs/rules/no-unknown-property.md index c4dcba6336..772898d78d 100644 --- a/docs/rules/no-unknown-property.md +++ b/docs/rules/no-unknown-property.md @@ -8,7 +8,7 @@ In JSX all DOM properties and attributes should be camelCased to be consistent w The following patterns are considered warnings: -```js +```jsx var React = require('react'); var Hello =
Hello World
; @@ -16,7 +16,7 @@ var Hello =
Hello World
; The following patterns are not considered warnings: -```js +```jsx var React = require('react'); var Hello =
Hello World
; diff --git a/docs/rules/prefer-es6-class.md b/docs/rules/prefer-es6-class.md index 1c742d02aa..371272feeb 100644 --- a/docs/rules/prefer-es6-class.md +++ b/docs/rules/prefer-es6-class.md @@ -16,7 +16,7 @@ Will enforce ES6 classes for React Components. This is the default mode. The following patterns are considered warnings: -```js +```jsx var Hello = React.createClass({ render: function() { return
Hello {this.props.name}
; @@ -26,7 +26,7 @@ var Hello = React.createClass({ The following patterns are not considered warnings: -```js +```jsx class Hello extends React.Component { render() { return
Hello {this.props.name}
; @@ -40,7 +40,7 @@ Will enforce ES5 classes for React Components The following patterns are considered warnings: -```js +```jsx class Hello extends React.Component { render() { return
Hello {this.props.name}
; @@ -50,7 +50,7 @@ class Hello extends React.Component { The following patterns are not considered warnings: -```js +```jsx var Hello = React.createClass({ render: function() { return
Hello {this.props.name}
; diff --git a/docs/rules/react-in-jsx-scope.md b/docs/rules/react-in-jsx-scope.md index f5f2fec9b1..551661bf9c 100644 --- a/docs/rules/react-in-jsx-scope.md +++ b/docs/rules/react-in-jsx-scope.md @@ -9,11 +9,11 @@ If you are using the @jsx pragma this rule will check the designated variable an The following patterns are considered warnings: -```js +```jsx var Hello =
Hello {this.props.name}
; ``` -```js +```jsx /** @jsx Foo.bar */ var React = require('react'); @@ -22,19 +22,19 @@ var Hello =
Hello {this.props.name}
; The following patterns are not considered warnings: -```js +```jsx import React from 'react'; var Hello =
Hello {this.props.name}
; ``` -```js +```jsx var React = require('react'); var Hello =
Hello {this.props.name}
; ``` -```js +```jsx /** @jsx Foo.bar */ var Foo = require('foo'); diff --git a/docs/rules/require-default-props.md b/docs/rules/require-default-props.md index 65e9256feb..91c5b276d1 100644 --- a/docs/rules/require-default-props.md +++ b/docs/rules/require-default-props.md @@ -8,7 +8,8 @@ The same also holds true for stateless functional components: default function p To illustrate, consider the following example: With `defaultProps`: -```js + +```jsx const HelloWorld = ({ name }) => (

Hello, {name.first} {name.last}!

); @@ -30,7 +31,8 @@ ReactDOM.render(, document.getElementById('app')); ``` Without `defaultProps`: -```js + +```jsx const HelloWorld = ({ name = 'John Doe' }) => (

Hello, {name.first} {name.last}!

); @@ -51,7 +53,7 @@ ReactDOM.render(, document.getElementById('app')); The following patterns are considered warnings: -```js +```jsx function MyStatelessComponent({ foo, bar }) { return
{foo}{bar}
; } @@ -62,7 +64,7 @@ MyStatelessComponent.propTypes = { }; ``` -```js +```jsx var Greeting = React.createClass({ render: function() { return
Hello {this.props.foo} {this.props.bar}
; @@ -81,7 +83,7 @@ var Greeting = React.createClass({ }); ``` -```js +```jsx class Greeting extends React.Component { render() { return ( @@ -100,7 +102,7 @@ Greeting.defaultProps = { }; ``` -```js +```jsx class Greeting extends React.Component { render() { return ( @@ -119,7 +121,7 @@ class Greeting extends React.Component { } ``` -```js +```jsx type Props = { foo: string, bar?: string @@ -132,7 +134,7 @@ function MyStatelessComponent(props: Props) { The following patterns are not considered warnings: -```js +```jsx function MyStatelessComponent({ foo, bar }) { return
{foo}{bar}
; } @@ -143,7 +145,7 @@ MyStatelessComponent.propTypes = { }; ``` -```js +```jsx function MyStatelessComponent({ foo, bar }) { return
{foo}{bar}
; } @@ -158,7 +160,7 @@ MyStatelessComponent.defaultProps = { }; ``` -```js +```jsx type Props = { foo: string, bar?: string diff --git a/docs/rules/require-render-return.md b/docs/rules/require-render-return.md index 5e25661b8c..cf744318b4 100644 --- a/docs/rules/require-render-return.md +++ b/docs/rules/require-render-return.md @@ -6,7 +6,7 @@ When writing the `render` method in a component it is easy to forget to return t The following patterns are considered warnings: -```js +```jsx var Hello = React.createClass({ render() {
Hello
; @@ -22,7 +22,7 @@ class Hello extends React.Component { The following patterns are not considered warnings: -```js +```jsx var Hello = React.createClass({ render() { return
Hello
; diff --git a/docs/rules/sort-comp.md b/docs/rules/sort-comp.md index e592df4d8f..fc171e7e8d 100644 --- a/docs/rules/sort-comp.md +++ b/docs/rules/sort-comp.md @@ -15,7 +15,7 @@ The default configuration ensures that the following order must be followed: The following patterns are considered warnings: -```js +```jsx var Hello = React.createClass({ render: function() { return
Hello
; @@ -26,7 +26,7 @@ var Hello = React.createClass({ The following patterns are not considered warnings: -```js +```jsx var Hello = React.createClass({ displayName : 'Hello', render: function() { @@ -109,7 +109,7 @@ For example, if you want to place your event handlers (`onClick`, `onSubmit`, et With the above configuration, the following patterns are considered warnings: -```js +```jsx var Hello = React.createClass({ render: function() { return
Hello
; @@ -120,7 +120,7 @@ var Hello = React.createClass({ With the above configuration, the following patterns are not considered warnings: -```js +```jsx var Hello = React.createClass({ onClick: function() {}, render: function() { @@ -150,7 +150,7 @@ If you want to split your `render` method into smaller ones and keep them just b With the above configuration, the following patterns are considered warnings: -```js +```jsx var Hello = React.createClass({ renderButton: function() {}, onClick: function() {}, @@ -162,7 +162,7 @@ var Hello = React.createClass({ With the above configuration, the following patterns are not considered warnings: -```js +```jsx var Hello = React.createClass({ onClick: function() {}, renderButton: function() {}, @@ -188,7 +188,7 @@ If you want to flow annotations to be at the top: With the above configuration, the following patterns are considered warnings: -```js +```jsx class Hello extends React.Component { onClick() { this._someElem = true; } props: Props; @@ -201,7 +201,7 @@ class Hello extends React.Component { With the above configuration, the following patterns are not considered warnings: -```js +```jsx type Props = {}; class Hello extends React.Component { props: Props; diff --git a/docs/rules/sort-prop-types.md b/docs/rules/sort-prop-types.md index c665328e52..e569af8847 100644 --- a/docs/rules/sort-prop-types.md +++ b/docs/rules/sort-prop-types.md @@ -8,7 +8,7 @@ This rule checks all components and verifies that all propTypes declarations are The following patterns are considered warnings: -```js +```jsx var Component = React.createClass({ propTypes: { z: React.PropTypes.number, @@ -41,7 +41,7 @@ class Component extends React.Component { The following patterns are considered okay and do not cause warnings: -```js +```jsx var Component = React.createClass({ propTypes: { a: React.PropTypes.number,