From: XhmikosR Date: Tue, 18 Feb 2014 17:39:47 +0000 (+0200) Subject: Enable JSHint's `quotmark` rule. X-Git-Url: https://git.ndcode.org/public/gitweb.cgi?a=commitdiff_plain;h=9e534cd36932ce01cdc2cf628616c33a425a6d8b;p=html-minifier.git Enable JSHint's `quotmark` rule. --- diff --git a/.jshintrc b/.jshintrc index eec9331..b16e44f 100644 --- a/.jshintrc +++ b/.jshintrc @@ -10,6 +10,7 @@ "loopfunc": true, "newcap": false, "node": true, + "quotmark": "single", "strict": false, "undef": true, "unused": true diff --git a/dist/htmlminifier.js b/dist/htmlminifier.js index 45601d9..c48692b 100644 --- a/dist/htmlminifier.js +++ b/dist/htmlminifier.js @@ -45,23 +45,23 @@ endIgnore = /(%|\?)>/; // Empty Elements - HTML 4.01 - var empty = makeMap("area,base,basefont,br,col,frame,hr,img,input,isindex,link,meta,param,embed"); + var empty = makeMap('area,base,basefont,br,col,frame,hr,img,input,isindex,link,meta,param,embed'); // Block Elements - HTML 4.01 - // var block = makeMap("address,applet,blockquote,button,center,dd,del,dir,div,dl,dt,fieldset,form,frameset,hr,iframe,ins,isindex,li,map,menu,noframes,noscript,object,ol,p,pre,script,table,tbody,td,tfoot,th,thead,tr,ul"); + // var block = makeMap('address,applet,blockquote,button,center,dd,del,dir,div,dl,dt,fieldset,form,frameset,hr,iframe,ins,isindex,li,map,menu,noframes,noscript,object,ol,p,pre,script,table,tbody,td,tfoot,th,thead,tr,ul'); // Inline Elements - HTML 4.01 - var inline = makeMap("a,abbr,acronym,applet,b,basefont,bdo,big,br,button,cite,code,del,dfn,em,font,i,iframe,img,input,ins,kbd,label,map,object,q,s,samp,script,select,small,span,strike,strong,sub,sup,textarea,tt,u,var"); + var inline = makeMap('a,abbr,acronym,applet,b,basefont,bdo,big,br,button,cite,code,del,dfn,em,font,i,iframe,img,input,ins,kbd,label,map,object,q,s,samp,script,select,small,span,strike,strong,sub,sup,textarea,tt,u,var'); // Elements that you can, intentionally, leave open // (and which close themselves) - var closeSelf = makeMap("colgroup,dd,dt,li,options,p,td,tfoot,th,thead,tr,source"); + var closeSelf = makeMap('colgroup,dd,dt,li,options,p,td,tfoot,th,thead,tr,source'); - // Attributes that have their values filled in disabled="disabled" - var fillAttrs = makeMap("checked,compact,declare,defer,disabled,ismap,multiple,nohref,noresize,noshade,nowrap,readonly,selected"); + // Attributes that have their values filled in disabled='disabled' + var fillAttrs = makeMap('checked,compact,declare,defer,disabled,ismap,multiple,nohref,noresize,noshade,nowrap,readonly,selected'); // Special Elements (can contain anything) - var special = makeMap("script,style"); + var special = makeMap('script,style'); var reCache = { }, stackedTag, reStackedTag, tagMatch; @@ -78,8 +78,8 @@ if ( !stack.last() || !special[ stack.last() ] ) { // Comment: - if ( html.indexOf(""); + if ( html.indexOf(''); if ( index >= 0 ) { if ( handler.comment ) @@ -109,7 +109,7 @@ } // End tag: - else if ( html.indexOf("]*>", "i")); + reStackedTag = reCache[stackedTag] || (reCache[stackedTag] = new RegExp('([\\s\\S]*?)<\/' + stackedTag + '[^>]*>', 'i')); html = html.replace(reStackedTag, function(all, text) { if (stackedTag !== 'script' && stackedTag !== 'style') { text = text - .replace(//g, "$1") - .replace(//g, "$1"); + .replace(//g, '$1') + .replace(//g, '$1'); } if ( handler.chars ) handler.chars( text ); - return ""; + return ''; }); - parseEndTag( "", stackedTag ); + parseEndTag( '', stackedTag ); } if ( html === last ) - throw "Parse Error: " + html; + throw 'Parse Error: ' + html; last = html; } @@ -188,11 +188,11 @@ var unarySlash = false; while ( !handler.html5 && stack.last() && inline[ stack.last() ]) { - parseEndTag( "", stack.last() ); + parseEndTag( '', stack.last() ); } if ( closeSelf[ tagName ] && stack.last() === tagName ) { - parseEndTag( "", tagName ); + parseEndTag( '', tagName ); } unary = empty[ tagName ] || !!unary; @@ -210,7 +210,7 @@ var value = arguments[2] ? arguments[2] : arguments[3] ? arguments[3] : arguments[4] ? arguments[4] : - fillAttrs[name] ? name : ""; + fillAttrs[name] ? name : ''; attrs.push({ name: name, value: value, @@ -249,25 +249,25 @@ }; global.HTMLtoXML = function( html ) { - var results = ""; + var results = ''; HTMLParser(html, { start: function( tag, attrs, unary ) { - results += "<" + tag; + results += '<' + tag; for ( var i = 0; i < attrs.length; i++ ) - results += " " + attrs[i].name + '="' + attrs[i].escaped + '"'; + results += ' ' + attrs[i].name + '="' + attrs[i].escaped + '"'; - results += (unary ? "/" : "") + ">"; + results += (unary ? '/' : '') + '>'; }, end: function( tag ) { - results += ""; + results += ''; }, chars: function( text ) { results += text; }, comment: function( text ) { - results += ""; + results += ''; }, ignore: function(text) { results += text; @@ -279,21 +279,21 @@ global.HTMLtoDOM = function( html, doc ) { // There can be only one of these elements - var one = makeMap("html,head,body,title"); + var one = makeMap('html,head,body,title'); // Enforce a structure for the document var structure = { - link: "head", - base: "head" + link: 'head', + base: 'head' }; if ( !doc ) { - if ( typeof DOMDocument !== "undefined" ) + if ( typeof DOMDocument !== 'undefined' ) doc = new DOMDocument(); - else if ( typeof document !== "undefined" && document.implementation && document.implementation.createDocument ) - doc = document.implementation.createDocument("", "", null); - else if ( typeof ActiveX !== "undefined" ) - doc = new ActiveXObject("Msxml.DOMDocument"); + else if ( typeof document !== 'undefined' && document.implementation && document.implementation.createDocument ) + doc = document.implementation.createDocument('', '', null); + else if ( typeof ActiveX !== 'undefined' ) + doc = new ActiveXObject('Msxml.DOMDocument'); } else doc = doc.ownerDocument || @@ -308,11 +308,11 @@ // need to pre-populate it with the HTML document structure if ( !documentElement && doc.createElement ) { (function(){ - var html = doc.createElement("html"); - var head = doc.createElement("head"); - head.appendChild( doc.createElement("title") ); + var html = doc.createElement('html'); + var head = doc.createElement('head'); + head.appendChild( doc.createElement('title') ); html.appendChild( head ); - html.appendChild( doc.createElement("body") ); + html.appendChild( doc.createElement('body') ); doc.appendChild( html ); })(); } @@ -340,7 +340,7 @@ for ( var attr in attrs ) elem.setAttribute( attrs[ attr ].name, attrs[ attr ].value ); - if ( structure[ tagName ] && typeof one[ structure[ tagName ] ] !== "boolean" ) + if ( structure[ tagName ] && typeof one[ structure[ tagName ] ] !== 'boolean' ) one[ structure[ tagName ] ].appendChild( elem ); else if ( curParentNode && curParentNode.appendChild ) @@ -372,7 +372,7 @@ }; function makeMap(str){ - var obj = {}, items = str.split(","); + var obj = {}, items = str.split(','); for ( var i = 0; i < items.length; i++ ) { obj[ items[i] ] = true; obj[ items[i].toUpperCase() ] = true; @@ -805,7 +805,7 @@ } // for CommonJS enviroments, export everything - if ( typeof exports !== "undefined" ) { + if ( typeof exports !== 'undefined' ) { exports.minify = minify; } else { global.minify = minify; diff --git a/src/htmlminifier.js b/src/htmlminifier.js index 27d4ccd..2053e39 100644 --- a/src/htmlminifier.js +++ b/src/htmlminifier.js @@ -422,7 +422,7 @@ } // for CommonJS enviroments, export everything - if ( typeof exports !== "undefined" ) { + if ( typeof exports !== 'undefined' ) { exports.minify = minify; } else { global.minify = minify; diff --git a/src/htmlparser.js b/src/htmlparser.js index cc75977..2d565d9 100644 --- a/src/htmlparser.js +++ b/src/htmlparser.js @@ -40,23 +40,23 @@ endIgnore = /(%|\?)>/; // Empty Elements - HTML 4.01 - var empty = makeMap("area,base,basefont,br,col,frame,hr,img,input,isindex,link,meta,param,embed"); + var empty = makeMap('area,base,basefont,br,col,frame,hr,img,input,isindex,link,meta,param,embed'); // Block Elements - HTML 4.01 - // var block = makeMap("address,applet,blockquote,button,center,dd,del,dir,div,dl,dt,fieldset,form,frameset,hr,iframe,ins,isindex,li,map,menu,noframes,noscript,object,ol,p,pre,script,table,tbody,td,tfoot,th,thead,tr,ul"); + // var block = makeMap('address,applet,blockquote,button,center,dd,del,dir,div,dl,dt,fieldset,form,frameset,hr,iframe,ins,isindex,li,map,menu,noframes,noscript,object,ol,p,pre,script,table,tbody,td,tfoot,th,thead,tr,ul'); // Inline Elements - HTML 4.01 - var inline = makeMap("a,abbr,acronym,applet,b,basefont,bdo,big,br,button,cite,code,del,dfn,em,font,i,iframe,img,input,ins,kbd,label,map,object,q,s,samp,script,select,small,span,strike,strong,sub,sup,textarea,tt,u,var"); + var inline = makeMap('a,abbr,acronym,applet,b,basefont,bdo,big,br,button,cite,code,del,dfn,em,font,i,iframe,img,input,ins,kbd,label,map,object,q,s,samp,script,select,small,span,strike,strong,sub,sup,textarea,tt,u,var'); // Elements that you can, intentionally, leave open // (and which close themselves) - var closeSelf = makeMap("colgroup,dd,dt,li,options,p,td,tfoot,th,thead,tr,source"); + var closeSelf = makeMap('colgroup,dd,dt,li,options,p,td,tfoot,th,thead,tr,source'); - // Attributes that have their values filled in disabled="disabled" - var fillAttrs = makeMap("checked,compact,declare,defer,disabled,ismap,multiple,nohref,noresize,noshade,nowrap,readonly,selected"); + // Attributes that have their values filled in disabled='disabled' + var fillAttrs = makeMap('checked,compact,declare,defer,disabled,ismap,multiple,nohref,noresize,noshade,nowrap,readonly,selected'); // Special Elements (can contain anything) - var special = makeMap("script,style"); + var special = makeMap('script,style'); var reCache = { }, stackedTag, reStackedTag, tagMatch; @@ -73,8 +73,8 @@ if ( !stack.last() || !special[ stack.last() ] ) { // Comment: - if ( html.indexOf(""); + if ( html.indexOf(''); if ( index >= 0 ) { if ( handler.comment ) @@ -104,7 +104,7 @@ } // End tag: - else if ( html.indexOf("]*>", "i")); + reStackedTag = reCache[stackedTag] || (reCache[stackedTag] = new RegExp('([\\s\\S]*?)<\/' + stackedTag + '[^>]*>', 'i')); html = html.replace(reStackedTag, function(all, text) { if (stackedTag !== 'script' && stackedTag !== 'style') { text = text - .replace(//g, "$1") - .replace(//g, "$1"); + .replace(//g, '$1') + .replace(//g, '$1'); } if ( handler.chars ) handler.chars( text ); - return ""; + return ''; }); - parseEndTag( "", stackedTag ); + parseEndTag( '', stackedTag ); } if ( html === last ) - throw "Parse Error: " + html; + throw 'Parse Error: ' + html; last = html; } @@ -183,11 +183,11 @@ var unarySlash = false; while ( !handler.html5 && stack.last() && inline[ stack.last() ]) { - parseEndTag( "", stack.last() ); + parseEndTag( '', stack.last() ); } if ( closeSelf[ tagName ] && stack.last() === tagName ) { - parseEndTag( "", tagName ); + parseEndTag( '', tagName ); } unary = empty[ tagName ] || !!unary; @@ -205,7 +205,7 @@ var value = arguments[2] ? arguments[2] : arguments[3] ? arguments[3] : arguments[4] ? arguments[4] : - fillAttrs[name] ? name : ""; + fillAttrs[name] ? name : ''; attrs.push({ name: name, value: value, @@ -244,25 +244,25 @@ }; global.HTMLtoXML = function( html ) { - var results = ""; + var results = ''; HTMLParser(html, { start: function( tag, attrs, unary ) { - results += "<" + tag; + results += '<' + tag; for ( var i = 0; i < attrs.length; i++ ) - results += " " + attrs[i].name + '="' + attrs[i].escaped + '"'; + results += ' ' + attrs[i].name + '="' + attrs[i].escaped + '"'; - results += (unary ? "/" : "") + ">"; + results += (unary ? '/' : '') + '>'; }, end: function( tag ) { - results += ""; + results += ''; }, chars: function( text ) { results += text; }, comment: function( text ) { - results += ""; + results += ''; }, ignore: function(text) { results += text; @@ -274,21 +274,21 @@ global.HTMLtoDOM = function( html, doc ) { // There can be only one of these elements - var one = makeMap("html,head,body,title"); + var one = makeMap('html,head,body,title'); // Enforce a structure for the document var structure = { - link: "head", - base: "head" + link: 'head', + base: 'head' }; if ( !doc ) { - if ( typeof DOMDocument !== "undefined" ) + if ( typeof DOMDocument !== 'undefined' ) doc = new DOMDocument(); - else if ( typeof document !== "undefined" && document.implementation && document.implementation.createDocument ) - doc = document.implementation.createDocument("", "", null); - else if ( typeof ActiveX !== "undefined" ) - doc = new ActiveXObject("Msxml.DOMDocument"); + else if ( typeof document !== 'undefined' && document.implementation && document.implementation.createDocument ) + doc = document.implementation.createDocument('', '', null); + else if ( typeof ActiveX !== 'undefined' ) + doc = new ActiveXObject('Msxml.DOMDocument'); } else doc = doc.ownerDocument || @@ -303,11 +303,11 @@ // need to pre-populate it with the HTML document structure if ( !documentElement && doc.createElement ) { (function(){ - var html = doc.createElement("html"); - var head = doc.createElement("head"); - head.appendChild( doc.createElement("title") ); + var html = doc.createElement('html'); + var head = doc.createElement('head'); + head.appendChild( doc.createElement('title') ); html.appendChild( head ); - html.appendChild( doc.createElement("body") ); + html.appendChild( doc.createElement('body') ); doc.appendChild( html ); })(); } @@ -335,7 +335,7 @@ for ( var attr in attrs ) elem.setAttribute( attrs[ attr ].name, attrs[ attr ].value ); - if ( structure[ tagName ] && typeof one[ structure[ tagName ] ] !== "boolean" ) + if ( structure[ tagName ] && typeof one[ structure[ tagName ] ] !== 'boolean' ) one[ structure[ tagName ] ].appendChild( elem ); else if ( curParentNode && curParentNode.appendChild ) @@ -367,7 +367,7 @@ }; function makeMap(str){ - var obj = {}, items = str.split(","); + var obj = {}, items = str.split(','); for ( var i = 0; i < items.length; i++ ) { obj[ items[i] ] = true; obj[ items[i].toUpperCase() ] = true; diff --git a/tests/lint.js b/tests/lint.js index 1e4da1f..e93ccbe 100644 --- a/tests/lint.js +++ b/tests/lint.js @@ -15,10 +15,10 @@ test('lint API', function() { equal(0, lint.log.length, '`log` property exists'); - equal("function", typeof lint.populate, '`populate` method exists'); - equal("function", typeof lint.test, '`test` method exists'); - equal("function", typeof lint.testElement, '`testElement` method exists'); - equal("function", typeof lint.testAttribute, '`testAttribute` method exists'); + equal('function', typeof lint.populate, '`populate` method exists'); + equal('function', typeof lint.test, '`test` method exists'); + equal('function', typeof lint.testElement, '`testElement` method exists'); + equal('function', typeof lint.testAttribute, '`testAttribute` method exists'); }); test('deprecated element (font)', function(){