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..3a7391e24d 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, + }, + ], } : [] )), });