Skip to content

Lint against unnecessary await #1526

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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
10 changes: 9 additions & 1 deletion packages/host/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
'use strict';

const { resolve } = require('path');

module.exports = {
root: true,
parserOptions: {
ecmaVersion: 'latest',
sourceType: 'module',
},
env: {
browser: true,
},
overrides: [
{
files: ['**/*.{js,ts}'],
files: ['**/*.ts'],
parser: '@typescript-eslint/parser',
parserOptions: {
ecmaVersion: 'latest',
Expand All @@ -21,6 +27,7 @@ module.exports = {
],
],
},
project: [resolve(__dirname, './tsconfig.json')],
},
plugins: ['ember', '@typescript-eslint', 'window-mock'],
extends: [
Expand All @@ -43,6 +50,7 @@ module.exports = {
'@typescript-eslint/explicit-module-boundary-types': 'off',
'@typescript-eslint/no-this-alias': 'off',
'@typescript-eslint/no-non-null-assertion': 'off',
'@typescript-eslint/await-thenable': 'error',
'no-undef': 'off',
'ember/no-runloop': 'off',
'window-mock/mock-window-only': 'error',
Expand Down
2 changes: 1 addition & 1 deletion packages/host/app/lib/current-run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ export class CurrentRun {
log.warn(
`encountered error loading module "${url.href}": ${err.message}`,
);
let deps = await (
let deps = (
await this.loaderService.loader.getConsumedModules(url.href)
).filter((u) => u !== url.href);
await this.batch.updateEntry(url, {
Expand Down
21 changes: 7 additions & 14 deletions packages/host/app/lib/matrix-handlers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,12 +100,10 @@ export async function addRoomEvent(context: EventSendingContext, event: Event) {
room = new RoomState();
context.setRoom(roomId, room);
}
let resolvedRoom = await room; //look at the note in the EventSendingContext interface for why this is awaited

// duplicate events may be emitted from matrix, as well as the resolved room card might already contain this event
if (!resolvedRoom.events.find((e) => e.event_id === eventId)) {
resolvedRoom.events = [
...(resolvedRoom.events ?? []),
if (!room.events.find((e) => e.event_id === eventId)) {
room.events = [
...(room.events ?? []),
event as unknown as DiscreteMatrixEvent,
];
}
Expand Down Expand Up @@ -137,14 +135,10 @@ export async function updateRoomEvent(
`bug: unknown room for event ${JSON.stringify(event, null, 2)}`,
);
}
let resolvedRoom = await room; //look at the note in the EventSendingContext interface for why this is awaited
let oldEventIndex = resolvedRoom.events.findIndex(
(e) => e.event_id === oldEventId,
);
let oldEventIndex = room.events.findIndex((e) => e.event_id === oldEventId);
if (oldEventIndex >= 0) {
resolvedRoom.events[oldEventIndex] =
event as unknown as DiscreteMatrixEvent;
resolvedRoom.events = [...resolvedRoom.events];
room.events[oldEventIndex] = event as unknown as DiscreteMatrixEvent;
room.events = [...room.events];
}
}

Expand All @@ -158,8 +152,7 @@ export async function getRoomEvents(
);
}
let room = context.getRoom(roomId);
let resolvedRoom = await room;
return resolvedRoom?.events ?? [];
return room?.events ?? [];
}

export async function getCommandResultEvents(
Expand Down
2 changes: 1 addition & 1 deletion packages/host/app/lib/matrix-handlers/timeline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ async function processDecryptedEvent(
return;
}

let roomState = await context.getRoom(roomId);
let roomState = context.getRoom(roomId);
// patch in any missing room events--this will support dealing with local
// echoes, migrating older histories as well as handle any matrix syncing gaps
// that might occur
Expand Down
2 changes: 1 addition & 1 deletion packages/host/app/resources/room.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ export class RoomResource extends Resource<Args> {

private load = restartableTask(async (roomId: string) => {
try {
this.room = roomId ? await this.matrixService.getRoom(roomId) : undefined; //look at the note in the EventSendingContext interface for why this is awaited
this.room = roomId ? this.matrixService.getRoom(roomId) : undefined; //look at the note in the EventSendingContext interface for why this is awaited
if (this.room) {
await this.loadRoomMembers(roomId);
await this.loadRoomMessages(roomId);
Expand Down
8 changes: 4 additions & 4 deletions packages/host/tests/acceptance/ai-assistant-test.gts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ async function selectCardFromCatalog(cardId: string) {
await click('[data-test-card-catalog-go-button]');
}

async function assertMessages(
function assertMessages(
assert: Assert,
messages: {
from: string;
Expand All @@ -51,7 +51,7 @@ async function assertMessages(
assert
.dom(`[data-test-message-idx="${index}"] [data-test-message-cards]`)
.exists({ count: 1 });
await assert
assert
.dom(`[data-test-message-idx="${index}"] [data-test-attached-card]`)
.exists({ count: cards.length });
cards.map(async (card) => {
Expand All @@ -70,15 +70,15 @@ async function assertMessages(
}

if (card.realmIconUrl) {
await assert
assert
.dom(
`[data-test-message-idx="${index}"] [data-test-attached-card="${card.id}"] [data-test-realm-icon-url="${card.realmIconUrl}"]`,
)
.exists({ count: 1 });
}
});
} else {
await assert
assert
.dom(`[data-test-message-idx="${index}"] [data-test-message-cards]`)
.doesNotExist();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -582,10 +582,8 @@ module('Acceptance | code submode | schema editor tests', function (hooks) {
?.textContent?.includes('BigInteger'),
);

await assert.dom('[data-test-selected-field-realm-icon] img').exists();
await assert
.dom('[data-test-selected-field-display-name]')
.hasText('BigInteger');
assert.dom('[data-test-selected-field-realm-icon] img').exists();
assert.dom('[data-test-selected-field-display-name]').hasText('BigInteger');

await click('[data-test-choose-card-button]');

Expand All @@ -606,7 +604,7 @@ module('Acceptance | code submode | schema editor tests', function (hooks) {
?.textContent?.includes('Date'),
);

await assert.dom('[data-test-selected-field-display-name]').hasText('Date');
assert.dom('[data-test-selected-field-display-name]').hasText('Date');
assert.dom('[data-test-save-field-button]').hasAttribute('disabled');

await fillIn('[data-test-field-name-input]', ' birth date');
Expand Down
4 changes: 2 additions & 2 deletions packages/host/tests/helpers/adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ export class TestRealmAdapter implements RealmAdapter {
// a quirk of our test file system's traverse is that it creates
// directories as it goes--so do our best to determine if we are checking for
// a file that exists (because of this behavior directories always exist)
await this.#traverse(
this.#traverse(
path.split('/'),
maybeFilename.includes('.') ? 'file' : 'directory',
);
Expand All @@ -182,7 +182,7 @@ export class TestRealmAdapter implements RealmAdapter {
}
if (err.name === 'TypeMismatchError') {
try {
await this.#traverse(path.split('/'), 'file');
this.#traverse(path.split('/'), 'file');
return true;
} catch (err: any) {
if (err.name === 'NotFoundError') {
Expand Down
Loading