Skip to content

Unstable attributes sorting #732

@gebsh

Description

@gebsh

The xmlSortAttributesByKey option is unstable when comparing an xmlns attribute with another prefixed attribute. For example, consider the following XML element:

<foo xmlns:foo="http://www.example.org" foo:foo="1" />

Formatting it with prettier --plugin=@prettier/plugin-xml --write --xml-sort-attributes-by-key swaps attributes:

<foo foo:foo="1" xmlns:foo="http://www.example.org" />

However, running the same command again, swaps the attributes once more, changing the code back to its original form.

The possible culprit of this behavior may be the following line:

if (rightNS === "xlmns") return 1;

There's a typo in the if statement—instead of xmlns, it's xlmns.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions