Skip to content

Commit

Permalink
feat(lint-config): remove no-return-await add require-await (#752)
Browse files Browse the repository at this point in the history
There is no built-in rule or rule plugin that adds more of these best practices. So follow this one for now.

This should improve the stacktrace in async scenarios

Closes #751
  • Loading branch information
dirkdev98 committed Mar 17, 2021
1 parent 2604c95 commit f00aa30
Show file tree
Hide file tree
Showing 27 changed files with 78 additions and 84 deletions.
6 changes: 3 additions & 3 deletions packages/cli/scripts/test.js
Expand Up @@ -69,7 +69,7 @@ async function main(logger) {
}
}

const workers = await initializeWorkers();
const workers = initializeWorkers();
const testResult = await runTests(workers, files);

// Early exit on test failure
Expand Down Expand Up @@ -198,9 +198,9 @@ function listTestFiles() {
/**
* Create workers and wait till they are initialized.
*
* @returns {Promise<Worker[]>}
* @returns {Worker[]}
*/
async function initializeWorkers() {
function initializeWorkers() {
const workers = [];

for (let i = 0; i < cpus().length - 1; ++i) {
Expand Down
4 changes: 2 additions & 2 deletions packages/cli/src/commands/proxy.js
Expand Up @@ -5,9 +5,9 @@ import proxy from "http-proxy";
/**
* @param {Logger} logger
* @param {UtilCommand} command
* @returns {Promise<void>}
* @returns {void}
*/
export async function proxyCommand(logger, command) {
export function proxyCommand(logger, command) {
const verbose = command.arguments.indexOf("--verbose") !== -1;
const port = parseInt(
(environment.API_URL ?? environment.NEXT_PUBLIC_API_URL ?? "")
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/execute.js
Expand Up @@ -33,7 +33,7 @@ const execCommands = {
* @param {ScriptCollection} scriptCollection
* @returns {Promise<void>}
*/
export async function execute(logger, command, scriptCollection) {
export function execute(logger, command, scriptCollection) {
if (command.type === "util") {
const fn = utilCommands[command.name];
if (fn) {
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/utils.js
Expand Up @@ -159,7 +159,7 @@ export function watchOptionsToIgnoredArray(options) {
* @param commandArgs
* @param {CliWatchOptions} watchOptions
*/
export async function executeCommand(
export function executeCommand(
logger,
verbose,
watch,
Expand Down
2 changes: 1 addition & 1 deletion packages/code-gen/src/generator/index.js
Expand Up @@ -37,7 +37,7 @@ import { generateValidatorFile } from "./validator.js";
* @param {CodeGenStructure} structure
* @returns {Promise<void>}
*/
export async function generate(logger, options, structure) {
export function generate(logger, options, structure) {
// We can always use '.js' as the import extension and TS will happily resolve to the
// .ts files Not exactly sure how it all works, but should be good enough for now. The
// issue when not providing any extension in imports / exports is that TS won't add
Expand Down
6 changes: 3 additions & 3 deletions packages/code-gen/src/generator/sql/query-basics.js
Expand Up @@ -51,7 +51,7 @@ function selectQuery(context, imports, type) {
* @returns {Promise<${type.uniqueName}[]>}
*/
export async function ${type.name}Select(sql, where) {
return query${upperCaseFirst(type.name)}({ where }).exec(sql);
return await query${upperCaseFirst(type.name)}({ where }).exec(sql);
}
`;
}
Expand Down Expand Up @@ -93,7 +93,7 @@ function deleteQuery(context, imports, type) {
* @param {${type.uniqueName}Where} [where={}]
* @returns {Promise<void>}
*/
export function ${type.name}Delete${
export async function ${type.name}Delete${
type.queryOptions.withSoftDeletes ? "Permanent" : ""
}(sql,
where = {}
Expand All @@ -103,7 +103,7 @@ function deleteQuery(context, imports, type) {
? "where.deletedAtIncludeNotNull = true;"
: ""
}
return query\`
return await query\`
DELETE FROM "${type.name}" ${type.shortName}
WHERE $\{${type.name}Where(where)}
\`.exec(sql);
Expand Down
9 changes: 4 additions & 5 deletions packages/code-gen/src/generator/sql/query-builder.js
Expand Up @@ -272,11 +272,10 @@ function queryBuilderForType(context, imports, type) {
type.name,
)}' directly. Please use '.exec' or '.execRaw'."
});
}, execRaw: (sql) => qb.exec(sql), exec: (sql) => {
return qb.exec(sql).then(result => {
transform${upperCaseFirst(type.name)}(result, builder);
return result;
});
}, execRaw: async (sql) => await qb.exec(sql), exec: async (sql) => {
const result = await qb.exec(sql);
transform${upperCaseFirst(type.name)}(result, builder);
return result;
}, get queryPart() {
return qb;
}
Expand Down
2 changes: 1 addition & 1 deletion packages/insight/src/postgres.test.js
Expand Up @@ -8,7 +8,7 @@ import { postgresTableSizes } from "./postgres.js";

mainTestFn(import.meta);

test("insight/postgres", async (t) => {
test("insight/postgres", (t) => {
let sql = undefined;

t.test("create a test db", async (t) => {
Expand Down
2 changes: 1 addition & 1 deletion packages/lint-config/index.js
Expand Up @@ -33,13 +33,13 @@ const settings = {
"default-case-last": "error",
"no-else-return": "error",
"no-return-assign": "error",
"no-return-await": "error",
"no-sequences": "error",
"no-throw-literal": "error",
"prefer-promise-reject-errors": "error",
"no-var": "error",
"prefer-const": "error",
"prefer-template": "error",
"require-await": "error",

// ESLint plugin import
"import/export": "off",
Expand Down
2 changes: 1 addition & 1 deletion packages/server/src/app.test.js
Expand Up @@ -5,7 +5,7 @@ import { closeTestApp, createTestAppAndClient, getApp } from "../index.js";

mainTestFn(import.meta);

test("server/app", async (t) => {
test("server/app", (t) => {
const app = getApp();
const client = Axios.create();

Expand Down
12 changes: 6 additions & 6 deletions packages/server/src/middleware/compose.test.js
Expand Up @@ -91,7 +91,7 @@ test("Koa Compose", (t) => {
t.deepEqual(out, ctx2.arr);
});

t.test("should only accept an array", async (t) => {
t.test("should only accept an array", (t) => {
try {
compose();
t.fail("should throw");
Expand All @@ -100,7 +100,7 @@ test("Koa Compose", (t) => {
}
});

t.test("should create next functions that return a Promise", async (t) => {
t.test("should create next functions that return a Promise", (t) => {
const stack = [];
const arr = [];
for (let i = 0; i < 5; i++) {
Expand All @@ -124,7 +124,7 @@ test("Koa Compose", (t) => {
}
});

t.test("should only accept middleware as functions", async (t) => {
t.test("should only accept middleware as functions", (t) => {
try {
compose([{}]);
t.fail("should throw");
Expand Down Expand Up @@ -200,7 +200,7 @@ test("Koa Compose", (t) => {
arr.push(3);
});

stack.push(async () => {
stack.push(() => {
arr.push(4);
throw new Error();
});
Expand All @@ -212,7 +212,7 @@ test("Koa Compose", (t) => {
t.test("should compose w/ next", async (t) => {
let called = false;

await compose([])({}, async () => {
await compose([])({}, () => {
called = true;
});
t.ok(called);
Expand Down Expand Up @@ -313,7 +313,7 @@ test("Koa Compose", (t) => {
t.equal(val, 1);
});

t.test("should not affect the original middleware array", async (t) => {
t.test("should not affect the original middleware array", (t) => {
const middleware = [];
const fn1 = (ctx, next) => {
return next();
Expand Down
2 changes: 1 addition & 1 deletion packages/server/src/middleware/log.js
Expand Up @@ -100,7 +100,7 @@ class StreamLength extends Transform {
* @param ctx
* @returns {Promise<void>}
*/
async function bodyCloseOrFinish(ctx) {
function bodyCloseOrFinish(ctx) {
return new Promise((resolve) => {
const onFinish = done.bind(null, "finish");
const onClose = done.bind(null, "close");
Expand Down
4 changes: 2 additions & 2 deletions packages/server/src/middleware/session.test.js
Expand Up @@ -11,7 +11,7 @@ import { session } from "./session.js";

mainTestFn(import.meta);

test("server/session", async (t) => {
test("server/session", (t) => {
const app = new Koa();
const client = Axios.create();

Expand Down Expand Up @@ -70,7 +70,7 @@ test("server/session", async (t) => {
});
});

test("server/session synced cookie", async (t) => {
test("server/session synced cookie", (t) => {
const app = new Koa();
const client = Axios.create();

Expand Down
2 changes: 1 addition & 1 deletion packages/stdlib/src/node.js
Expand Up @@ -83,7 +83,7 @@ export async function streamToBuffer(stream) {
return Buffer.from([]);
}

return new Promise((resolve, reject) => {
return await new Promise((resolve, reject) => {
const buffers = [];

stream.on("data", function (chunk) {
Expand Down
2 changes: 1 addition & 1 deletion packages/store/src/file-cache.test.js
Expand Up @@ -137,7 +137,7 @@ test("store/file-cache", async (t) => {
);
});

t.test("clear file removes from cache", async () => {
t.test("clear file removes from cache", () => {
cache.clear(files.large.id);
});

Expand Down
2 changes: 1 addition & 1 deletion packages/store/src/file-group.js
Expand Up @@ -41,7 +41,7 @@ const fileGroupQueries = {
* @returns {Promise<StoreFileGroup[]>}
*/
export async function hoistChildrenToParent(sql, fileGroup) {
return queries.fileGroupUpdate(
return await queries.fileGroupUpdate(
sql,
{ parent: fileGroup.parent ?? null },
{ parent: fileGroup.id },
Expand Down
4 changes: 2 additions & 2 deletions packages/store/src/files.js
Expand Up @@ -96,9 +96,9 @@ export async function getFileStream(
start = start || 0;
const size = end === undefined ? 0 : end - start;

return minio.getPartialObject(bucketName, id, start, size);
return await minio.getPartialObject(bucketName, id, start, size);
}
return minio.getObject(bucketName, id);
return await minio.getObject(bucketName, id);
}

/**
Expand Down
17 changes: 8 additions & 9 deletions packages/store/src/generated/database/file.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 8 additions & 9 deletions packages/store/src/generated/database/fileGroup.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 6 additions & 7 deletions packages/store/src/generated/database/fileGroupView.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 8 additions & 9 deletions packages/store/src/generated/database/job.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit f00aa30

Please sign in to comment.