Update JSCS config.
authorXhmikosR <xhmikosr@gmail.com>
Wed, 24 Dec 2014 16:17:14 +0000 (18:17 +0200)
committerXhmikosR <xhmikosr@gmail.com>
Wed, 24 Dec 2014 16:45:51 +0000 (18:45 +0200)
.jscsrc
cli.js
dist/htmlminifier.js
src/htmlminifier.js
tests/minifier.js

diff --git a/.jscsrc b/.jscsrc
index 1429c95..a7ce4ee 100644 (file)
--- a/.jscsrc
+++ b/.jscsrc
@@ -1,9 +1,11 @@
 {
-    "requireCurlyBraces": ["if", "else", "for", "while", "do", "switch", "return", "try", "catch"],
+    "requireCurlyBraces": ["if", "else", "for", "while", "do", "switch", "try", "catch"],
     "requireSpaceAfterBinaryOperators": ["+", "-", "/", "*", "=", "==", "===", "!=", "!==", ">", "<", ">=", "<="],
     "requireSpaceAfterKeywords": ["if", "else", "for", "while", "do", "switch", "return", "try", "catch"],
     "requireSpaceBeforeBinaryOperators": ["+", "-", "/", "*", "=", "==", "===", "!=", "!==", ">", "<", ">=", "<="],
     "requireSpacesInFunctionExpression": { "beforeOpeningCurlyBrace": true },
+    //"requireOperatorBeforeLineBreak": ["+", "-", "/", "*", "=", "==", "===", "!=", "!==", ">", "<", ">=", "<="],
+    "requireSpacesInConditionalExpression": true,
 
     "requireCapitalizedConstructors": true,
     "requireCommaBeforeLineBreak": true,
@@ -17,8 +19,7 @@
     "disallowQuotedKeysInObjects": "allButReserved",
     "disallowSpaceAfterObjectKeys": true,
 
-    "disallowSpaceAfterPrefixUnaryOperators": ["!"],
-    "disallowSpaceBeforeBinaryOperators": [","],
+    //"disallowSpaceBeforeBinaryOperators": [","],
     "disallowSpaceAfterPrefixUnaryOperators": ["++", "--", "+", "-", "~", "!"],
     "disallowSpaceBeforePostfixUnaryOperators": ["++", "--"],
 
     "disallowMixedSpacesAndTabs": true,
     //"disallowMultipleLineBreaks": true,
     "disallowMultipleLineStrings": true,
+    //"disallowMultipleVarDecl": true,
+    "disallowSpacesInCallExpression": true,
     "disallowTrailingWhitespace": true,
 
     "validateIndentation": 2,
     "validateLineBreaks": "LF",
+    "validateParameterSeparator": ", ",
     "validateQuoteMarks": "'",
 
     "safeContextKeyword": "_this"
diff --git a/cli.js b/cli.js
index 361268e..2e1c62f 100755 (executable)
--- a/cli.js
+++ b/cli.js
@@ -223,7 +223,9 @@ cli.main(function(args, options) {
     process.stderr.write('Error: Minification error');
   }
 
-  minifyOptions.lint && minifyOptions.lint.populate();
+  if (minifyOptions.lint) {
+    minifyOptions.lint.populate();
+  }
 
   if (minified !== null) {
     // Write the output
index 1eb4f72..c51146a 100644 (file)
     lineBreakStamp = 'htmlmincollapsedlinebreak';
 
     if (prevTag && prevTag !== 'img' && prevTag !== 'input' && (prevTag.substr(0, 1) !== '/'
-      || ( prevTag.substr(0, 1) === '/' && tags.indexOf(prevTag.substr(1)) === -1))) {
+      || (prevTag.substr(0, 1) === '/' && tags.indexOf(prevTag.substr(1)) === -1))) {
       str = str.replace(/^\s+/, options.conservativeCollapse ? ' ' : options.preserveLineBreaks ? preserveBefore : '');
     }
 
     if (nextTag && nextTag !== 'img' && nextTag !== 'input' && (nextTag.substr(0, 1) === '/'
-      || ( nextTag.substr(0, 1) !== '/' && tags.indexOf(nextTag) === -1))) {
+      || (nextTag.substr(0, 1) !== '/' && tags.indexOf(nextTag) === -1))) {
       str = str.replace(/\s+$/, options.conservativeCollapse ? ' ' : options.preserveLineBreaks ? preserveAfter : '');
     }
 
 
   function canRemoveAttributeQuotes(value) {
     // http://mathiasbynens.be/notes/unquoted-attribute-values
-    return (/^[^\x20\t\n\f\r"'`=<>]+$/).test(value) && !(/\/$/ ).test(value) &&
+    return (/^[^\x20\t\n\f\r"'`=<>]+$/).test(value) && !(/\/$/).test(value) &&
     // make sure trailing slash is not interpreted as HTML self-closing tag
         !(/\/$/).test(value);
   }
 
   function attributesInclude(attributes, attribute) {
-    for (var i = attributes.length; i--; ) {
+    for (var i = attributes.length; i--;) {
       if (attributes[i].name.toLowerCase() === attribute) {
         return true;
       }
     new HTMLParser(value, {
       html5: typeof options.html5 !== 'undefined' ? options.html5 : true,
 
-      start: function( tag, attrs, unary, unarySlash ) {
+      start: function(tag, attrs, unary, unarySlash) {
         if (isIgnoring) {
           buffer.push('<' + tag, attrsToMarkup(attrs), unarySlash ? '/' : '', '>');
           return;
 
         var openTag = '<' + tag;
         var closeTag = ((unarySlash && options.keepClosingSlash) ? '/' : '') + '>';
-        if ( attrs.length === 0) {
+        if (attrs.length === 0) {
           openTag += closeTag;
         }
 
         buffer.push(openTag);
 
-        lint && lint.testElement(tag);
+        if (lint) {
+          lint.testElement(tag);
+        }
 
         var token;
-        for ( var i = 0, len = attrs.length; i < len; i++ ) {
-          lint && lint.testAttribute(tag, attrs[i].name.toLowerCase(), attrs[i].escaped);
+        for (var i = 0, len = attrs.length; i < len; i++) {
+          if (lint) {
+            lint.testAttribute(tag, attrs[i].name.toLowerCase(), attrs[i].escaped);
+          }
           token = normalizeAttribute(attrs[i], attrs, tag, unarySlash, i, options);
-          if ( i === len - 1 ) {
+          if (i === len - 1) {
             token += closeTag;
           }
           buffer.push(token);
         }
       },
-      end: function( tag, attrs ) {
+      end: function(tag, attrs) {
 
         if (isIgnoring) {
           buffer.push('</' + tag + '>');
         var isElementEmpty = currentChars === '' && tag === currentTag;
         if ((options.removeEmptyElements && isElementEmpty && canRemoveElement(tag, attrs))) {
           // remove last "element" from buffer, return
-          for ( var i = buffer.length - 1; i >= 0; i-- ) {
-            if ( /^<[^\/!]/.test(buffer[i]) ) {
+          for (var i = buffer.length - 1; i >= 0; i--) {
+            if (/^<[^\/!]/.test(buffer[i])) {
               buffer.splice(i);
               break;
             }
         buffer.length = 0;
         currentChars = '';
       },
-      chars: function( text, prevTag, nextTag ) {
+      chars: function(text, prevTag, nextTag) {
         prevTag = prevTag === '' ? 'comment' : prevTag;
         nextTag = nextTag === '' ? 'comment' : nextTag;
 
           }
         }
         currentChars = text;
-        lint && lint.testChars(text);
+        if (lint) {
+          lint.testChars(text);
+        }
         buffer.push(text);
       },
-      comment: function( text, nonStandard ) {
+      comment: function(text, nonStandard) {
 
         var prefix = nonStandard ? '<!' : '<!--';
         var suffix = nonStandard ? '>' : '-->';
     return str;
   }
 
-  function joinResultSegments( results, options ) {
+  function joinResultSegments(results, options) {
     var str;
     var maxLineLength = options.maxLineLength;
-    if ( maxLineLength ) {
+    if (maxLineLength) {
       var token;
       var lines = [];
       var line = '';
-      for ( var i = 0, len = results.length; i < len; i++ ) {
+      for (var i = 0, len = results.length; i < len; i++) {
         token = results[i];
-        if ( line.length + token.length < maxLineLength ) {
+        if (line.length + token.length < maxLineLength) {
           line += token;
         }
         else {
   }
 
   // for CommonJS enviroments, export everything
-  if ( typeof exports !== 'undefined' ) {
+  if (typeof exports !== 'undefined') {
     exports.minify = minify;
   }
   else {
index d49387f..de6abd4 100644 (file)
     lineBreakStamp = 'htmlmincollapsedlinebreak';
 
     if (prevTag && prevTag !== 'img' && prevTag !== 'input' && (prevTag.substr(0, 1) !== '/'
-      || ( prevTag.substr(0, 1) === '/' && tags.indexOf(prevTag.substr(1)) === -1))) {
+      || (prevTag.substr(0, 1) === '/' && tags.indexOf(prevTag.substr(1)) === -1))) {
       str = str.replace(/^\s+/, options.conservativeCollapse ? ' ' : options.preserveLineBreaks ? preserveBefore : '');
     }
 
     if (nextTag && nextTag !== 'img' && nextTag !== 'input' && (nextTag.substr(0, 1) === '/'
-      || ( nextTag.substr(0, 1) !== '/' && tags.indexOf(nextTag) === -1))) {
+      || (nextTag.substr(0, 1) !== '/' && tags.indexOf(nextTag) === -1))) {
       str = str.replace(/\s+$/, options.conservativeCollapse ? ' ' : options.preserveLineBreaks ? preserveAfter : '');
     }
 
 
   function canRemoveAttributeQuotes(value) {
     // http://mathiasbynens.be/notes/unquoted-attribute-values
-    return (/^[^\x20\t\n\f\r"'`=<>]+$/).test(value) && !(/\/$/ ).test(value) &&
+    return (/^[^\x20\t\n\f\r"'`=<>]+$/).test(value) && !(/\/$/).test(value) &&
     // make sure trailing slash is not interpreted as HTML self-closing tag
         !(/\/$/).test(value);
   }
 
   function attributesInclude(attributes, attribute) {
-    for (var i = attributes.length; i--; ) {
+    for (var i = attributes.length; i--;) {
       if (attributes[i].name.toLowerCase() === attribute) {
         return true;
       }
     new HTMLParser(value, {
       html5: typeof options.html5 !== 'undefined' ? options.html5 : true,
 
-      start: function( tag, attrs, unary, unarySlash ) {
+      start: function(tag, attrs, unary, unarySlash) {
         if (isIgnoring) {
           buffer.push('<' + tag, attrsToMarkup(attrs), unarySlash ? '/' : '', '>');
           return;
 
         var openTag = '<' + tag;
         var closeTag = ((unarySlash && options.keepClosingSlash) ? '/' : '') + '>';
-        if ( attrs.length === 0) {
+        if (attrs.length === 0) {
           openTag += closeTag;
         }
 
         buffer.push(openTag);
 
-        lint && lint.testElement(tag);
+        if (lint) {
+          lint.testElement(tag);
+        }
 
         var token;
-        for ( var i = 0, len = attrs.length; i < len; i++ ) {
-          lint && lint.testAttribute(tag, attrs[i].name.toLowerCase(), attrs[i].escaped);
+        for (var i = 0, len = attrs.length; i < len; i++) {
+          if (lint) {
+            lint.testAttribute(tag, attrs[i].name.toLowerCase(), attrs[i].escaped);
+          }
           token = normalizeAttribute(attrs[i], attrs, tag, unarySlash, i, options);
-          if ( i === len - 1 ) {
+          if (i === len - 1) {
             token += closeTag;
           }
           buffer.push(token);
         }
       },
-      end: function( tag, attrs ) {
+      end: function(tag, attrs) {
 
         if (isIgnoring) {
           buffer.push('</' + tag + '>');
         var isElementEmpty = currentChars === '' && tag === currentTag;
         if ((options.removeEmptyElements && isElementEmpty && canRemoveElement(tag, attrs))) {
           // remove last "element" from buffer, return
-          for ( var i = buffer.length - 1; i >= 0; i-- ) {
-            if ( /^<[^\/!]/.test(buffer[i]) ) {
+          for (var i = buffer.length - 1; i >= 0; i--) {
+            if (/^<[^\/!]/.test(buffer[i])) {
               buffer.splice(i);
               break;
             }
         buffer.length = 0;
         currentChars = '';
       },
-      chars: function( text, prevTag, nextTag ) {
+      chars: function(text, prevTag, nextTag) {
         prevTag = prevTag === '' ? 'comment' : prevTag;
         nextTag = nextTag === '' ? 'comment' : nextTag;
 
           }
         }
         currentChars = text;
-        lint && lint.testChars(text);
+        if (lint) {
+          lint.testChars(text);
+        }
         buffer.push(text);
       },
-      comment: function( text, nonStandard ) {
+      comment: function(text, nonStandard) {
 
         var prefix = nonStandard ? '<!' : '<!--';
         var suffix = nonStandard ? '>' : '-->';
     return str;
   }
 
-  function joinResultSegments( results, options ) {
+  function joinResultSegments(results, options) {
     var str;
     var maxLineLength = options.maxLineLength;
-    if ( maxLineLength ) {
+    if (maxLineLength) {
       var token;
       var lines = [];
       var line = '';
-      for ( var i = 0, len = results.length; i < len; i++ ) {
+      for (var i = 0, len = results.length; i < len; i++) {
         token = results[i];
-        if ( line.length + token.length < maxLineLength ) {
+        if (line.length + token.length < maxLineLength) {
           line += token;
         }
         else {
   }
 
   // for CommonJS enviroments, export everything
-  if ( typeof exports !== 'undefined' ) {
+  if (typeof exports !== 'undefined') {
     exports.minify = minify;
   }
   else {
index 5f278b7..5cfc86d 100644 (file)
   });
 
   test('cleaning class/style attributes', function() {
-    input = '<p class=" foo bar  ">foo bar baz</p>', output;
+    input = '<p class=" foo bar  ">foo bar baz</p>';
     equal(minify(input, { cleanAttributes: true }), '<p class="foo bar">foo bar baz</p>');
 
     input = '<p class=" foo      ">foo bar baz</p>';