From 22a5962095a158b1941d614c09369b4beac3c09b Mon Sep 17 00:00:00 2001 From: Issei Horie Date: Fri, 28 Jan 2022 01:24:38 +0900 Subject: [PATCH] fix: ignore hidden input without label fix #866 --- dist/core/rules/input-requires-label.js | 6 ++++-- dist/htmlhint.js | 4 +++- dist/htmlhint.min.js | 2 +- src/core/rules/input-requires-label.ts | 5 ++++- test/rules/input-requires-label.spec.js | 6 ++++++ 5 files changed, 18 insertions(+), 5 deletions(-) diff --git a/dist/core/rules/input-requires-label.js b/dist/core/rules/input-requires-label.js index 68d390400..59c054cd2 100644 --- a/dist/core/rules/input-requires-label.js +++ b/dist/core/rules/input-requires-label.js @@ -11,7 +11,9 @@ exports.default = { const mapAttrs = parser.getMapAttrs(event.attrs); const col = event.col + tagName.length + 1; if (tagName === 'input') { - inputTags.push({ event: event, col: col, id: mapAttrs['id'] }); + if (mapAttrs['type'] !== 'hidden') { + inputTags.push({ event: event, col: col, id: mapAttrs['id'] }); + } } if (tagName === 'label') { if ('for' in mapAttrs && mapAttrs['for'] !== '') { @@ -37,4 +39,4 @@ exports.default = { } }, }; -//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5wdXQtcmVxdWlyZXMtbGFiZWwuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi8uLi9zcmMvY29yZS9ydWxlcy9pbnB1dC1yZXF1aXJlcy1sYWJlbC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOztBQUdBLGtCQUFlO0lBQ2IsRUFBRSxFQUFFLHNCQUFzQjtJQUMxQixXQUFXLEVBQUUsOERBQThEO0lBQzNFLElBQUksQ0FBQyxNQUFNLEVBQUUsUUFBUTtRQUNuQixNQUFNLFNBQVMsR0FJVixFQUFFLENBQUE7UUFDUCxNQUFNLFNBQVMsR0FBc0QsRUFBRSxDQUFBO1FBRXZFLE1BQU0sQ0FBQyxXQUFXLENBQUMsVUFBVSxFQUFFLENBQUMsS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QUFDLG1CQUFtQixDQUFDLFFBQVEsQ0FBQyxFQUFFO29CQUNsQyxRQUFRLENBQUMsSUFBSSxDQUNYLGtDQUFrQyxFQUNsQyxRQUFRLENBQUMsS0FBSyxDQUFDLElBQUksRUFDbkIsUUFBUSxDQUFDLEdBQUcsRUFDWixJQUFJLEVBQ0osUUFBUSxDQUFDLEtBQUssQ0FBQyxHQUFHLENBQ25CLENBQUE7aUJBQ0Y7WUFDSCxDQUFDLENBQUMsQ0FBQTtRQUNKLENBQUMsQ0FBQyxDQUFBO1FBRUYsU0FBUyxtQkFBbUIsQ0FBQyxRQUF5QjtZQUNwRCxJQUFJLEtBQUssR0FBRyxLQUFLLENBQUE7WUFDakIsU0FBUyxDQUFDLE9BQU8sQ0FBQyxDQUFDLFFBQVEsRUFBRSxFQUFFO2dCQUM3QixJQUFJLFFBQVEsQ0FBQyxFQUFFLElBQUksUUFBUSxDQUFDLEVBQUUsS0FBSyxRQUFRLENBQUMsUUFBUSxFQUFFO29CQUNwRCxLQUFLLEdBQUcsSUFBSSxDQUFBO2lCQUNiO1lBQ0gsQ0FBQyxDQUFDLENBQUE7WUFDRixPQUFPLEtBQUssQ0FBQTtRQUNkLENBQUM7SUFDSCxDQUFDO0NBQ00sQ0FBQSJ9 \ No newline at end of file diff --git a/dist/htmlhint.js b/dist/htmlhint.js index 05e040d49..55753504b 100644 --- a/dist/htmlhint.js +++ b/dist/htmlhint.js @@ -986,7 +986,9 @@ const mapAttrs = parser.getMapAttrs(event.attrs); const col = event.col + tagName.length + 1; if (tagName === 'input') { - inputTags.push({ event: event, col: col, id: mapAttrs['id'] }); + if (mapAttrs['type'] !== 'hidden') { + inputTags.push({ event: event, col: col, id: mapAttrs['id'] }); + } } if (tagName === 'label') { if ('for' in mapAttrs && mapAttrs['for'] !== '') { diff --git a/dist/htmlhint.min.js b/dist/htmlhint.min.js index 5fd325611..21e17322e 100644 --- a/dist/htmlhint.min.js +++ b/dist/htmlhint.min.js @@ -1 +1 @@ -!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e="undefined"!=typeof globalThis?globalThis:e||self).HTMLHint=t()}(this,(function(){"use strict";function e(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var t={},a={};Object.defineProperty(a,"__esModule",{value:!0});a.default=class{constructor(){this._listeners={},this._mapCdataTags=this.makeMap("script,style"),this._arrBlocks=[],this.lastEvent=null}makeMap(e){const t={},a=e.split(",");for(let e=0;e]+)\s*|!--([\s\S]*?)--|!([^>]*?)|([\w\-:]+)((?:\s+[^\s"'>\/=\x00-\x0F\x7F\x80-\x9F]+(?:\s*=\s*(?:"[^"]*"|'[^']*'|[^\s"'>]*))?)*?)\s*(\/?))>/g,r=/\s*([^\s"'>\/=\x00-\x0F\x7F\x80-\x9F]+)(?:\s*=\s*(?:(")([^"]*)"|(')([^']*)'|([^\s"'>]*)))?/g,n=/\r?\n/g;let s,i,l,o,u,d,c=0,f=null,g=[],h=0,p=0,m=1;const b=this._arrBlocks;this.fire("start",{pos:0,line:1,col:1});const v=()=>{const e=o.find((e=>"type"===e.name))||{value:""};return t[l]&&-1===e.value.indexOf("text/ng-template")},y=(e,t,a,r)=>{const s=a-p+1;for(void 0===r&&(r={}),r.raw=t,r.pos=a,r.line=m,r.col=s,b.push(r),this.fire(e,r);n.exec(t);)m++,p=a+n.lastIndex};for(;s=a.exec(e);)if(i=s.index,i>c&&(d=e.substring(c,i),f?g.push(d):y("text",d,c)),c=a.lastIndex,!(l=s[1])||(f&&l===f&&(d=g.join(""),y("cdata",d,h,{tagName:f,attrs:u}),f=null,u=void 0,g=[]),f))if(f)g.push(s[0]);else if(l=s[4]){o=[];const e=s[5];let t,a=0;for(;t=r.exec(e);){const e=t[1],r=t[2]?t[2]:t[4]?t[4]:"",n=t[3]?t[3]:t[5]?t[5]:t[6]?t[6]:"";o.push({name:e,value:n,quote:r,index:t.index,raw:t[0]}),a+=t[0].length}a===e.length?(y("tagstart",s[0],i,{tagName:l,attrs:o,close:s[6]}),v()&&(f=l,u=o.concat(),g=[],h=c)):y("text",s[0],i)}else(s[2]||s[3])&&y("comment",s[0],i,{content:s[2]||s[3],long:!!s[2]});else y("tagend",s[0],i,{tagName:l});e.length>c&&(d=e.substring(c,e.length),y("text",d,c)),this.fire("end",{pos:c,line:m,col:e.length-p+1})}addListener(e,t){const a=this._listeners,r=e.split(/[,\s]/);let n;for(let e=0,s=r.length;e0?(s+=r,n=a[r].length+1):n=e.col+t,{line:s,col:n}}getMapAttrs(e){const t={};let a;for(let r=0,n=e.length;ru&&a element must be present and alt attribute of area[href] and input[type=image] must have a value.",init(e,t){e.addListener("tagstart",(a=>{const r=a.tagName.toLowerCase(),n=e.getMapAttrs(a.attrs),s=a.col+r.length+1;let i;"img"!==r||"alt"in n?("area"===r&&"href"in n||"input"===r&&"image"===n.type)&&("alt"in n&&""!==n.alt||(i="area"===r?"area[href]":"input[type=image]",t.warn(`The alt attribute of ${i} must have a value.`,a.line,s,this,a.raw))):t.warn("An alt attribute must be present on elements.",a.line,s,this,a.raw)}))}};var i={};Object.defineProperty(i,"__esModule",{value:!0});const l=["allowReorder","attributeName","attributeType","autoReverse","baseFrequency","baseProfile","calcMode","clipPath","clipPathUnits","contentScriptType","contentStyleType","diffuseConstant","edgeMode","externalResourcesRequired","filterRes","filterUnits","glyphRef","gradientTransform","gradientUnits","kernelMatrix","kernelUnitLength","keyPoints","keySplines","keyTimes","lengthAdjust","limitingConeAngle","markerHeight","markerUnits","markerWidth","maskContentUnits","maskUnits","numOctaves","onBlur","onChange","onClick","onFocus","onKeyUp","onLoad","pathLength","patternContentUnits","patternTransform","patternUnits","pointsAtX","pointsAtY","pointsAtZ","preserveAlpha","preserveAspectRatio","primitiveUnits","refX","refY","repeatCount","repeatDur","requiredExtensions","requiredFeatures","specularConstant","specularExponent","spreadMethod","startOffset","stdDeviation","stitchTiles","surfaceScale","systemLanguage","tableValues","targetX","targetY","textLength","viewBox","viewTarget","xChannelSelector","yChannelSelector","zoomAndPan"];function o(e,t){if(t instanceof RegExp)return!!t.test(e)&&{match:e,pattern:t};const a=t[0],r=t[t.length-1],n=t[t.length-2],s="/"===a&&("/"===r||"/"===n&&"i"===r);if(s){return s&&"i"===r?new RegExp(t.slice(1,-2),"i").test(e):new RegExp(t.slice(1,-1)).test(e)}return e===t}i.default={id:"attr-lowercase",description:"All attribute names must be in lowercase.",init(e,t,a){const r=(Array.isArray(a)?a:[]).concat(l);e.addListener("tagstart",(e=>{const a=e.attrs;let n;const s=e.col+e.tagName.length+1;for(let i=0,l=a.length;io(l,e)))||l===l.toLowerCase()||t.error(`The attribute name of [ ${l} ] must be in lowercase.`,e.line,s+n.index,this,n.raw)}}))}};var u={};Object.defineProperty(u,"__esModule",{value:!0}),u.default={id:"attr-sorted",description:"Attribute tags must be in proper order.",init(e,t){const a={},r=["class","id","name","src","for","type","href","value","title","alt","role"];for(let e=0;e{const r=e.attrs,n=[];for(let e=0;enull==a[e]&&null==a[t]?0:null==a[e]?1:null==a[t]?-1:a[e]-a[t]||e.localeCompare(t))),s!==JSON.stringify(n)&&t.error(`Inaccurate order ${s} should be in hierarchy ${JSON.stringify(n)} `,e.line,e.col,this,e.raw)}))}};var d={};Object.defineProperty(d,"__esModule",{value:!0}),d.default={id:"attr-no-duplication",description:"Elements cannot have duplicate attributes.",init(e,t){e.addListener("tagstart",(e=>{const a=e.attrs;let r,n;const s=e.col+e.tagName.length+1,i={};for(let l=0,o=a.length;l{const a=e.attrs;let r;const n=e.col+e.tagName.length+1,s=/[\u0000-\u0008\u000b\u000c\u000e-\u001f\u007f-\u009f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/;let i;for(let l=0,o=a.length;l{const a=e.attrs;let r;const n=e.col+e.tagName.length+1;for(let s=0,i=a.length;s{const a=e.attrs;let r;const n=e.col+e.tagName.length+1;for(let s=0,i=a.length;s{const a=e.attrs;let r;const n=e.col+e.tagName.length+1;for(let s=0,i=a.length;s{const a=e.attrs;let n;const s=e.col+e.tagName.length+1;a.forEach((a=>{n=a;const i=a.name;-1===r.indexOf(i)&&(a.value.trim()!==a.value&&t.error(`The attributes of [ ${i} ] must not have leading or trailing whitespace.`,e.line,s+n.index,this,n.raw),a.value.replace(/ +(?= )/g,"")!==a.value&&t.error(`The attributes of [ ${i} ] must be separated by only one space.`,e.line,s+n.index,this,n.raw))}))}))}};var m={};Object.defineProperty(m,"__esModule",{value:!0}),m.default={id:"doctype-first",description:"Doctype must be declared first.",init(e,t){const a=r=>{"start"===r.type||"text"===r.type&&/^\s*$/.test(r.raw)||(("comment"!==r.type&&!1===r.long||!1===/^DOCTYPE\s+/i.test(r.content))&&t.error("Doctype must be declared first.",r.line,r.col,this,r.raw),e.removeListener("all",a))};e.addListener("all",a)}};var b={};Object.defineProperty(b,"__esModule",{value:!0}),b.default={id:"doctype-html5",description:'Invalid doctype. Use: ""',init(e,t){const a=e=>{!1===e.long&&"doctype html"!==e.content.toLowerCase()&&t.warn('Invalid doctype. Use: ""',e.line,e.col,this,e.raw)},r=()=>{e.removeListener("comment",a),e.removeListener("tagstart",r)};e.addListener("all",a),e.addListener("tagstart",r)}};var v={};Object.defineProperty(v,"__esModule",{value:!0}),v.default={id:"head-script-disabled",description:"The