Skip to content
This repository has been archived by the owner on Jan 27, 2019. It is now read-only.

Commit

Permalink
Merge pull request #41 from hoffi/jshint
Browse files Browse the repository at this point in the history
Added JSHint and enhanced Travis config
  • Loading branch information
johno committed Jun 11, 2015
2 parents 60d33f2 + 76fc625 commit fef4673
Show file tree
Hide file tree
Showing 10 changed files with 68 additions and 13 deletions.
49 changes: 49 additions & 0 deletions .jshintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
{
// Settings
"passfail" : false, // Stop on first error.
"maxerr" : 50, // Maximum error before stopping.


// Predefined globals whom JSHint will ignore.
"browser" : false,
"node" : true,

"predef" : [ // Custom globals.
"describe",
"it",
"before",
"after"
],


// Development.
"debug" : false, // Allow debugger statements e.g. browser breakpoints.
"devel" : true, // Allow developments statements e.g. `console.log();`.


// The Good Parts.
"bitwise" : false, // Prohibit bitwise operators (&, |, ^, etc.).
"curly" : true, // Require {} for every new block or scope.
"eqeqeq" : true, // Require triple equals i.e. `===`.
"eqnull" : false, // Tolerate use of `== null`.
"evil" : false, // Tolerate use of `eval`.
"expr" : false, // Tolerate `ExpressionStatement` as Programs.
"immed" : true, // Require immediate invocations to be wrapped in parens e.g. `( function(){}() );`
"latedef" : false, // Prohibit variable use before definition.
"loopfunc" : false, // Allow functions to be defined within loops.
"noarg" : true, // Prohibit use of `arguments.caller` and `arguments.callee`.
"regexp" : true, // Prohibit `.` and `[^...]` in regular expressions.
"undef" : true, // Require all non-global variables be declared before they are used.


// Personal styling preferences.
"newcap" : true, // Require capitalization of all constructor functions e.g. `new F()`.
"noempty" : true, // Prohibit use of empty blocks.
"nomen" : true, // Prohibit use of initial or trailing underbars in names.
"onevar" : false, // Allow only one `var` statement per function.
"plusplus" : false, // Prohibit use of `++` & `--`.
"sub" : false, // Tolerate all forms of subscript notation besides dot notation e.g. `dict['key']` instead of `dict.key`.
"trailing" : true, // Prohibit trailing whitespaces.
"white" : true, // Check against strict whitespace and indentation rules.
"indent" : 2 // Specify indentation spacing
}
4 changes: 4 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,7 @@ language: node_js
node_js:
- 0.10
- 0.11
install: npm install
script:
- npm test
- npm run jshint
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ module.exports = function(cssStringOrAST, options) {
throw new TypeError('cssstats expects a string or PostCSS AST');
}

if (!obj) return false;
if (!obj) { return false; }

result.averages = {};
result.size = size(string);
Expand Down
2 changes: 1 addition & 1 deletion lib/declarations.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ module.exports = function(obj) {
});

obj.eachAtRule(function(atRule) {
if (atRule.name != 'media') return;
if (atRule.name !== 'media') { return; }
var key = camelCase(atRule.params);
if (!result.byMedia[key]) {
result.byMedia[key] = [];
Expand Down
2 changes: 1 addition & 1 deletion lib/rules.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ module.exports = function(obj) {
obj.eachRule(function(rule) {
var declarations = [];
rule.nodes.forEach(function(node) {
if (node.type == 'decl') {
if (node.type === 'decl') {
declarations.push(node);
}
});
Expand Down
8 changes: 4 additions & 4 deletions lib/selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ module.exports = function(obj) {
var b = parseInt(values[1], 10) * 100;
var c = parseInt(values[2], 10) * 10;
var d = parseInt(values[3], 10);
if (a > 10000) a = 10000;
if (b > 1000) b = 1000;
if (c > 100) c = 100;
if (d > 10) d = 10;
if (a > 10000) { a = 10000; }
if (b > 1000) { b = 1000; }
if (c > 100) { c = 100; }
if (d > 10) { d = 10; }
return (a + b + c + d);
}

Expand Down
2 changes: 1 addition & 1 deletion lib/util/font-shorthand.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ module.exports = function handleFontShorthand(obj) {
}
});
}
}
};

function generateDeclaration(prop, value, index) {
return {
Expand Down
4 changes: 2 additions & 2 deletions lib/util/unique-declarations.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
var _uniq = require('lodash').uniq;

module.exports = function uniqueDeclarations(obj) {
uniqueDecls = {};
var uniqueDecls = {};

Object.keys(obj.byProperty).forEach(function(propKey){
uniqueDecls[propKey] = _uniq(obj.byProperty[propKey], 'value');
});

return uniqueDecls;
}
};
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,11 @@
"homepage": "https://github.com/jxnblk/css-statistics",
"devDependencies": {
"get-css": "0.0.2",
"mocha": "^2.1.0"
"mocha": "^2.1.0",
"jshint": "2.8.0"
},
"scripts": {
"test": "mocha test"
"test": "mocha test",
"jshint": "jshint index.js lib test"
}
}
2 changes: 1 addition & 1 deletion test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ describe('css-statistics', function() {

it('should correctly count the number of unique declarations', function() {
assert.equal(stats.declarations.uniqueDeclarationsCount, 19);
})
});

it('should correctly count the number of declarations that reset properties', function() {
assert.deepEqual(stats.declarations.propertyResetDeclarations, {'margin': 1, 'marginBottom': 1});
Expand Down

0 comments on commit fef4673

Please sign in to comment.