From 7f3934acc419c4b6b330fbab31ccdf9b6d57274d Mon Sep 17 00:00:00 2001 From: Pascal Corpet Date: Sun, 13 May 2018 00:53:42 +0200 Subject: [PATCH] Fix crash in boolean-prop-naming when encountering a required shape prop type. Fixes #1791. --- CHANGELOG.md | 4 ++++ lib/rules/boolean-prop-naming.js | 5 ++++- tests/lib/rules/boolean-prop-naming.js | 11 +++++++++++ 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7424cc2df3..9f43d0048b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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) diff --git a/lib/rules/boolean-prop-naming.js b/lib/rules/boolean-prop-naming.js index ccfdf6f3bb..3d414a724c 100644 --- a/lib/rules/boolean-prop-naming.js +++ b/lib/rules/boolean-prop-naming.js @@ -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; } diff --git a/tests/lib/rules/boolean-prop-naming.js b/tests/lib/rules/boolean-prop-naming.js index f83c8dd999..e90fc39788 100644 --- a/tests/lib/rules/boolean-prop-naming.js +++ b/tests/lib/rules/boolean-prop-naming.js @@ -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
; } + }); + `, + options: [{ + rule: '^is[A-Z]([A-Za-z0-9]?)+' + }] }], invalid: [{