Enable JSHint's `quotmark` rule.
authorXhmikosR <xhmikosr@users.sourceforge.net>
Tue, 18 Feb 2014 17:39:47 +0000 (19:39 +0200)
committerXhmikosR <xhmikosr@users.sourceforge.net>
Tue, 18 Feb 2014 17:43:19 +0000 (19:43 +0200)
.jshintrc
dist/htmlminifier.js
src/htmlminifier.js
src/htmlparser.js
tests/lint.js

index eec9331..b16e44f 100644 (file)
--- a/.jshintrc
+++ b/.jshintrc
@@ -10,6 +10,7 @@
   "loopfunc":   true,
   "newcap":     false,
   "node":       true,
+  "quotmark":   "single",
   "strict":     false,
   "undef":      true,
   "unused":     true
index 45601d9..c48692b 100644 (file)
       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("<!--") === 0 ) {
-          index = html.indexOf("-->");
+        if ( html.indexOf('<!--') === 0 ) {
+          index = html.indexOf('-->');
 
           if ( index >= 0 ) {
             if ( handler.comment )
         }
 
         // End tag:
-        else if ( html.indexOf("</") === 0 ) {
+        else if ( html.indexOf('</') === 0 ) {
           match = html.match( endTag );
 
           if ( match ) {
           }
 
         // Start tag:
-        } else if ( html.indexOf("<") === 0 ) {
+        } else if ( html.indexOf('<') === 0 ) {
           match = html.match( startTag );
 
           if ( match ) {
         }
 
         if ( chars ) {
-          index = html.indexOf("<");
+          index = html.indexOf('<');
 
           var text = index < 0 ? html : html.substring( 0, index );
-          html = index < 0 ? "" : html.substring( index );
+          html = index < 0 ? '' : html.substring( index );
 
           // next tag
           tagMatch = html.match( startTag );
       } else {
 
         stackedTag = stack.last().toLowerCase();
-        reStackedTag = reCache[stackedTag] || (reCache[stackedTag] = new RegExp("([\\s\\S]*?)<\/" + stackedTag + "[^>]*>", "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(/<!--([\s\S]*?)-->/g, "$1")
-              .replace(/<!\[CDATA\[([\s\S]*?)\]\]>/g, "$1");
+              .replace(/<!--([\s\S]*?)-->/g, '$1')
+              .replace(/<!\[CDATA\[([\s\S]*?)\]\]>/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;
     }
 
       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;
           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,
   };
 
   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 += "</" + tag + ">";
+        results += '</' + tag + '>';
       },
       chars: function( text ) {
         results += text;
       },
       comment: function( text ) {
-        results += "<!--" + text + "-->";
+        results += '<!--' + text + '-->';
       },
       ignore: function(text) {
         results += text;
 
   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 ||
     // 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 );
       })();
     }
         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 )
   };
 
   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;
   }
 
   // for CommonJS enviroments, export everything
-  if ( typeof exports !== "undefined" ) {
+  if ( typeof exports !== 'undefined' ) {
     exports.minify = minify;
   } else {
     global.minify = minify;
index 27d4ccd..2053e39 100644 (file)
   }
 
   // for CommonJS enviroments, export everything
-  if ( typeof exports !== "undefined" ) {
+  if ( typeof exports !== 'undefined' ) {
     exports.minify = minify;
   } else {
     global.minify = minify;
index cc75977..2d565d9 100644 (file)
       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("<!--") === 0 ) {
-          index = html.indexOf("-->");
+        if ( html.indexOf('<!--') === 0 ) {
+          index = html.indexOf('-->');
 
           if ( index >= 0 ) {
             if ( handler.comment )
         }
 
         // End tag:
-        else if ( html.indexOf("</") === 0 ) {
+        else if ( html.indexOf('</') === 0 ) {
           match = html.match( endTag );
 
           if ( match ) {
           }
 
         // Start tag:
-        } else if ( html.indexOf("<") === 0 ) {
+        } else if ( html.indexOf('<') === 0 ) {
           match = html.match( startTag );
 
           if ( match ) {
         }
 
         if ( chars ) {
-          index = html.indexOf("<");
+          index = html.indexOf('<');
 
           var text = index < 0 ? html : html.substring( 0, index );
-          html = index < 0 ? "" : html.substring( index );
+          html = index < 0 ? '' : html.substring( index );
 
           // next tag
           tagMatch = html.match( startTag );
       } else {
 
         stackedTag = stack.last().toLowerCase();
-        reStackedTag = reCache[stackedTag] || (reCache[stackedTag] = new RegExp("([\\s\\S]*?)<\/" + stackedTag + "[^>]*>", "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(/<!--([\s\S]*?)-->/g, "$1")
-              .replace(/<!\[CDATA\[([\s\S]*?)\]\]>/g, "$1");
+              .replace(/<!--([\s\S]*?)-->/g, '$1')
+              .replace(/<!\[CDATA\[([\s\S]*?)\]\]>/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;
     }
 
       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;
           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,
   };
 
   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 += "</" + tag + ">";
+        results += '</' + tag + '>';
       },
       chars: function( text ) {
         results += text;
       },
       comment: function( text ) {
-        results += "<!--" + text + "-->";
+        results += '<!--' + text + '-->';
       },
       ignore: function(text) {
         results += text;
 
   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 ||
     // 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 );
       })();
     }
         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 )
   };
 
   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;
index 1e4da1f..e93ccbe 100644 (file)
 
   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(){