Skip to content

Instantly share code, notes, and snippets.

@jonesnxt
Created October 17, 2022 23:58
Show Gist options
  • Save jonesnxt/8159a34a9ab45516054b933209cad7c8 to your computer and use it in GitHub Desktop.
Save jonesnxt/8159a34a9ab45516054b933209cad7c8 to your computer and use it in GitHub Desktop.
S('JSXOpeningElement').each((openingTag) => {
const attributeSortingGroups = [];
let currentAttributeGroup = [];
openingTag
.children('JSXAttribute, JSXSpreadAttribute')
.each((attribute, i) => {
if (attribute.type() === 'JSXSpreadAttribute') {
attributeSortingGroups.push(currentAttributeGroup.sort());
currentAttributeGroup = [];
return;
}
currentAttributeGroup.push(attribute.text());
});
attributeSortingGroups.push(currentAttributeGroup.sort());
const sortedAttributes = attributeSortingGroups.flat();
openingTag
.children('JSXAttribute')
.each((attribute, i) => attribute.text(sortedAttributes[i]));
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment