Skip to content

Commit

Permalink
Merge pull request #1504 from mrichmond/bugfix/no-typos-TypeError
Browse files Browse the repository at this point in the history
Fix TypeError for undefined node in PropType.shape
  • Loading branch information
ljharb committed Jan 3, 2018
2 parents a7bc91b + d9c36bf commit c23d395
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/rules/no-typos.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ module.exports = {
}

function checkValidPropObject (node) {
if (node.type === 'ObjectExpression') {
if (node && node.type === 'ObjectExpression') {
node.properties.forEach(prop => checkValidProp(prop.value));
}
}
Expand Down
25 changes: 24 additions & 1 deletion tests/lib/rules/no-typos.js
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ ruleTester.run('no-typos', rule, {
const contextTypes = "CONTEXTTYPES"
const childContextTypes = "CHILDCONTEXTTYPES"
const defautProps = "DEFAULTPROPS"
class First extends React.Component {}
First[propTypes] = {};
First[contextTypes] = {};
Expand Down Expand Up @@ -338,6 +338,29 @@ ruleTester.run('no-typos', rule, {
`,
parser: 'babel-eslint',
parserOptions: parserOptions
}, {
// ensure that an absent arg to PropTypes.shape does not crash
code: `class Component extends React.Component {};
Component.propTypes = {
a: PropTypes.shape(),
};
Component.contextTypes = {
a: PropTypes.shape(),
};
`,
parserOptions: parserOptions
}, {
// ensure that an absent arg to PropTypes.shape does not crash
code: `class Component extends React.Component {};
Component.propTypes = {
a: PropTypes.shape(),
};
Component.contextTypes = {
a: PropTypes.shape(),
};
`,
parser: 'babel-eslint',
parserOptions: parserOptions
}, {
code: `
const fn = (err, res) => {
Expand Down

0 comments on commit c23d395

Please sign in to comment.