Skip to content
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

Lint against unnecessary await #1526

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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 @@ -345,7 +345,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
20 changes: 7 additions & 13 deletions packages/host/app/lib/matrix-handlers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,11 @@ export async function addRoomEvent(context: MatrixService, event: Event) {
room = new RoomState();
context.setRoom(roomId, room);
}
let resolvedRoom = await room; //look at the note in the MatrixService 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 @@ -105,14 +104,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 MatrixService 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 @@ -126,8 +121,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 @@ -104,7 +104,7 @@ async function processDecryptedEvent(
return;
}

let roomState = await MatrixService.getRoom(roomId);
let roomState = MatrixService.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: 2 additions & 0 deletions packages/host/app/resources/room.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ export class RoomResource extends Resource<Args> {

private load = restartableTask(async (roomId: string) => {
try {
// TODO: figure out why the line below requires await despite not being a promise. Probably related to e-concurrency
// eslint-disable-next-line @typescript-eslint/await-thenable
this.room = roomId ? await 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);
Expand Down
2 changes: 1 addition & 1 deletion packages/host/tests/acceptance/ai-assistant-test.gts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,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 Down
Original file line number Diff line number Diff line change
Expand Up @@ -585,10 +585,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 @@ -609,7 +607,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