Skip to content

Commit

Permalink
fix: enable @typescript-eslint/no-floating-promises rule to address…
Browse files Browse the repository at this point in the history
… several un-awaited promises (#2939)
  • Loading branch information
Blackbaud-SteveBrush authored Dec 10, 2024
1 parent fb2a1f3 commit 58a248b
Show file tree
Hide file tree
Showing 119 changed files with 788 additions and 652 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import { SkyIllustrationResolverService } from '@skyux/indicators';
@Injectable()
export class IllustrationResolverService extends SkyIllustrationResolverService {
public override async resolveUrl(): Promise<string> {
return 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAoAAAAKAQMAAAC3/F3+AAAAA1BMVEUM2XM3lppuAAAACklEQVQI12PACwAAHgAB2nHFigAAAABJRU5ErkJggg==';
return await Promise.resolve(
'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAoAAAAKAQMAAAC3/F3+AAAAA1BMVEUM2XM3lppuAAAACklEQVQI12PACwAAHgAB2nHFigAAAABJRU5ErkJggg==',
);
}
}
5 changes: 3 additions & 2 deletions apps/integration/src/app/home/home.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,12 @@ export class HomeComponent implements AfterViewInit {
const integrationsRoute = router.config.find(
(route) => route.path === 'integrations',
);

if (integrationsRoute?.loadChildren) {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
(integrationsRoute.loadChildren() as Promise<any>).then(
void (integrationsRoute.loadChildren() as Promise<any>).then(
(integrationsRoutes) => {
this.createComponentData(
void this.createComponentData(
integrationsRoutes.routes,
'integrations',
).then(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export class FlyoutDemoComponent implements OnInit {
}

public ngOnInit(): void {
this.addData(false);
void this.addData(false);
}

public openModal(): void {
Expand All @@ -54,17 +54,16 @@ export class FlyoutDemoComponent implements OnInit {
});
}

public goToPage(): void {
this.#router.navigate(['/']);
public async goToPage(): Promise<void> {
await this.#router.navigate(['/']);
}

public addData(delay = true): void {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
this.#mockRemote(delay).then((result: any) => {
this.infiniteScrollData = this.infiniteScrollData.concat(result.data);
this.enableInfiniteScroll = result.hasMore;
this.#changeDetector.markForCheck();
});
public async addData(delay = true): Promise<void> {
const result = await this.#mockRemote(delay);

this.infiniteScrollData = this.infiniteScrollData.concat(result.data);
this.enableInfiniteScroll = result.hasMore;
this.#changeDetector.markForCheck();
}

// eslint-disable-next-line @typescript-eslint/no-explicit-any
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import { SkyIllustrationResolverService } from '@skyux/indicators';
@Injectable()
export class IllustrationResolverService extends SkyIllustrationResolverService {
public override async resolveUrl(): Promise<string> {
return 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAoAAAAKAQMAAAC3/F3+AAAAA1BMVEUM2XM3lppuAAAACklEQVQI12PACwAAHgAB2nHFigAAAABJRU5ErkJggg==';
return await Promise.resolve(
'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAoAAAAKAQMAAAC3/F3+AAAAA1BMVEUM2XM3lppuAAAACklEQVQI12PACwAAHgAB2nHFigAAAABJRU5ErkJggg==',
);
}
}
10 changes: 5 additions & 5 deletions apps/playground/src/app/home/home.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,12 @@ export class HomeComponent implements AfterViewInit {
private changeDetector: ChangeDetectorRef,
private dataManagerService: SkyDataManagerService,
) {
(
void (
router.config
.find((route) => route.path === 'components')
.loadChildren() as Promise<any>
).then((componentsRoutes) => {
this.createComponentData(componentsRoutes.routes, 'components').then(
void this.createComponentData(componentsRoutes.routes, 'components').then(
() => {
this.defaultDataState.filterData.filters = {
libraries: [
Expand Down Expand Up @@ -117,7 +117,7 @@ export class HomeComponent implements AfterViewInit {
});
}

public ngAfterViewInit() {
public ngAfterViewInit(): void {
this.dataManagerService
.getDataStateUpdates('playgroundComponents')
.subscribe((state) => {
Expand All @@ -134,9 +134,9 @@ export class HomeComponent implements AfterViewInit {
private createComponentData(
routes: ComponentRouteInfo[],
parentPath: string,
): Promise<any> {
): Promise<unknown> {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const promises: Promise<any>[] = [];
const promises: Promise<unknown>[] = [];

for (const route of routes) {
if (route.loadChildren) {
Expand Down
3 changes: 3 additions & 0 deletions eslint-overrides.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ module.exports = [
'error',
{ overrides: { constructors: 'no-public' } },
],
'@typescript-eslint/no-floating-promises': 'error',
'require-await': 'off',
'@typescript-eslint/require-await': 'error',
'no-return-await': 'off',
'@typescript-eslint/return-await': ['error', 'always'],
complexity: ['warn', { max: 10 }],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ describe('Summary Action Bar action components', () => {
fixture.detectChanges();
mediaQueryController.setBreakpoint('xs');
fixture.detectChanges();
fixture.whenStable();
await fixture.whenStable();
await expectAsync(fixture.nativeElement).toBeAccessible();
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ describe('Summary Action Bar component', () => {
).toBe('0px');
});

it('should remove the correct modal footer padding if the action bar is in a modal footer and there are two modals', async () => {
it('should remove the correct modal footer padding if the action bar is in a modal footer and there are two modals', () => {
cmp.hideMainActionBar = true;
fixture.detectChanges();
debugElement
Expand Down Expand Up @@ -583,11 +583,11 @@ describe('Summary Action Bar component', () => {
describe('body stylings', () => {
it('should set a margin on the body if the action bar is displayed on initial load', (done) => {
fixture.detectChanges();
fixture.whenStable().then(() => {
void fixture.whenStable().then(() => {
fixture.detectChanges();
setTimeout(async () => {
setTimeout(() => {
fixture.detectChanges();
fixture.whenStable().then(() => {
void fixture.whenStable().then(() => {
const actionBarHeight = getActionBarHeight(debugElement);
expect(document.body.style.marginBottom).toBe(
actionBarHeight + 'px',
Expand All @@ -611,15 +611,15 @@ describe('Summary Action Bar component', () => {
cmp.showBar1 = false;
cmp.showBar2 = true;
fixture.detectChanges();
fixture.whenStable().then(() => {
void fixture.whenStable().then(() => {
fixture.detectChanges();
cmp.activeTab = 1;
fixture.detectChanges();
fixture.whenStable().then(() => {
void fixture.whenStable().then(() => {
fixture.detectChanges();
setTimeout(() => {
fixture.detectChanges();
fixture.whenStable().then(() => {
void fixture.whenStable().then(() => {
const actionBarHeight = getActionBarHeight(debugElement);
expect(document.body.style.marginBottom).toBe(
actionBarHeight + 'px',
Expand All @@ -633,19 +633,19 @@ describe('Summary Action Bar component', () => {

it('should set a margin on the body if the action bar is displayed via multiple tab changes', (done) => {
fixture.detectChanges();
fixture.whenStable().then(() => {
void fixture.whenStable().then(() => {
fixture.detectChanges();
cmp.activeTab = 1;
fixture.detectChanges();
fixture.whenStable().then(() => {
void fixture.whenStable().then(() => {
fixture.detectChanges();
cmp.activeTab = 0;
fixture.detectChanges();
fixture.whenStable().then(() => {
void fixture.whenStable().then(() => {
fixture.detectChanges();
setTimeout(() => {
fixture.detectChanges();
fixture.whenStable().then(() => {
void fixture.whenStable().then(() => {
const actionBarHeight = getActionBarHeight(debugElement);
expect(document.body.style.marginBottom).toBe(
actionBarHeight + 'px',
Expand Down Expand Up @@ -703,20 +703,18 @@ describe('Summary Action Bar component', () => {
});

describe('body stylings', () => {
it('should set a margin on the split view workspace content if the action bar is displayed on initial load', (done) => {
it('should set a margin on the split view workspace content if the action bar is displayed on initial load', async () => {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
spyOn(window as any, 'setTimeout').and.callFake((fun: () => void) => {
fun();
});
fixture.detectChanges();
fixture.whenStable().then(() => {
fixture.detectChanges();
const workspacePaddingBottom = debugElement.query(
By.css('.sky-split-view-workspace-content'),
).nativeElement.style.paddingBottom;
expect(workspacePaddingBottom).toBe('20px');
done();
});
await fixture.whenStable();
fixture.detectChanges();
const workspacePaddingBottom = debugElement.query(
By.css('.sky-split-view-workspace-content'),
).nativeElement.style.paddingBottom;
expect(workspacePaddingBottom).toBe('20px');
});

it('should not set a margin on the body if the action bar is not displayed on initial load', async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -214,14 +214,14 @@ describe('Summary action bar fixture', () => {
});

describe('summary content', () => {
it('should support summary body query selectors', async () => {
it('should support summary body query selectors', () => {
const summaryContent = summaryActionBarFixture.querySummaryBody('div');
expect(SkyAppTestUtility.getText(summaryContent)).toEqual(
testComponent.summaryBody,
);
});

it('should support summary body query all selectors', async () => {
it('should support summary body query all selectors', () => {
const results = summaryActionBarFixture.queryAllSummaryBody('div');
expect(results).toExist();
expect(results.length).toBe(1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ describe('SkyAgGridWrapperComponent', () => {
expect(autoHeightGridWrapperComponent.isNormalLayout).toEqual(true);
});

it('should apply ag-theme', async () => {
it('should apply ag-theme', () => {
expect(
gridWrapperNativeElement.querySelector('.sky-ag-grid'),
).toHaveCssClass('ag-theme-sky-data-grid-default');
Expand Down Expand Up @@ -461,7 +461,7 @@ describe('SkyAgGridWrapperComponent', () => {
expect(agGrid.api.setFocusedHeader).not.toHaveBeenCalled();
});

it('should track focus on header', async () => {
it('should track focus on header', () => {
const column = new AgColumn({}, {}, 'name', true);

agGrid.headerFocused.next({
Expand Down Expand Up @@ -494,7 +494,7 @@ describe('SkyAgGridWrapperComponent', () => {
}
});

it('should track focus on cells', async () => {
it('should track focus on cells', () => {
const column = new AgColumn({}, {}, 'name', true);
const focusGridInnerElement = agGrid.gridOptions?.focusGridInnerElement;
if (focusGridInnerElement) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ describe('SkyAgGridCellRendererRowSelectorComponent', () => {

describe('updateRow', () => {
it(`should set the rowNode selected property and the row data's column-defined field property
to the component's checked property value if column field provided`, async () => {
to the component's checked property value if column field provided`, () => {
cellRendererParams.value = false;

rowSelectorCellFixture.detectChanges();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ describe('SkyAgGridCellValidatorTooltipComponent', () => {
expect(fixture.componentInstance.validatorMessage).toBe('Test message XYZ');
}));

it('should show popover on delayed hover', fakeAsync(() => {
it('should show popover on delayed hover', fakeAsync(async () => {
const fixture = TestBed.createComponent(
SkyAgGridCellValidatorTooltipComponent,
);
Expand Down Expand Up @@ -116,20 +116,20 @@ describe('SkyAgGridCellValidatorTooltipComponent', () => {
eventHandlers['keyup']({ key: 'ArrowRight' } as KeyboardEvent);
tick();
fixture.detectChanges();
fixture.whenStable();
await fixture.whenStable();
expect(popover()).toBeTruthy();
eventHandlers['mouseleave']({} as MouseEvent);
tick();
fixture.detectChanges();
tick();
fixture.detectChanges();
fixture.whenStable();
await fixture.whenStable();
expect(popover()).toBeFalsy();
eventHandlers['mouseenter']({} as MouseEvent);
tick();
flush();
fixture.detectChanges();
fixture.whenStable();
await fixture.whenStable();
expect(popover()).toBeTruthy();
}));
});
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ describe('HeaderComponent', () => {
expect(fixture.debugElement.query(By.css('.ag-filter-icon'))).toBeTruthy();
});

it('should not show sort button when sort is disabled', async () => {
it('should not show sort button when sort is disabled', () => {
params = {
...params,
enableSorting: false,
Expand All @@ -202,7 +202,7 @@ describe('HeaderComponent', () => {
expect(document.querySelector('.ag-sort-indicator-container')).toBeNull();
});

it('should not sort when sort is disabled', async () => {
it('should not sort when sort is disabled', () => {
params = {
...params,
enableSorting: false,
Expand Down
Loading

0 comments on commit 58a248b

Please sign in to comment.