Skip to content

Commit

Permalink
fixup! 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 25, 2018
1 parent 3fe2abf commit 978b946
Show file tree
Hide file tree
Showing 22 changed files with 150 additions and 155 deletions.
4 changes: 3 additions & 1 deletion lib/chain.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ const async = op => {
case 'series': return series;
case 'find': return find;
}
return null;
return (items, fn, callback) => {
callback(null, items.slice());
};
};

function ArrayChain(array) {
Expand Down
4 changes: 2 additions & 2 deletions lib/collector.functor.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@ const collect = expected => {
const collector = (key, err, value) => {
if (isDone) return collector;
if (!isDistinct || !(key in data)) {
if (!isCount && !keys.has(key)) return null;
if (!isCount && !keys.has(key)) return collector;
count++;
}
if (err) {
collector.finalize(err, data);
return null;
return collector;
}
data[key] = value;
if (expected === count) {
Expand Down
8 changes: 2 additions & 6 deletions lib/fp.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,7 @@ const asAsync = (
const of = (
// Hint: pure :: Applicative f => a -> f a
...args // array
) => (
asAsync(callback => callback(null, ...args))
);
) => asAsync(callback => callback(null, ...args));

const concat = (
// Hint: concat :: Monoid m => a -> a -> a
Expand All @@ -57,9 +55,7 @@ const ap = (
// Hint: <*> :: Applicative f => f (a -> b) -> f a -> f b
fn, // function
funcA // function
) => (
concat(funcA, (f, callback) => fmap(fn, f)(callback))
);
) => concat(funcA, (f, callback) => fmap(fn, f)(callback));

asyncChainMethods = { fmap, ap, concat };

Expand Down
4 changes: 2 additions & 2 deletions lib/poolify.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const poolify = (factory, min, norm, max) => {
if (delayed) delayed(item);
else pool.items.push(item);
}
return undefined;
return pool;
}
if (pool.items.length < min && allocated < max) {
const grow = Math.min(max - allocated, norm - pool.items.length);
Expand All @@ -31,7 +31,7 @@ const poolify = (factory, min, norm, max) => {
const callback = provide(par);
if (res) callback(res);
else pool.delayed.push(callback);
return undefined;
return pool;
};
return Object.assign(pool, {
items: duplicate(factory, norm),
Expand Down
7 changes: 4 additions & 3 deletions lib/poolify.opt.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ const poolify = (factory, min, norm, max) => {
let allocated = norm;
const items = duplicate(factory, norm);
const delayed = [];
return par => {
const pool = par => {
if (Array.isArray(par)) {
while (par.length) {
const item = par.shift();
const request = delayed.shift();
if (request) request(item);
else items.push(item);
}
return undefined;
return pool;
}
if (items.length < min && allocated < max) {
const grow = Math.min(max - allocated, norm - items.length);
Expand All @@ -33,8 +33,9 @@ const poolify = (factory, min, norm, max) => {
const callback = provide(par);
if (res) callback(res);
else delayed.push(callback);
return undefined;
return pool;
};
return pool;
};

module.exports = { poolify };
4 changes: 2 additions & 2 deletions lib/poolify.symbol.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const poolify = (factory, min, norm, max) => {
const delayed = pool.delayed.shift();
if (delayed) delayed(par);
else pool.items.push(par);
return undefined;
return pool;
}
if (pool.items.length < min && allocated < max) {
const grow = Math.min(max - allocated, norm - pool.items.length);
Expand All @@ -34,7 +34,7 @@ const poolify = (factory, min, norm, max) => {
const callback = provide(par);
if (res) callback(res);
else pool.delayed.push(callback);
return undefined;
return pool;
};
return Object.assign(pool, {
items: duplicate(factory, norm),
Expand Down
36 changes: 11 additions & 25 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
"babel-cli": "^6.26.0",
"babel-preset-env": "^1.7.0",
"eslint": "^5.7.0",
"eslint-config-metarhia": "^5.0.0",
"eslint-config-metarhia": "^6.0.0",
"eslint-plugin-import": "^2.14.0",
"metaschema": "^0.0.7",
"metatests": "^0.2.1"
Expand Down
4 changes: 2 additions & 2 deletions test/array.every.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ metatests.test('every with error', test => {
});
});

metatests.test('every with empty array', test => (
metatests.test('every with empty array', test =>
strictSameResult([], true, test, () => test.end())
));
);

metatests.test(
'every with one-element arrays',
Expand Down
8 changes: 4 additions & 4 deletions test/array.filter.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ metatests.test('successful filter', test => {
'do', 'ut', 'et', 'magna',
];

metasync.filter(arr, (str, callback) => process.nextTick(() => (
metasync.filter(arr, (str, callback) => process.nextTick(() =>
callback(null, str.length < 6)
)), (err, res) => {
), (err, res) => {
test.error(err);
test.same(res.join(), expectedArr.join());
test.end();
Expand All @@ -27,9 +27,9 @@ metatests.test('filter with empty array', test => {
const arr = [];
const expectedArr = [];

metasync.filter(arr, (str, callback) => process.nextTick(() => (
metasync.filter(arr, (str, callback) => process.nextTick(() =>
callback(null, str.length < 6)
)), (err, res) => {
), (err, res) => {
test.error(err);
test.strictSame(res, expectedArr);
test.end();
Expand Down
36 changes: 20 additions & 16 deletions test/array.find.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ metatests.test('find with error', test => {
metatests.test('find', test => {
const data = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16];
const expected = 15;
const predicate = (item, callback) => process.nextTick(() => (
const predicate = (item, callback) => process.nextTick(() =>
callback(null, item % 3 === 0 && item % 5 === 0)
));
);

metasync.find(data, predicate, (err, result) => {
test.error(err, 'must not return an error');
Expand All @@ -36,22 +36,26 @@ metatests.test('find', test => {
});

metatests.test('with empty array', test => {
metasync.find([], (el, callback) => (
process.nextTick(() => callback(null, true))
), (err, result) => {
test.error(err);
test.strictSame(result, undefined);
test.end();
});
metasync.find(
[],
(el, callback) => process.nextTick(() => callback(null, true)),
(err, result) => {
test.error(err);
test.strictSame(result, undefined);
test.end();
}
);
});

metatests.test('with array without element which is searching', test => {
const data = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16];
metasync.find(data, (el, callback) => (
process.nextTick(() => callback(null, el === 20))
), (err, result) => {
test.error(err);
test.strictSame(result, undefined);
test.end();
});
metasync.find(
data,
(el, callback) => process.nextTick(() => callback(null, el === 20)),
(err, result) => {
test.error(err);
test.strictSame(result, undefined);
test.end();
}
);
});
32 changes: 18 additions & 14 deletions test/array.map.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,30 @@ metatests.test('succesfull map', test => {
const arr = [1, 2, 3];
const expectedArr = [1, 4, 9];

metasync.map(arr, (x, callback) => (
process.nextTick(() => callback(null, x * x))
), (err, res) => {
test.error(err);
test.strictSame(res, expectedArr);
test.end();
});
metasync.map(
arr,
(x, callback) => process.nextTick(() => callback(null, x * x)),
(err, res) => {
test.error(err);
test.strictSame(res, expectedArr);
test.end();
}
);
});

metatests.test('map with empty array', test => {
const arr = [];
const expectedArr = [];

metasync.map(arr, (x, callback) => (
process.nextTick(() => callback(null, x * x))
), (err, res) => {
test.error(err);
test.strictSame(res, expectedArr);
test.end();
});
metasync.map(
arr,
(x, callback) => process.nextTick(() => callback(null, x * x)),
(err, res) => {
test.error(err);
test.strictSame(res, expectedArr);
test.end();
}
);
});

metatests.test('map with error', test => {
Expand Down
Loading

0 comments on commit 978b946

Please sign in to comment.