Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[fix] jsx-props-no-multi-spaces: support generic components (ts) #2256

Merged
merged 1 commit into from May 2, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
27 changes: 26 additions & 1 deletion lib/rules/jsx-props-no-multi-spaces.js
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
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