Minor cleanup. Added JSHint validation.
authorGoalSmashers <jakub@goalsmashers.com>
Sat, 3 Nov 2012 19:40:48 +0000 (19:40 +0000)
committerGoalSmashers <jakub@goalsmashers.com>
Sat, 3 Nov 2012 19:42:14 +0000 (19:42 +0000)
* JSHint validation via 'make check' (it's a new dev dependency).
* Fixed minor errors pointed out by JSHint.
* Added license info link and library header.

.jshintignore [new file with mode: 0644]
.jshintrc [new file with mode: 0644]
Makefile
README.md
lib/clean.js
package.json
test/batch-test.js
test/binary-test.js
test/custom-test.js
test/unit-test.js

diff --git a/.jshintignore b/.jshintignore
new file mode 100644 (file)
index 0000000..4e06b70
--- /dev/null
@@ -0,0 +1,3 @@
+node_modules
+.git
+
diff --git a/.jshintrc b/.jshintrc
new file mode 100644 (file)
index 0000000..d233bc3
--- /dev/null
+++ b/.jshintrc
@@ -0,0 +1,16 @@
+{
+  "node" : true,
+  "es5" : true,
+  "browser" : false,
+
+  "camelcase": true,
+  "curly": false,
+  "eqeqeq": false,
+  "latedef": true,
+  "noarg": true,
+  "plusplus": false,
+  "regexp": false,
+  "strict": false,
+  "trailing": false,
+  "unused": true
+}
index 15c2a68..27fec28 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -1,5 +1,6 @@
 TEST_DIR = test
-VOWS = ./node_modules/vows/bin/vows
+VOWS = ./node_modules/.bin/vows
+JSHINT = ./node_modules/.bin/jshint
 
 all: test
 
@@ -11,4 +12,8 @@ bench:
        @@echo "Running benchmark on big.css file"
        @@node test/bench.js
 
-.PHONY: all test bench
\ No newline at end of file
+check:
+       @@echo "Running JSHint on all project files..."
+       @@${JSHINT} .
+
+.PHONY: all test bench check
\ No newline at end of file
index 28524d9..ae8b197 100644 (file)
--- a/README.md
+++ b/README.md
@@ -65,4 +65,4 @@ on *nix systems. If you are under Windows then run:
 
 ## License ##
 
-Clean-css is released under the MIT license.
+Clean-css is released under the [MIT License](http://opensource.org/licenses/MIT).
index e10edd0..1c22c0e 100644 (file)
@@ -1,4 +1,9 @@
-var util = require('util');
+/**
+ * Clean-css - https://github.com/GoalSmashers/clean-css
+ * Released under the terms of MIT license
+ *
+ * Copyright (C) 2011-2012 GoalSmashers.com
+ */
 
 var CleanCSS = {
   colors: {
@@ -13,7 +18,7 @@ var CleanCSS = {
       specialComments: [],
       contentBlocks: []
     };
-    var replace = function(pattern, replacement) {
+    var replace = function() {
       if (typeof arguments[0] == 'function')
         arguments[0]();
       else
@@ -89,7 +94,7 @@ var CleanCSS = {
     replace(/content :/g, 'content:');
 
     // restore spaces inside IE filters (IE 7 issue)
-    replace(/progid:[^(]+\(([^\)]+)/g, function(match, contents) {
+    replace(/progid:[^(]+\(([^\)]+)/g, function(match) {
       return match.replace(/,/g, ', ');
     });
 
@@ -117,8 +122,10 @@ var CleanCSS = {
 
     // replace standard colors with hex values (only if color name is longer then hex value)
     replace(/(color|background):(\w+)/g, function(match, property, colorName) {
-      if (CleanCSS.colors[colorName]) return property + ':' + CleanCSS.colors[colorName];
-      else return match;
+      if (CleanCSS.colors[colorName])
+        return property + ':' + CleanCSS.colors[colorName];
+      else
+        return match;
     });
 
     // replace #f00 with red as it's shorter
@@ -126,8 +133,10 @@ var CleanCSS = {
 
     // replace font weight with numerical value
     replace(/font\-weight:(\w+)/g, function(match, weight) {
-      if (weight == 'normal') return 'font-weight:400';
-      else if (weight == 'bold') return 'font-weight:700';
+      if (weight == 'normal')
+        return 'font-weight:400';
+      else if (weight == 'bold')
+        return 'font-weight:700';
       else return match;
     });
 
@@ -155,7 +164,7 @@ var CleanCSS = {
 
     // empty elements
     if (options.removeEmpty)
-      replace(/[^}]+?{}/g, '');
+      replace(/[^\}]+?\{\}/g, '');
 
     // move first charset to the beginning
     if (data.indexOf('charset') > 0)
@@ -173,7 +182,7 @@ var CleanCSS = {
     replace(/calc\([^\}]+\}/g, function(match) {
       return match.replace(/\+/g, ' + ');
     });
-    replace(/__CSSCOMMENT__/g, function(i) {
+    replace(/__CSSCOMMENT__/g, function() {
       switch (options.keepSpecialComments) {
         case '*':
           return context.specialComments.shift();
@@ -205,7 +214,8 @@ var CleanCSS = {
     for (; nextEnd < data.length; ) {
       nextStart = data.indexOf('/*', nextEnd);
       nextEnd = data.indexOf('*/', nextStart);
-      if (nextStart == -1 || nextEnd == -1) break;
+      if (nextStart == -1 || nextEnd == -1)
+        break;
 
       tempData.push(data.substring(cursor, nextStart));
       if (data[nextStart + 2] == '!') {
@@ -228,7 +238,6 @@ var CleanCSS = {
     var tempData = [],
       nextStart = 0,
       nextEnd = 0,
-      tempStart = 0,
       cursor = 0,
       matchedParenthesis = null;
 
@@ -240,24 +249,30 @@ var CleanCSS = {
 
       if (matchedParenthesis) {
         min = data.indexOf(matchedParenthesis, pos);
-        if (min == -1) min = max;
+        if (min == -1)
+          min = max;
       } else {
         var next1 = data.indexOf("'", pos);
         var next2 = data.indexOf('"', pos);
-        if (next1 == -1) next1 = max;
-        if (next2 == -1) next2 = max;
+        if (next1 == -1)
+          next1 = max;
+        if (next2 == -1)
+          next2 = max;
 
         min = next1 > next2 ? next2 : next1;
       }
 
-      if (min == max) return -1;
+      if (min == max)
+        return -1;
 
       if (matchedParenthesis) {
         matchedParenthesis = null;
         return min;
       } else {
         // check if there's anything else between pos and min that doesn't match ':' or whitespace
-        if (/[^:\s]/.test(data.substring(pos, min))) return -1;
+        if (/[^:\s]/.test(data.substring(pos, min)))
+          return -1;
+
         matchedParenthesis = data.charAt(min);
         return min + 1;
       }
@@ -265,11 +280,13 @@ var CleanCSS = {
 
     for (; nextEnd < data.length; ) {
       nextStart = data.indexOf('content', nextEnd);
-      if (nextStart == -1) break;
+      if (nextStart == -1)
+        break;
 
       nextStart = nextParenthesis(nextStart + 7);
       nextEnd = nextParenthesis(nextStart);
-      if (nextStart == -1 || nextEnd == -1) break;
+      if (nextStart == -1 || nextEnd == -1)
+        break;
 
       tempData.push(data.substring(cursor, nextStart - 1));
       tempData.push('__CSSCONTENT__');
index 54c446c..0020849 100644 (file)
@@ -20,7 +20,8 @@
     "optimist": "0.3.x"
   },
   "devDependencies": {
-    "vows": "0.6.x"
+    "vows": "0.6.x",
+    "jshint": "0.9.x"
   },
   "engines": {
     "node": ">=0.6.0"
index acc70ea..c7ecfa9 100644 (file)
@@ -22,7 +22,7 @@ var batchContexts = function() {
           minimized: fs.readFileSync(minPath, 'utf-8')
         };
       }
-    }
+    };
     context[testName]['minimizing ' + testName + '.css'] = function(data) {
       var processed = cleanCSS.process(data.plain, {
         removeEmpty: true,
index eb32362..6f9129c 100644 (file)
@@ -34,7 +34,7 @@ exports.commandsSuite = vows.describe('binary commands').addBatch({
     }
   }),
   'help': binaryContext('-h', {
-    'should output help': function(error, stdout, stderr) {
+    'should output help': function(error, stdout) {
       assert.equal(/usage:/.test(stdout), true);
     }
   }),
@@ -79,7 +79,7 @@ exports.commandsSuite = vows.describe('binary commands').addBatch({
     'should give no output': function(error, stdout) {
       assert.equal(stdout, '');
     },
-    'should minimize': function(stdout) {
+    'should minimize': function() {
       var minimized = fs.readFileSync('./test/data/reset-min.css', 'utf-8').replace(lineBreak, '');
       var target = fs.readFileSync('./reset-min.css', 'utf-8').replace(lineBreak, '');
       assert.equal(minimized, target);
index ca863f7..6c537ab 100644 (file)
@@ -13,5 +13,4 @@ vows.describe('clean-custom')
       }
     }
   })
-  .export(module)
-
+  .export(module);
index 98e09ab..5370883 100644 (file)
@@ -7,7 +7,7 @@ var cssContext = function(groups, options) {
   var clean = function(cleanedCSS) {
     return function(css) {
       assert.equal(cleanCSS.process(css, options), cleanedCSS);
-    }
+    };
   };
 
   for (var g in groups) {
@@ -340,7 +340,7 @@ vows.describe('clean-units').addBatch({
     ],
     'not add a space before url\'s hash': [
       "url(\"../fonts/d90b3358-e1e2-4abb-ba96-356983a54c22.svg#d90b3358-e1e2-4abb-ba96-356983a54c22\")",
-      "url(../fonts/d90b3358-e1e2-4abb-ba96-356983a54c22.svg#d90b3358-e1e2-4abb-ba96-356983a54c22)",
+      "url(../fonts/d90b3358-e1e2-4abb-ba96-356983a54c22.svg#d90b3358-e1e2-4abb-ba96-356983a54c22)"
     ]
   }),
   'ie filters': cssContext({
@@ -395,6 +395,6 @@ vows.describe('clean-units').addBatch({
     'empty #1': 'a{}',
     'empty #2': 'div>a{}',
     'empty #3': 'div:nth-child(2n){}',
-    'empty #3': 'a{color:#fff}div{}p{line-height:2em}'
+    'empty #4': 'a{color:#fff}div{}p{line-height:2em}'
   })
 }).export(module);
\ No newline at end of file