Skip to content

Commit cab2907

Browse files
is2einschonni
authored andcommitted
fix: ignore hidden input without label
fix #866
1 parent fdd4c21 commit cab2907

File tree

5 files changed

+18
-5
lines changed

5 files changed

+18
-5
lines changed

dist/core/rules/input-requires-label.js

+4-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/htmlhint.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -986,7 +986,9 @@
986986
const mapAttrs = parser.getMapAttrs(event.attrs);
987987
const col = event.col + tagName.length + 1;
988988
if (tagName === 'input') {
989-
inputTags.push({ event: event, col: col, id: mapAttrs['id'] });
989+
if (mapAttrs['type'] !== 'hidden') {
990+
inputTags.push({ event: event, col: col, id: mapAttrs['id'] });
991+
}
990992
}
991993
if (tagName === 'label') {
992994
if ('for' in mapAttrs && mapAttrs['for'] !== '') {

dist/htmlhint.min.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/core/rules/input-requires-label.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,10 @@ export default {
1818
const col = event.col + tagName.length + 1
1919

2020
if (tagName === 'input') {
21-
inputTags.push({ event: event, col: col, id: mapAttrs['id'] })
21+
// label is not required for hidden input
22+
if (mapAttrs['type'] !== 'hidden') {
23+
inputTags.push({ event: event, col: col, id: mapAttrs['id'] })
24+
}
2225
}
2326

2427
if (tagName === 'label') {

test/rules/input-requires-label.spec.js

+6
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,12 @@ describe(`Rules: ${ruleId}`, () => {
2222
const messages = HTMLHint.verify(code, ruleOptions)
2323
expect(messages.length).to.be(0)
2424
})
25+
26+
it('Hidden input tag with no matching label should result in no error', () => {
27+
const code = '<input id="some-id" type="hidden" />'
28+
const messages = HTMLHint.verify(code, ruleOptions)
29+
expect(messages.length).to.be(0)
30+
})
2531
})
2632

2733
describe('Error cases', () => {

0 commit comments

Comments
 (0)