Skip to content

Commit

Permalink
Use eslint-config-metarhia and fix linting issues
Browse files Browse the repository at this point in the history
  • Loading branch information
belochub committed Oct 18, 2018
1 parent 0d07aec commit 5e58368
Show file tree
Hide file tree
Showing 67 changed files with 879 additions and 660 deletions.
174 changes: 1 addition & 173 deletions .eslintrc.yml
Original file line number Diff line number Diff line change
@@ -1,173 +1 @@
env:
es6: true
node: true
extends: 'eslint:recommended'
globals:
api: false
rules:
indent:
- error
- 2
- SwitchCase: 1
VariableDeclarator:
var: 2
let: 2
const: 3
MemberExpression: 1
linebreak-style:
- error
- unix
quotes:
- error
- single
semi:
- error
- always
eqeqeq:
- error
- always
no-loop-func:
- error
strict:
- error
- global
block-spacing:
- error
- always
brace-style:
- error
- 1tbs
- allowSingleLine: true
camelcase:
- error
comma-style:
- error
- last
comma-spacing:
- error
- before: false
after: true
eol-last:
- error
func-call-spacing:
- error
- never
key-spacing:
- error
- beforeColon: false
afterColon: true
mode: minimum
keyword-spacing:
- error
- before: true
after: true
overrides:
function:
after: false
max-len:
- error
- code: 80
ignoreUrls: true
max-nested-callbacks:
- error
- max: 7
new-cap:
- error
- newIsCap: true
capIsNew: true
properties: true
new-parens:
- error
no-lonely-if:
- error
no-trailing-spaces:
- error
no-unneeded-ternary:
- error
no-whitespace-before-property:
- error
object-curly-spacing:
- error
- always
operator-assignment:
- error
- always
operator-linebreak:
- error
- after
semi-spacing:
- error
- before: false
after: true
space-before-blocks:
- error
- always
space-before-function-paren:
- error
- never
space-in-parens:
- error
- never
space-infix-ops:
- error
space-unary-ops:
- error
- words: true
nonwords: false
overrides:
typeof: false
no-unreachable:
- error
no-global-assign:
- error
no-self-compare:
- error
no-unmodified-loop-condition:
- error
no-constant-condition:
- error
- checkLoops: false
no-console:
- off
no-useless-concat:
- error
no-useless-escape:
- error
no-shadow-restricted-names:
- error
no-use-before-define:
- error
- functions: false
arrow-body-style:
- error
- as-needed
arrow-spacing:
- error
no-confusing-arrow:
- error
- allowParens: true
no-useless-computed-key:
- error
no-useless-rename:
- error
no-var:
- error
object-shorthand:
- error
- always
prefer-arrow-callback:
- error
prefer-const:
- error
prefer-numeric-literals:
- error
prefer-rest-params:
- error
prefer-spread:
- error
rest-spread-spacing:
- error
- never
template-curly-spacing:
- error
- never
extends: 'metarhia'
27 changes: 12 additions & 15 deletions lib/adapters.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@

const common = require('metarhia-common');

const callbackify = (
// Convert source to callback-last contract
source // promise or regular synchronous function
// Returns: callback, function
) => {
// Convert source to callback-last contract
// source - promise or regular synchronous function
// Returns: callback, function
const callbackify = source => {
if (typeof source === 'function') {
return (...args) => {
const callback = common.unsafeCallback(args);
Expand All @@ -27,11 +26,10 @@ const callbackify = (
}
};

const promisify = (
// Convert async function to Promise object
func // function, callback-last function
// Returns: object, Promise instance
) => {
// Convert async function to Promise object
// func - function, callback-last function
// Returns: object, Promise instance
const promisify = func => {
const promisified = (...args) => {
const promise = new Promise((resolve, reject) => {
func(...args, (err, data) => {
Expand All @@ -44,11 +42,10 @@ const promisify = (
return promisified;
};

const promisifySync = (
// Convert sync function to Promise object
func // function, regular synchronous function
// Returns: object, Promise instance
) => (...args) => new Promise((resolve, reject) => {
// Convert sync function to Promise object
// func - function, regular synchronous function
// Returns: object, Promise instance
const promisifySync = func => (...args) => new Promise((resolve, reject) => {
const result = func(...args);
if (result instanceof Error) reject(result);
else resolve(result);
Expand Down
4 changes: 2 additions & 2 deletions lib/array.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ const each = (
let count = 0;
let errored = false;

const next = (err) => {
const next = err => {
if (errored) return;
if (err) {
errored = true;
Expand Down Expand Up @@ -181,7 +181,7 @@ const series = (
done(null, items);
return;
}
fn(items[i], (err) => {
fn(items[i], err => {
if (err) {
done(err);
return;
Expand Down
22 changes: 12 additions & 10 deletions lib/chain.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ const async = op => {
case 'series': return series;
case 'find': return find;
}
return null;
};

function ArrayChain(array) {
Expand All @@ -23,7 +24,7 @@ ArrayChain.prototype.execute = function(err) {

if (!item.op) {
if (err) throw err;
else return;
else return null;
}

const next = (err, data) => {
Expand All @@ -37,7 +38,7 @@ ArrayChain.prototype.execute = function(err) {

if (err) {
this.execute(err);
return;
return null;
}

if (item.isSync) {
Expand All @@ -47,6 +48,8 @@ ArrayChain.prototype.execute = function(err) {
const op = async(item.op);
op(this.array, item.fn, next);
}

return null;
};

ArrayChain.prototype.fetch = function(fn) {
Expand Down Expand Up @@ -90,15 +93,15 @@ const syncDelegates = {
opNames: ['concat', 'slice', 'includes'],
handler(op, ...args) {
return this.array[op](...args);
}
},
},
modify: {
opNames: ['reverse', 'sort', 'shift', 'unshift', 'push', 'pop'],
handler(op, ...args) {
this.array[op](...args);
return this.array;
}
}
},
},
};

for (const delegateType in syncDelegates) {
Expand All @@ -112,11 +115,10 @@ for (const delegateType in syncDelegates) {
}
}

const forArrayChain = (
// Create an ArrayChain instance
array // array, start mutations from this data
// Returns: ArrayChain instance
) => (
// Create an ArrayChain instance
// array - array, start mutations from this data
// Returns: ArrayChain instance
const forArrayChain = array => (
new ArrayChain(array)
);

Expand Down
9 changes: 4 additions & 5 deletions lib/collector.class.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,11 +115,10 @@ class Collector {
}
}

const collect = (
// Collector instance constructor
expected // number or array of string,
// Returns: Collector, instance
) => (
// Collector instance constructor
// expected - number or array of string,
// Returns: Collector, instance
const collect = expected => (
new Collector(expected)
);

Expand Down
22 changes: 10 additions & 12 deletions lib/collector.functor.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,10 @@
const TYPE_ERROR = 'Metasync: Collect unexpected type';
const COLLECT_TIMEOUT = 'Metasync: Collector timed out';

const collect = (
// Collector instance constructor
expected // number or array of string, count or keys
// Returns: functor, collector
) => {
// Collector instance constructor
// expected - number or array of string, count or keys
// Returns: functor, collector
const collect = expected => {
const isCount = typeof expected === 'number';
const isKeys = Array.isArray(expected);
if (!(isCount || isKeys)) throw new TypeError(TYPE_ERROR);
Expand All @@ -26,12 +25,12 @@ const collect = (
const collector = (key, err, value) => {
if (isDone) return collector;
if (!isDistinct || !(key in data)) {
if (!isCount && !keys.has(key)) return;
if (!isCount && !keys.has(key)) return null;
count++;
}
if (err) {
collector.finalize(err, data);
return;
return null;
}
data[key] = value;
if (expected === count) {
Expand All @@ -50,7 +49,7 @@ const collect = (
return collector;
},

timeout: (msec) => {
timeout: msec => {
if (msec) {
timer = setTimeout(() => {
const err = new Error(COLLECT_TIMEOUT);
Expand All @@ -61,9 +60,8 @@ const collect = (
return collector;
},

done: (
callback // function, (error, data)
) => {
// callback - function, (error, data)
done: callback => {
onDone = callback;
return collector;
},
Expand All @@ -78,7 +76,7 @@ const collect = (
distinct: (value = true) => {
isDistinct = value;
return collector;
}
},
};

return Object.assign(collector, methods);
Expand Down
Loading

0 comments on commit 5e58368

Please sign in to comment.