Skip to content

Commit 5c690e0

Browse files
committed
Issue#2366 sorted attributes respects comments, cleaned up syntax
1 parent 51ed373 commit 5c690e0

File tree

2 files changed

+3
-6
lines changed

2 files changed

+3
-6
lines changed

lib/rules/jsx-sort-props.js

+3-5
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
'use strict';
77

88
const propName = require('jsx-ast-utils/propName');
9-
//const astUtils = require(".node_modules\eslint\lib\rules\utils\ast-utils.js");
109
const includes = require('array-includes');
1110
const docsUrl = require('../util/docsUrl');
1211
const jsxUtil = require('../util/jsx');
@@ -29,7 +28,7 @@ const messages = {
2928
listIsEmpty: 'A customized reserved first list must not be empty',
3029
listReservedPropsFirst: 'Reserved props must be listed before all other props',
3130
listCallbacksLast: 'Callbacks must be listed after all other props',
32-
listShorthandFirst: 'S horthand props must be listed before all other props',
31+
listShorthandFirst: 'Shorthand props must be listed before all other props',
3332
listShorthandLast: 'Shorthand props must be listed after all other props',
3433
listMultilineFirst: 'Multiline props must be listed before all other props',
3534
listMultilineLast: 'Multiline props must be listed after all other props',
@@ -236,7 +235,7 @@ const generateFixerFunction = (node, context, reservedList) => {
236235
const sortableAttributeGroups = getGroupsOfSortableAttributes(attributes, context);
237236
const sortedAttributeGroups = sortableAttributeGroups
238237
.slice(0)
239-
.map((group) => group.slice(0).sort((a, b) => contextCompare(a, b, options) ));
238+
.map((group) => group.slice(0).sort((a, b) => contextCompare(a, b, options)));
240239

241240
return function fixFunction(fixer) {
242241
const fixers = [];
@@ -257,7 +256,7 @@ const generateFixerFunction = (node, context, reservedList) => {
257256
fixers.sort((a, b) => b.range[0] - a.range[0]);
258257

259258
const rangeStart = fixers[fixers.length - 1].range[0];
260-
const rangeEnd = fixers[0].range[1];
259+
const rangeEnd = fixers[0].range[1];
261260

262261
fixers.forEach((fix) => {
263262
source = `${source.substr(0, fix.range[0])}${fix.text}${source.substr(fix.range[1])}`;
@@ -329,7 +328,6 @@ function reportNodeAttribute(nodeAttribute, errorType, node, context, reservedLi
329328
report(context, messages[errorType], errorType, {
330329
node: nodeAttribute.name,
331330
fix: generateFixerFunction(node, context, reservedList),
332-
333331
});
334332
}
335333

tests/lib/rules/jsx-sort-props.js

-1
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,6 @@ const multilineAndShorthandAndCallbackLastArgs = [
119119
callbacksLast: true,
120120
},
121121
];
122-
//const commentbetween = [{ commentbetween: true }];
123122

124123
ruleTester.run('jsx-sort-props', rule, {
125124
valid: parsers.all([].concat(

0 commit comments

Comments
 (0)