Skip to content

Commit d66808b

Browse files
committed
Modernize to use let and const
1 parent 560b77a commit d66808b

File tree

1 file changed

+16
-16
lines changed

1 file changed

+16
-16
lines changed

lib/rules/jsx-sort-props.js

+16-16
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ function alphabeticalCompare(a, b, ignoreCase) {
5757
function getGroupsOfSortableAttributes(attributes) {
5858
const sortableAttributeGroups = [];
5959
let groupCount = 0;
60-
for (var i = 0; i < attributes.length; i++) {
60+
for (let i = 0; i < attributes.length; i++) {
6161
const lastAttr = attributes[i - 1];
6262
// If we have no groups or if the last attribute was JSXSpreadAttribute
6363
// then we start a new group. Append attributes to the group until we
@@ -77,30 +77,30 @@ function getGroupsOfSortableAttributes(attributes) {
7777
return sortableAttributeGroups;
7878
}
7979

80-
function generateFixerFunction(node, context) {
81-
var sourceCode = context.getSourceCode();
82-
var attributes = node.attributes.slice(0);
83-
var configuration = context.options[0] || {};
84-
var ignoreCase = configuration.ignoreCase || false;
80+
const generateFixerFunction = (node, context) => {
81+
const sourceCode = context.getSourceCode();
82+
const attributes = node.attributes.slice(0);
83+
const configuration = context.options[0] || {};
84+
const ignoreCase = configuration.ignoreCase || false;
8585

8686
// Sort props according to the context. Only supports ignoreCase.
8787
// Since we cannot safely move JSXSpreadAttribute (due to potential variable overrides),
8888
// we only consider groups of sortable attributes.
8989
const sortableAttributeGroups = getGroupsOfSortableAttributes(attributes);
90-
const sortedAttributeGroups = sortableAttributeGroups.slice(0).map(function(group) {
91-
return group.slice(0).sort(function(a, b) {
92-
return alphabeticalCompare(propName(a), propName(b), ignoreCase);
93-
});
94-
});
90+
const sortedAttributeGroups = sortableAttributeGroups.slice(0).map(group =>
91+
group.slice(0).sort((a, b) =>
92+
alphabeticalCompare(propName(a), propName(b), ignoreCase)
93+
)
94+
);
9595

9696
return function(fixer) {
9797
const fixers = [];
9898

9999
// Replace each unsorted attribute with the sorted one.
100-
sortableAttributeGroups.forEach(function(sortableGroup, ii) {
101-
sortableGroup.forEach(function(attr, jj) {
102-
var sortedAttr = sortedAttributeGroups[ii][jj];
103-
var sortedAttrText = sourceCode.getText(sortedAttr);
100+
sortableAttributeGroups.forEach((sortableGroup, ii) => {
101+
sortableGroup.forEach((attr, jj) => {
102+
const sortedAttr = sortedAttributeGroups[ii][jj];
103+
const sortedAttrText = sourceCode.getText(sortedAttr);
104104
fixers.push(
105105
fixer.replaceTextRange([attr.start, attr.end], sortedAttrText)
106106
);
@@ -109,7 +109,7 @@ function generateFixerFunction(node, context) {
109109

110110
return fixers;
111111
};
112-
}
112+
};
113113

114114
/**
115115
* Checks if the `reservedFirst` option is valid

0 commit comments

Comments
 (0)