From 515202e4042066528bf1e0396ee8027d22ed0023 Mon Sep 17 00:00:00 2001 From: Ross <52366381+ROSSROSALES@users.noreply.github.com> Date: Tue, 30 Aug 2022 19:50:51 +0000 Subject: [PATCH] [Fix] jsx-sort-props issue #3371 --- lib/rules/jsx-sort-props.js | 4 +++- tests/lib/rules/jsx-sort-props.js | 26 ++++++++++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/lib/rules/jsx-sort-props.js b/lib/rules/jsx-sort-props.js index dea9085035..4e971633b7 100644 --- a/lib/rules/jsx-sort-props.js +++ b/lib/rules/jsx-sort-props.js @@ -181,9 +181,11 @@ function getGroupsOfSortableAttributes(attributes, context) { addtoSortableAttributeGroups(attribute); i += 1; } else if (attributeline === commentline) { - if (firstComment.type === 'Block') { + if (firstComment.type === 'Block' && nextAttribute) { attributeMap.set(attribute, [nextAttribute.range[1], true]); i += 1; + } else if (firstComment.type === 'Block') { + attributeMap.set(attribute, [firstComment.range[1], true]); } else { attributeMap.set(attribute, [firstComment.range[1], false]); } diff --git a/tests/lib/rules/jsx-sort-props.js b/tests/lib/rules/jsx-sort-props.js index 3c74dba74c..3d5c439430 100644 --- a/tests/lib/rules/jsx-sort-props.js +++ b/tests/lib/rules/jsx-sort-props.js @@ -1047,6 +1047,32 @@ ruleTester.run('jsx-sort-props', rule, { line: 2, }, ], + } : [], + semver.satisfies(eslintPkg.version, '> 3') ? { + code: ` + + `, + output: ` + + `, + errors: [ + { + messageId: 'sortPropsByAlpha', + line: 2, + }, + { + messageId: 'sortPropsByAlpha', + line: 2, + }, + { + messageId: 'sortPropsByAlpha', + line: 2, + }, + { + messageId: 'sortPropsByAlpha', + line: 2, + }, + ], } : [] )), });