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

Async rule changes #156

Merged
merged 12 commits into from
Sep 26, 2024
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "minor",
"comment": "Rule changes for asynchronous code:\\n 1. Functions marked `async` must now include an `await`. The rule `'@typescript-eslint/require-await'` changed from `'off'` to `'error'`.\\n 2. Test code must now correctly handle promises. The rule `'@typescript-eslint/no-floating-promises'` changed from `'off'` to `'error'`.",
"packageName": "@ni/eslint-config-angular",
"email": "[email protected]",
"dependentChangeType": "patch"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "minor",
"comment": "Rule changes for asynchronous code:\\n 1. Functions marked `async` must now include an `await`. The rule `'require-await'` changed from `'off'` to `'error'`.\\n 2. It is now acceptable for a function to return an awaited promise. The rule `'no-return-await'` changed from `'error'` to `'off'`.",
"packageName": "@ni/eslint-config-javascript",
"email": "[email protected]",
"dependentChangeType": "patch"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "minor",
"comment": "Rule changes for asynchronous code:\\n 1. Functions marked `async` must now include an `await`. The rule `'@typescript-eslint/require-await'` changed from `'off'` to `'error'`.",
"packageName": "@ni/eslint-config-typescript",
"email": "[email protected]",
"dependentChangeType": "patch"
}
5 changes: 2 additions & 3 deletions packages/eslint-config-angular/requiring-type-checking.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,9 @@ module.exports = {
files: ['*.spec.ts'],
rules: {
/*
The jasminewd2 library used by Angular applications results in a significant number of
floating promises and unbound methods so these rules are disabled for test specs in Angular projects.
Spies used by Angular application tests result in a significant number of
unbound methods so this rule is disabled for test specs in Angular projects.
*/
'@typescript-eslint/no-floating-promises': 'off',
'@typescript-eslint/unbound-method': 'off',
jattasNI marked this conversation as resolved.
Show resolved Hide resolved
}
},
Expand Down
7 changes: 7 additions & 0 deletions packages/eslint-config-javascript/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,11 @@ module.exports = {
selector: 'CallExpression[callee.object.name=\'console\'][callee.property.name=/^(debug|info|time|timeEnd|trace)$/]',
message: 'Unexpected property on console object was called'
}],
/*
This rule is deprecated since ESLint 8.46.0 because returning an awaited value no longer generates an extra microtask.
https://eslint.org/docs/latest/rules/no-return-await
*/
'no-return-await': 'off',

/*
Disallow returning values from setters.
Expand Down Expand Up @@ -424,6 +429,8 @@ module.exports = {
*/
'prefer-regex-literals': 'error',

'require-await': 'error',
jattasNI marked this conversation as resolved.
Show resolved Hide resolved

/*
This configuration already supports the JSDoc syntax. Add additional syntax as line or
block exceptions or markers when necessary.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ module.exports = {
'no-throw-literal': 'off',
'@typescript-eslint/no-throw-literal': 'error',

// Defined by Airbnb
// Defined by NI
'require-await': 'off',
'@typescript-eslint/require-await': 'off',
'@typescript-eslint/require-await': 'error',

// Defined by Airbnb
'no-return-await': 'off',
Expand Down
4 changes: 2 additions & 2 deletions tests/angular/custom-ignore-attributes/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ describe('MyComponent', () => {
it('should have a div', async () => {
await fixture.whenStable();

expect(hostComponent.div).toBeDefined();
expect(hostComponent.myMethod).not.toHaveBeenCalled();
await expect(hostComponent.div).toBeDefined();
await expect(hostComponent.myMethod).not.toHaveBeenCalled();
jattasNI marked this conversation as resolved.
Show resolved Hide resolved
});
});
4 changes: 2 additions & 2 deletions tests/angular/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ describe('MyComponent', () => {
it('should have a div', async () => {
await fixture.whenStable();

expect(hostComponent.div).toBeDefined();
expect(hostComponent.myMethod).not.toHaveBeenCalled();
await expect(hostComponent.div).toBeDefined();
await expect(hostComponent.myMethod).not.toHaveBeenCalled();
});
});
4 changes: 4 additions & 0 deletions tests/javascript/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,8 @@ export class NI {
makeAwesomer() {
this._awesomeLevel += 1;
}

async asyncAwesomeness() {
await new Promise();
jattasNI marked this conversation as resolved.
Show resolved Hide resolved
}
}
6 changes: 6 additions & 0 deletions tests/typescript-requiring-type-checking/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,10 @@ export class NI {
public makeAwesomer(): void {
this._awesomeLevel += 1;
}

public async asyncAwesomeness(): Promise<void> {
await new Promise(resolve => {
resolve(true);
jattasNI marked this conversation as resolved.
Show resolved Hide resolved
});
jattasNI marked this conversation as resolved.
Show resolved Hide resolved
}
}