Skip to content

Commit

Permalink
Update PropTypes usage to reflect changes in React 15.5.0
Browse files Browse the repository at this point in the history
  • Loading branch information
yannickcr committed Apr 23, 2017
1 parent f651b8f commit 6b5dbe0
Show file tree
Hide file tree
Showing 16 changed files with 479 additions and 479 deletions.
20 changes: 10 additions & 10 deletions docs/rules/forbid-prop-types.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ The following patterns are considered warnings:
```jsx
var Component = createReactClass({
propTypes: {
a: React.PropTypes.any,
r: React.PropTypes.array,
o: React.PropTypes.object
a: PropTypes.any,
r: PropTypes.array,
o: PropTypes.object
},
...
});
Expand All @@ -23,16 +23,16 @@ class Component extends React.Component {
...
}
Component.propTypes = {
a: React.PropTypes.any,
r: React.PropTypes.array,
o: React.PropTypes.object
a: PropTypes.any,
r: PropTypes.array,
o: PropTypes.object
};

class Component extends React.Component {
static propTypes = {
a: React.PropTypes.any,
r: React.PropTypes.array,
o: React.PropTypes.object
a: PropTypes.any,
r: PropTypes.array,
o: PropTypes.object
}
render() {
return <div />;
Expand All @@ -50,7 +50,7 @@ class Component extends React.Component {

### `forbid`

An array of strings, with the names of `React.PropTypes` keys that are forbidden. The default value for this option is `['any', 'array', 'object']`.
An array of strings, with the names of `PropTypes` keys that are forbidden. The default value for this option is `['any', 'array', 'object']`.

## When not to use

Expand Down
2 changes: 1 addition & 1 deletion docs/rules/no-deprecated.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ React.renderToStaticMarkup(<MyComponent />);
React.createClass({ /* Class object */ });

const propTypes = {
foo: React.PropTypes.bar,
foo: PropTypes.bar,
};
```

Expand Down
12 changes: 6 additions & 6 deletions docs/rules/no-unused-prop-types.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ The following patterns are considered warnings:
```jsx
var Hello = createReactClass({
propTypes: {
name: React.PropTypes.string
name: PropTypes.string
},
render: function() {
return <div>Hello Bob</div>;
Expand All @@ -18,9 +18,9 @@ var Hello = createReactClass({

var Hello = createReactClass({
propTypes: {
firstname: React.PropTypes.string.isRequired,
middlename: React.PropTypes.string.isRequired, // middlename is never used below
lastname: React.PropTypes.string.isRequired
firstname: PropTypes.string.isRequired,
middlename: PropTypes.string.isRequired, // middlename is never used below
lastname: PropTypes.string.isRequired
},
render: function() {
return <div>Hello {this.props.firstname} {this.props.lastname}</div>;
Expand All @@ -33,7 +33,7 @@ The following patterns are not considered warnings:
```jsx
var Hello = createReactClass({
propTypes: {
name: React.PropTypes.string
name: PropTypes.string
},
render: function() {
return <div>Hello {this.props.name}</div>;
Expand All @@ -53,7 +53,7 @@ This rule can take one argument to ignore some specific props during validation.

* `enabled`: for enabling the rule. 0=off, 1=warn, 2=error. Defaults to 0.
* `customValidators`: optional array of validators used for propTypes validation.
* `skipShapeProps`: In some cases it is impossible to accurately detect whether or not a `React.PropTypes.shape`'s values are being used. Setting this option to `true` will skip validation of `PropTypes.shape` (`true` by default).
* `skipShapeProps`: In some cases it is impossible to accurately detect whether or not a `PropTypes.shape`'s values are being used. Setting this option to `true` will skip validation of `PropTypes.shape` (`true` by default).

## Caveats

Expand Down
14 changes: 7 additions & 7 deletions docs/rules/prop-types.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ var Hello = createReactClass({

var Hello = createReactClass({
propTypes: {
firstname: React.PropTypes.string.isRequired
firstname: PropTypes.string.isRequired
},
render: function() {
return <div>Hello {this.props.firstname} {this.props.lastname}</div>; // lastname type is not defined in propTypes
Expand All @@ -34,7 +34,7 @@ Examples of correct usage without warnings:
```jsx
var Hello = createReactClass({
propTypes: {
name: React.PropTypes.string.isRequired,
name: PropTypes.string.isRequired,
},
render: function() {
return <div>Hello {this.props.name}</div>;
Expand All @@ -48,13 +48,13 @@ class HelloEs6 extends React.Component {
}
}
HelloEs6.propTypes = {
name: React.PropTypes.string.isRequired,
name: PropTypes.string.isRequired,
};

// ES6 + Public Class Fields (draft: https://tc39.github.io/proposal-class-public-fields/)
class HelloEs6WithPublicClassField extends React.Component {
static propTypes = {
name: React.PropTypes.string.isRequired,
name: PropTypes.string.isRequired,
}
render() {
return <div>Hello {this.props.name}</div>;
Expand All @@ -73,7 +73,7 @@ var Hello = createReactClass({

var Hello = createReactClass({
propTypes: {
name: React.PropTypes.string.isRequired
name: PropTypes.string.isRequired
},
render: function() {
return <div>Hello {this.props.name}</div>;
Expand All @@ -92,7 +92,7 @@ function Hello({ name }) {
return <div>Hello {name}</div>;
}
Hello.propTypes = {
name: React.PropTypes.string.isRequired,
name: PropTypes.string.isRequired,
};
```

Expand Down Expand Up @@ -123,7 +123,7 @@ As it aptly noticed in
> Most components don't need `this.props.children`, so that makes it extra important
to document `children` in the propTypes.

Generally, you should use `React.PropTypes.node` for `children`. It accepts
Generally, you should use `PropTypes.node` for `children`. It accepts
anything that can be rendered: numbers, strings, elements or an array containing
these types.

Expand Down
40 changes: 20 additions & 20 deletions docs/rules/require-default-props.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ const HelloWorld = ({ name }) => (
);

HelloWorld.propTypes = {
name: React.PropTypes.shape({
first: React.PropTypes.string,
last: React.PropTypes.string,
name: PropTypes.shape({
first: PropTypes.string,
last: PropTypes.string,
})
};

Expand All @@ -38,9 +38,9 @@ const HelloWorld = ({ name = 'John Doe' }) => (
);

HelloWorld.propTypes = {
name: React.PropTypes.shape({
first: React.PropTypes.string,
last: React.PropTypes.string,
name: PropTypes.shape({
first: PropTypes.string,
last: PropTypes.string,
})
};

Expand All @@ -59,8 +59,8 @@ function MyStatelessComponent({ foo, bar }) {
}

MyStatelessComponent.propTypes = {
foo: React.PropTypes.string.isRequired,
bar: React.PropTypes.string
foo: PropTypes.string.isRequired,
bar: PropTypes.string
};
```

Expand All @@ -71,8 +71,8 @@ var Greeting = createReactClass({
},

propTypes: {
foo: React.PropTypes.string,
bar: React.PropTypes.string
foo: PropTypes.string,
bar: PropTypes.string
},

getDefaultProps: function() {
Expand All @@ -93,8 +93,8 @@ class Greeting extends React.Component {
}

Greeting.propTypes = {
foo: React.PropTypes.string,
bar: React.PropTypes.string
foo: PropTypes.string,
bar: PropTypes.string
};

Greeting.defaultProps = {
Expand All @@ -111,8 +111,8 @@ class Greeting extends React.Component {
}

static propTypes = {
foo: React.PropTypes.string,
bar: React.PropTypes.string.isRequired
foo: PropTypes.string,
bar: PropTypes.string.isRequired
};

static defaultProps = {
Expand Down Expand Up @@ -140,8 +140,8 @@ function MyStatelessComponent({ foo, bar }) {
}

MyStatelessComponent.propTypes = {
foo: React.PropTypes.string.isRequired,
bar: React.PropTypes.string.isRequired
foo: PropTypes.string.isRequired,
bar: PropTypes.string.isRequired
};
```

Expand All @@ -151,8 +151,8 @@ function MyStatelessComponent({ foo, bar }) {
}

MyStatelessComponent.propTypes = {
foo: React.PropTypes.string.isRequired,
bar: React.PropTypes.string
foo: PropTypes.string.isRequired,
bar: PropTypes.string
};

MyStatelessComponent.defaultProps = {
Expand All @@ -179,8 +179,8 @@ MyStatelessComponent.defaultProps = {
function NotAComponent({ foo, bar }) {}

NotAComponent.propTypes = {
foo: React.PropTypes.string,
bar: React.PropTypes.string.isRequired
foo: PropTypes.string,
bar: PropTypes.string.isRequired
};
```

Expand Down
52 changes: 26 additions & 26 deletions docs/rules/sort-prop-types.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ The following patterns are considered warnings:
```jsx
var Component = createReactClass({
propTypes: {
z: React.PropTypes.number,
a: React.PropTypes.any,
b: React.PropTypes.string
z: PropTypes.number,
a: PropTypes.any,
b: PropTypes.string
},
...
});
Expand All @@ -22,16 +22,16 @@ class Component extends React.Component {
...
}
Component.propTypes = {
z: React.PropTypes.number,
a: React.PropTypes.any,
b: React.PropTypes.string
z: PropTypes.number,
a: PropTypes.any,
b: PropTypes.string
};

class Component extends React.Component {
static propTypes = {
z: React.PropTypes.any,
y: React.PropTypes.any,
a: React.PropTypes.any
z: PropTypes.any,
y: PropTypes.any,
a: PropTypes.any
}
render() {
return <div />;
Expand All @@ -44,9 +44,9 @@ The following patterns are considered okay and do not cause warnings:
```jsx
var Component = createReactClass({
propTypes: {
a: React.PropTypes.number,
b: React.PropTypes.any,
c: React.PropTypes.string
a: PropTypes.number,
b: PropTypes.any,
c: PropTypes.string
},
...
});
Expand All @@ -55,16 +55,16 @@ class Component extends React.Component {
...
}
Component.propTypes = {
a: React.PropTypes.string,
b: React.PropTypes.any,
c: React.PropTypes.string
a: PropTypes.string,
b: PropTypes.any,
c: PropTypes.string
};

class Component extends React.Component {
static propTypes = {
a: React.PropTypes.any,
b: React.PropTypes.any,
c: React.PropTypes.any
a: PropTypes.any,
b: PropTypes.any,
c: PropTypes.any
}
render() {
return <div />;
Expand Down Expand Up @@ -95,10 +95,10 @@ When `true`, propTypes for props beginning with "on" must be listed after all ot
```js
var Component = createReactClass({
propTypes: {
a: React.PropTypes.number,
z: React.PropTypes.string,
onBar: React.PropTypes.func,
onFoo: React.PropTypes.func,
a: PropTypes.number,
z: PropTypes.string,
onBar: PropTypes.func,
onFoo: PropTypes.func,
},
...
});
Expand All @@ -111,10 +111,10 @@ When `true`, prop types for required props must be listed before all other props
```js
var Component = createReactClass({
propTypes: {
barRequired: React.PropTypes.any.isRequired,
fooRequired: React.PropTypes.any.isRequired,
a: React.PropTypes.number,
z: React.PropTypes.string,
barRequired: PropTypes.any.isRequired,
fooRequired: PropTypes.any.isRequired,
a: PropTypes.number,
z: PropTypes.string,
},
...
});
Expand Down
4 changes: 2 additions & 2 deletions lib/rules/no-unused-prop-types.js
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ module.exports = {
/**
* Creates the representation of the React propTypes for the component.
* The representation is used to verify nested used properties.
* @param {ASTNode} value Node of the React.PropTypes for the desired property
* @param {ASTNode} value Node of the PropTypes for the desired property
* @param {String} parentName Name of the parent prop node.
* @return {Object|Boolean} The representation of the declaration, true means
* the property is declared without the need for further analysis.
Expand All @@ -318,7 +318,7 @@ module.exports = {
value = value.object;
}

// Verify React.PropTypes that are functions
// Verify PropTypes that are functions
if (
value &&
value.type === 'CallExpression' &&
Expand Down
4 changes: 2 additions & 2 deletions lib/rules/prop-types.js
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ module.exports = {
/**
* Creates the representation of the React propTypes for the component.
* The representation is used to verify nested used properties.
* @param {ASTNode} value Node of the React.PropTypes for the desired property
* @param {ASTNode} value Node of the PropTypes for the desired property
* @return {Object|Boolean} The representation of the declaration, true means
* the property is declared without the need for further analysis.
*/
Expand All @@ -362,7 +362,7 @@ module.exports = {
value = value.object;
}

// Verify React.PropTypes that are functions
// Verify PropTypes that are functions
if (
value &&
value.type === 'CallExpression' &&
Expand Down

0 comments on commit 6b5dbe0

Please sign in to comment.