configure the rest of eslint.

This commit is contained in:
Luke Page 2015-08-04 21:32:22 +01:00
parent 8155d300f0
commit bf5ae3c54e
16 changed files with 737 additions and 713 deletions

136
.eslintrc
View file

@ -2,10 +2,10 @@
"ecmaFeatures": {},
"rules": {
"no-alert": 2,
"no-array-constructor": 1,
"no-array-constructor": 0,
"no-bitwise": 0,
"no-caller": 2,
"no-catch-shadow": 1,
"no-catch-shadow": 2,
"no-class-assign": 2,
"no-cond-assign": 2,
"no-console": 2,
@ -26,15 +26,15 @@
"no-eq-null": 0,
"no-eval": 2,
"no-ex-assign": 2,
"no-extend-native": 0,
"no-extend-native": 2,
"no-extra-bind": 1,
"no-extra-boolean-cast": 2,
"no-extra-parens": 0,
"no-extra-semi": 2,
"no-fallthrough": 2,
"no-floating-decimal": 0,
"no-floating-decimal": 1,
"no-func-assign": 2,
"no-implicit-coercion": 0,
"no-implicit-coercion": 1,
"no-implied-eval": 1,
"no-inline-comments": 0,
"no-inner-declarations": [2, "functions"],
@ -45,26 +45,26 @@
"no-label-var": 1,
"no-labels": 1,
"no-lone-blocks": 1,
"no-lonely-if": 0,
"no-lonely-if": 1,
"no-loop-func": 1,
"no-mixed-requires": [0, false],
"no-mixed-requires": [1, false],
"no-mixed-spaces-and-tabs": [2, false],
"linebreak-style": [0, "unix"],
"no-multi-spaces": 1,
"no-multi-str": 0,
"no-multiple-empty-lines": [0, {"max": 2}],
"no-native-reassign": 0,
"no-multiple-empty-lines": [1, {"max": 2}],
"no-native-reassign": 2,
"no-negated-in-lhs": 2,
"no-nested-ternary": 0,
"no-new": 0,
"no-new-func": 0,
"no-new-object": 0,
"no-new-require": 0,
"no-new-wrappers": 0,
"no-nested-ternary": 1,
"no-new": 1,
"no-new-func": 1,
"no-new-object": 1,
"no-new-require": 1,
"no-new-wrappers": 1,
"no-obj-calls": 2,
"no-octal": 2,
"no-octal-escape": 0,
"no-param-reassign": 0,
"no-param-reassign": 1,
"no-path-concat": 0,
"no-plusplus": 0,
"no-process-env": 0,
@ -73,23 +73,23 @@
"no-redeclare": 2,
"no-regex-spaces": 2,
"no-restricted-modules": 0,
"no-return-assign": 0,
"no-return-assign": 1,
"no-script-url": 0,
"no-self-compare": 0,
"no-sequences": 0,
"no-self-compare": 1,
"no-sequences": 1,
"no-shadow": 1,
"no-shadow-restricted-names": 0,
"no-shadow-restricted-names": 1,
"no-spaced-func": 1,
"no-sparse-arrays": 2,
"no-sync": 0,
"no-ternary": 0,
"no-trailing-spaces": 1,
"no-this-before-super": 0,
"no-throw-literal": 0,
"no-this-before-super": 1,
"no-throw-literal": 1,
"no-undef": 2,
"no-undef-init": 0,
"no-undef-init": 1,
"no-undefined": 0,
"no-unexpected-multiline": 0,
"no-unexpected-multiline": 1,
"no-underscore-dangle": 0,
"no-unneeded-ternary": 0,
"no-unreachable": 2,
@ -99,73 +99,75 @@
"no-useless-call": 2,
"no-void": 0,
"no-var": 0,
"no-warning-comments": [0, { "terms": ["todo", "fixme", "xxx"], "location": "start" }],
"no-with": 0,
"no-warning-comments": [1, { "terms": ["todo", "fixme", "xxx"], "location": "start" }],
"no-with": 1,
"array-bracket-spacing": [0, "never"],
"arrow-parens": 0,
"arrow-spacing": 0,
"accessor-pairs": 0,
"array-bracket-spacing": [1, "never"],
"arrow-parens": 1,
"arrow-spacing": 1,
"accessor-pairs": 1,
"block-scoped-var": 0,
"brace-style": [0, "1tbs"],
"callback-return": 0,
"camelcase": 0,
"brace-style": [1, "1tbs"],
"callback-return": [2, ["callback", "cb", "next"]],
"camelcase": [2, {"properties": "always"}],
"comma-dangle": [2, "never"],
"comma-spacing": 0,
"comma-style": 0,
"complexity": [0, 11],
"comma-spacing": 2,
"comma-style": 1,
"complexity": [1, 10],
"computed-property-spacing": [0, "never"],
"consistent-return": 0,
"consistent-this": [0, "that"],
"constructor-super": 0,
"curly": [0, "all"],
"default-case": 0,
"dot-location": 0,
"dot-notation": [0, { "allowKeywords": true }],
"constructor-super": 1,
"curly": [1, "all"],
"default-case": 1,
"dot-location": [1, "property"],
"dot-notation": [1, { "allowKeywords": true }],
"eol-last": 0,
"eqeqeq": 0,
"eqeqeq": 1,
"func-names": 0,
"func-style": [0, "declaration"],
"generator-star-spacing": 0,
"guard-for-in": 0,
"handle-callback-err": 0,
"id-length": 0,
"indent": 0,
"guard-for-in": 1,
"handle-callback-err": 2,
"id-length": [2, {"min": 3, "max": 20, "exceptions":["x", "y", "i", "j"]}],
"indent": [1, 2, {"SwitchCase": 1}],
"init-declarations": 0,
"key-spacing": [0, { "beforeColon": false, "afterColon": true }],
"key-spacing": [1, { "beforeColon": false, "afterColon": true }],
"lines-around-comment": 0,
"max-depth": [0, 4],
"max-len": [0, 80, 4],
"max-nested-callbacks": [0, 2],
"max-params": [0, 3],
"max-statements": [0, 10],
"new-cap": 0,
"new-parens": 0,
"max-depth": [1, 4],
"max-len": [1, 160, 2],
"max-nested-callbacks": [1, 2],
"max-params": [1, 5],
"max-statements": [1, 30],
"new-cap": 1,
"new-parens": 1,
"newline-after-var": 0,
"object-curly-spacing": [0, "never"],
"object-curly-spacing": [1, "always"],
"object-shorthand": 0,
"one-var": 0,
"one-var": [1, {
"initialized": "never"
}],
"operator-assignment": [0, "always"],
"operator-linebreak": 0,
"operator-linebreak": [1, "after"],
"padded-blocks": 0,
"prefer-const": 0,
"prefer-spread": 0,
"prefer-reflect": 0,
"quote-props": 0,
"quotes": [0, "double"],
"quotes": [1, "single"],
"radix": 0,
"id-match": 0,
"require-yield": 0,
"semi": 0,
"semi-spacing": [0, {"before": false, "after": true}],
"semi": [1, "always"],
"semi-spacing": [1, {"before": false, "after": true}],
"sort-vars": 0,
"space-after-keywords": [0, "always"],
"space-before-blocks": [0, "always"],
"space-before-function-paren": [0, "always"],
"space-in-parens": [0, "never"],
"space-infix-ops": 0,
"space-return-throw-case": 0,
"space-unary-ops": [0, { "words": true, "nonwords": false }],
"space-after-keywords": [1, "always"],
"space-before-blocks": [1, "always"],
"space-before-function-paren": [1, "never"],
"space-in-parens": [1, "never"],
"space-infix-ops": 1,
"space-return-throw-case": 1,
"space-unary-ops": [1, { "words": true, "nonwords": false }],
"spaced-comment": 0,
"strict": [2, "global"],
"use-isnan": 2,

View file

@ -33,16 +33,17 @@ function bitRetriever(data, depth) {
var leftOver = [];
var i = 0;
function split() {
if (i === data.length) {
throw new Error("Ran out of data");
throw new Error('Ran out of data');
}
var byte = data[i];
i++;
var byte8, byte7, byte6, byte5, byte4, byte3, byte2, byte1
var byte8, byte7, byte6, byte5, byte4, byte3, byte2, byte1;
switch (depth) {
default:
throw new Error("unrecognised depth");
throw new Error('unrecognised depth');
case 16:
byte2 = data[i];
i++;
@ -73,6 +74,7 @@ function bitRetriever(data, depth) {
break;
}
}
return {
get: function(count) {
while (leftOver.length < count) {
@ -87,7 +89,8 @@ function bitRetriever(data, depth) {
},
end: function() {
if (i !== data.length) {
throw new Error("extra data found");
// todo these exceptions should be emitting errors
throw new Error('extra data found');
}
}
};
@ -138,7 +141,7 @@ exports.dataToBitMap = function(data, width, height, bpp, depth, interlace) {
var idx = pixelBppMap[bpp][i];
if (depth === 8) {
if (i === data.length) {
throw new Error("Ran out of data");
throw new Error('Ran out of data');
}
pxData[pxPos + i] = idx !== 0xff ? data[idx + rawPos] : maxBit;
} else {
@ -155,7 +158,7 @@ exports.dataToBitMap = function(data, width, height, bpp, depth, interlace) {
}
if (depth === 8) {
if (rawPos !== data.length) {
throw new Error("extra data found");
throw new Error('extra data found');
}
} else {
bits.end();

View file

@ -21,8 +21,8 @@
'use strict';
var util = require('util'),
Stream = require('stream');
var util = require('util');
var Stream = require('stream');
var ChunkStream = module.exports = function() {
@ -67,24 +67,31 @@ ChunkStream.prototype.write = function(data, encoding) {
return false;
}
if (!Buffer.isBuffer(data))
data = new Buffer(data, encoding || this._encoding);
var dataBuffer;
if (Buffer.isBuffer(data)) {
dataBuffer = data;
} else {
dataBuffer = new Buffer(data, encoding || this._encoding);
}
this._buffers.push(data);
this._buffered += data.length;
this._buffers.push(dataBuffer);
this._buffered += dataBuffer.length;
this._process();
// ok if there are no more read requests
if (this._reads && this._reads.length == 0)
if (this._reads && this._reads.length == 0) {
this._paused = true;
}
return this.writable && !this._paused;
};
ChunkStream.prototype.end = function(data, encoding) {
if (data) this.write(data, encoding);
if (data) {
this.write(data, encoding);
}
this.writable = false;
@ -115,7 +122,9 @@ ChunkStream.prototype._end = function() {
ChunkStream.prototype.destroy = function() {
if (!this._buffers) return;
if (!this._buffers) {
return;
}
this.writable = false;
this._reads = null;
@ -161,15 +170,15 @@ ChunkStream.prototype._process = function() {
this._reads.shift(); // == read
var pos = 0,
count = 0,
data = new Buffer(read.length);
var pos = 0;
var count = 0;
var data = new Buffer(read.length);
// create buffer for all data
while (pos < read.length) {
var buf = this._buffers[count++],
len = Math.min(buf.length, read.length - pos);
var buf = this._buffers[count++];
var len = Math.min(buf.length, read.length - pos);
buf.copy(data, pos, 0, len);
pos += len;

View file

@ -29,8 +29,10 @@ module.exports = {
TYPE_IEND: 0x49454e44,
TYPE_IDAT: 0x49444154,
TYPE_PLTE: 0x504c5445,
/*eslint camelcase: 0*/
TYPE_tRNS: 0x74524e53,
TYPE_gAMA: 0x67414d41,
/*eslint camelcase: 1*/
COLOR_PALETTE: 1,
COLOR_COLOR: 2,

View file

@ -24,15 +24,15 @@ var crcTable = [];
(function() {
for (var i = 0; i < 256; i++) {
var c = i;
var currentCrc = i;
for (var j = 0; j < 8; j++) {
if (c & 1) {
c = 0xedb88320 ^ (c >>> 1);
if (currentCrc & 1) {
currentCrc = 0xedb88320 ^ (currentCrc >>> 1);
} else {
c = c >>> 1;
currentCrc = currentCrc >>> 1;
}
}
crcTable[i] = c;
crcTable[i] = currentCrc;
}
}());

View file

@ -20,9 +20,9 @@
'use strict';
var util = require('util'),
ChunkStream = require('./chunkstream'),
Filter = require('./filter');
var util = require('util');
var ChunkStream = require('./chunkstream');
var Filter = require('./filter');
var FilterAsync = module.exports = function(width, height, Bpp, depth, interlace, options) {

View file

@ -20,8 +20,8 @@
'use strict';
var SyncReader = require('./sync-reader'),
Filter = require('./filter');
var SyncReader = require('./sync-reader');
var Filter = require('./filter');
exports.process = function(inBuffer, width, height, Bpp, depth, interlace, options) {
@ -33,7 +33,8 @@ exports.process = function(inBuffer, width, height, Bpp, depth, interlace, optio
write: function(bufferPart) {
outBuffers.push(bufferPart);
},
complete: function(){}
complete: function() {
}
});
filter.start();

View file

@ -21,12 +21,12 @@
'use strict';
var util = require('util'),
Stream = require('stream'),
zlib = require('zlib'),
Filter = require('./filter'),
CrcStream = require('./crc'),
constants = require('./constants');
var util = require('util');
var Stream = require('stream');
var zlib = require('zlib');
var Filter = require('./filter');
var CrcStream = require('./crc');
var constants = require('./constants');
var Packer = module.exports = function(options) {

View file

@ -21,12 +21,12 @@
'use strict';
var util = require('util'),
zlib = require('zlib'),
ChunkStream = require('./chunkstream'),
FilterAsync = require('./filter-async'),
Parser = require('./parser'),
bitmapper = require('./bitmapper');
var util = require('util');
var zlib = require('zlib');
var ChunkStream = require('./chunkstream');
var FilterAsync = require('./filter-async');
var Parser = require('./parser');
var bitmapper = require('./bitmapper');
var ParserAsync = module.exports = function(options) {

View file

@ -21,11 +21,11 @@
'use strict';
var zlib = require('zlib'),
SyncReader = require('./sync-reader'),
FilterSync = require('./filter-sync'),
Parser = require('./parser'),
bitmapper = require('./bitmapper');
var zlib = require('zlib');
var SyncReader = require('./sync-reader');
var FilterSync = require('./filter-sync');
var Parser = require('./parser');
var bitmapper = require('./bitmapper');
var ParserSync = module.exports = function(buffer, options) {
@ -38,7 +38,8 @@ var ParserSync = module.exports = function(buffer, options) {
error: this._handleError.bind(this),
metadata: this._metaData.bind(this),
gamma: this._gamma.bind(this),
finished: function() {},
finished: function() {
},
inflateData: this._inflateData.bind(this),
createData: this._createData.bind(this)
});

View file

@ -21,8 +21,8 @@
'use strict';
var constants = require('./constants'),
CrcCalculator = require('./crc');
var constants = require('./constants');
var CrcCalculator = require('./crc');
var Parser = module.exports = function(options, dependencies) {

View file

@ -26,8 +26,7 @@ var Parser = require('./parser-sync');
exports.read = function(buffer, options) {
options = options || {};
var parser = new Parser(buffer, options);
var parser = new Parser(buffer, options || {});
if (parser.err) {
throw parser.err;

View file

@ -21,17 +21,17 @@
'use strict';
var util = require('util'),
Stream = require('stream'),
Parser = require('./parser-async'),
Packer = require('./packer'),
PNGSync = require('./png-sync');
var util = require('util');
var Stream = require('stream');
var Parser = require('./parser-async');
var Packer = require('./packer');
var PNGSync = require('./png-sync');
var PNG = exports.PNG = function(options) {
Stream.call(this);
options = options || {};
options = options || {}; // eslint-disable-line no-param-reassign
this.width = options.width || 0;
this.height = options.height || 0;
@ -81,21 +81,23 @@ PNG.prototype.pack = function() {
PNG.prototype.parse = function(data, callback) {
if (callback) {
var onParsed = null, onError = null;
var onParsed, onError;
this.once('parsed', onParsed = function(parsedData) {
onParsed = function(parsedData) {
this.removeListener('error', onError);
this.data = parsedData;
callback(null, this);
}.bind(this);
}.bind(this));
this.once('error', onError = function(err) {
onError = function(err) {
this.removeListener('parsed', onParsed);
callback(err, null);
}.bind(this));
}.bind(this);
this.once('parsed', onParsed);
this.once('error', onError);
}
this.end(data);
@ -123,32 +125,35 @@ PNG.prototype._gamma = function(gamma) {
};
PNG.prototype._handleClose = function() {
if (!this._parser.writable && !this._packer.readable)
if (!this._parser.writable && !this._packer.readable) {
this.emit('close');
}
};
PNG.bitblt = function(src, dst, sx, sy, w, h, dx, dy) {
if (sx > src.width || sy > src.height
|| sx + w > src.width || sy + h > src.height)
PNG.bitblt = function(src, dst, srcX, srcY, width, height, deltaX, deltaY) { // eslint-disable-line max-params
if (srcX > src.width || srcY > src.height || srcX + width > src.width || srcY + height > src.height) {
throw new Error('bitblt reading outside image');
if (dx > dst.width || dy > dst.height
|| dx + w > dst.width || dy + h > dst.height)
throw new Error('bitblt writing outside image');
}
for (var y = 0; y < h; y++) {
if (deltaX > dst.width || deltaY > dst.height || deltaX + width > dst.width || deltaY + height > dst.height) {
throw new Error('bitblt writing outside image');
}
for (var y = 0; y < height; y++) {
src.data.copy(dst.data,
((dy + y) * dst.width + dx) << 2,
((sy + y) * src.width + sx) << 2,
((sy + y) * src.width + sx + w) << 2
((deltaY + y) * dst.width + deltaX) << 2,
((srcY + y) * src.width + srcX) << 2,
((srcY + y) * src.width + srcX + width) << 2
);
}
};
PNG.prototype.bitblt = function(dst, sx, sy, w, h, dx, dy) {
PNG.prototype.bitblt = function(src, dst, srcX, srcY, width, height, deltaX, deltaY) { // eslint-disable-line max-params
PNG.bitblt(this, dst, sx, sy, w, h, dx, dy);
PNG.bitblt(this, dst, srcX, srcY, width, height, deltaX, deltaY);
return this;
};
@ -169,4 +174,6 @@ PNG.adjustGamma = function(src) {
}
};
PNG.prototype.adjustGamma = function() { PNG.adjustGamma(this); };
PNG.prototype.adjustGamma = function() {
PNG.adjustGamma(this);
};