Skip to content

Commit

Permalink
fix: address violations of "no-floating-promises" rule
Browse files Browse the repository at this point in the history
Signed-off-by: Miroslav Bajtoš <mbajtoss@gmail.com>
  • Loading branch information
bajtos committed Jun 24, 2019
1 parent a07445e commit b38c696
Show file tree
Hide file tree
Showing 26 changed files with 136 additions and 27 deletions.
7 changes: 6 additions & 1 deletion bin/run-lerna.js
Expand Up @@ -25,4 +25,9 @@ async function run(argv, options) {
}

module.exports = run;
if (require.main === module) run(process.argv);
if (require.main === module) {
run(process.argv).catch(err => {
console.error(err);
process.exit(1);
});
}
7 changes: 6 additions & 1 deletion bin/sync-dev-deps.js
Expand Up @@ -87,7 +87,12 @@ function updatePackageJson(pkgFile, masterDeps) {
return true;
}

if (require.main === module) syncDevDeps();
if (require.main === module) {
syncDevDeps().catch(err => {
console.error(err);
process.exit(1);
});
}

function readPackageJson(filePath) {
return JSON.parse(fs.readFileSync(filePath, 'utf-8'));
Expand Down
7 changes: 6 additions & 1 deletion bin/update-template-deps.js
Expand Up @@ -63,4 +63,9 @@ async function updateTemplateDeps() {
}
}

if (require.main === module) updateTemplateDeps();
if (require.main === module) {
updateTemplateDeps().catch(err => {
console.error(err);
process.exit(1);
});
}
7 changes: 6 additions & 1 deletion examples/context/src/binding-types.ts
Expand Up @@ -96,4 +96,9 @@ export async function main() {
console.log(greeter.hello());
}

if (require.main === module) main();
if (require.main === module) {
main().catch(err => {
console.error(err);
process.exit(1);
});
}
7 changes: 6 additions & 1 deletion examples/context/src/configuration-injection.ts
Expand Up @@ -46,4 +46,9 @@ export async function main() {
console.log(greeter.greet('Ray'));
}

if (require.main === module) main();
if (require.main === module) {
main().catch(err => {
console.error(err);
process.exit(1);
});
}
7 changes: 6 additions & 1 deletion examples/context/src/context-chain.ts
Expand Up @@ -44,4 +44,9 @@ export async function main() {
console.log(greeter.greet('John'));
}

if (require.main === module) main();
if (require.main === module) {
main().catch(err => {
console.error(err);
process.exit(1);
});
}
7 changes: 6 additions & 1 deletion examples/context/src/context-observation.ts
Expand Up @@ -88,4 +88,9 @@ export async function main() {
await requestCtx.waitUntilObserversNotified();
}

if (require.main === module) main();
if (require.main === module) {
main().catch(err => {
console.error(err);
process.exit(1);
});
}
7 changes: 6 additions & 1 deletion examples/context/src/custom-configuration-resolver.ts
Expand Up @@ -77,4 +77,9 @@ export async function main() {
console.log(barConfig);
}

if (require.main === module) main();
if (require.main === module) {
main().catch(err => {
console.error(err);
process.exit(1);
});
}
7 changes: 6 additions & 1 deletion examples/context/src/custom-inject-decorator.ts
Expand Up @@ -33,4 +33,9 @@ export async function main() {
console.log(greeter.hello());
}

if (require.main === module) main();
if (require.main === module) {
main().catch(err => {
console.error(err);
process.exit(1);
});
}
7 changes: 6 additions & 1 deletion examples/context/src/custom-inject-resolve.ts
Expand Up @@ -52,4 +52,9 @@ export async function main() {
console.log(greeter.hello());
}

if (require.main === module) main();
if (require.main === module) {
main().catch(err => {
console.error(err);
process.exit(1);
});
}
7 changes: 6 additions & 1 deletion examples/context/src/dependency-injection.ts
Expand Up @@ -138,4 +138,9 @@ export async function main() {
console.log(greeting);
}

if (require.main === module) main();
if (require.main === module) {
main().catch(err => {
console.error(err);
process.exit(1);
});
}
7 changes: 6 additions & 1 deletion examples/context/src/find-bindings.ts
Expand Up @@ -75,4 +75,9 @@ export async function main() {
console.log(view.bindings.map(b => b.key));
}

if (require.main === module) main();
if (require.main === module) {
main().catch(err => {
console.error(err);
process.exit(1);
});
}
5 changes: 4 additions & 1 deletion examples/context/src/index.ts
Expand Up @@ -27,5 +27,8 @@ export async function main() {
if (require.main === module) {
process.env.FOO = JSON.stringify({bar: 'xyz'});

main();
main().catch(err => {
console.error(err);
process.exit(1);
});
}
7 changes: 6 additions & 1 deletion examples/context/src/injection-without-binding.ts
Expand Up @@ -36,4 +36,9 @@ export async function main() {
await sayHello(ctx);
}

if (require.main === module) main();
if (require.main === module) {
main().catch(err => {
console.error(err);
process.exit(1);
});
}
7 changes: 6 additions & 1 deletion examples/context/src/interceptor-proxy.ts
Expand Up @@ -109,4 +109,9 @@ export async function main() {
console.log(await greeter!.greet('John'));
}

if (require.main === module) main();
if (require.main === module) {
main().catch(err => {
console.error(err);
process.exit(1);
});
}
7 changes: 6 additions & 1 deletion examples/context/src/parameterized-decoration.ts
Expand Up @@ -63,4 +63,9 @@ export async function main() {
console.log('2: %s', greeting2.hello());
}

if (require.main === module) main();
if (require.main === module) {
main().catch(err => {
console.error(err);
process.exit(1);
});
}
7 changes: 6 additions & 1 deletion examples/context/src/sync-async.ts
Expand Up @@ -76,4 +76,9 @@ export async function main() {
await greetWithAsyncUser(ctx);
}

if (require.main === module) main();
if (require.main === module) {
main().catch(err => {
console.error(err);
process.exit(1);
});
}
7 changes: 6 additions & 1 deletion examples/context/src/value-promise.ts
Expand Up @@ -121,4 +121,9 @@ async function greetFromAll(greetersView: ContextView<Greeter>) {
await transformValueOrPromise(greetingsByLanguage, console.log);
}

if (require.main === module) main();
if (require.main === module) {
main().catch(err => {
console.error(err);
process.exit(1);
});
}
5 changes: 4 additions & 1 deletion examples/greeter-extension/index.js
Expand Up @@ -7,5 +7,8 @@ module.exports = require('./dist');

if (require.main === module) {
const app = new module.exports.GreetingApplication();
app.main();
app.main().catch(err => {
console.error(err);
process.exit(1);
});
}
5 changes: 4 additions & 1 deletion packages/cli/bin/download-connector-list.js
Expand Up @@ -51,4 +51,7 @@ async function download() {
await writeFileAsync(DEST, JSON.stringify(out, null, 2));
}

download();
download().catch(err => {
console.error(err);
process.exit(1);
});
2 changes: 2 additions & 0 deletions packages/context/src/__tests__/unit/resolver.unit.ts
Expand Up @@ -56,6 +56,7 @@ describe('constructor injection', () => {
}

expect(() => {
// eslint-disable-next-line @typescript-eslint/no-floating-promises
instantiateClass(TestClass, ctx);
}).to.throw(/Cannot resolve injected arguments/);
});
Expand Down Expand Up @@ -383,6 +384,7 @@ describe('property injection', () => {
}

expect(() => {
// eslint-disable-next-line @typescript-eslint/no-floating-promises
instantiateClass(TestClass, ctx);
}).to.throw(/Cannot resolve injected property/);
});
Expand Down
1 change: 1 addition & 0 deletions packages/context/src/__tests__/unit/value-promise.unit.ts
Expand Up @@ -26,6 +26,7 @@ describe('tryWithFinally', () => {
let finalActionInvoked = false;
const action = () => 1;
const finalAction = () => (finalActionInvoked = true);
// eslint-disable-next-line @typescript-eslint/no-floating-promises
tryWithFinally(action, finalAction);
expect(finalActionInvoked).to.be.true();
});
Expand Down
Expand Up @@ -49,9 +49,9 @@ describe('getFilterJsonSchemaFor', () => {
expectSchemaToAllowFilter(customerFilterSchema, filter);
});

it('describes "where" as an object', () => {
it('describes "where" as an object', async () => {
const filter = {where: 'invalid-where'};
ajv.validate(customerFilterSchema, filter);
await ajv.validate(customerFilterSchema, filter);
expect(ajv.errors || []).to.containDeep([
{
keyword: 'type',
Expand All @@ -63,6 +63,7 @@ describe('getFilterJsonSchemaFor', () => {

it('describes "fields" as an object', () => {
const filter = {fields: 'invalid-fields'};
// eslint-disable-next-line @typescript-eslint/no-floating-promises
ajv.validate(customerFilterSchema, filter);
expect(ajv.errors || []).to.containDeep([
{
Expand All @@ -75,6 +76,7 @@ describe('getFilterJsonSchemaFor', () => {

it('describes "include" as an array for models with relations', () => {
const filter = {include: 'invalid-include'};
// eslint-disable-next-line @typescript-eslint/no-floating-promises
ajv.validate(customerFilterSchema, filter);
expect(ajv.errors || []).to.containDeep([
{
Expand All @@ -92,6 +94,7 @@ describe('getFilterJsonSchemaFor', () => {

it('describes "offset" as an integer', () => {
const filter = {offset: 'invalid-offset'};
// eslint-disable-next-line @typescript-eslint/no-floating-promises
ajv.validate(customerFilterSchema, filter);
expect(ajv.errors || []).to.containDeep([
{
Expand All @@ -104,6 +107,7 @@ describe('getFilterJsonSchemaFor', () => {

it('describes "limit" as an integer', () => {
const filter = {limit: 'invalid-limit'};
// eslint-disable-next-line @typescript-eslint/no-floating-promises
ajv.validate(customerFilterSchema, filter);
expect(ajv.errors || []).to.containDeep([
{
Expand All @@ -116,6 +120,7 @@ describe('getFilterJsonSchemaFor', () => {

it('describes "skip" as an integer', () => {
const filter = {skip: 'invalid-skip'};
// eslint-disable-next-line @typescript-eslint/no-floating-promises
ajv.validate(customerFilterSchema, filter);
expect(ajv.errors || []).to.containDeep([
{
Expand All @@ -128,6 +133,7 @@ describe('getFilterJsonSchemaFor', () => {

it('describes "order" as an array', () => {
const filter = {order: 'invalid-order'};
// eslint-disable-next-line @typescript-eslint/no-floating-promises
ajv.validate(customerFilterSchema, filter);
expect(ajv.errors || []).to.containDeep([
{
Expand Down
Expand Up @@ -38,7 +38,7 @@ describe('Sequence', () => {
let server: RestServer;
beforeEach(givenAppWithController);
it('provides a default sequence', async () => {
whenIRequest()
await whenIRequest()
.get('/name')
.expect('SequenceApp');
});
Expand All @@ -52,7 +52,7 @@ describe('Sequence', () => {
.expect('hello world');
});

it('allows users to define a custom sequence as a class', () => {
it('allows users to define a custom sequence as a class', async () => {
class MySequence implements SequenceHandler {
constructor(@inject(SequenceActions.SEND) private send: Send) {}

Expand All @@ -63,7 +63,7 @@ describe('Sequence', () => {
// bind user defined sequence
server.sequence(MySequence);

whenIRequest()
await whenIRequest()
.get('/')
.expect('hello world');
});
Expand Down
5 changes: 4 additions & 1 deletion packages/tsdocs/bin/extract-apis.js
Expand Up @@ -27,4 +27,7 @@ async function main() {
await runExtractorForMonorepo({silent, dryRun, apiReportEnabled});
}

main();
main().catch(err => {
console.error(err);
process.exit(1);
});
5 changes: 4 additions & 1 deletion packages/tsdocs/bin/update-apidocs.js
Expand Up @@ -15,4 +15,7 @@ async function main() {
await updateApiDocs({silent, dryRun});
}

main();
main().catch(err => {
console.error(err);
process.exit(1);
});

0 comments on commit b38c696

Please sign in to comment.