Fix JSCS warnings.
authorXhmikosR <xhmikosr@users.sourceforge.net>
Sun, 9 Mar 2014 07:49:35 +0000 (09:49 +0200)
committerXhmikosR <xhmikosr@users.sourceforge.net>
Tue, 11 Mar 2014 05:25:02 +0000 (07:25 +0200)
Gruntfile.js
master.js
src/htmllint.js
src/htmlminifier.js
src/htmlparser.js
tests/minifier.js

index 07675a4..ba89a53 100644 (file)
@@ -60,9 +60,7 @@ module.exports = function(grunt) {
         banner: '<%= banner %>'
       },
       dist: {
-        src: ['src/htmlparser.js',
-              'src/htmlminifier.js',
-              'src/htmllint.js'],
+        src: ['src/htmlparser.js', 'src/htmlminifier.js', 'src/htmllint.js'],
         dest: 'dist/htmlminifier.js'
       }
     },
@@ -82,7 +80,6 @@ module.exports = function(grunt) {
       }
     }
 
-
   });
 
   require('load-grunt-tasks')(grunt, { scope: 'devDependencies' });
index 2ac8845..b8b51ff 100644 (file)
--- a/master.js
+++ b/master.js
@@ -60,7 +60,7 @@
         lint.populate(byId('report'));
       }
     }
-    catch(err) {
+    catch (err) {
       byId('output').value = '';
       byId('stats').innerHTML = '<span class="failure">' + escapeHTML(err) + '</span>';
     }
index cbcf925..dd3d0b6 100644 (file)
     if (isDeprecatedElement(tag)) {
       this.log.push(
         '<li>Found <span class="deprecated-element">deprecated</span> <strong><code>&lt;' +
-          tag + '&gt;</code></strong> element</li>');
+          tag + '&gt;</code></strong> element</li>'
+      );
     }
     else if (isPresentationalElement(tag)) {
       this.log.push(
         '<li>Found <span class="presentational-element">presentational</span> <strong><code>&lt;' +
-          tag + '&gt;</code></strong> element</li>');
+          tag + '&gt;</code></strong> element</li>'
+      );
     }
     else {
       this.checkRepeatingElement(tag);
     if (isEventAttribute(attrName)) {
       this.log.push(
         '<li>Found <span class="event-attribute">event attribute</span> (<strong>',
-        attrName, '</strong>) on <strong><code>&lt;' + tag + '&gt;</code></strong> element</li>');
+        attrName, '</strong>) on <strong><code>&lt;' + tag + '&gt;</code></strong> element</li>'
+      );
     }
     else if (isDeprecatedAttribute(tag, attrName)) {
       this.log.push(
         '<li>Found <span class="deprecated-attribute">deprecated</span> <strong>' +
-          attrName + '</strong> attribute on <strong><code>&lt;', tag, '&gt;</code></strong> element</li>');
+          attrName + '</strong> attribute on <strong><code>&lt;', tag, '&gt;</code></strong> element</li>'
+      );
     }
     else if (isStyleAttribute(attrName)) {
       this.log.push(
-        '<li>Found <span class="style-attribute">style attribute</span> on <strong><code>&lt;', tag, '&gt;</code></strong> element</li>');
+        '<li>Found <span class="style-attribute">style attribute</span> on <strong><code>&lt;', tag, '&gt;</code></strong> element</li>'
+      );
     }
     else if (isInaccessibleAttribute(attrName, attrValue)) {
       this.log.push(
-        '<li>Found <span class="inaccessible-attribute">inaccessible attribute</span> '+
-          '(on <strong><code>&lt;', tag, '&gt;</code></strong> element)</li>');
+        '<li>Found <span class="inaccessible-attribute">inaccessible attribute</span> ' +
+          '(on <strong><code>&lt;', tag, '&gt;</code></strong> element)</li>'
+      );
     }
   };
 
index f8272bd..858caa9 100644 (file)
 
   var reStartDelimiter = {
     // account for js + html comments (e.g.: //<!--)
-    'script': /^\s*(?:\/\/)?\s*<!--.*\n?/,
-    'style': /^\s*<!--\s*/
+    script: /^\s*(?:\/\/)?\s*<!--.*\n?/,
+    style: /^\s*<!--\s*/
   };
   var reEndDelimiter = {
-    'script': /\s*(?:\/\/)?\s*-->\s*$/,
-    'style': /\s*-->\s*$/
+    script: /\s*(?:\/\/)?\s*-->\s*$/,
+    style: /\s*-->\s*$/
   };
   function removeComments(text, tag) {
     return text.replace(reStartDelimiter[tag], '').replace(reEndDelimiter[tag], '');
     return (' ' + attrFragment);
   }
 
-
   function setDefaultTesters(options) {
 
     var defaultTesters = ['canCollapseWhitespace','canTrimWhitespace'];
         if (options.removeComments) {
           if (isConditionalComment(text)) {
             text = '<!--' + cleanConditionalComment(text) + '-->';
-          } else if (isIgnoredComment(text)) {
+          }
+          else if (isIgnoredComment(text)) {
             text = '<!--' + text + '-->';
           }
           else {
   // for CommonJS enviroments, export everything
   if ( typeof exports !== 'undefined' ) {
     exports.minify = minify;
-  } else {
+  }
+  else {
     global.minify = minify;
   }
 
index 7814360..6225ebe 100644 (file)
           if ( match ) {
             html = html.substring( match[0].length );
             match[0].replace( endTag, parseEndTag );
-            prevTag = '/'+match[1];
+            prevTag = '/' + match[1];
             chars = false;
           }
 
         // Start tag:
-        } else if ( html.indexOf('<') === 0 ) {
+        }
+        else if ( html.indexOf('<') === 0 ) {
           match = html.match( startTag );
 
           if ( match ) {
           tagMatch = html.match( startTag );
           if (tagMatch) {
             nextTag = tagMatch[1];
-          } else {
+          }
+          else {
             tagMatch = html.match( endTag );
             if (tagMatch) {
-              nextTag = '/'+tagMatch[1];
-            } else {
+              nextTag = '/' + tagMatch[1];
+            }
+            else {
               nextTag = '';
             }
           }
 
         }
 
-      } else {
+      }
+      else {
 
         stackedTag = stack.last().toLowerCase();
         reStackedTag = reCache[stackedTag] || (reCache[stackedTag] = new RegExp('([\\s\\S]*?)<\/' + stackedTag + '[^>]*>', 'i'));
 
       if ( !unary ) {
         stack.push( tagName );
-      } else {
+      }
+      else {
         unarySlash = tag.match( endingSlash );
       }
 
       // If no tag name is provided, clean shop
       if ( !tagName ) {
         pos = 0;
-      } else {      // Find the closest opened tag of the same type
+      }
+      else {      // Find the closest opened tag of the same type
         for ( pos = stack.length - 1; pos >= 0; pos-- ) {
           if ( stack[ pos ] === tagName ) {
             break;
     if ( !doc ) {
       if ( typeof DOMDocument !== 'undefined' ) {
         doc = new DOMDocument();
-      } else if ( typeof document !== 'undefined' && document.implementation && document.implementation.createDocument ) {
+      }
+      else if ( typeof document !== 'undefined' && document.implementation && document.implementation.createDocument ) {
         doc = document.implementation.createDocument('', '', null);
-      } else if ( typeof ActiveX !== 'undefined' ) {
+      }
+      else if ( typeof ActiveX !== 'undefined' ) {
         doc = new ActiveXObject('Msxml.DOMDocument');
       }
 
-    } else {
+    }
+    else {
       doc = doc.ownerDocument ||
         doc.getOwnerDocument && doc.getOwnerDocument() ||
         doc;
 
         if ( structure[ tagName ] && typeof one[ structure[ tagName ] ] !== 'boolean' ) {
           one[ structure[ tagName ] ].appendChild( elem );
-        } else if ( curParentNode && curParentNode.appendChild ) {
+        }
+        else if ( curParentNode && curParentNode.appendChild ) {
           curParentNode.appendChild( elem );
         }
 
index 8e5343c..5f52892 100644 (file)
@@ -13,8 +13,8 @@
     equal(minify('<p foo-bar=baz>xxx</p>'), '<p foo-bar="baz">xxx</p>');
     equal(minify('<p foo:bar=baz>xxx</p>'), '<p foo:bar="baz">xxx</p>');
 
-    input = '<div><div><div><div><div><div><div><div><div><div>'+
-                  'i\'m 10 levels deep'+
+    input = '<div><div><div><div><div><div><div><div><div><div>' +
+                  'i\'m 10 levels deep' +
                 '</div></div></div></div></div></div></div></div></div></div>';
 
     equal(minify(input), input);
     equal(minify('<a href="#"><p>Click me</p></a>'), '<a href="#"><p>Click me</p></a>');
     equal(minify('<span><button>Hit me</button></span>'), '<span><button>Hit me</button></span>');
     equal(minify('<object type="image/svg+xml" data="image.svg"><div>[fallback image]</div></object>'),
-      '<object type="image/svg+xml" data="image.svg"><div>[fallback image]</div></object>');
+      '<object type="image/svg+xml" data="image.svg"><div>[fallback image]</div></object>'
+    );
 
     equal(minify('<ng-include src="x"></ng-include>'), '<ng-include src="x"></ng-include>');
     equal(minify('<ng:include src="x"></ng:include>'), '<ng:include src="x"></ng:include>');
     equal(minify('<ng-include src="\'views/partial-notification.html\'"></ng-include><div ng-view></div>'),
-      '<ng-include src="\'views/partial-notification.html\'"></ng-include><div ng-view=""></div>');
+      '<ng-include src="\'views/partial-notification.html\'"></ng-include><div ng-view=""></div>'
+    );
 
     // https://github.com/kangax/html-minifier/issues/41
     equal(minify('<some-tag-1></some-tag-1><some-tag-2></some-tag-2>'),
-      '<some-tag-1></some-tag-1><some-tag-2></some-tag-2>');
+      '<some-tag-1></some-tag-1><some-tag-2></some-tag-2>'
+    );
 
     // https://github.com/kangax/html-minifier/issues/40
     equal(minify('[\']["]'), '[\']["]');
     equal(minify('   <p>blah</p>\n\n\n   '), '<p>blah</p>');
     // tags from collapseWhitespaceSmart()
     ['a', 'b', 'big', 'button', 'code', 'em', 'font', 'i', 'kbd', 'mark', 'q', 's', 'small', 'span', 'strike', 'strong', 'sub', 'sup', 'time', 'tt', 'u'].forEach(function(el){
-      equal(minify('<p>foo <'+el+'>baz</'+el+'> bar</p>', {collapseWhitespace: true}), '<p>foo <'+el+'>baz</'+el+'> bar</p>');
-      equal(minify('<p>foo<'+el+'>baz</'+el+'>bar</p>', {collapseWhitespace: true}), '<p>foo<'+el+'>baz</'+el+'>bar</p>');
-      equal(minify('<p>foo <'+el+'>baz</'+el+'>bar</p>', {collapseWhitespace: true}), '<p>foo <'+el+'>baz</'+el+'>bar</p>');
-      equal(minify('<p>foo<'+el+'>baz</'+el+'> bar</p>', {collapseWhitespace: true}), '<p>foo<'+el+'>baz</'+el+'> bar</p>');
-      equal(minify('<p>foo <'+el+'> baz </'+el+'> bar</p>', {collapseWhitespace: true}), '<p>foo <'+el+'>baz</'+el+'> bar</p>');
-      equal(minify('<p>foo<'+el+'> baz </'+el+'>bar</p>', {collapseWhitespace: true}), '<p>foo<'+el+'>baz</'+el+'>bar</p>');
-      equal(minify('<p>foo <'+el+'> baz </'+el+'>bar</p>', {collapseWhitespace: true}), '<p>foo <'+el+'>baz</'+el+'>bar</p>');
-      equal(minify('<p>foo<'+el+'> baz </'+el+'> bar</p>', {collapseWhitespace: true}), '<p>foo<'+el+'>baz</'+el+'> bar</p>');
+      equal(minify('<p>foo <' + el + '>baz</' + el + '> bar</p>', { collapseWhitespace: true }), '<p>foo <' + el + '>baz</' + el + '> bar</p>');
+      equal(minify('<p>foo<' + el + '>baz</' + el + '>bar</p>', { collapseWhitespace: true }), '<p>foo<' + el + '>baz</' + el + '>bar</p>');
+      equal(minify('<p>foo <' + el + '>baz</' + el + '>bar</p>', { collapseWhitespace: true }), '<p>foo <' + el + '>baz</' + el + '>bar</p>');
+      equal(minify('<p>foo<' + el + '>baz</' + el + '> bar</p>', { collapseWhitespace: true }), '<p>foo<' + el + '>baz</' + el + '> bar</p>');
+      equal(minify('<p>foo <' + el + '> baz </' + el + '> bar</p>', { collapseWhitespace: true }), '<p>foo <' + el + '>baz</' + el + '> bar</p>');
+      equal(minify('<p>foo<' + el + '> baz </' + el + '>bar</p>', { collapseWhitespace: true }), '<p>foo<' + el + '>baz</' + el + '>bar</p>');
+      equal(minify('<p>foo <' + el + '> baz </' + el + '>bar</p>', { collapseWhitespace: true }), '<p>foo <' + el + '>baz</' + el + '>bar</p>');
+      equal(minify('<p>foo<' + el + '> baz </' + el + '> bar</p>', { collapseWhitespace: true }), '<p>foo<' + el + '>baz</' + el + '> bar</p>');
     });
-    equal(minify('<p>foo <img> bar</p>', {collapseWhitespace: true}), '<p>foo <img> bar</p>');
-    equal(minify('<p>foo<img>bar</p>', {collapseWhitespace: true}), '<p>foo<img>bar</p>');
-    equal(minify('<p>foo <img>bar</p>', {collapseWhitespace: true}), '<p>foo <img>bar</p>');
-    equal(minify('<p>foo<img> bar</p>', {collapseWhitespace: true}), '<p>foo<img> bar</p>');
+    equal(minify('<p>foo <img> bar</p>', { collapseWhitespace: true }), '<p>foo <img> bar</p>');
+    equal(minify('<p>foo<img>bar</p>', { collapseWhitespace: true }), '<p>foo<img>bar</p>');
+    equal(minify('<p>foo <img>bar</p>', { collapseWhitespace: true }), '<p>foo <img>bar</p>');
+    equal(minify('<p>foo<img> bar</p>', { collapseWhitespace: true }), '<p>foo<img> bar</p>');
   });
 
   test('doctype normalization', function() {
     input = '<!--[if IE 7]>\n\n   \t\n   \t\t ' +
               '<link rel="stylesheet" href="/css/ie7-fixes.css" type="text/css" />\n\t' +
             '<![endif]-->';
-    output = '<!--[if IE 7]>'+
-                '<link rel="stylesheet" href="/css/ie7-fixes.css" type="text/css" />'+
+    output = '<!--[if IE 7]>' +
+                '<link rel="stylesheet" href="/css/ie7-fixes.css" type="text/css" />' +
              '<![endif]-->';
     equal(minify(input, { removeComments: true }), output);
 
     input = '<p id="" class="" STYLE=" " title="\n" lang="" dir="">x</p>';
     equal(minify(input, { removeEmptyAttributes: true }), '<p>x</p>');
 
-    input = '<p onclick=""   ondblclick=" " onmousedown="" ONMOUSEUP="" onmouseover=" " onmousemove="" onmouseout="" '+
+    input = '<p onclick=""   ondblclick=" " onmousedown="" ONMOUSEUP="" onmouseover=" " onmousemove="" onmouseout="" ' +
             'onkeypress=\n\n  "\n     " onkeydown=\n"" onkeyup\n="">x</p>';
     equal(minify(input, { removeEmptyAttributes: true }), '<p>x</p>');
 
 
   test('removing optional tags in tables', function(){
 
-    input = '<table>'+
-              '<thead><tr><th>foo</th><th>bar</th></tr></thead>'+
-              '<tfoot><tr><th>baz</th><th>qux</th></tr></tfoot>'+
-              '<tbody><tr><td>boo</td><td>moo</td></tr></tbody>'+
+    input = '<table>' +
+              '<thead><tr><th>foo</th><th>bar</th></tr></thead>' +
+              '<tfoot><tr><th>baz</th><th>qux</th></tr></tfoot>' +
+              '<tbody><tr><td>boo</td><td>moo</td></tr></tbody>' +
             '</table>';
 
-    output = '<table>'+
-              '<thead><tr><th>foo<th>bar'+
-              '<tfoot><tr><th>baz<th>qux'+
-              '<tbody><tr><td>boo<td>moo'+
+    output = '<table>' +
+              '<thead><tr><th>foo<th>bar' +
+              '<tfoot><tr><th>baz<th>qux' +
+              '<tbody><tr><td>boo<td>moo' +
              '</table>';
 
     equal(minify(input, { removeOptionalTags: true }), output);
 
     // example from htmldog.com
     input = '<select name="catsndogs">' +
-              '<optgroup label="Cats">'+
-                '<option>Tiger</option><option>Leopard</option><option>Lynx</option>'+
+              '<optgroup label="Cats">' +
+                '<option>Tiger</option><option>Leopard</option><option>Lynx</option>' +
               '</optgroup>' +
-              '<optgroup label="Dogs">'+
-                '<option>Grey Wolf</option><option>Red Fox</option><option>Fennec</option>'+
+              '<optgroup label="Dogs">' +
+                '<option>Grey Wolf</option><option>Red Fox</option><option>Fennec</option>' +
               '</optgroup>' +
             '</select>';
 
     output = '<select name="catsndogs">' +
-              '<optgroup label="Cats">'+
-                '<option>Tiger<option>Leopard<option>Lynx'+
+              '<optgroup label="Cats">' +
+                '<option>Tiger<option>Leopard<option>Lynx' +
               '</optgroup>' +
-              '<optgroup label="Dogs">'+
-                '<option>Grey Wolf<option>Red Fox<option>Fennec'+
+              '<optgroup label="Dogs">' +
+                '<option>Grey Wolf<option>Red Fox<option>Fennec' +
               '</optgroup>' +
             '</select>';
 
 
   test('source', function() {
 
-    input = '<audio controls="controls">'+
-              '<source src="foo.wav">'+
-              '<source src="far.wav">'+
-              '<source src="foobar.wav">'+
+    input = '<audio controls="controls">' +
+              '<source src="foo.wav">' +
+              '<source src="far.wav">' +
+              '<source src="foobar.wav">' +
             '</audio>';
-    output = '<audio controls="controls">'+
-              '<source src="foo.wav">'+
-              '<source src="far.wav">'+
-              '<source src="foobar.wav">'+
+    output = '<audio controls="controls">' +
+              '<source src="foo.wav">' +
+              '<source src="far.wav">' +
+              '<source src="foobar.wav">' +
             '</audio>';
 
     equal(minify(input, { removeOptionalTags: true }), output);