Skip to content

Commit bbcab62

Browse files
bebehrcoliff
andauthored
fix(tag-pair): point tag-pair error message to correct line and colum… (#1503)
* fix(tag-pair): point tag-pair error message to correct line and column number fix #1284 * Update /dist/ --------- Co-authored-by: Christian Oliff <[email protected]>
1 parent e863cc7 commit bbcab62

File tree

5 files changed

+21
-7
lines changed

5 files changed

+21
-7
lines changed

dist/core/rules/tag-pair.js

Lines changed: 3 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/htmlhint.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1155,6 +1155,7 @@
11551155
stack.push({
11561156
tagName: tagName,
11571157
line: event.line,
1158+
col: event.col,
11581159
raw: event.raw,
11591160
});
11601161
}
@@ -1174,7 +1175,7 @@
11741175
}
11751176
if (arrTags.length > 0) {
11761177
const lastEvent = stack[stack.length - 1];
1177-
reporter.error(`Tag must be paired, missing: [ ${arrTags.join('')} ], start tag match failed [ ${lastEvent.raw} ] on line ${lastEvent.line}.`, event.line, event.col, this, event.raw);
1178+
reporter.error(`Tag must be paired, missing: [ ${arrTags.join('')} ], start tag match failed [ ${lastEvent.raw} ] on line ${lastEvent.line}.`, lastEvent.line || event.line, lastEvent.col || event.col, this, event.raw);
11781179
}
11791180
stack.length = pos;
11801181
}

dist/htmlhint.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/core/rules/tag-pair.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ export default {
1616
stack.push({
1717
tagName: tagName,
1818
line: event.line,
19+
col: event.col,
1920
raw: event.raw,
2021
})
2122
}
@@ -46,8 +47,8 @@ export default {
4647
)} ], start tag match failed [ ${lastEvent.raw} ] on line ${
4748
lastEvent.line
4849
}.`,
49-
event.line,
50-
event.col,
50+
lastEvent.line || event.line,
51+
lastEvent.col || event.col,
5152
this,
5253
event.raw
5354
)

test/rules/tag-pair.spec.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ describe(`Rules: ${ruleId}`, () => {
1212
expect(messages.length).toBe(2)
1313
expect(messages[0].rule.id).toBe(ruleId)
1414
expect(messages[0].line).toBe(1)
15-
expect(messages[0].col).toBe(9)
15+
expect(messages[0].col).toBe(5)
1616
expect(messages[1].rule.id).toBe(ruleId)
1717
expect(messages[1].line).toBe(1)
1818
expect(messages[1].col).toBe(20)
@@ -24,6 +24,17 @@ describe(`Rules: ${ruleId}`, () => {
2424
expect(messages[0].col).toBe(9)
2525
})
2626

27+
it('No end tag should result in an error with correct line number and column of the start tag', () => {
28+
const code = '<div>\r\n <h1>\r\n <p>aaa</p>\r\n</div>'
29+
const messages = HTMLHint.verify(code, ruleOptions)
30+
expect(messages.length).toBe(1)
31+
expect(messages[0].rule.id).toBe(ruleId)
32+
expect(messages[0].line).not.toBe(4)
33+
expect(messages[0].col).not.toBe(1)
34+
expect(messages[0].line).toBe(2)
35+
expect(messages[0].col).toBe(3)
36+
})
37+
2738
it('No start tag should result in an error', () => {
2839
const code = '</div>'
2940
const messages = HTMLHint.verify(code, ruleOptions)

0 commit comments

Comments
 (0)