Skip to content

Commit 3d5d47e

Browse files
committed
[Fix] jsx-props-no-multi-spaces: avoid a crash on long member chains in tag names in typescript-eslint parser
1 parent 8746b41 commit 3d5d47e

File tree

3 files changed

+10
-4
lines changed

3 files changed

+10
-4
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ This change log adheres to standards from [Keep a CHANGELOG](http://keepachangel
1212
### Fixed
1313
* [`propTypes`]: add `VoidFunctionComponent` to react generic list ([#3092][] @vedadeepta)
1414
* [`jsx-fragments`], [`jsx-no-useless-fragment`]: avoid a crash on fragment syntax in `typescript-eslint` parser (@ljharb)
15+
* [`jsx-props-no-multi-spaces`]: avoid a crash on long member chains in tag names in `typescript-eslint` parser (@ljharb)
1516

1617
[#3092]: https://github.com/yannickcr/eslint-plugin-react/pull/3092
1718
[#2166]: https://github.com/yannickcr/eslint-plugin-react/pull/2166

lib/rules/jsx-props-no-multi-spaces.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,9 @@ module.exports = {
4444
case 'JSXMemberExpression':
4545
return `${getPropName(propNode.object)}.${propNode.property.name}`;
4646
default:
47-
return propNode.name.name;
47+
return propNode.name
48+
? propNode.name.name
49+
: `${context.getSourceCode().getText(propNode.object)}.${propNode.property.name}`; // needed for typescript-eslint parser
4850
}
4951
}
5052

tests/lib/rules/jsx-props-no-multi-spaces.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -242,15 +242,18 @@ ruleTester.run('jsx-props-no-multi-spaces', rule, {
242242
],
243243
},
244244
{
245-
code: '<Foobar.Foo.Bar.Baz.Qux.Quux.Quuz.Corge.Grault.Garply.Waldo.Fred.Plugh xyzzy="thud" />',
246-
output: '<Foobar.Foo.Bar.Baz.Qux.Quux.Quuz.Corge.Grault.Garply.Waldo.Fred.Plugh xyzzy="thud" />',
245+
code: `
246+
<Foobar.Foo.Bar.Baz.Qux.Quux.Quuz.Corge.Grault.Garply.Waldo.Fred.Plugh xyzzy="thud" />
247+
`,
248+
output: `
249+
<Foobar.Foo.Bar.Baz.Qux.Quux.Quuz.Corge.Grault.Garply.Waldo.Fred.Plugh xyzzy="thud" />
250+
`,
247251
errors: [
248252
{
249253
messageId: 'onlyOneSpace',
250254
data: { prop1: 'Foobar.Foo.Bar.Baz.Qux.Quux.Quuz.Corge.Grault.Garply.Waldo.Fred.Plugh', prop2: 'xyzzy' },
251255
},
252256
],
253-
features: ['no-ts-old'], // TODO: FIXME: remove `no-ts-old` and fix
254257
},
255258
{
256259
code: `

0 commit comments

Comments
 (0)