Skip to content
This repository was archived by the owner on Jun 24, 2024. It is now read-only.

Commit e7d1b3e

Browse files
committed
update lint setup to airbnb
1 parent 2df90d4 commit e7d1b3e

21 files changed

+165
-128
lines changed

.eslintrc

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,16 @@
11
{
22
"root": true,
3-
"plugins": ["import"],
4-
"extends": [
5-
"plugin:import/recommended",
6-
"finn",
7-
"finn/node",
8-
"finn-prettier"
9-
],
10-
"parserOptions": {
11-
"ecmaVersion": 2018
12-
},
3+
"plugins": ["prettier"],
4+
"extends": ["airbnb-base", "prettier"],
135
"rules": {
146
"import/no-extraneous-dependencies": [
157
"error",
168
{
179
"devDependencies": false
1810
}
19-
]
11+
],
12+
"strict": [0, "global"],
13+
"class-methods-use-this": [0]
2014
},
2115
"overrides": [
2216
{

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,5 @@ tmp/**/*
77
*.iml
88
*.log
99
.vscode
10-
coverage
10+
coverage
11+
node_modules/**/*

.prettierrc

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"singleQuote": true,
3+
"trailingComma": "all",
4+
"tabWidth": 4,
5+
"overrides": [
6+
{
7+
"files": [
8+
".prettierrc",
9+
"*.json",
10+
"*.yml",
11+
".travis.yml",
12+
".eslintrc"
13+
],
14+
"options": {
15+
"tabWidth": 2
16+
}
17+
}
18+
]
19+
}

bin/app.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ app.use((req, res) => {
5555
break;
5656
case 'html':
5757
res.status(404).send(
58-
'<html><body><h1>Not found</h1></body></html>'
58+
'<html><body><h1>Not found</h1></body></html>',
5959
);
6060
break;
6161
case 'text':

bin/server.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
#!/usr/bin/env node
2+
23
'use strict';
34

5+
const bole = require('bole');
46
const config = require('../config/config.js');
57
const server = require('./app.js');
6-
const bole = require('bole');
8+
79
const log = bole('server');
810

911
// Start application
@@ -17,7 +19,7 @@ server.listen(config.get('httpServerPort'), () => {
1719
process.on('uncaughtException', error => {
1820
log.error(
1921
error,
20-
'shutdown - server taken down by force due to a uncaughtException'
22+
'shutdown - server taken down by force due to a uncaughtException',
2123
);
2224
server.close();
2325
process.nextTick(() => {

lib/bundler.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
1+
/* eslint-disable no-restricted-syntax */
2+
/* eslint-disable global-require */
3+
14
'use strict';
25

36
const assert = require('assert');
47
const Boom = require('boom');
58
const { promisify } = require('util');
69
const body = promisify(require('body/json'));
7-
const schemas = require('./schemas');
810
const parseJson = require('parse-json');
911
const { hasher } = require('@asset-pipe/common');
1012
const { default: Worker } = require('jest-worker');
13+
const schemas = require('./schemas');
1114

1215
module.exports = class Bundler {
1316
constructor({ bundleInProcess = false, workers = 6 } = {}) {
@@ -28,7 +31,7 @@ module.exports = class Bundler {
2831
ids.map(async fileName => ({
2932
fileName,
3033
contents: await sink.get(fileName),
31-
}))
34+
})),
3235
);
3336
} catch (err) {
3437
throw Boom.boomify(err, {
@@ -84,7 +87,7 @@ module.exports = class Bundler {
8487
async bundleAndUpload({ sink, type, feedIds, uri, ...options }) {
8588
assert(
8689
Array.isArray(feedIds) && feedIds.length > 0,
87-
`Expected at least 1 feed id, but got ${feedIds}`
90+
`Expected at least 1 feed id, but got ${feedIds}`,
8891
);
8992

9093
const fetchedFeeds = await this.fetchFeeds(sink, feedIds, 3);

lib/hasher.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
/* eslint-disable no-param-reassign */
2+
13
'use strict';
24

35
const { hasher: contentHasher } = require('@asset-pipe/common');

lib/main.js

Lines changed: 28 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,22 @@
1+
/* eslint-disable prefer-destructuring */
2+
/* eslint-disable no-unneeded-ternary */
3+
/* eslint-disable no-restricted-syntax */
4+
/* eslint-disable consistent-return */
5+
/* eslint-disable no-underscore-dangle */
6+
/* eslint-disable max-classes-per-file */
7+
18
'use strict';
29

310
const EventEmitter = require('events');
411
const express = require('express');
512
const SinkMem = require('@asset-pipe/sink-mem');
613
const Boom = require('boom');
714
const uuid = require('uuid/v4');
15+
const Metrics = require('@metrics/client');
816
const mime = require('mime-types');
917
const { Transform } = require('readable-stream');
1018
const params = require('./params');
1119
const MetaStorage = require('./meta-storage');
12-
const Metrics = require('@metrics/client');
1320
const { booleanWithDefault } = require('./utils');
1421
const OptimisticBundler = require('../lib/optimistic-bundler');
1522

@@ -40,7 +47,7 @@ async function getBody(req) {
4047
statusCode: 400,
4148
message:
4249
'Unparsable feed data given in POST-body. Invalid or empty JSON payload.',
43-
})
50+
}),
4451
);
4552
}
4653
});
@@ -146,7 +153,7 @@ module.exports = class Router extends EventEmitter {
146153
this.app.post(
147154
'/feed/:type/:id?',
148155
this.postFeedPersistCallback(),
149-
this.postFeedResponseCallback()
156+
this.postFeedResponseCallback(),
150157
);
151158

152159
this.app.get('/feed/:file', this.getFileCallback());
@@ -162,7 +169,7 @@ module.exports = class Router extends EventEmitter {
162169
const meta = await this.bundler.publishAssets(payload, {
163170
minify: booleanWithDefault(
164171
req.query.minify,
165-
this.options.isProduction
172+
this.options.isProduction,
166173
),
167174
sourceMaps: booleanWithDefault(req.query.sourceMaps, false),
168175
rebundle: booleanWithDefault(req.query.rebundle, true),
@@ -184,7 +191,9 @@ module.exports = class Router extends EventEmitter {
184191
};
185192

186193
this.options.logger.info(
187-
`sync requested by client, sending data ${JSON.stringify(data)}`
194+
`sync requested by client, sending data ${JSON.stringify(
195+
data,
196+
)}`,
188197
);
189198

190199
res.json(data);
@@ -196,7 +205,7 @@ module.exports = class Router extends EventEmitter {
196205
await this.bundler.publishInstructions(payload, {
197206
minify: booleanWithDefault(
198207
req.query.minify,
199-
this.options.isProduction
208+
this.options.isProduction,
200209
),
201210
sourceMaps: booleanWithDefault(req.query.sourceMaps, false),
202211
});
@@ -213,7 +222,7 @@ module.exports = class Router extends EventEmitter {
213222
req.method,
214223
req.path,
215224
res.locals.payload,
216-
error
225+
error,
217226
);
218227
next(error);
219228
});
@@ -257,7 +266,7 @@ module.exports = class Router extends EventEmitter {
257266

258267
fileWriteStream.on(
259268
'file not saved',
260-
this.onError(next, 'File not saved')
269+
this.onError(next, 'File not saved'),
261270
);
262271

263272
fileWriteStream.on('error', this.onError(next));
@@ -291,7 +300,7 @@ module.exports = class Router extends EventEmitter {
291300
res.locals.track,
292301
req.method,
293302
req.path,
294-
res.locals.response.file
303+
res.locals.response.file,
295304
);
296305
};
297306
}
@@ -309,16 +318,16 @@ module.exports = class Router extends EventEmitter {
309318
this.emit(
310319
'info',
311320
`Successfully parsed feed data from request body. Result: ${JSON.stringify(
312-
payload
313-
)}`
321+
payload,
322+
)}`,
314323
);
315324

316325
this.emit('info', `Validating parsed feed data against schema`);
317326
const feedIds = this.bundler.validateFeeds(payload);
318327

319328
this.emit(
320329
'info',
321-
`Producing and saving asset bundle for requested feeds`
330+
`Producing and saving asset bundle for requested feeds`,
322331
);
323332
const response = await this.bundler.bundleAndUpload({
324333
sink: this.sink,
@@ -331,7 +340,7 @@ module.exports = class Router extends EventEmitter {
331340
});
332341
this.emit(
333342
'info',
334-
`Requested asset bundle produced and successfully uploaded.`
343+
`Requested asset bundle produced and successfully uploaded.`,
335344
);
336345

337346
if (id) {
@@ -348,7 +357,7 @@ module.exports = class Router extends EventEmitter {
348357
res.locals.track,
349358
req.method,
350359
req.path,
351-
response.file
360+
response.file,
352361
);
353362
res.json(response);
354363
} catch (e) {
@@ -373,8 +382,8 @@ module.exports = class Router extends EventEmitter {
373382
return () => {
374383
next(
375384
Boom.badRequest(
376-
'Could not load 1 or more of the resources in the payload from storage'
377-
)
385+
'Could not load 1 or more of the resources in the payload from storage',
386+
),
378387
);
379388
};
380389
}
@@ -387,7 +396,7 @@ module.exports = class Router extends EventEmitter {
387396
res.locals.track,
388397
req.method,
389398
req.path,
390-
req.params.file
399+
req.params.file,
391400
);
392401
}
393402

@@ -399,13 +408,13 @@ module.exports = class Router extends EventEmitter {
399408
fileReadStream.on('error', next);
400409
fileReadStream.on('file not found', this.onFileNotFound(next));
401410
fileReadStream.on('file found', () =>
402-
this.fileFoundCallback(req, res, fileReadStream)
411+
this.fileFoundCallback(req, res, fileReadStream),
403412
);
404413
} catch (err) {
405414
next(
406415
Boom.boomify(err, {
407416
message: `Attempting to read the file (${file}) caused an unknown error. This likely means that the underlying stream mechanism failed in an unexpected way when trying to read the file and this could not be handled.`,
408-
})
417+
}),
409418
);
410419
}
411420
};

lib/meta-storage.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ module.exports = class MetaStorage {
1717
assert(fileContent, '"value" required');
1818
return this.sink.set(
1919
this.getKey(fileName),
20-
JSON.stringify(fileContent)
20+
JSON.stringify(fileContent),
2121
);
2222
}
2323

@@ -28,7 +28,7 @@ module.exports = class MetaStorage {
2828
return JSON.parse(result);
2929
} catch (e) {
3030
throw new Error(
31-
`Failed parsing payload from key "${fileName}"`
31+
`Failed parsing payload from key "${fileName}"`,
3232
);
3333
}
3434
}

0 commit comments

Comments
 (0)