Skip to content

Fix TypeError for undefined node in PropType.shape #1504

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 3, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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