Skip to content

Commit

Permalink
updated eslint rules & coding style
Browse files Browse the repository at this point in the history
  • Loading branch information
Vitaly Puzrin committed Dec 10, 2014
1 parent 14d0e15 commit c342090
Show file tree
Hide file tree
Showing 9 changed files with 101 additions and 24 deletions.
1 change: 1 addition & 0 deletions .eslintignore
@@ -1,3 +1,4 @@
benchmark/implementations
demo/
dist/
node_modules/
98 changes: 84 additions & 14 deletions .eslintrc
Expand Up @@ -8,11 +8,13 @@ plugins:
rules:
block-scoped-var: 2
brace-style: [ 2, '1tbs', { allowSingleLine: true } ]
camelcase: 0
consistent-return: 2
comma-spacing: 2
comma-style: 2
consistent-this: [ 2, self ]
curly: [ 2, all ]
default-case: 2
consistent-return: 2
curly: 2
# default-case: 2
dot-notation: 2
eol-last: 2
eqeqeq: 2
guard-for-in: 2
Expand All @@ -21,26 +23,94 @@ rules:
max-nested-callbacks: [ 1, 4 ]
# string can exceed 80 chars, but should not overflow github website :)
max-len: [ 2, 120, 1000 ]
new-cap: 2
new-parens: 2
no-alert: 2
no-bitwise: 0
no-array-constructor: 2
# no-bitwise: 2
no-caller: 2
no-catch-shadow: 2
no-comma-dangle: 2
no-console: 2
no-cond-assign: 2
no-console: 1
no-constant-condition: 2
no-control-regex: 2
no-debugger: 2
no-delete-var: 2
no-dupe-keys: 2
no-div-regex: 2
no-empty: 2
no-empty-class: 2
no-empty-label: 2
no-else-return: 2
no-eq-null: 2
no-ex-assign: 2
no-extend-native: 2
no-extra-bind: 2
no-extra-boolean-cast: 2
no-extra-semi: 2
no-extra-strict: 2
no-eval: 2
no-floating-decimal: 2
no-func-assign: 2
no-implied-eval: 2
no-inner-declarations: 2
no-invalid-regexp: 2
no-irregular-whitespace: 2
no-label-var: 2
no-labels: 2
no-lone-blocks: 2
no-lonely-if: 2
no-process-exit: 0
no-loop-func: 2
no-mixed-requires: 2
no-mixed-spaces-and-tabs: 2
no-multi-str: 2
no-native-reassign: 2
no-negated-in-lhs: 2
no-new: 2
no-new-func: 2
no-new-object: 2
no-new-require: 2
no-new-wrappers: 2
no-obj-calls: 2
no-octal: 2
no-octal-escape: 2
no-path-concat: 2
no-redeclare: 2
no-regex-spaces: 2
no-reserved-keys: 2
no-return-assign: 2
no-script-url: 2
no-sequences: 2
no-shadow: 2
no-shadow-restricted-names: 2
no-space-before-semi: 2
no-sparse-arrays: 2
no-trailing-spaces: 2
no-underscore-dangle: 0
no-undef: 2
no-undef-init: 2
no-undefined: 2
no-unreachable: 2
no-unused-expressions: 2
no-unused-vars: 2
no-use-before-define: 2
no-with: 2
no-wrap-func: 2
quotes: [ 2, single, avoid-escape ]
radix: 2
space-after-keywords: [ 2, always ] # Fixed in master
space-in-brackets: [ 1, always ]
space-infix-ops: 0

# temporary
no-func-assign: 0
semi: 2
space-after-keywords: [ 2, always, , { "checkFunctionKeyword": true } ]
space-before-blocks: 2
space-in-brackets: [ 2, always, { propertyName: false } ]
space-in-parens: [ 2, never ]
space-infix-ops: 2
space-return-throw-case: 2
space-unary-ops: 2
spaced-line-comment: [ 2, always, { exceptions: [ '/' ] } ]
strict: 2
use-isnan: 2
yoda: 2
valid-typeof: 2

#
# Our custom rules
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Expand Up @@ -23,7 +23,7 @@ help:


lint:
./node_modules/.bin/eslint ./
./node_modules/.bin/eslint --reset ./


test: lint
Expand Down
2 changes: 1 addition & 1 deletion benchmark/benchmark.js
Expand Up @@ -22,7 +22,7 @@ fs.readdirSync(IMPLS_DIRECTORY).sort().forEach(function (name) {
var file = path.join(IMPLS_DIRECTORY, name);
var code = require(file);

IMPLS_PATHS[ name ] = file;
IMPLS_PATHS[name] = file;
IMPLS.push({
name: name,
code: code
Expand Down
2 changes: 1 addition & 1 deletion index.js
Expand Up @@ -85,7 +85,7 @@ function resizeBuffer(options, callback) {
// Fallback to sync call, if WebWorkers not available
_opts.dest = options.dest;
resize(_opts, callback);
return undefined;
return null;
}


Expand Down
3 changes: 2 additions & 1 deletion lib/pure/blur.js
Expand Up @@ -13,7 +13,7 @@ var _blurKernel = new Uint8Array([
var _bkWidth = Math.floor(Math.sqrt(_blurKernel.length));
var _bkHalf = Math.floor(_bkWidth / 2);
var _bkWsum = 0;
for (var wc=0; wc < _blurKernel.length; wc++) { _bkWsum += _blurKernel[wc]; }
for (var wc = 0; wc < _blurKernel.length; wc++) { _bkWsum += _blurKernel[wc]; }


function blurPoint(gs, x, y, srcW, srcH) {
Expand Down Expand Up @@ -50,6 +50,7 @@ function blurPoint(gs, x, y, srcW, srcH) {
bPtr++;
}
}
/*eslint-disable space-infix-ops*/
return ((br - (br % wsum)) / wsum)|0;
}

Expand Down
12 changes: 8 additions & 4 deletions lib/pure/resize.js
Expand Up @@ -79,7 +79,7 @@ function createFilters(quality, srcSize, destSize) {
floatFilter, fxpFilter, total, fixedTotal, pxl, idx, floatVal, fixedVal;
var leftNotEmpty, rightNotEmpty, filterShift, filterSize;

var maxFilterElementSize = Math.floor((srcWindow + 1) * 2 );
var maxFilterElementSize = Math.floor((srcWindow + 1) * 2);
var packedFilter = new Int16Array((maxFilterElementSize + 2) * destSize);
var packedFilterPtr = 0;

Expand Down Expand Up @@ -174,6 +174,8 @@ function convolveHorizontally(src, dest, srcW, srcH, destW, filters) {
for (srcY = 0; srcY < srcH; srcY++) {
filterPtr = 0;

/*eslint-disable space-infix-ops*/

// Apply precomputed filters to each destination row point
for (destX = 0; destX < destW; destX++) {
// Get the filter that determines the current output pixel.
Expand Down Expand Up @@ -226,6 +228,8 @@ function convolveVertically(src, dest, srcW, srcH, destW, filters) {
for (srcY = 0; srcY < srcH; srcY++) {
filterPtr = 0;

/*eslint-disable space-infix-ops*/

// Apply precomputed filters to each destination row point
for (destX = 0; destX < destW; destX++) {
// Get the filter that determines the current output pixel.
Expand Down Expand Up @@ -277,10 +281,10 @@ function resize(options) {
var destW = options.toWidth;
var destH = options.toHeight;
var dest = options.dest || new Uint8Array(destW * destH * 4);
var quality = options.quality === undefined ? 3 : options.quality;
var quality = typeof options.quality === 'undefined' ? 3 : options.quality;
var alpha = options.alpha || false;
var unsharpAmount = options.unsharpAmount === undefined ? 0 : (options.unsharpAmount|0);
var unsharpThreshold = options.unsharpThreshold === undefined ? 0 : (options.unsharpThreshold|0);
var unsharpAmount = typeof options.unsharpAmount === 'undefined' ? 0 : (options.unsharpAmount|0);
var unsharpThreshold = typeof options.unsharpThreshold === 'undefined' ? 0 : (options.unsharpThreshold|0);

if (srcW < 1 || srcH < 1 || destW < 1 || destH < 1) { return []; }

Expand Down
1 change: 1 addition & 0 deletions lib/pure/unsharp.js
Expand Up @@ -27,6 +27,7 @@ function greyscale(src, srcW, srcH) {
var i, srcPtr;

for (i = 0, srcPtr = 0; i < size; i++) {
/*eslint-disable space-infix-ops*/
result[i] = (src[srcPtr + 2] * 7471 // blue
+ src[srcPtr + 1] * 38470 // green
+ src[srcPtr] * 19595) >>> 8; // red
Expand Down
4 changes: 2 additions & 2 deletions package.json
Expand Up @@ -31,8 +31,8 @@
},
"devDependencies": {
"browserify": "*",
"eslint": "0.8.0",
"eslint-plugin-nodeca": "^1.0.0",
"eslint": "0.10.1",
"eslint-plugin-nodeca": "^1.0.3",
"uglify-js": "*",
"canvas": "1.1.x",
"benchmark": "1.0.x",
Expand Down

0 comments on commit c342090

Please sign in to comment.