Skip to content

Commit

Permalink
Updates for switch to eslint return-await to always (#2412)
Browse files Browse the repository at this point in the history
# Pull Request

## 🀨 Rationale

Adopting the soon to update `return-await` configuration in the `always`
mode.

## πŸ‘©β€πŸ’» Implementation

- Updated the eslint rule
- Ran the fixer (via `npm run format`)
- Made a couple minor tweaks pointed out below

## πŸ§ͺ Testing

Rely on CI

## βœ… Checklist

- [x] I have updated the project documentation to reflect my changes or
determined no changes are needed.
  • Loading branch information
rajsite authored Sep 26, 2024
1 parent 1203a22 commit 7ab95a3
Show file tree
Hide file tree
Showing 103 changed files with 196 additions and 167 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "patch",
"comment": "Updates for async eslint rule change",
"packageName": "@ni/nimble-angular",
"email": "[email protected]",
"dependentChangeType": "patch"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "patch",
"comment": "Updated for async eslint rule change",
"packageName": "@ni/nimble-components",
"email": "[email protected]",
"dependentChangeType": "patch"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "patch",
"comment": "Updates for async eslint rule change",
"packageName": "@ni/spright-components",
"email": "[email protected]",
"dependentChangeType": "patch"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "patch",
"comment": "Updated for async eslint rule change",
"packageName": "@ni/xliff-to-json-converter",
"email": "[email protected]",
"dependentChangeType": "patch"
}
32 changes: 16 additions & 16 deletions package-lock.json

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

Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export class NimbleDialogDirective<CloseReason = void> {
public constructor(private readonly renderer: Renderer2, private readonly elementRef: ElementRef<Dialog<CloseReason>>) {}

public async show(): Promise<CloseReason | UserDismissed> {
return this.elementRef.nativeElement.show();
return await this.elementRef.nativeElement.show();
}

public close(reason: CloseReason): void {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export class NimbleDrawerDirective<CloseReason = void> {
public constructor(private readonly renderer: Renderer2, private readonly elementRef: ElementRef<Drawer<CloseReason>>) {}

public async show(): Promise<CloseReason | UserDismissed> {
return this.elementRef.nativeElement.show();
return await this.elementRef.nativeElement.show();
}

public close(reason: CloseReason): void {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,18 +84,18 @@ export class NimbleTableDirective<TData extends TableRecord = TableRecord> imple
}

public async setData(data: readonly TData[]): Promise<void> {
return this.elementRef.nativeElement.setData(data);
await this.elementRef.nativeElement.setData(data);
}

public async getSelectedRecordIds(): Promise<string[]> {
return this.elementRef.nativeElement.getSelectedRecordIds();
return await this.elementRef.nativeElement.getSelectedRecordIds();
}

public async setSelectedRecordIds(recordIds: string[]): Promise<void> {
return this.elementRef.nativeElement.setSelectedRecordIds(recordIds);
await this.elementRef.nativeElement.setSelectedRecordIds(recordIds);
}

public async setRecordHierarchyOptions(hierarchyOptions: TableSetRecordHierarchyOptions[]): Promise<void> {
return this.elementRef.nativeElement.setRecordHierarchyOptions(hierarchyOptions);
await this.elementRef.nativeElement.setRecordHierarchyOptions(hierarchyOptions);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export class TablePageObject<T extends TableRecord> extends NimbleComponentsTabl
const originalSetDataFn = tableElement.setData.bind(tableElement);
tableElement.setData = async (...args): Promise<void> => {
this.mostRecentSetDataPromise = originalSetDataFn(...args);
return this.mostRecentSetDataPromise;
await this.mostRecentSetDataPromise;
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ describe('Nimble table', () => {
}] as const;

public async initializeTableData(): Promise<void> {
return this.directive.setData(this.originalData);
await this.directive.setData(this.originalData);
}
}

Expand Down
4 changes: 0 additions & 4 deletions packages/eslint-config-nimble/javascript.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,6 @@ module.exports = {
ecmaVersion: 2020
},
rules: {
// Enabled to prevent accidental usage of async-await
'require-await': 'error',
'no-return-await': 'off',

// This rule's configuration is based on the NI javascript styleguide:
// https://github.com/ni/javascript-styleguide/blob/a1a6abd7adca7d9acd002705101b351d695b2442/packages/eslint-config-javascript/index.js
// The only difference is that we're increasing the value of minProperties (from 6) so
Expand Down
4 changes: 2 additions & 2 deletions packages/eslint-config-nimble/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@
"./components.js": "./components.js"
},
"peerDependencies": {
"@ni/eslint-config-javascript": "^4.2.0",
"@ni/eslint-config-typescript": "^4.2.0",
"@ni/eslint-config-javascript": "^4.3.0",
"@ni/eslint-config-typescript": "^4.4.0",
"eslint": "^8.7.0"
}
}
6 changes: 0 additions & 6 deletions packages/eslint-config-nimble/typescript.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,6 @@ module.exports = {
// see: https://github.com/ni/javascript-styleguide/#strict-null-checks
'@typescript-eslint/no-non-null-assertion': 'off',

// Enabled to prevent accidental usage of async-await
'require-await': 'off',
'@typescript-eslint/require-await': 'error',
'no-return-await': 'off',
'@typescript-eslint/return-await': 'error',

// This rule's configuration is based on the NI javascript styleguide:
// https://github.com/ni/javascript-styleguide/blob/a1a6abd7adca7d9acd002705101b351d695b2442/packages/eslint-config-javascript/index.js
// The only difference is that we're increasing the value of minProperties (from 6) so
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { waitForUpdatesAsync } from '../../testing/async-helpers';
import { fixture, Fixture } from '../../utilities/tests/fixture';

async function setup(): Promise<Fixture<AnchorButton>> {
return fixture<AnchorButton>(
return await fixture<AnchorButton>(
html`<nimble-anchor-button></nimble-anchor-button>`
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ describe('Anchor Menu Item', () => {
}

async function setup(source: Model): Promise<Fixture<AnchorMenuItem>> {
return fixture<AnchorMenuItem>(
return await fixture<AnchorMenuItem>(
html`<nimble-anchor-menu-item href="#">
<nimble-xmark-icon
${ref('xmarkIcon')}
Expand Down Expand Up @@ -116,7 +116,7 @@ describe('Anchor Menu Item', () => {
}

async function setup(source: Model): Promise<Fixture<Menu>> {
return fixture<Menu>(
return await fixture<Menu>(
html`
<nimble-menu>
<nimble-menu-item>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ import { waitForUpdatesAsync } from '../../testing/async-helpers';
import { Fixture, fixture } from '../../utilities/tests/fixture';

async function setup(): Promise<Fixture<AnchorTab>> {
return fixture<AnchorTab>(html`<nimble-anchor-tab></nimble-anchor-tab>`);
return await fixture<AnchorTab>(
html`<nimble-anchor-tab></nimble-anchor-tab>`
);
}

describe('AnchorTab', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ describe('AnchorTabs', () => {

describe('without hrefs', () => {
async function setup(): Promise<Fixture<AnchorTabs>> {
return fixture<AnchorTabs>(
return await fixture<AnchorTabs>(
html`<nimble-anchor-tabs activeid="tab-two">
<nimble-anchor-tab></nimble-anchor-tab>
<nimble-anchor-tab id="tab-two"></nimble-anchor-tab>
Expand Down Expand Up @@ -158,7 +158,7 @@ describe('AnchorTabs', () => {

describe('with hrefs', () => {
async function setupWithHrefs(): Promise<Fixture<AnchorTabs>> {
return fixture<AnchorTabs>(
return await fixture<AnchorTabs>(
html`<nimble-anchor-tabs activeid="tab-two">
<nimble-anchor-tab href="foo"></nimble-anchor-tab>
<nimble-anchor-tab
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ describe('Anchor Tree Item', () => {
}

async function setup(source: Model): Promise<Fixture<AnchorTreeItem>> {
return fixture<AnchorTreeItem>(
return await fixture<AnchorTreeItem>(
html`<nimble-anchor-tree-item href="#">
<nimble-xmark-icon
${ref('xmarkIcon')}
Expand Down Expand Up @@ -125,7 +125,7 @@ describe('Anchor Tree Item', () => {
}

async function setup(source: Model): Promise<Fixture<TreeView>> {
return fixture<TreeView>(
return await fixture<TreeView>(
// prettier-ignore
html<Model>`
<nimble-tree-view ${ref('treeView')}>
Expand Down
4 changes: 2 additions & 2 deletions packages/nimble-components/src/anchor/tests/anchor.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { waitForUpdatesAsync } from '../../testing/async-helpers';
import { fixture, Fixture } from '../../utilities/tests/fixture';

async function setup(): Promise<Fixture<Anchor>> {
return fixture<Anchor>(html`<nimble-anchor></nimble-anchor>`);
return await fixture<Anchor>(html`<nimble-anchor></nimble-anchor>`);
}

describe('Anchor', () => {
Expand Down Expand Up @@ -156,7 +156,7 @@ describe('Anchor', () => {

describe('with contenteditable without value', () => {
async function setupWithContenteditable(): Promise<Fixture<Anchor>> {
return fixture<Anchor>(
return await fixture<Anchor>(
html`<nimble-anchor contenteditable></nimble-anchor>`
);
}
Expand Down
4 changes: 2 additions & 2 deletions packages/nimble-components/src/banner/tests/banner.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
import { buttonTag } from '../../button';

async function setup(): Promise<Fixture<Banner>> {
return fixture<Banner>(html`
return await fixture<Banner>(html`
<nimble-banner>
<span slot="title">Title</span>
Message text
Expand All @@ -21,7 +21,7 @@ async function setup(): Promise<Fixture<Banner>> {
}

async function setupWithLabelProvider(): Promise<Fixture<ThemeProvider>> {
return fixture<ThemeProvider>(html`
return await fixture<ThemeProvider>(html`
<${themeProviderTag}>
<${labelProviderCoreTag}></${labelProviderCoreTag}>
<nimble-banner>
Expand Down
2 changes: 1 addition & 1 deletion packages/nimble-components/src/button/tests/button.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { waitForUpdatesAsync } from '../../testing/async-helpers';

describe('Button', () => {
async function setup(): Promise<Fixture<Button>> {
return fixture<Button>(html`<${buttonTag}></${buttonTag}>`);
return await fixture<Button>(html`<${buttonTag}></${buttonTag}>`);
}

it('should export its tag', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { waitForUpdatesAsync } from '../../testing/async-helpers';

describe('Checkbox', () => {
async function setup(): Promise<Fixture<Checkbox>> {
return fixture<Checkbox>(html`<${checkboxTag}></${checkboxTag}>`);
return await fixture<Checkbox>(html`<${checkboxTag}></${checkboxTag}>`);
}

it('should export its tag', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ async function setup(): Promise<Fixture<Combobox>> {
<nimble-list-option value="two">Two</nimble-list-option>
</nimble-combobox>
`;
return fixture<Combobox>(viewTemplate);
return await fixture<Combobox>(viewTemplate);
}

async function setupWithLabel(): Promise<Fixture<Combobox>> {
Expand All @@ -21,7 +21,7 @@ async function setupWithLabel(): Promise<Fixture<Combobox>> {
<nimble-list-option value="two">Two</nimble-list-option>
</nimble-combobox>
`;
return fixture<Combobox>(viewTemplate);
return await fixture<Combobox>(viewTemplate);
}

describe('Combobox Page Object', () => {
Expand Down
10 changes: 5 additions & 5 deletions packages/nimble-components/src/combobox/tests/combobox.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ describe('Combobox', () => {
<${listOptionTag} disabled>Four</${listOptionTag}>
</${comboboxTag}>
`;
return fixture<Combobox>(viewTemplate);
return await fixture<Combobox>(viewTemplate);
}

let element: Combobox;
Expand Down Expand Up @@ -466,7 +466,7 @@ describe('Combobox', () => {
<${listOptionTag}>Two</${listOptionTag}>
</${comboboxTag}>
`;
return fixture<Combobox>(viewTemplate);
return await fixture<Combobox>(viewTemplate);
}

it('should respect value set before connect is completed', async () => {
Expand All @@ -493,7 +493,7 @@ describe('Combobox', () => {
<${listOptionTag}>One</${listOptionTag}>
</${comboboxTag}>
`;
return fixture<Combobox>(viewTemplate);
return await fixture<Combobox>(viewTemplate);
}

it('should set classes based on open, disabled, and position', async () => {
Expand Down Expand Up @@ -533,7 +533,7 @@ describe('Combobox', () => {
<${listOptionTag}>1000</${listOptionTag}>
</${comboboxTag}>
`;
return fixture<Combobox>(viewTemplate);
return await fixture<Combobox>(viewTemplate);
}

let element: Combobox;
Expand Down Expand Up @@ -586,7 +586,7 @@ describe('Combobox', () => {
</<${comboboxTag}>>
</div>
`;
return fixture<Combobox>(viewTemplate);
return await fixture<Combobox>(viewTemplate);
}

it('should not confine dropdown to div with "overflow: auto"', async () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/nimble-components/src/dialog/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ export class Dialog<CloseReason = void> extends FoundationElement {
throw new Error('Dialog is already open');
}
this.dialogElement.showModal();
return new Promise((resolve, _reject) => {
return await new Promise((resolve, _reject) => {
this.resolveShow = resolve;
});
}
Expand Down
Loading

0 comments on commit 7ab95a3

Please sign in to comment.