Skip to content

Commit 3aac310

Browse files
committed
Add support for React 16.3 lifecycle methods to no-typos
1 parent 5f3f04f commit 3aac310

File tree

3 files changed

+84
-0
lines changed

3 files changed

+84
-0
lines changed

docs/rules/no-typos.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,18 @@ no casing typos:
1717

1818
and the following react lifecycle methods:
1919

20+
* getDerivedStateFromProps
2021
* componentWillMount
22+
* UNSAFE_componentWillMount
2123
* componentDidMount
2224
* componentWillReceiveProps
25+
* UNSAFE_componentWillReceiveProps
2326
* shouldComponentUpdate
2427
* componentWillUpdate
28+
* UNSAFE_componentWillUpdate
29+
* getSnapshotBeforeUpdate
2530
* componentDidUpdate
31+
* componentDidCatch
2632
* componentWillUnmount
2733
* render
2834

lib/rules/no-typos.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,18 @@ const docsUrl = require('../util/docsUrl');
1212

1313
const STATIC_CLASS_PROPERTIES = ['propTypes', 'contextTypes', 'childContextTypes', 'defaultProps'];
1414
const LIFECYCLE_METHODS = [
15+
'getDerivedStateFromProps',
1516
'componentWillMount',
17+
'UNSAFE_componentWillMount',
1618
'componentDidMount',
1719
'componentWillReceiveProps',
20+
'UNSAFE_componentWillReceiveProps',
1821
'shouldComponentUpdate',
1922
'componentWillUpdate',
23+
'UNSAFE_componentWillUpdate',
24+
'getSnapshotBeforeUpdate',
2025
'componentDidUpdate',
26+
'componentDidCatch',
2127
'componentWillUnmount',
2228
'render'
2329
];

tests/lib/rules/no-typos.js

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -732,12 +732,18 @@ ruleTester.run('no-typos', rule, {
732732
}, {
733733
code: `
734734
class Hello extends React.Component {
735+
static GetDerivedStateFromProps() { }
735736
ComponentWillMount() { }
737+
UNSAFE_ComponentWillMount() { }
736738
ComponentDidMount() { }
737739
ComponentWillReceiveProps() { }
740+
UNSAFE_ComponentWillReceiveProps() { }
738741
ShouldComponentUpdate() { }
739742
ComponentWillUpdate() { }
743+
UNSAFE_ComponentWillUpdate() { }
744+
GetSnapshotBeforeUpdate() { }
740745
ComponentDidUpdate() { }
746+
ComponentDidCatch() { }
741747
ComponentWillUnmount() { }
742748
render() {
743749
return <div>Hello {this.props.name}</div>;
@@ -766,16 +772,40 @@ ruleTester.run('no-typos', rule, {
766772
}, {
767773
message: ERROR_MESSAGE_LIFECYCLE_METHOD,
768774
type: 'MethodDefinition'
775+
}, {
776+
message: ERROR_MESSAGE_LIFECYCLE_METHOD,
777+
type: 'MethodDefinition'
778+
}, {
779+
message: ERROR_MESSAGE_LIFECYCLE_METHOD,
780+
type: 'MethodDefinition'
781+
}, {
782+
message: ERROR_MESSAGE_LIFECYCLE_METHOD,
783+
type: 'MethodDefinition'
784+
}, {
785+
message: ERROR_MESSAGE_LIFECYCLE_METHOD,
786+
type: 'MethodDefinition'
787+
}, {
788+
message: ERROR_MESSAGE_LIFECYCLE_METHOD,
789+
type: 'MethodDefinition'
790+
}, {
791+
message: ERROR_MESSAGE_LIFECYCLE_METHOD,
792+
type: 'MethodDefinition'
769793
}]
770794
}, {
771795
code: `
772796
class Hello extends React.Component {
797+
static Getderivedstatefromprops() { }
773798
Componentwillmount() { }
799+
UNSAFE_Componentwillmount() { }
774800
Componentdidmount() { }
775801
Componentwillreceiveprops() { }
802+
UNSAFE_Componentwillreceiveprops() { }
776803
Shouldcomponentupdate() { }
777804
Componentwillupdate() { }
805+
UNSAFE_Componentwillupdate() { }
806+
Getsnapshotbeforeupdate() { }
778807
Componentdidupdate() { }
808+
Componentdidcatch() { }
779809
Componentwillunmount() { }
780810
Render() {
781811
return <div>Hello {this.props.name}</div>;
@@ -807,16 +837,40 @@ ruleTester.run('no-typos', rule, {
807837
}, {
808838
message: ERROR_MESSAGE_LIFECYCLE_METHOD,
809839
type: 'MethodDefinition'
840+
}, {
841+
message: ERROR_MESSAGE_LIFECYCLE_METHOD,
842+
type: 'MethodDefinition'
843+
}, {
844+
message: ERROR_MESSAGE_LIFECYCLE_METHOD,
845+
type: 'MethodDefinition'
846+
}, {
847+
message: ERROR_MESSAGE_LIFECYCLE_METHOD,
848+
type: 'MethodDefinition'
849+
}, {
850+
message: ERROR_MESSAGE_LIFECYCLE_METHOD,
851+
type: 'MethodDefinition'
852+
}, {
853+
message: ERROR_MESSAGE_LIFECYCLE_METHOD,
854+
type: 'MethodDefinition'
855+
}, {
856+
message: ERROR_MESSAGE_LIFECYCLE_METHOD,
857+
type: 'MethodDefinition'
810858
}]
811859
}, {
812860
code: `
813861
class Hello extends React.Component {
862+
static getderivedstatefromprops() { }
814863
componentwillmount() { }
864+
unsafe_componentwillmount() { }
815865
componentdidmount() { }
816866
componentwillreceiveprops() { }
867+
unsafe_componentwillreceiveprops() { }
817868
shouldcomponentupdate() { }
818869
componentwillupdate() { }
870+
unsafe_componentwillupdate() { }
871+
getsnapshotbeforeupdate() { }
819872
componentdidupdate() { }
873+
componentdidcatch() { }
820874
componentwillunmount() { }
821875
render() {
822876
return <div>Hello {this.props.name}</div>;
@@ -845,6 +899,24 @@ ruleTester.run('no-typos', rule, {
845899
}, {
846900
message: ERROR_MESSAGE_LIFECYCLE_METHOD,
847901
type: 'MethodDefinition'
902+
}, {
903+
message: ERROR_MESSAGE_LIFECYCLE_METHOD,
904+
type: 'MethodDefinition'
905+
}, {
906+
message: ERROR_MESSAGE_LIFECYCLE_METHOD,
907+
type: 'MethodDefinition'
908+
}, {
909+
message: ERROR_MESSAGE_LIFECYCLE_METHOD,
910+
type: 'MethodDefinition'
911+
}, {
912+
message: ERROR_MESSAGE_LIFECYCLE_METHOD,
913+
type: 'MethodDefinition'
914+
}, {
915+
message: ERROR_MESSAGE_LIFECYCLE_METHOD,
916+
type: 'MethodDefinition'
917+
}, {
918+
message: ERROR_MESSAGE_LIFECYCLE_METHOD,
919+
type: 'MethodDefinition'
848920
}]
849921
}, {
850922
code: `

0 commit comments

Comments
 (0)