Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ESLint #27

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
module.exports = {
"extends": "babel",
"plugins": [
"jest",
"jasmine",
],
"env": {
"node": true,
"jest": true,
"jasmine": true,
},
};
10 changes: 9 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
"package": "npm run clean && npm run build && npm run bundle",
"test": "jest & npm run flow",
"build": "babel src --out-dir dist --ignore __tests__",
"flow": "flow check"
"flow": "flow check",
"eslint": "eslint src/ --format=codeframe",
"eslint-fix": "eslint src/ --fix --format=codeframe"
},
"author": "Andrew Levine",
"license": "MIT",
Expand All @@ -22,6 +24,7 @@
},
"devDependencies": {
"babel-cli": "^6.18.0",
"babel-eslint": "^7.1.1",
"babel-plugin-transform-async-to-generator": "^6.22.0",
"babel-plugin-transform-class-properties": "^6.19.0",
"babel-plugin-transform-es2015-destructuring": "^6.19.0",
Expand All @@ -30,6 +33,11 @@
"babel-plugin-transform-es2015-spread": "^6.8.0",
"babel-plugin-transform-flow-strip-types": "^6.21.0",
"babel-plugin-transform-object-rest-spread": "^6.20.2",
"eslint": "^3.18.0",
"eslint-config-babel": "^6.0.0",
"eslint-plugin-flowtype": "^2.30.3",
"eslint-plugin-jasmine": "^2.2.0",
"eslint-plugin-jest": "^19.0.1",
"flow-bin": "^0.37.4",
"jest": "^18.0.0"
},
Expand Down
48 changes: 24 additions & 24 deletions src/__tests__/logger.js
Original file line number Diff line number Diff line change
@@ -1,34 +1,34 @@
// @flow

import Logger from '../logger';
import Logger from "../logger";

describe('Logger', () => {
beforeEach(() => {
spyOn(console, 'log');
});
describe("Logger", () => {
beforeEach(() => {
spyOn(console, "log");
});

afterEach(() => {
delete process.env.LOG_LEVEL;
});
afterEach(() => {
delete process.env.LOG_LEVEL;
});

it('does not log when level is not allowed', () => {
process.env.LOG_LEVEL = 'normal';
const { log } = new Logger('test.js');
log('foo', 'verbose');
it("does not log when level is not allowed", () => {
process.env.LOG_LEVEL = "normal";
const { log } = new Logger("test.js");
log("foo", "verbose");

expect(console.log).toHaveBeenCalledTimes(0);
});
expect(console.log).toHaveBeenCalledTimes(0);
});

it('logs when level is allowed', () => {
process.env.LOG_LEVEL = 'verbose';
const { log } = new Logger('test.js');
log('foo', 'verbose');
it("logs when level is allowed", () => {
process.env.LOG_LEVEL = "verbose";
const { log } = new Logger("test.js");
log("foo", "verbose");

expect(console.log).toHaveBeenCalledTimes(1);
});
expect(console.log).toHaveBeenCalledTimes(1);
});

it('defaults to normal log level when not provided to `log`', () => {
const logger = new Logger('test.js');
expect(logger.level).toBe(0);
});
it("defaults to normal log level when not provided to `log`", () => {
const logger = new Logger("test.js");
expect(logger.level).toBe(0);
});
});
30 changes: 15 additions & 15 deletions src/__tests__/util.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
const fs = require('fs');
const path = require('path');
const util = require('../util');
const diff = fs.readFileSync(path.join(__dirname, '__fixtures__/diff.txt'), 'UTF-8');
const fs = require("fs");
const path = require("path");
const util = require("../util");
const diff = fs.readFileSync(path.join(__dirname, "__fixtures__/diff.txt"), "UTF-8");

const setsAreEqual = (setA, setB) => {
const pred = val => setB.has(val);
return Array.from(setA).every(pred);
const pred = (val) => setB.has(val);
return Array.from(setA).every(pred);
};

describe('packagesFromDiff', () => {
it('should return list of package names from diff', () => {
const packages = util.packagesFromDiff(diff);
const expectedPackages = new Set([
'babel-types',
'babel-plugin-transform-es2015-function-name'
]);
describe("packagesFromDiff", () => {
it("should return list of package names from diff", () => {
const packages = util.packagesFromDiff(diff);
const expectedPackages = new Set([
"babel-types",
"babel-plugin-transform-es2015-function-name"
]);

expect(setsAreEqual(packages, expectedPackages)).toBe(true);
});
expect(setsAreEqual(packages, expectedPackages)).toBe(true);
});
});
20 changes: 10 additions & 10 deletions src/auth.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
// @flow

import crypto from 'crypto';
import timingSafeEqual from 'timing-safe-equal';
import Logger from './logger';
import crypto from "crypto";
import timingSafeEqual from "timing-safe-equal";
import Logger from "./logger";

const { log } = new Logger('auth.js');
const { log } = new Logger("auth.js");

exports.isValid = (rawBody: string, signature: string, secret: string): bool => {
const newSignature = crypto
.createHmac('sha1', secret)
.update(new Buffer(rawBody, 'utf-8'))
.digest('hex');
const newSignature = crypto
.createHmac("sha1", secret)
.update(new Buffer(rawBody, "utf-8"))
.digest("hex");

log(`Received sha was ${signature}, new sha is ${newSignature}`, 'verbose');
log(`Received sha was ${signature}, new sha is ${newSignature}`, "verbose");

return timingSafeEqual(
return timingSafeEqual(
// Note: Should change to `Buffer.from` when AWS Lambda supports node >= 6
new Buffer(signature),
new Buffer(`sha1=${newSignature}`)
Expand Down
68 changes: 34 additions & 34 deletions src/github.js
Original file line number Diff line number Diff line change
@@ -1,39 +1,39 @@
// @flow

const got = require('got');
const got = require("got");

const BASE_URI = exports.BASE_URI = 'https://api.github.com';
const BASE_URI = exports.BASE_URI = "https://api.github.com";
const headers = {
Authorization: `token ${process.env.GITHUB_API_KEY || ''}`
Authorization: `token ${process.env.GITHUB_API_KEY || ""}`
};

const post = exports.post = (path: string, body: Object | Array<any>) => {
return got.post(`${BASE_URI}${path}`, {
headers,
body: JSON.stringify(body)
});
return got.post(`${BASE_URI}${path}`, {
headers,
body: JSON.stringify(body)
});
};

const get = exports.get = (uri: string, opts: Object) => got.get(uri, { headers, ...opts });

const del = exports.del = (path: string) => {
return got.delete(`${BASE_URI}${path}`, {
headers
});
return got.delete(`${BASE_URI}${path}`, {
headers
});
};

exports.addIssueComment = (issueId: string | number, owner: string, repo: string, comment: string) => {
const uri = `/repos/${owner}/${repo}/issues/${issueId}/comments`;
return post(uri, { body: comment });
const uri = `/repos/${owner}/${repo}/issues/${issueId}/comments`;
return post(uri, { body: comment });
};

exports.addLabels = (id: string | number, owner: string, repo: string, labels: Array<string>) => {
return post(`/repos/${owner}/${repo}/issues/${id}/labels`, labels);
return post(`/repos/${owner}/${repo}/issues/${id}/labels`, labels);
};

type OrgPayload = Promise<Array<{ login: string }>>;
exports.getUserOrgs = (username: string): OrgPayload => {
return get(`${BASE_URI}/users/${username}/orgs`, { json: true })
return get(`${BASE_URI}/users/${username}/orgs`, { json: true })
.then(({ body }) => body);
};

Expand All @@ -45,12 +45,12 @@ type NewIssueParams = {
};
type NewIssueResponse = { html_url: string; };
exports.newIssue = ({ title, body, owner, repo }: NewIssueParams): Promise<NewIssueResponse> => {
console.log('posting new issue');
return got.post(`${BASE_URI}/repos/${owner}/${repo}/issues`, {
headers,
json: true,
body: JSON.stringify({ title, body })
}).then(({ body }) => body);
console.log("posting new issue");
return got.post(`${BASE_URI}/repos/${owner}/${repo}/issues`, {
headers,
json: true,
body: JSON.stringify({ title, body })
}).then(({ body }) => body);
};

type CloseIssueParams = {
Expand All @@ -59,9 +59,9 @@ type CloseIssueParams = {
repo: string;
};
exports.closeIssue = ({ id, owner, repo }: CloseIssueParams) => {
return got.patch(`${BASE_URI}/repos/${owner}/${repo}/issues/${id}`, {
body: JSON.stringify({ state: 'closed' })
});
return got.patch(`${BASE_URI}/repos/${owner}/${repo}/issues/${id}`, {
body: JSON.stringify({ state: "closed" })
});
};

type IssueCommentParams = {
Expand All @@ -71,8 +71,8 @@ type IssueCommentParams = {
};
// https://developer.github.com/v3/issues/comments/#delete-a-comment
exports.deleteIssueComment = ({ id, owner, repo }: IssueCommentParams) => {
return del(`/repos/${owner}/${repo}/issues/comments/${id}`);
}
return del(`/repos/${owner}/${repo}/issues/comments/${id}`);
};

type IssueParams = {
content: string;
Expand All @@ -82,12 +82,12 @@ type IssueParams = {
};
// https://developer.github.com/v3/reactions/#create-reaction-for-an-issue
exports.createIssueReaction = ({ content, number, owner, repo }: IssueParams) => {
return got.post(`${BASE_URI}/repos/${owner}/${repo}/issues/${number}/reactions`, {
headers: {
...headers,
Accept: 'application/vnd.github.squirrel-girl-preview'
},
json: true,
body: JSON.stringify({ content })
}).then(({ body }) => body);
}
return got.post(`${BASE_URI}/repos/${owner}/${repo}/issues/${number}/reactions`, {
headers: {
...headers,
Accept: "application/vnd.github.squirrel-girl-preview"
},
json: true,
body: JSON.stringify({ content })
}).then(({ body }) => body);
};
Loading