From c2ae5d39ffaef41806a9562d20e549cb7b09057a Mon Sep 17 00:00:00 2001 From: Eugene Tihonov Date: Mon, 8 Oct 2018 20:35:39 +0500 Subject: [PATCH] [Fix] `jsx-sort-comp`: Fix fixer in case of more than 10 props Fixes #1993. Fixes #1922. --- lib/rules/jsx-sort-props.js | 2 +- tests/lib/rules/jsx-sort-props.js | 95 +++++++++++++++++++++++++++++++ 2 files changed, 96 insertions(+), 1 deletion(-) diff --git a/lib/rules/jsx-sort-props.js b/lib/rules/jsx-sort-props.js index d6e5a982ef..7528c1905c 100644 --- a/lib/rules/jsx-sort-props.js +++ b/lib/rules/jsx-sort-props.js @@ -107,7 +107,7 @@ const generateFixerFunction = (node, context, reservedList) => { }); }); - fixers.sort((a, b) => a.range[0] < b.range[0]); + fixers.sort((a, b) => b.range[0] - a.range[0]); const rangeStart = fixers[fixers.length - 1].range[0]; const rangeEnd = fixers[0].range[1]; diff --git a/tests/lib/rules/jsx-sort-props.js b/tests/lib/rules/jsx-sort-props.js index 2f32e6b2ac..082ef11f4e 100644 --- a/tests/lib/rules/jsx-sort-props.js +++ b/tests/lib/rules/jsx-sort-props.js @@ -238,6 +238,101 @@ ruleTester.run('jsx-sort-props', rule, { `, errors: 3 }, + { + code: '', + output: '', + errors: 1 + }, + { + code: ``, + output: ``, + errors: 10 + }, + { + code: ``, + output: ``, + errors: 13 + }, { code: '', errors: [expectedShorthandLastError],