Skip to content

Commit

Permalink
Merge pull request #2256 from mateuszsokola/master
Browse files Browse the repository at this point in the history
[fix] `jsx-props-no-multi-spaces`: support generic components (ts)
  • Loading branch information
ljharb authored May 2, 2019
2 parents 8bd3837 + b5fc9bf commit e73a692
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
27 changes: 26 additions & 1 deletion lib/rules/jsx-props-no-multi-spaces.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,37 @@ module.exports = {
}
}

function containsGenericType(node) {
const containsTypeParams = typeof node.typeParameters !== 'undefined';
return containsTypeParams && node.typeParameters.type === 'TSTypeParameterInstantiation';
}

function getGenericNode(node) {
const name = node.name;
if (containsGenericType(node)) {
const type = node.typeParameters;

return Object.assign(
{},
node,
{
range: [
name.range[0],
type.range[1]
]
}
);
}

return name;
}

return {
JSXOpeningElement: function (node) {
node.attributes.reduce((prev, prop) => {
checkSpacing(prev, prop);
return prop;
}, node.name);
}, getGenericNode(node));
}
};
}
Expand Down
5 changes: 5 additions & 0 deletions tests/lib/rules/jsx-props-no-multi-spaces.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
const rule = require('../../../lib/rules/jsx-props-no-multi-spaces');
const RuleTester = require('eslint').RuleTester;

const parsers = require('../../helpers/parsers');

const parserOptions = {
ecmaVersion: 2018,
sourceType: 'module',
Expand Down Expand Up @@ -58,6 +60,9 @@ ruleTester.run('jsx-props-no-multi-spaces', rule, {
' foo {...test}',
' bar />'
].join('\n')
}, {
code: '<App<T> foo bar />',
parser: parsers.TYPESCRIPT_ESLINT
}, {
code: '<Foo.Bar baz="quux" />'
}, {
Expand Down

0 comments on commit e73a692

Please sign in to comment.