Skip to content

Commit 4a6827d

Browse files
committed
[Fix] jsx-no-constructed-context-values: avoid a crash with boolean shorthand
Fixes #2895
1 parent 1b5e450 commit 4a6827d

File tree

3 files changed

+21
-1
lines changed

3 files changed

+21
-1
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ This change log adheres to standards from [Keep a CHANGELOG](http://keepachangel
77

88
### Fixed
99
* [`jsx-no-constructed-context-values`]: avoid a crash with `as X` TS code ([#2894][] @ljharb)
10+
* [`jsx-no-constructed-context-values`]: avoid a crash with boolean shorthand ([#2895][] @ljharb)
1011

12+
[#2895]: https://github.com/yannickcr/eslint-plugin-react/issues/2895
1113
[#2894]: https://github.com/yannickcr/eslint-plugin-react/issues/2894
1214

1315
## [7.22.0] - 2020.12.29

lib/rules/jsx-no-constructed-context-values.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,10 @@ module.exports = {
167167
}
168168

169169
const valueNode = jsxValueAttribute.value;
170+
if (!valueNode) {
171+
// attribute is a boolean shorthand
172+
return;
173+
}
170174
if (valueNode.type !== 'JSXExpressionContainer') {
171175
// value could be a literal
172176
return;

tests/lib/rules/jsx-no-constructed-context-values.js

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,21 @@ ruleTester.run('react-no-constructed-context-values', rule, {
141141
`,
142142
parser: parsers['@TYPESCRIPT_ESLINT']
143143
}
144-
)
144+
),
145+
{
146+
code: `
147+
import React from 'react';
148+
import BooleanContext from './BooleanContext';
149+
150+
function ContextProvider(props) {
151+
return (
152+
<BooleanContext.Provider value>
153+
{props.children}
154+
</BooleanContext.Provider>
155+
)
156+
}
157+
`
158+
}
145159
),
146160
invalid: [
147161
{

0 commit comments

Comments
 (0)