Enable `requireSpacesInFunctionExpression`.
authorXhmikosR <xhmikosr@users.sourceforge.net>
Sun, 9 Mar 2014 12:25:21 +0000 (14:25 +0200)
committerXhmikosR <xhmikosr@users.sourceforge.net>
Tue, 11 Mar 2014 05:25:03 +0000 (07:25 +0200)
.jscsrc
dist/htmlminifier.js
master.js
src/htmlminifier.js
src/htmlparser.js
test.js
tests/lint.js
tests/minifier.js

diff --git a/.jscsrc b/.jscsrc
index 2376224..2058190 100644 (file)
--- a/.jscsrc
+++ b/.jscsrc
@@ -2,7 +2,8 @@
     "requireCurlyBraces": ["if", "else", "for", "while", "do", "switch", "return", "try", "catch"],
     "requireSpaceAfterBinaryOperators": ["+", "-", "*", "=", "==", "===", "!=", "!=="],
     "requireSpaceAfterKeywords": ["if", "else", "for", "while", "do", "switch", "return", "try", "catch"],
-    "requireSpaceBeforeBinaryOperators": ["+", "-", "*", "=", "==", "===", "!=", "!=="],
+    "requireSpaceBeforeBinaryOperators": ["+", "-", "/", "*", "=", "==", "===", "!=", "!==", ">", "<", ">=", "<="],
+    "requireSpacesInFunctionExpression": { "beforeOpeningCurlyBrace": true },
 
     "requireCamelCaseOrUpperCaseIdentifiers": true,
     "requireCapitalizedConstructors": true,
index 02a6b2d..157296c 100644 (file)
@@ -33,7 +33,7 @@
 
  /* global ActiveXObject, DOMDocument */
 
-(function(global){
+(function(global) {
   'use strict';
 
   // Regular Expressions for parsing tags and attributes
   // Special Elements (can contain anything)
   var special = makeMap('script,style');
 
-  var reCache = { }, stackedTag, reStackedTag, tagMatch;
+  var reCache = {}, stackedTag, reStackedTag, tagMatch;
 
   var HTMLParser = global.HTMLParser = function( html, handler ) {
     var index, chars, match, stack = [], last = html, prevTag, nextTag;
-    stack.last = function(){
+    stack.last = function() {
       return this[ this.length - 1 ];
     };
 
     // If we're dealing with an empty document then we
     // need to pre-populate it with the HTML document structure
     if ( !documentElement && doc.createElement ) {
-      (function(){
+      (function() {
         var html = doc.createElement('html');
         var head = doc.createElement('head');
         head.appendChild( doc.createElement('title') );
     return doc;
   };
 
-  function makeMap(str){
+  function makeMap(str) {
     var obj = {}, items = str.split(',');
     for ( var i = 0; i < items.length; i++ ) {
       obj[ items[i] ] = true;
   }
 })(typeof exports === 'undefined' ? this : exports);
 
-(function(global){
+(function(global) {
   'use strict';
 
   var log, HTMLParser;
     };
   }
   else {
-    log = function()};
+    log = function() {};
   }
 
   if (global.HTMLParser) {
 
   function minify(value, options) {
 
-    options = options || { };
+    options = options || {};
     value = trimWhitespace(value);
     setDefaultTesters(options);
 
index b8b51ff..bc37a5a 100644 (file)
--- a/master.js
+++ b/master.js
@@ -1,5 +1,5 @@
 /* global HTMLLint, minify */
-(function(){
+(function() {
   'use strict';
 
   function byId(id) {
index 858caa9..b609be5 100644 (file)
@@ -1,4 +1,4 @@
-(function(global){
+(function(global) {
   'use strict';
 
   var log, HTMLParser;
@@ -9,7 +9,7 @@
     };
   }
   else {
-    log = function()};
+    log = function() {};
   }
 
   if (global.HTMLParser) {
 
   function minify(value, options) {
 
-    options = options || { };
+    options = options || {};
     value = trimWhitespace(value);
     setDefaultTesters(options);
 
index 6225ebe..d11272b 100644 (file)
@@ -28,7 +28,7 @@
 
  /* global ActiveXObject, DOMDocument */
 
-(function(global){
+(function(global) {
   'use strict';
 
   // Regular Expressions for parsing tags and attributes
   // Special Elements (can contain anything)
   var special = makeMap('script,style');
 
-  var reCache = { }, stackedTag, reStackedTag, tagMatch;
+  var reCache = {}, stackedTag, reStackedTag, tagMatch;
 
   var HTMLParser = global.HTMLParser = function( html, handler ) {
     var index, chars, match, stack = [], last = html, prevTag, nextTag;
-    stack.last = function(){
+    stack.last = function() {
       return this[ this.length - 1 ];
     };
 
     // If we're dealing with an empty document then we
     // need to pre-populate it with the HTML document structure
     if ( !documentElement && doc.createElement ) {
-      (function(){
+      (function() {
         var html = doc.createElement('html');
         var head = doc.createElement('head');
         head.appendChild( doc.createElement('title') );
     return doc;
   };
 
-  function makeMap(str){
+  function makeMap(str) {
     var obj = {}, items = str.split(',');
     for ( var i = 0; i < items.length; i++ ) {
       obj[ items[i] ] = true;
diff --git a/test.js b/test.js
index 7aaa783..e996399 100644 (file)
--- a/test.js
+++ b/test.js
@@ -12,7 +12,7 @@ testrunner.run({
     './tests/lint.js',
   ]
 }, function(err, report) {
-  if(report.failed > 0){
+  if(report.failed > 0) {
     process.on('exit', function() {
       process.exit(1);
     });
index 8588afc..429e9fb 100644 (file)
@@ -1,5 +1,5 @@
 /* global test, ok, equal */
-(function(global){
+(function(global) {
   'use strict';
 
   var minify = global.minify || require('../dist/htmlminifier.js').minify,
@@ -22,7 +22,7 @@
     equal('function', typeof lint.testAttribute, '`testAttribute` method exists');
   });
 
-  test('deprecated element (font)', function(){
+  test('deprecated element (font)', function() {
     minify('<font>foo</font>', { lint: lint });
     var log = lint.log.join('');
 
index 5f52892..9535af0 100644 (file)
@@ -1,5 +1,5 @@
 /* global test, ok, equal */
-(function(global){
+(function(global) {
   'use strict';
 
   var minify = global.minify || require('../dist/htmlminifier.js').minify,
     equal(minify('<input title="bar"       id="boo"    value="hello world">'), '<input title="bar" id="boo" value="hello world">');
   });
 
-  test('space normalization around text', function(){
+  test('space normalization around text', function() {
     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){
+    ['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(input, { useShortDoctype: false }), input);
   });
 
-  test('removing comments', function(){
+  test('removing comments', function() {
     input = '<!-- test -->';
     equal(minify(input, { removeComments: true }), '');
 
     equal(minify(input, { removeComments: true }), '<style><!-- alert(1) --><\/style>');
   });
 
-  test('ignoring comments', function(){
+  test('ignoring comments', function() {
     input = '<!--! test -->';
     equal(minify(input, { removeComments: true }), input);
     equal(minify(input, { removeComments: false }), input);
     equal(minify(input, { removeComments: true }), input);
   });
 
-  test('conditional comments', function(){
+  test('conditional comments', function() {
     input = '<!--[if IE 6]>test<![endif]-->';
     equal(minify(input, { removeComments: true }), input);
 
     equal(minify(input, { removeComments: true }), input);
   });
 
-  test('collapsing space in conditional comments', function(){
+  test('collapsing space in conditional comments', 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]-->';
     equal(minify(input, { removeComments: true }), output);
   });
 
-  test('remove comments from scripts', function(){
+  test('remove comments from scripts', function() {
     input = '<script><!--alert(1)--><\/script>';
     output = '<script><\/script>';
     equal(minify(input, { removeCommentsFromCDATA: true }), output);
     equal(minify(input, { removeCommentsFromCDATA: true }), output);
   });
 
-  test('remove comments from styles', function(){
+  test('remove comments from styles', function() {
     input = '<style type="text/css"><!-- p { color: red } --><\/style>';
     output = '<style type="text/css">p { color: red }<\/style>';
     equal(minify(input, { removeCommentsFromCDATA: true }), output);
     equal(minify(input, { removeCommentsFromCDATA: true }), input);
   });
 
-  test('remove CDATA sections from scripts/styles', function(){
+  test('remove CDATA sections from scripts/styles', function() {
     input = '<script>/*<![CDATA[*/alert(1)/*]]>*/<\/script>';
     output = '<script>alert(1)<\/script>';
     equal(minify(input, { removeCDATASectionsFromCDATA: true }), output);
 
   });
 
-  test('empty attributes', function(){
+  test('empty attributes', function() {
     input = '<p id="" class="" STYLE=" " title="\n" lang="" dir="">x</p>';
     equal(minify(input, { removeEmptyAttributes: true }), '<p>x</p>');
 
     equal(minify(input, { removeEmptyAttributes: true }), '<img src="" alt="">');
   });
 
-  test('cleaning class/style attributes', function(){
+  test('cleaning class/style attributes', function() {
     input = '<p class=" foo bar  ">foo bar baz</p>', output;
     equal(minify(input, { cleanAttributes: true }), '<p class="foo bar">foo bar baz</p>');
 
     equal(minify(input, { cleanAttributes: true }), output);
   });
 
-  test('cleaning URI-based attributes', function(){
+  test('cleaning URI-based attributes', function() {
     input = '<a href="   http://example.com  ">x</a>';
     output = '<a href="http://example.com">x</a>';
     equal(minify(input, { cleanAttributes: true }), output);
     equal(minify(input, { cleanAttributes: true }), output);
   });
 
-  test('removing redundant attributes (&lt;form method="get" ...>)', function(){
+  test('removing redundant attributes (&lt;form method="get" ...>)', function() {
     input = '<form method="get">hello world</form>';
     equal(minify(input, { removeRedundantAttributes: true }), '<form>hello world</form>');
 
     equal(minify(input, { removeRedundantAttributes: true }), '<form method="post">hello world</form>');
   });
 
-  test('removing redundant attributes (&lt;input type="text" ...>)', function(){
+  test('removing redundant attributes (&lt;input type="text" ...>)', function() {
     input = '<input type="text">';
     equal(minify(input, { removeRedundantAttributes: true }), '<input>');
 
     equal(minify(input, { removeRedundantAttributes: true }), '<input type="checkbox">');
   });
 
-  test('removing redundant attributes (&lt;a name="..." id="..." ...>)', function(){
+  test('removing redundant attributes (&lt;a name="..." id="..." ...>)', function() {
     input = '<a id="foo" name="foo">blah</a>';
     equal(minify(input, { removeRedundantAttributes: true }), '<a id="foo">blah</a>');
 
     equal(minify(input, { removeRedundantAttributes: true }), '<a href="..." id="bar">blah</a>');
   });
 
-  test('removing redundant attributes (&lt;script src="..." charset="...">)', function(){
+  test('removing redundant attributes (&lt;script src="..." charset="...">)', function() {
     input = '<script type="text/javascript" charset="UTF-8">alert(222);<\/script>';
     output = '<script type="text/javascript">alert(222);<\/script>';
     equal(minify(input, { removeRedundantAttributes: true }), output);
     equal(minify(input, { removeRedundantAttributes: true }), output);
   });
 
-  test('removing redundant attributes (&lt;... language="javascript" ...>)', function(){
+  test('removing redundant attributes (&lt;... language="javascript" ...>)', function() {
     input = '<script language="Javascript">x=2,y=4<\/script>';
     equal(minify(input, { removeRedundantAttributes: true }), '<script>x=2,y=4<\/script>');
 
     equal(minify(input, { removeRedundantAttributes: true }), '<script>x=2,y=4<\/script>');
   });
 
-  test('removing redundant attributes (&lt;area shape="rect" ...>)', function(){
+  test('removing redundant attributes (&lt;area shape="rect" ...>)', function() {
     input = '<area shape="rect" coords="696,25,958,47" href="#" title="foo">';
     output = '<area coords="696,25,958,47" href="#" title="foo">';
     equal(minify(input, { removeRedundantAttributes: true }), output);
   });
 
-  test('removing redundant attributes (&lt;... = "javascript: ..." ...>)', function(){
+  test('removing redundant attributes (&lt;... = "javascript: ..." ...>)', function() {
     input = '<p onclick="javascript:alert(1)">x</p>';
     equal(minify(input, { cleanAttributes: true }), '<p onclick="alert(1)">x</p>');
 
     input = '<p onclick=" JavaScript: x">x</p>';
     equal(minify(input, { cleanAttributes: true }), '<p onclick="x">x</p>');
 
-    input = '<p title="javascript:(function(){ /* some stuff here */ })()">x</p>';
+    input = '<p title="javascript:(function() { /* some stuff here */ })()">x</p>';
     equal(minify(input, { cleanAttributes: true }), input);
   });
 
-  test('removing type="text/javascript" attributes', function(){
+  test('removing type="text/javascript" attributes', function() {
     input = '<script type="text/javascript">alert(1)<\/script>';
     output = '<script>alert(1)<\/script>';
 
     equal(minify(input, { removeScriptTypeAttributes: true }), output);
   });
 
-  test('removing type="text/css" attributes', function(){
+  test('removing type="text/css" attributes', function() {
     input = '<style type="text/css">.foo { color: red }<\/style>';
     output = '<style>.foo { color: red }<\/style>';
 
     equal(minify(input, { removeStyleLinkTypeAttributes: true }), input);
   });
 
-  test('removing attribute quotes', function(){
+  test('removing attribute quotes', function() {
     input = '<p title="blah" class="a23B-foo.bar_baz:qux" id="moo">foo</p>';
     equal(minify(input, { removeAttributeQuotes: true }), '<p title=blah class=a23B-foo.bar_baz:qux id=moo>foo</p>');
 
     equal(minify(input, { removeEmptyElements: true }), output);
   });
 
-  test('collapsing boolean attributes', function(){
+  test('collapsing boolean attributes', function() {
     input = '<input disabled="disabled">';
     equal(minify(input, { collapseBooleanAttributes: true }), '<input disabled>');
 
     equal(minify(input, { collapseBooleanAttributes: true }), '<input multiple>');
   });
 
-  test('keeping trailing slashes in tags', function(){
+  test('keeping trailing slashes in tags', function() {
     equal(minify('<img src="test"/>', { keepClosingSlash: true }), '<img src="test"/>');
   });
 
-  test('removing optional tags', function(){
+  test('removing optional tags', function() {
     input = '<html><head><title>hello</title></head><body><p>foo<span>bar</span></p></body></html>';
     output = '<html><head><title>hello</title><body><p>foo<span>bar</span></p>';
     equal(minify(input, { removeOptionalTags: true }), output);
     equal(minify(input), input);
   });
 
-  test('removing optional tags in tables', function(){
+  test('removing optional tags in tables', function() {
 
     input = '<table>' +
               '<thead><tr><th>foo</th><th>bar</th></tr></thead>' +
     equal(minify(input), input);
   });
 
-  test('removing optional tags in options', function(){
+  test('removing optional tags in options', function() {
     input = '<select><option>foo</option><option>bar</option></select>';
     output = '<select><option>foo<option>bar</select>';
     equal(minify(input, { removeOptionalTags: true }), output);
     equal(minify(input, { removeOptionalTags: true }), output);
   });
 
-  test('custom components', function(){
+  test('custom components', function() {
     input = '<custom-component>Oh, my.</custom-component>';
     output = '<custom-component>Oh, my.</custom-component>';
 
     equal(minify(input), output);
   });
 
-  test('HTML4: anchor with block elements', function(){
+  test('HTML4: anchor with block elements', function() {
     input = '<a href="#"><div>Well, look at me! I\'m a div!</div></a>';
     output = '<a href="#"></a><div>Well, look at me! I\'m a div!</div>';
 
     equal(minify(input, { html5: false }), output);
   });
 
-  test('HTML5: anchor with block elements', function(){
+  test('HTML5: anchor with block elements', function() {
     input = '<a href="#"><div>Well, look at me! I\'m a div!</div></a>';
     output = '<a href="#"><div>Well, look at me! I\'m a div!</div></a>';
 
     equal(minify(input, { html5: true }), output);
   });
 
-  test('HTML5: enabled by default', function(){
+  test('HTML5: enabled by default', function() {
     input = '<a href="#"><div>Well, look at me! I\'m a div!</div></a>';
 
     equal(minify(input, { html5: true }), minify(input));