Skip to content

Commit 1dc1b87

Browse files
feat(attr-sort): sort unknown attributes alphabetically
Previously unknown attributes were just ignored. Now they get sorted alphabetically. BREAKING CHANGE: HTMLHint will now throw an error if unkown attributes are not sorted. fix htmlhint#661
1 parent d5bda0d commit 1dc1b87

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

Diff for: src/core/rules/attr-sorted.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ export default {
3434
const originalAttrs = JSON.stringify(listOfAttributes)
3535
listOfAttributes.sort((a, b) => {
3636
if (orderMap[a] == undefined && orderMap[b] == undefined) {
37-
return 0
37+
return a.localeCompare(b)
3838
}
3939
if (orderMap[a] == undefined) {
4040
return 1

Diff for: test/rules/attr-sorted.spec.js

+12-2
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,24 @@ describe(`Rules: ${ruleId}`, () => {
1616
expect(messages[0].message).toContain('["id","class","title"]')
1717
})
1818

19-
it('Attribute unsorted tags that are unrecognizable should not throw error', () => {
20-
const code = '<div img="image" meta="meta" font="font"></div>'
19+
it('Attribute sorted tags that are unrecognizable should not throw error', () => {
20+
const code = '<div font="font" img="image" meta="meta"></div>'
2121

2222
const messages = HTMLHint.verify(code, ruleOptions)
2323

2424
expect(messages.length).toBe(0)
2525
})
2626

27+
it('Attribute unsorted tags that are unrecognizable should throw error', () => {
28+
const code = '<div img="image" meta="meta" font="font"></div>'
29+
30+
const messages = HTMLHint.verify(code, ruleOptions)
31+
32+
expect(messages.length).to.be(1)
33+
expect(messages[0].rule.id).to.be(ruleId)
34+
expect(messages[0].message).to.contain('["img","meta","font"]')
35+
})
36+
2737
it('Attribute unsorted of tags of various types should throw error', () => {
2838
const code = '<div type="type" img="image" id="id" font="font"></div>'
2939

0 commit comments

Comments
 (0)