Skip to content

Commit 7f3934a

Browse files
committed
Fix crash in boolean-prop-naming when encountering a required shape prop type. Fixes #1791.
1 parent 431977b commit 7f3934a

File tree

3 files changed

+19
-1
lines changed

3 files changed

+19
-1
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@ All notable changes to this project will be documented in this file.
33
This project adheres to [Semantic Versioning](http://semver.org/).
44
This change log adheres to standards from [Keep a CHANGELOG](http://keepachangelog.com).
55

6+
## [Unreleased]
7+
### Fixed
8+
* Fix crash in [`boolean-prop-naming`] when encountering a required shape prop type ([#1791][] @pcorpet)
9+
610
## [7.8.1] - 2018-05-12
711
### Fixed
812
* Fix crash in [`no-deprecated`][] when encountering a class constructor ([#1785][] @taddei)

lib/rules/boolean-prop-naming.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,10 @@ module.exports = {
7676
if (node.value.property) {
7777
const name = node.value.property.name;
7878
if (name === 'isRequired') {
79-
return node.value.object.property.name;
79+
if (node.value.object && node.value.object.property) {
80+
return node.value.object.property.name;
81+
}
82+
return null;
8083
}
8184
return name;
8285
}

tests/lib/rules/boolean-prop-naming.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,17 @@ ruleTester.run('boolean-prop-naming', rule, {
348348
hasValue: PropTypes.bool.isRequired
349349
}
350350
`
351+
}, {
352+
// Ensure the rule does not throw when a shape prop isRequired.
353+
code: `
354+
var Hello = createReactClass({
355+
propTypes: {something: PropTypes.shape({}).isRequired},
356+
render: function() { return <div />; }
357+
});
358+
`,
359+
options: [{
360+
rule: '^is[A-Z]([A-Za-z0-9]?)+'
361+
}]
351362
}],
352363

353364
invalid: [{

0 commit comments

Comments
 (0)