Skip to content

Commit

Permalink
Fix isReactComponent in react-lifecycle-order rule for generic compon…
Browse files Browse the repository at this point in the history
…ents
  • Loading branch information
yarkeev authored and jwbay committed Mar 15, 2018
1 parent db7c619 commit 66c63ca
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
2 changes: 1 addition & 1 deletion rules/reactLifecycleOrderRule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ class ReactLifecyleOrderRule extends Lint.RuleWalker {
'React.PureComponent',
'Component',
'PureComponent',
].indexOf(ancestor.getText(this.getSourceFile())) > -1
].indexOf(ancestor.getText(this.getSourceFile()).replace(/<.+?>$/, '')) > -1
)
}
}
23 changes: 23 additions & 0 deletions test/reactLifecycleOrderRule/reactLifecycleOrderRule.tsx.lint
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,18 @@ class PassesToo extends React.Component {
baz() {}
}

class PassesGeneric extends React.Component<any, any> {
property: any;
componentWillMount() {}
componentWillReceiveProps() {}
componentDidMount() {}
shouldComponentUpdate() {}
componentWillUpdate() {}
componentDidUpdate() {}
render() {}
componentWillUnmount() {}
}

class PassesNotComponent extends NotComponent {
constructor() {}
foo() {}
Expand Down Expand Up @@ -88,3 +100,14 @@ class FailsPureComponent extends PureComponent {
~~~~~~~~~~~~~~~~~~ [expected React lifecyle method 'render']
baz() {}
}

class FailsReactComponentGeneric extends React.Component<any, any> {
constructor() {}
foo() {}
render() {}
~~~~~~ [expected React lifecyle method 'componentWillMount']
bar() {}
componentWillMount() {}
~~~~~~~~~~~~~~~~~~ [expected React lifecyle method 'render']
baz() {}
}

0 comments on commit 66c63ca

Please sign in to comment.