Skip to content

Commit

Permalink
Fix crash in boolean-prop-naming when encountering a required shape p…
Browse files Browse the repository at this point in the history
…rop type. Fixes #1791.
  • Loading branch information
pcorpet committed May 13, 2018
1 parent 431977b commit 7f3934a
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ All notable changes to this project will be documented in this file.
This project adheres to [Semantic Versioning](http://semver.org/).
This change log adheres to standards from [Keep a CHANGELOG](http://keepachangelog.com).

## [Unreleased]
### Fixed
* Fix crash in [`boolean-prop-naming`] when encountering a required shape prop type ([#1791][] @pcorpet)

## [7.8.1] - 2018-05-12
### Fixed
* Fix crash in [`no-deprecated`][] when encountering a class constructor ([#1785][] @taddei)
Expand Down
5 changes: 4 additions & 1 deletion lib/rules/boolean-prop-naming.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,10 @@ module.exports = {
if (node.value.property) {
const name = node.value.property.name;
if (name === 'isRequired') {
return node.value.object.property.name;
if (node.value.object && node.value.object.property) {
return node.value.object.property.name;
}
return null;
}
return name;
}
Expand Down
11 changes: 11 additions & 0 deletions tests/lib/rules/boolean-prop-naming.js
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,17 @@ ruleTester.run('boolean-prop-naming', rule, {
hasValue: PropTypes.bool.isRequired
}
`
}, {
// Ensure the rule does not throw when a shape prop isRequired.
code: `
var Hello = createReactClass({
propTypes: {something: PropTypes.shape({}).isRequired},
render: function() { return <div />; }
});
`,
options: [{
rule: '^is[A-Z]([A-Za-z0-9]?)+'
}]
}],

invalid: [{
Expand Down

0 comments on commit 7f3934a

Please sign in to comment.