From 68423d7312668e461b038cd2676b1f1b48a8b387 Mon Sep 17 00:00:00 2001 From: Christoph Guttandin Date: Tue, 17 Aug 2021 01:10:41 +0200 Subject: [PATCH] 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 #661 --- src/core/rules/attr-sorted.ts | 2 +- test/rules/attr-sort.spec.js | 14 ++++++++++++-- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/core/rules/attr-sorted.ts b/src/core/rules/attr-sorted.ts index a1f85df98..e99b73dc8 100644 --- a/src/core/rules/attr-sorted.ts +++ b/src/core/rules/attr-sorted.ts @@ -34,7 +34,7 @@ export default { const originalAttrs = JSON.stringify(listOfAttributes) listOfAttributes.sort((a, b) => { if (orderMap[a] == undefined && orderMap[b] == undefined) { - return 0 + return a.localeCompare(b) } if (orderMap[a] == undefined) { return 1 diff --git a/test/rules/attr-sort.spec.js b/test/rules/attr-sort.spec.js index 1bfcd68a9..760feb018 100644 --- a/test/rules/attr-sort.spec.js +++ b/test/rules/attr-sort.spec.js @@ -18,14 +18,24 @@ describe(`Rules: ${ruleId}`, () => { expect(messages[0].message).to.contain('["id","class","title"]') }) - it('Attribute unsorted tags that are unrecognizable should not throw error', () => { - const code = '
' + it('Attribute sorted tags that are unrecognizable should not throw error', () => { + const code = '
' const messages = HTMLHint.verify(code, ruleOptions) expect(messages.length).to.be(0) }) + it('Attribute unsorted tags that are unrecognizable should throw error', () => { + const code = '
' + + const messages = HTMLHint.verify(code, ruleOptions) + + expect(messages.length).to.be(1) + expect(messages[0].rule.id).to.be(ruleId) + expect(messages[0].message).to.contain('["img","meta","font"]') + }) + it('Attribute unsorted of tags of various types should throw error', () => { const code = '
'