Skip to content

Commit c23d395

Browse files
authored
Merge pull request #1504 from mrichmond/bugfix/no-typos-TypeError
Fix TypeError for undefined node in PropType.shape
2 parents a7bc91b + d9c36bf commit c23d395

File tree

2 files changed

+25
-2
lines changed

2 files changed

+25
-2
lines changed

lib/rules/no-typos.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ module.exports = {
7373
}
7474

7575
function checkValidPropObject (node) {
76-
if (node.type === 'ObjectExpression') {
76+
if (node && node.type === 'ObjectExpression') {
7777
node.properties.forEach(prop => checkValidProp(prop.value));
7878
}
7979
}

tests/lib/rules/no-typos.js

+24-1
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ ruleTester.run('no-typos', rule, {
174174
const contextTypes = "CONTEXTTYPES"
175175
const childContextTypes = "CHILDCONTEXTTYPES"
176176
const defautProps = "DEFAULTPROPS"
177-
177+
178178
class First extends React.Component {}
179179
First[propTypes] = {};
180180
First[contextTypes] = {};
@@ -338,6 +338,29 @@ ruleTester.run('no-typos', rule, {
338338
`,
339339
parser: 'babel-eslint',
340340
parserOptions: parserOptions
341+
}, {
342+
// ensure that an absent arg to PropTypes.shape does not crash
343+
code: `class Component extends React.Component {};
344+
Component.propTypes = {
345+
a: PropTypes.shape(),
346+
};
347+
Component.contextTypes = {
348+
a: PropTypes.shape(),
349+
};
350+
`,
351+
parserOptions: parserOptions
352+
}, {
353+
// ensure that an absent arg to PropTypes.shape does not crash
354+
code: `class Component extends React.Component {};
355+
Component.propTypes = {
356+
a: PropTypes.shape(),
357+
};
358+
Component.contextTypes = {
359+
a: PropTypes.shape(),
360+
};
361+
`,
362+
parser: 'babel-eslint',
363+
parserOptions: parserOptions
341364
}, {
342365
code: `
343366
const fn = (err, res) => {

0 commit comments

Comments
 (0)