Skip to content

Commit 0441e92

Browse files
committed
Lint rules and flow annotations for rest of the files
1 parent c9b710c commit 0441e92

36 files changed

+77
-51
lines changed

.eslintignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
server/migrations/*.js

.eslintrc

+1
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
"prettier/prettier": [
3737
"error",
3838
{
39+
"printWidth": 80,
3940
"trailingComma": "es5",
4041
"singleQuote": true
4142
}

server/api/apiKeys.js

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// @flow
12
import Router from 'koa-router';
23
import httpErrors from 'http-errors';
34

server/api/hooks.js

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// @flow
12
import Router from 'koa-router';
23
import httpErrors from 'http-errors';
34
import { Document, User } from '../models';

server/api/index.js

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// @flow
12
import bodyParser from 'koa-bodyparser';
23
import Koa from 'koa';
34
import Router from 'koa-router';

server/api/middlewares/apiWrapper.js

+9-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,16 @@
1-
export default function apiWrapper(_options) {
2-
return async function apiWrapperMiddleware(ctx, next) {
1+
// @flow
2+
import { type Context } from 'koa';
3+
4+
export default function apiWrapper() {
5+
return async function apiWrapperMiddleware(
6+
ctx: Context,
7+
next: () => Promise<void>
8+
) {
39
await next();
410

511
const ok = ctx.status < 400;
612

13+
// $FlowFixMe
714
ctx.body = {
815
...ctx.body,
916
status: ctx.status,

server/api/middlewares/authentication.js

+10-3
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
1+
// @flow
12
import httpErrors from 'http-errors';
23
import JWT from 'jsonwebtoken';
4+
import { type Context } from 'koa';
35

46
import { User, ApiKey } from '../../models';
57

6-
export default function auth({ require = true } = {}) {
7-
return async function authMiddleware(ctx, next) {
8+
export default function auth({ require = true }: { require?: boolean } = {}) {
9+
return async function authMiddleware(
10+
ctx: Context,
11+
next: () => Promise<void>
12+
) {
813
let token;
914

1015
const authorizationHeader = ctx.request.get('authorization');
@@ -25,6 +30,7 @@ export default function auth({ require = true } = {}) {
2530
);
2631
}
2732
}
33+
// $FlowFixMe
2834
} else if (ctx.body.token) {
2935
token = ctx.body.token;
3036
} else if (ctx.request.query.token) {
@@ -38,7 +44,7 @@ export default function auth({ require = true } = {}) {
3844
if (token) {
3945
let user;
4046

41-
if (token.match(/^[\w]{38}$/)) {
47+
if (String(token).match(/^[\w]{38}$/)) {
4248
// API key
4349
let apiKey;
4450
try {
@@ -83,6 +89,7 @@ export default function auth({ require = true } = {}) {
8389

8490
ctx.state.token = token;
8591
ctx.state.user = user;
92+
// $FlowFixMe
8693
ctx.cache[user.id] = user;
8794
}
8895

server/api/middlewares/pagination.js

+14-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
1+
// @flow
12
import httpErrors from 'http-errors';
23
import querystring from 'querystring';
4+
import { type Context } from 'koa';
35

4-
export default function pagination(options) {
5-
return async function paginationMiddleware(ctx, next) {
6+
export default function pagination(options?: Object) {
7+
return async function paginationMiddleware(
8+
ctx: Context,
9+
next: () => Promise<void>
10+
) {
611
const opts = {
712
defaultLimit: 15,
813
maxLimit: 100,
@@ -11,7 +16,9 @@ export default function pagination(options) {
1116

1217
let query = ctx.request.query;
1318
let body = ctx.request.body;
19+
// $FlowFixMe
1420
let limit = parseInt(query.limit || body.limit, 10);
21+
// $FlowFixMe
1522
let offset = parseInt(query.offset || body.offset, 10);
1623
limit = isNaN(limit) ? opts.defaultLimit : limit;
1724
offset = isNaN(offset) ? 0 : offset;
@@ -27,9 +34,13 @@ export default function pagination(options) {
2734
offset: offset,
2835
};
2936

37+
// $FlowFixMe
3038
query.limit = ctx.state.pagination.limit;
39+
// $FlowFixMe
3140
query.offset = ctx.state.pagination.offset + query.limit;
32-
ctx.state.pagination.nextPath = `/api${ctx.request.path}?${querystring.stringify(query)}`;
41+
ctx.state.pagination.nextPath = `/api${
42+
ctx.request.path
43+
}?${querystring.stringify(query)}`;
3344

3445
return next();
3546
};

server/api/user.js

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// @flow
12
import uuid from 'uuid';
23
import Router from 'koa-router';
34

server/api/user.test.js

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/* eslint-disable flowtype/require-valid-file-annotation */
12
import TestServer from 'fetch-test-server';
23

34
import app from '..';

server/errors.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1+
// @flow
12
import httpErrors from 'http-errors';
23

3-
const apiError = (code, id, message) => {
4+
const apiError = (code: number, id: string, message: string) => {
45
return httpErrors(code, message, { id });
56
};
67

server/middlewares/methodOverride.js

+8-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
1+
// @flow
12
import queryString from 'query-string';
3+
import { type Context } from 'koa';
24

3-
export default function methodOverride(_options) {
4-
return async function methodOverrideMiddleware(ctx, next) {
5+
export default function methodOverride() {
6+
return async function methodOverrideMiddleware(
7+
ctx: Context,
8+
next: () => Promise<void>
9+
) {
510
if (ctx.method === 'POST') {
11+
// $FlowFixMe
612
ctx.body = ctx.request.body;
713
} else if (ctx.method === 'GET') {
814
ctx.method = 'POST'; // eslint-disable-line

server/middlewares/subdomainRedirect.js

+8-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
1-
export default function subdomainRedirect(options) {
2-
return async function subdomainRedirectMiddleware(ctx, next) {
1+
// @flow
2+
import { type Context } from 'koa';
3+
4+
export default function subdomainRedirect() {
5+
return async function subdomainRedirectMiddleware(
6+
ctx: Context,
7+
next: () => Promise<void>
8+
) {
39
if (ctx.headers.host === 'getoutline.com') {
410
ctx.redirect(`https://www.${ctx.headers.host}${ctx.path}`);
511
} else {

server/migrations/20160619080644-initial.js

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
'use strict';
2-
31
module.exports = {
42
up: function(queryInterface, Sequelize) {
53
queryInterface.createTable('teams', {

server/migrations/20160622043741-add-parent-document.js

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
'use strict';
2-
31
module.exports = {
42
up: function(queryInterface, Sequelize) {
53
queryInterface.addColumn('documents', 'parentDocumentId', {

server/migrations/20160626063409-add-indexes.js

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
'use strict';
2-
31
module.exports = {
42
up: function(queryInterface, Sequelize) {
53
queryInterface.addIndex('documents', ['urlId']);

server/migrations/20160626175224-add-revisions.js

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
'use strict';
2-
31
module.exports = {
42
up: function(queryInterface, Sequelize) {
53
queryInterface.createTable('revisions', {

server/migrations/20160711071958-search-index.js

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
'use strict';
2-
31
module.exports = {
42
up: function(queryInterface, Sequelize) {
53
const searchDocument = `

server/migrations/20160726061511-atlas-creator.js

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
'use strict';
2-
31
module.exports = {
42
up: function(queryInterface, Sequelize) {
53
queryInterface.addColumn('atlases', 'creatorId', {

server/migrations/20160812145029-document-atlas-soft-delete.js

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
'use strict';
2-
31
module.exports = {
42
up: function(queryInterface, Sequelize) {
53
queryInterface.addColumn('atlases', 'deletedAt', {

server/migrations/20160814083127-paranoia-indeces.js

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
'use strict';
2-
31
module.exports = {
42
up: function(queryInterface, Sequelize) {
53
// Remove old indeces

server/migrations/20160814095336-add-document-createdById.js

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
'use strict';
2-
31
module.exports = {
42
up: function(queryInterface, Sequelize) {
53
queryInterface.addColumn('documents', 'createdById', {

server/migrations/20160814111419-add-document-collaboratorIds.js

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
'use strict';
2-
31
module.exports = {
42
up: function(queryInterface, Sequelize) {
53
queryInterface.addColumn('documents', 'collaboratorIds', {

server/migrations/20160815142720-app-collection-urlId.js

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
'use strict';
2-
31
module.exports = {
42
up: function(queryInterface, Sequelize) {
53
queryInterface.addColumn('atlases', 'urlId', {

server/migrations/20160816082738-add-revision-index.js

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
'use strict';
2-
31
module.exports = {
42
up: function(queryInterface, Sequelize) {
53
queryInterface.addIndex('revisions', ['documentId']);

server/migrations/20160824062457-add-apikey-indeces.js

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
'use strict';
2-
31
module.exports = {
42
up: function(queryInterface, Sequelize) {
53
queryInterface.addIndex('apiKeys', ['secret', 'deletedAt']);

server/models/ApiKey.js

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// @flow
12
import { DataTypes, sequelize } from '../sequelize';
23
import randomstring from 'randomstring';
34

server/models/User.test.js

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/* eslint-disable flowtype/require-valid-file-annotation */
12
import { flushdb, seed } from '../test/support';
23

34
beforeEach(flushdb);

server/pages/About.js

+1-3
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,7 @@ export default function About() {
1212
</Helmet>
1313
<Hero>
1414
<h1>About Outline</h1>
15-
<p>
16-
Just a proof of concept for multiple pages.
17-
</p>
15+
<p>Just a proof of concept for multiple pages.</p>
1816
</Hero>
1917
</Grid>
2018
);

server/pages/Pricing.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ export default function Pricing() {
1313
<Hero>
1414
<h1>Pricing</h1>
1515
<p>
16-
Explore Outline with a 14 day trial, free forever for teams smaller than 5.
16+
Explore Outline with a 14 day trial, free forever for teams smaller
17+
than 5.
1718
</p>
1819
</Hero>
1920
</Grid>

server/presenters/apiKey.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
function present(ctx, key) {
1+
// @flow
2+
import { type Context } from 'koa';
3+
import { ApiKey } from '../models';
4+
5+
function present(ctx: Context, key: ApiKey) {
26
return {
37
id: key.id,
48
name: key.name,

server/presenters/user.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ function present(ctx: Object, user: User) {
88
id: user.id,
99
username: user.username,
1010
name: user.name,
11-
avatarUrl: user.avatarUrl ||
12-
(user.slackData ? user.slackData.image_192 : null),
11+
avatarUrl:
12+
user.avatarUrl || (user.slackData ? user.slackData.image_192 : null),
1313
};
1414
}
1515

server/presenters/user.test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1+
/* eslint-disable flowtype/require-valid-file-annotation */
12
import presentUser from './user';
2-
33
import ctx from '../../__mocks__/ctx';
44

55
it('presents a user', async () => {

server/redis.js

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// @flow
12
import redis from 'redis';
23
import redisLock from 'redis-lock';
34

server/utils/renderpage.js

+1-3
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,7 @@ const sheet = new ServerStyleSheet();
1010
export default function renderpage(ctx: Object, children: React$Element<*>) {
1111
const html = ReactDOMServer.renderToString(
1212
<StyleSheetManager sheet={sheet.instance}>
13-
<Layout>
14-
{children}
15-
</Layout>
13+
<Layout>{children}</Layout>
1614
</StyleSheetManager>
1715
);
1816

server/utils/updates.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,10 @@ export default async () => {
1616
'SECRET_KEY or URL env var is not set'
1717
);
1818
const secret = process.env.SECRET_KEY.slice(0, 6) + process.env.URL;
19-
const id = crypto.createHash('sha256').update(secret).digest('hex');
19+
const id = crypto
20+
.createHash('sha256')
21+
.update(secret)
22+
.digest('hex');
2023

2124
const [
2225
userCount,

0 commit comments

Comments
 (0)