Skip to content

Commit

Permalink
[#2] Configure ESLint using AirBnB style
Browse files Browse the repository at this point in the history
  • Loading branch information
vitorbaptista committed Jan 31, 2016
1 parent d4073c1 commit 2aedba6
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 23 deletions.
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
lib/schemas/*
5 changes: 5 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
parser: babel-eslint

This comment has been minimized.

Copy link
@pwalsh

pwalsh Feb 1, 2016

Contributor

https://github.com/okfn/coding-standards#tldr

Is there a reason not to use jscs? We are using now in many codebases, and I'd rather be consistent.

This comment has been minimized.

Copy link
@vitorbaptista

vitorbaptista Feb 1, 2016

Author Contributor

Oh, sorry, missed that in our standards. I would argue for us to move to eslint, though. See okfn/coding-standards#5

extends: airbnb/base
env:
node: true
browser: true
19 changes: 6 additions & 13 deletions lib/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import 'babel-polyfill';
import _ from 'underscore';
import fs from 'fs';
import path from 'path';
import csv from 'csv';
Expand All @@ -8,17 +7,11 @@ import 'isomorphic-fetch';

const DEFAULT_REGISTRY = Promise.promisify(csv.parse)(
fs.readFileSync(path.join(__dirname, 'schemas', 'registry.csv'), 'utf8'),
{columns: true}
{ columns: true }
);

let schemas = {
base: JSON.parse(fs.readFileSync(path.join(__dirname, 'schemas', 'data-package.json'), 'utf8')),
tabular: JSON.parse(fs.readFileSync(path.join(__dirname, 'schemas', 'tabular-data-package.json'), 'utf8')),
fiscal: JSON.parse(fs.readFileSync(path.join(__dirname, 'schemas', 'fiscal-data-package.json'), 'utf8')),
}

class Registry {
constructor(url=undefined) {
constructor(url = undefined) {
if (!url) {
this._registry = DEFAULT_REGISTRY;
} else {
Expand All @@ -27,15 +20,15 @@ class Registry {
}

get() {
return this._get_registry();
return this._getRegistry();
}

_get_registry() {
_getRegistry() {
if (this._registry) return this._registry;

this._registry = fetch(this._url)
.then((response) => {
if (response.status != 200) {
if (response.status !== 200) {
throw new Error('Bad response from server');
}

Expand All @@ -46,7 +39,7 @@ class Registry {
throw err;
}

return Promise.promisify(csv.parse)(text, {columns: true});
return Promise.promisify(csv.parse)(text, { columns: true });
});

return this._registry;
Expand Down
6 changes: 5 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
},
"devDependencies": {
"babel-cli": "^6.4.5",
"babel-eslint": "^5.0.0-beta8",
"babel-istanbul": "^0.6.0",
"babel-polyfill": "^6.3.14",
"babel-preset-es2015": "^6.3.13",
Expand All @@ -27,6 +28,8 @@
"browserify": "^13.0.0",
"chai": "^3.0.0",
"coveralls": "~2.11.4",
"eslint": "^1.10.3",
"eslint-config-airbnb": "^4.0.0",
"fetch-mock": "^4.1.0",
"karma": "^0.13.19",
"karma-browserify": "^5.0.1",
Expand All @@ -39,9 +42,10 @@
"watchify": "^3.7.0"
},
"scripts": {
"test": "npm run test:nodejs; npm run test:browser",
"test": "npm run lint; npm run test:nodejs; npm run test:browser",
"test:browser": "karma start",
"test:nodejs": "mocha --compilers js:babel-register --timeout 5000 ./test",
"lint": "eslint lib/**/*.js test/**/*.js",
"coverage": "babel-node ./node_modules/.bin/babel-istanbul cover _mocha ./test/*",
"coveralls": "cat ./coverage/lcov.info | coveralls"
},
Expand Down
5 changes: 5 additions & 0 deletions test/.eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
env:
mocha: true
rules:
no-unused-expressions: 0
18 changes: 9 additions & 9 deletions test/test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import fetchMock from 'fetch-mock';
import Registry from '..';
import chai from 'chai';
chai.should()
chai.should();

describe('Data Package Registry', () => {
const CONFIG = {
Expand All @@ -13,7 +13,7 @@ describe('Data Package Registry', () => {
fetchMock.restore();
fetchMock.mock(CONFIG.backend, 'id,title,schema,specification');

let registry = new Registry(CONFIG.backend);
const registry = new Registry(CONFIG.backend);

registry.get().then.should.be.not.undefined;
});
Expand All @@ -24,7 +24,7 @@ describe('Data Package Registry', () => {
fetchMock.restore();
fetchMock.mock(CONFIG.backend, 'id,title,schema,specification\n1,2,3,4');

let registry = new Registry(CONFIG.backend);
const registry = new Registry(CONFIG.backend);

registry.get().then((data) => {
data.should.be.not.empty;
Expand All @@ -38,7 +38,7 @@ describe('Data Package Registry', () => {
fetchMock.restore();
fetchMock.mock(CONFIG.backend, 'id,title,schema,specification');

let registry = new Registry(CONFIG.backend);
const registry = new Registry(CONFIG.backend);

registry.get().then((data) => {
data.should.be.empty;
Expand All @@ -52,9 +52,9 @@ describe('Data Package Registry', () => {
fetchMock.restore();
fetchMock.mock(CONFIG.backend, 500);

let registry = new Registry(CONFIG.backend);
const registry = new Registry(CONFIG.backend);

registry.get().catch((error) => {
registry.get().catch(() => {
done();
});
});
Expand All @@ -65,15 +65,15 @@ describe('Data Package Registry', () => {
fetchMock.restore();
fetchMock.mock(CONFIG.backend, 'id,title,schema,specification\n1,2,3,4');

let registry = new Registry(CONFIG.backend);
const registry = new Registry(CONFIG.backend);

registry.get().then(() => {
fetchMock.restore();
fetchMock.mock(CONFIG.backend, 500);

registry.get().then((data) => {
registry.get().then(() => {
done();
})
});
});
});
});
Expand Down

0 comments on commit 2aedba6

Please sign in to comment.