Skip to content

Commit

Permalink
Added jshint config etc. and made the code pass.
Browse files Browse the repository at this point in the history
  • Loading branch information
papandreou committed May 26, 2014
1 parent 739ed7f commit d08d775
Show file tree
Hide file tree
Showing 5 changed files with 111 additions and 16 deletions.
2 changes: 2 additions & 0 deletions .jshintignore
@@ -0,0 +1,2 @@
node_modules
testdata
93 changes: 93 additions & 0 deletions .jshintrc
@@ -0,0 +1,93 @@
{
// JSHint Default Configuration File (as on JSHint website)
// See http://jshint.com/docs/ for more details

"maxerr" : 50, // {int} Maximum error before stopping

// Enforcing
"bitwise" : true, // true: Prohibit bitwise operators (&, |, ^, etc.)
"camelcase" : false, // true: Identifiers must be in camelCase
"curly" : true, // true: Require {} for every new block or scope
"eqeqeq" : true, // true: Require triple equals (===) for comparison
"forin" : true, // true: Require filtering for..in loops with obj.hasOwnProperty()
"immed" : true, // true: Require immediate invocations to be wrapped in parens e.g. `(function () { } ());`
"indent" : 4, // {int} Number of spaces to use for indentation
"latedef" : true, // true: Require variables/functions to be defined before being used
"newcap" : true, // true: Require capitalization of all constructor functions e.g. `new F()`
"noarg" : true, // true: Prohibit use of `arguments.caller` and `arguments.callee`
"noempty" : true, // true: Prohibit use of empty blocks
"nonew" : false, // true: Prohibit use of constructors for side-effects (without assignment)
"plusplus" : true, // true: Prohibit use of `++` & `--`
"quotmark" : "single", // Quotation mark consistency:
// false : do nothing (default)
// true : ensure whatever is used is consistent
// "single" : require single quotes
// "double" : require double quotes
"undef" : true, // true: Require all non-global variables to be declared (prevents global leaks)
"unused" : "vars", // true: Require all defined variables be used
"strict" : false, // true: Requires all functions run in ES5 Strict Mode
"trailing" : true, // true: Prohibit trailing whitespaces
"maxparams" : false, // {int} Max number of formal params allowed per function
"maxdepth" : false, // {int} Max depth of nested blocks (within functions)
"maxstatements" : false, // {int} Max number statements per function
"maxcomplexity" : false, // {int} Max cyclomatic complexity per function
"maxlen" : false, // {int} Max number of characters per line

// Relaxing
"asi" : false, // true: Tolerate Automatic Semicolon Insertion (no semicolons)
"boss" : false, // true: Tolerate assignments where comparisons would be expected
"debug" : false, // true: Allow debugger statements e.g. browser breakpoints.
"eqnull" : false, // true: Tolerate use of `== null`
"es5" : false, // true: Allow ES5 syntax (ex: getters and setters)
"esnext" : false, // true: Allow ES.next (ES6) syntax (ex: `const`)
// (ex: `for each`, multiple try/catch, function expression…)
"evil" : false, // true: Tolerate use of `eval` and `new Function()`
"expr" : false, // true: Tolerate `ExpressionStatement` as Programs
"funcscope" : false, // true: Tolerate defining variables inside control statements"
"globalstrict" : false, // true: Allow global "use strict" (also enables 'strict')
"iterator" : false, // true: Tolerate using the `__iterator__` property
"lastsemic" : false, // true: Tolerate omitting a semicolon for the last statement of a 1-line block
"laxbreak" : false, // true: Tolerate possibly unsafe line breakings
"laxcomma" : false, // true: Tolerate comma-first style coding
"loopfunc" : true, // true: Tolerate functions being defined in loops
"multistr" : false, // true: Tolerate multi-line strings
"proto" : false, // true: Tolerate using the `__proto__` property
"scripturl" : false, // true: Tolerate script-targeted URLs
"smarttabs" : false, // true: Tolerate mixed tabs/spaces when used for alignment
"shadow" : false, // true: Allows re-define variables later in code e.g. `var x=1; x=2;`
"sub" : false, // true: Tolerate using `[]` notation when it can still be expressed in dot notation
"supernew" : false, // true: Tolerate `new function () { ... };` and `new Object;`
"validthis" : false, // true: Tolerate using this in a non-constructor function

// Environments
"browser" : false, // Web Browser (window, document, etc)
"couch" : false, // CouchDB
"devel" : true, // Development/debugging (alert, confirm, etc)
"dojo" : false, // Dojo Toolkit
"jquery" : true, // jQuery
"mootools" : false, // MooTools
"node" : true, // Node.js
"nonstandard" : true, // Widely adopted globals (escape, unescape, etc)
"prototypejs" : false, // Prototype and Scriptaculous
"rhino" : false, // Rhino
"worker" : false, // Web Workers
"wsh" : false, // Windows Scripting Host
"yui" : false, // Yahoo User Interface

// Legacy
"nomen" : false, // true: Prohibit dangling `_` in variables
"onevar" : false, // true: Allow only one `var` statement per function
"passfail" : false, // true: Stop on first error
"white" : true, // true: Check against strict whitespace and indentation rules

// Custom Globals
"predef" : [ // additional predefined global variables
"TR",
"TRPAT",
"GETTEXT",
"GETSTATICURL",
"INCLUDE",
"define",
"require"
]
}
8 changes: 3 additions & 5 deletions lib/packers/jimScott.js
Expand Up @@ -67,9 +67,7 @@ exports.pack = function (imageInfos, config) {
y: 0,
width: config.maxWidth || 999999,
height: config.maxHeight || 999999
},
packingWidth = 0,
packingHeight = 0;
};

// Sort by area, descending:
imageInfos.sort(function (a, b) {
Expand All @@ -85,7 +83,7 @@ exports.pack = function (imageInfos, config) {
imageInfos.forEach(function (existingImageInfo) {
var imageInfo = _.extend({}, existingImageInfo);
if (imageInfo.padding && imageInfo.padding.some(function (v) {return v > 0;})) {
throw new Error("jimScott.pack: Sprite padding not supported");
throw new Error('jimScott.pack: Sprite padding not supported');
}
// Perform the search
var coords = findCoords(root, imageInfo.width, imageInfo.height);
Expand All @@ -94,7 +92,7 @@ exports.pack = function (imageInfos, config) {
packingData.width = Math.max(packingData.width, coords.x + imageInfo.width);
packingData.height = Math.max(packingData.height, coords.y + imageInfo.height);
} else {
throw new Error("jimScott.pack: Cannot fit image");
throw new Error('jimScott.pack: Cannot fit image');
}
_.extend(imageInfo, coords);
packingData.imageInfos.push(imageInfo);
Expand Down
21 changes: 11 additions & 10 deletions lib/spriteBackgroundImages.js
Expand Up @@ -86,7 +86,7 @@ function extractInfoFromCssRule(cssRule, propertyNamePrefix) {
var keyName = propertyName.substr(propertyNamePrefix.length).replace(/-([a-z])/g, function ($0, $1) {
return $1.toUpperCase();
});
info[keyName] = cssRule.style[propertyName].replace(/^([\'\"])(.*)\1$/, "$2");
info[keyName] = cssRule.style[propertyName].replace(/^([\'\"])(.*)\1$/, '$2');
}
}
return info;
Expand All @@ -96,16 +96,16 @@ function extractInfoFromCssRule(cssRule, propertyNamePrefix) {
module.exports = function () {
return function spriteBackgroundImages(assetGraph, cb) {
if (!Canvas) {
console.warn("assetgraph-sprite: Canvas not found, skipping");
console.warn('assetgraph-sprite: Canvas not found, skipping');
return cb();
}

// Waiting for https://github.com/LearnBoost/node-canvas/issues/52
var cairoVersion = Canvas.cairoVersion.split(".").map(function (str) {
var cairoVersion = Canvas.cairoVersion.split('.').map(function (str) {
return parseInt(str, 10);
});
if (cairoVersion[0] < 1 || cairoVersion[1] < 10) {
console.warn("assetgraph-sprite: Cannot create sprites due to missing canvas.getContext('2d').drawImage() support. Please compile node-canvas with Cairo version 1.10.0 or above.");
console.warn('assetgraph-sprite: Cannot create sprites due to missing canvas.getContext(\'2d\').drawImage() support. Please compile node-canvas with Cairo version 1.10.0 or above.');
return cb();
}

Expand Down Expand Up @@ -143,7 +143,7 @@ module.exports = function () {
}
if (spriteGroupName in spriteGroups) {
if (spriteGroups[spriteGroupName].placeHolder) {
console.warn("assetgraph-sprite: Multiple definitions of " + spriteGroupName + " sprite");
console.warn('assetgraph-sprite: Multiple definitions of ' + spriteGroupName + ' sprite');
}
spriteGroups[spriteGroupName].placeHolder = _.extend(spriteInfo, {
asset: cssAsset,
Expand Down Expand Up @@ -255,17 +255,18 @@ module.exports = function () {
var relationSpriteInfo = getRelationSpriteInfoFromIncomingRelation(incomingRelation),
style = incomingRelation.cssRule.style,
existingBackgroundPositionValue = style['background-position'],
existingBackgroundValue = style['background'],
existingBackgroundValue = style.background,
backgroundOffsetsWereUpdated = false,
offsets = [
imageInfo.x,
imageInfo.y
];
],
existingOffsets;

if (existingBackgroundValue) {
var backgroundTokens = existingBackgroundValue.split(/\s+/),
positionTokenIndices = [],
existingOffsets = [];
positionTokenIndices = [];
existingOffsets = [];
backgroundTokens.forEach(function (existingBackgroundValueToken, i) {
if (/^(?:-?\d+px|0)$/i.test(existingBackgroundValueToken)) {
positionTokenIndices.push(i);
Expand Down Expand Up @@ -296,7 +297,7 @@ module.exports = function () {
} else if (existingBackgroundPositionValue) {
backgroundPositionPriority = style.getPropertyPriority('background-position');
// FIXME: Silently ignores other units than px
var existingOffsets = existingBackgroundPositionValue.split(' ').map(function (item) {
existingOffsets = existingBackgroundPositionValue.split(' ').map(function (item) {
return parseInt(item, 10);
});

Expand Down
3 changes: 2 additions & 1 deletion package.json
Expand Up @@ -22,6 +22,7 @@
},
"devDependencies": {
"assetgraph": "=1.2.3",
"jshint": "=2.5.1",
"vows": ">=0.6.2"
},
"engines": {
Expand All @@ -31,7 +32,7 @@
"lib": "./lib"
},
"scripts": {
"prepublish": "vows"
"lint": "jshint ."
},
"main": "lib/spriteBackgroundImages.js"
}

0 comments on commit d08d775

Please sign in to comment.