Skip to content

Commit

Permalink
Bump eslint-plugin-coorpacademy
Browse files Browse the repository at this point in the history
  • Loading branch information
godu committed Nov 16, 2016
1 parent 2fadd2d commit 846e5b8
Show file tree
Hide file tree
Showing 32 changed files with 198 additions and 192 deletions.
2 changes: 1 addition & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ charset = utf-8
end_of_line = lf
insert_final_newline = true
indent_style = space
indent_size = 4
indent_size = 2
trim_trailing_whitespace = true

# Do not trim in jade files
Expand Down
7 changes: 5 additions & 2 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,8 @@
],
"plugins": [
"@coorpacademy/coorpacademy"
]
}
],
"rules": {
"promise/no-native": 0
}
}
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
"rxjs": "^5.0.0-beta.7"
},
"devDependencies": {
"@coorpacademy/eslint-plugin-coorpacademy": "^1.2.1",
"@coorpacademy/eslint-plugin-coorpacademy": "^2.0.0",
"ava": "^0.16.0",
"babel-cli": "^6.18.0",
"babel-core": "^6.18.2",
Expand All @@ -49,6 +49,7 @@
"coveralls": "^2.11.15",
"eslint": "^3.10.2",
"eslint-plugin-ava": "^4.0.0",
"eslint-plugin-import": "^2.2.0",
"eslint-plugin-lodash-fp": "^2.1.3",
"nyc": "^9.0.1"
},
Expand Down
33 changes: 18 additions & 15 deletions src/api.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
import path from 'path';
import {
join,
relative
} from 'path';
import {
find,
getOr,
keys,
startsWith,
curry
} from 'lodash/fp';
import {stringify, parseValue} from './parse';
import {set$} from './util/etcd';
import createDebug from 'debug';
import {set$} from './util/etcd';
import {stringify, parseValue} from './parse';

const debug = createDebug('squirrel');

Expand All @@ -30,29 +33,29 @@ const createAPI = (store, client, options = {cwd: '/'}) => {
return getByRaw(index, key).then(getOr(null, ['value']));
};

const _get = curry((_path, node) => {
if (!node) return null;
if (relative(node.key, _path) === '') return node;

return _get(_path, find(function(child) {
return startsWith(child.key, _path);
}, node.nodes));
});

const get = path => {
debug(`get => ${path}`);
return store('node').then(_get(path));
};

const set = (_path, value) => {
_path = path.join(options.cwd, _path);
debug(`set => ${_path}`);
return set$(client, _path, stringify(value))
const fullPath = join(options.cwd, _path);
debug(`set => ${fullPath}`);
return set$(client, fullPath, stringify(value))
.pluck('node', 'value')
.map(parseValue)
.toPromise();
};

const _get = curry((_path, node) => {
if (!node) return null;
if (path.relative(node.key, _path) === '') return node;

return _get(_path, find(function(child) {
return startsWith(child.key, _path);
}, node.nodes));
});

return {
getBy,
getByRaw,
Expand Down
8 changes: 4 additions & 4 deletions src/bin/sync.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@

import {resolve} from 'path';
import minimist from 'minimist';

import makeEtcdClient from './etcd';
import {sync$} from '../util/cli';
import makeEtcdClient from './etcd';

const argz = minimist(process.argv.slice(2));

Expand All @@ -13,6 +12,7 @@ const pathETCD = resolve('/', argz._[1]);

const client = makeEtcdClient(argz);

sync$(client, pathFS, pathETCD).toPromise().then(() =>
process.stdout.write(`The end.\n`)
sync$(client, pathFS, pathETCD).toPromise().then( // eslint-disable-line promise/catch-or-return
() => process.stdout.write(`The end.\n`),
err => process.stderr.write(`${err.stack}\n`)
);
3 changes: 1 addition & 2 deletions src/bin/watch.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@

import {resolve} from 'path';
import minimist from 'minimist';

import makeEtcdClient from './etcd';
import createWatcher$ from '../watch';
import {stringify} from '../parse';
import makeEtcdClient from './etcd';

const argz = minimist(process.argv.slice(2));

Expand Down
24 changes: 16 additions & 8 deletions src/build-index.js
Original file line number Diff line number Diff line change
@@ -1,31 +1,39 @@
import {
assign,
cond,
constant,
flatMap,
get,
getOr,
map,
pipe,
reduce,
zipObject
} from 'lodash/fp';
import createDebug from 'debug';
const debug = createDebug('squirrel:indexer');

const updateIndexes = indexes => store => {
debug(`Update indexes ${indexes.join(',')}`);
return zipObject(indexes, map(function(index) {
return buildIndex(index, store);
}, indexes));
};
const debug = createDebug('squirrel:indexer');

const buildIndex = (index, node) => {
const value = get(index, node.value);

return pipe(
cond([
[get('dir'), getOr([], 'nodes')],
[constant(true), constant([])]
]),
flatMap(function(child) {
return buildIndex(index, child);
}),
reduce(assign, value ? zipObject([get(index, node.value)], [node]) : {})
)(node.dir && node.nodes || []);
)(node);
};

const updateIndexes = indexes => store => {
debug(`Update indexes ${indexes.join(',')}`);
return zipObject(indexes, map(function(index) {
return buildIndex(index, store);
}, indexes));
};

export default updateIndexes;
3 changes: 2 additions & 1 deletion src/combine.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {set, del} from './patch';
import createDebug from 'debug';
import {set, del} from './patch';

const debug = createDebug('squirrel:combine');

const createCombiner$ = event$ => {
Expand Down
3 changes: 2 additions & 1 deletion src/fallback.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import {readFile} from 'fs';
import {isString, identity} from 'lodash/fp';
import {Observable} from 'rxjs';
import {parseAction} from './parse';
import createDebug from 'debug';
import {parseAction} from './parse';

const debug = createDebug('squirrel:fallback');

const readFile$ = Observable.bindNodeCallback(readFile);
Expand Down
3 changes: 2 additions & 1 deletion src/fetch.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {Observable} from 'rxjs';
import {parseAction} from './parse';
import createDebug from 'debug';
import {parseAction} from './parse';

const debug = createDebug('squirrel:etcd');

const createFetch$ = (client, cwd) => {
Expand Down
7 changes: 3 additions & 4 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import {
import Etcd from 'node-etcd';
import {Observable} from 'rxjs';
import createDebug from 'debug';

import createEtcd$ from './etcd';
import createFallback$ from './fallback';
import createCombiner$ from './combine';
Expand All @@ -17,9 +16,9 @@ import createIndexBuilder from './build-index';

const debug = createDebug('squirrel');

const createSquirrel = options => {
const createSquirrel = _options => {
debug('Init');
options = assign({
const options = assign({
hosts: 'http://localhost:2379',
auth: null,
ca: null,
Expand All @@ -30,7 +29,7 @@ const createSquirrel = options => {

cwd: '/',
indexes: []
}, options);
}, _options);

const client = new Etcd(options.hosts, pick(['auth', 'ca', 'key', 'cert'], options));
const indexBuilder = createIndexBuilder(options.indexes);
Expand Down
8 changes: 4 additions & 4 deletions src/parse.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ export const parseNode = pipe(
);

export const parseAction = action => {
return reduce((action, key) => {
if (has(key, action)) {
return set(key, parseNode(get(key, action)), action);
return reduce((_action, key) => {
if (has(key, _action)) {
return set(key, parseNode(get(key, _action)), _action);
}
return action;
return _action;
}, action, ['node', 'prevNode']);
};
1 change: 1 addition & 0 deletions src/patch.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
startsWith
} from 'lodash/fp';
import createDebug from 'debug';

const debug = createDebug('squirrel:patch');

const get = (store, {action, node}) => {
Expand Down
3 changes: 2 additions & 1 deletion src/resync.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {Observable} from 'rxjs';
import createFetcher$ from './fetch';
import createDebug from 'debug';
import createFetcher$ from './fetch';

const debug = createDebug('squirrel:etcd');

const createResync$ = (client, cwd, events$) =>
Expand Down
1 change: 1 addition & 0 deletions src/save.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {Observable} from 'rxjs';
import {isString} from 'lodash/fp';
import createDebug from 'debug';
import {stringify} from './parse';

const debug = createDebug('squirrel:save');

const writeFile$ = Observable.bindNodeCallback(writeFile);
Expand Down
14 changes: 7 additions & 7 deletions src/test/api.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import test from 'ava';
import createEtcdMock from '../util/test/helpers/etcd';
import {stringify} from '../parse';

import createAPI from '../api';

const node = {
key: '/',
dir: true,
Expand Down Expand Up @@ -213,9 +213,9 @@ test('should get null if no node matches this path', async t => {
);
});

const createAction = (type, node) => ({
const createAction = (type, _node) => ({
type,
node
node: _node
});
const createNode = (key, value) => ({
key,
Expand All @@ -233,9 +233,9 @@ test('should set value if value setted', async t => {
values: [null, createAction('set', createNode('/foo', {foo: 'baz'})), null]
}]
});
const api = createAPI(getStore, client);
const _api = createAPI(getStore, client);
t.deepEqual(
await api.set('/foo', {foo: 'baz'}),
await _api.set('/foo', {foo: 'baz'}),
{foo: 'baz'}
);
});
Expand All @@ -244,9 +244,9 @@ test('should failed if error occured', async t => {
const client = createEtcdMock({
set: [[new Error('boom'), null, null]]
});
const api = createAPI(getStore, client);
const _api = createAPI(getStore, client);
t.throws(
api.set('/foo', {foo: 'baz'}),
_api.set('/foo', {foo: 'baz'}),
/boom/
);
});
2 changes: 0 additions & 2 deletions src/test/combine.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import test from 'ava';
import {Observable} from 'rxjs';

import createCombiner$ from '../combine';

import emptyRoot from './fixtures/empty-root';
import setEvent from './fixtures/set-event';

Expand Down
6 changes: 2 additions & 4 deletions src/test/etcd.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
import {EventEmitter} from 'events';
import {EventEmitter} from 'events'; // eslint-disable-line fp/no-events
import test from 'ava';

import createEtcd$ from '../etcd';

import createEtcdMock from '../util/test/helpers/etcd';
import setEvent from './fixtures/set-event';
import deleteEvent from './fixtures/delete-event';
import resyncEvent from './fixtures/resync-event';
import createEtcdMock from '../util/test/helpers/etcd';

test('should composite events observable', async t => {
const getMocks = [[null, {
Expand Down
4 changes: 1 addition & 3 deletions src/test/fallback.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import test from 'ava';
import {join} from 'path';
import test from 'ava';
import {parseNode} from '../parse';

import createFallback$ from '../fallback';

import expected from './fixtures/fallback';

test('should load fallback', async t => {
Expand Down
4 changes: 1 addition & 3 deletions src/test/fetch.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import test from 'ava';
import {pipe, fill, map, concat} from 'lodash/fp';

import createFetch$ from '../fetch';

import emptyRoot from './fixtures/empty-root';
import createEtcdMock from '../util/test/helpers/etcd';
import emptyRoot from './fixtures/empty-root';

test('should fetch nodes', t => {
const client = createEtcdMock({
Expand Down
2 changes: 1 addition & 1 deletion src/test/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import test from 'ava';
import createClient from '../index';
import createClient from '../index'; // eslint-disable-line import/default

test('should createClient', t => {
const client = createClient();
Expand Down
4 changes: 1 addition & 3 deletions src/test/resync.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
import test from 'ava';
import {Observable} from 'rxjs';

import createResyncer$ from '../resync';

import createEtcdMock from '../util/test/helpers/etcd';
import setEvent from './fixtures/set-event';
import resyncEvent from './fixtures/resync-event';
import createEtcdMock from '../util/test/helpers/etcd';

test('should transform resync event', async t => {
const client = createEtcdMock({
Expand Down
1 change: 0 additions & 1 deletion src/test/save.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import {readFile} from 'fs';
import test from 'ava';
import {Observable} from 'rxjs';
import createSave from '../save';

import fallback from './fixtures/fallback';

const readFile$ = Observable.bindNodeCallback(readFile);
Expand Down
Loading

0 comments on commit 846e5b8

Please sign in to comment.