Skip to content

Commit 1a28f3f

Browse files
authored
Merge pull request jsx-eslint#1890 from alexzherdev/1881-no-multi-spaces-undefined
Handle member expressions in jsx-props-no-multi-spaces
2 parents a0100f3 + 2aa0955 commit 1a28f3f

File tree

2 files changed

+25
-5
lines changed

2 files changed

+25
-5
lines changed

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

+9-5
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,16 @@ module.exports = {
2727
const sourceCode = context.getSourceCode();
2828

2929
function getPropName(propNode) {
30-
if (propNode.type === 'JSXSpreadAttribute') {
31-
return sourceCode.getText(propNode.argument);
32-
} else if (propNode.type === 'JSXIdentifier') {
33-
return propNode.name;
30+
switch (propNode.type) {
31+
case 'JSXSpreadAttribute':
32+
return sourceCode.getText(propNode.argument);
33+
case 'JSXIdentifier':
34+
return propNode.name;
35+
case 'JSXMemberExpression':
36+
return `${getPropName(propNode.object)}.${propNode.property.name}`;
37+
default:
38+
return propNode.name.name;
3439
}
35-
return propNode.name.name;
3640
}
3741

3842
function checkSpacing(prev, node) {

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

+16
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,10 @@ ruleTester.run('jsx-props-no-multi-spaces', rule, {
5858
' foo {...test}',
5959
' bar />'
6060
].join('\n')
61+
}, {
62+
code: '<Foo.Bar baz="quux" />'
63+
}, {
64+
code: '<Foobar.Foo.Bar.Baz.Qux.Quux.Quuz.Corge.Grault.Garply.Waldo.Fred.Plugh xyzzy="thud" />'
6165
}],
6266

6367
invalid: [{
@@ -106,5 +110,17 @@ ruleTester.run('jsx-props-no-multi-spaces', rule, {
106110
{message: 'Expected only one space between "foo" and "test"'},
107111
{message: 'Expected only one space between "test" and "bar"'}
108112
]
113+
}, {
114+
code: '<Foo.Bar baz="quux" />',
115+
output: '<Foo.Bar baz="quux" />',
116+
errors: [
117+
{message: 'Expected only one space between "Foo.Bar" and "baz"'}
118+
]
119+
}, {
120+
code: '<Foobar.Foo.Bar.Baz.Qux.Quux.Quuz.Corge.Grault.Garply.Waldo.Fred.Plugh xyzzy="thud" />',
121+
output: '<Foobar.Foo.Bar.Baz.Qux.Quux.Quuz.Corge.Grault.Garply.Waldo.Fred.Plugh xyzzy="thud" />',
122+
errors: [
123+
{message: 'Expected only one space between "Foobar.Foo.Bar.Baz.Qux.Quux.Quuz.Corge.Grault.Garply.Waldo.Fred.Plugh" and "xyzzy"'}
124+
]
109125
}]
110126
});

0 commit comments

Comments
 (0)