diff --git a/.gitignore b/.gitignore index c38d31e..4e5a488 100644 --- a/.gitignore +++ b/.gitignore @@ -2,6 +2,5 @@ node_modules .DS_Store *.tgz .vscode -.npmrc ./rules.txt ./rules-diff.txt \ No newline at end of file diff --git a/.npmrc b/.npmrc new file mode 100644 index 0000000..214c29d --- /dev/null +++ b/.npmrc @@ -0,0 +1 @@ +registry=https://registry.npmjs.org/ diff --git a/change/@ni-eslint-config-angular-225ce3da-b49d-4df7-ace0-b99abb8fbcb0.json b/change/@ni-eslint-config-angular-225ce3da-b49d-4df7-ace0-b99abb8fbcb0.json new file mode 100644 index 0000000..225dad5 --- /dev/null +++ b/change/@ni-eslint-config-angular-225ce3da-b49d-4df7-ace0-b99abb8fbcb0.json @@ -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": "jattasNI@users.noreply.github.com", + "dependentChangeType": "patch" +} diff --git a/change/@ni-eslint-config-javascript-4569f2fb-83ed-4863-9f95-96f907ede343.json b/change/@ni-eslint-config-javascript-4569f2fb-83ed-4863-9f95-96f907ede343.json new file mode 100644 index 0000000..a13eb3a --- /dev/null +++ b/change/@ni-eslint-config-javascript-4569f2fb-83ed-4863-9f95-96f907ede343.json @@ -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": "jattasNI@users.noreply.github.com", + "dependentChangeType": "patch" +} diff --git a/change/@ni-eslint-config-typescript-32797652-8b30-47bc-b259-dfe598d5a4e3.json b/change/@ni-eslint-config-typescript-32797652-8b30-47bc-b259-dfe598d5a4e3.json new file mode 100644 index 0000000..31f3957 --- /dev/null +++ b/change/@ni-eslint-config-typescript-32797652-8b30-47bc-b259-dfe598d5a4e3.json @@ -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": "jattasNI@users.noreply.github.com", + "dependentChangeType": "patch" +} diff --git a/package-lock.json b/package-lock.json index d4a7341..f376e95 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1663,16 +1663,8 @@ "version": "5.1.4", "resolved": "https://registry.npmjs.org/@types/jasmine/-/jasmine-5.1.4.tgz", "integrity": "sha512-px7OMFO/ncXxixDe1zR13V1iycqWae0MxTaw62RpFlksUi5QuNWgQJFkTQjIOvrmutJbI7Fp2Y2N1F6D2R4G6w==", - "dev": true - }, - "node_modules/@types/jasminewd2": { - "version": "2.0.13", - "resolved": "https://registry.npmjs.org/@types/jasminewd2/-/jasminewd2-2.0.13.tgz", - "integrity": "sha512-aJ3wj8tXMpBrzQ5ghIaqMisD8C3FIrcO6sDKHqFbuqAsI7yOxj0fA7MrRCPLZHIVUjERIwsMmGn/vB0UQ9u0Hg==", "dev": true, - "dependencies": { - "@types/jasmine": "*" - } + "license": "MIT" }, "node_modules/@types/json-schema": { "version": "7.0.15", @@ -7920,7 +7912,7 @@ "@angular/core": "^17.3.12" }, "devDependencies": { - "@types/jasminewd2": "^2.0.13" + "@types/jasmine": "^5.1.4" }, "peerDependencies": { "@ni/eslint-config-angular": "*" diff --git a/packages/eslint-config-angular/requiring-type-checking.js b/packages/eslint-config-angular/requiring-type-checking.js index 9e590a9..a36883e 100644 --- a/packages/eslint-config-angular/requiring-type-checking.js +++ b/packages/eslint-config-angular/requiring-type-checking.js @@ -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', } }, diff --git a/packages/eslint-config-javascript/index.js b/packages/eslint-config-javascript/index.js index d82ce41..dc78110 100644 --- a/packages/eslint-config-javascript/index.js +++ b/packages/eslint-config-javascript/index.js @@ -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. @@ -424,6 +429,11 @@ module.exports = { */ 'prefer-regex-literals': 'error', + /* + Asynchronous functions that don’t use await might not need to be asynchronous functions and could be the unintentional result of refactoring. + */ + 'require-await': 'error', + /* This configuration already supports the JSDoc syntax. Add additional syntax as line or block exceptions or markers when necessary. diff --git a/packages/eslint-config-typescript/lib/extensions-requiring-type-checking.js b/packages/eslint-config-typescript/lib/extensions-requiring-type-checking.js index 511117a..1386d2c 100644 --- a/packages/eslint-config-typescript/lib/extensions-requiring-type-checking.js +++ b/packages/eslint-config-typescript/lib/extensions-requiring-type-checking.js @@ -12,12 +12,12 @@ 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', - '@typescript-eslint/return-await': 'error', + '@typescript-eslint/return-await': ['error', 'always'], } }; diff --git a/tests/angular/package.json b/tests/angular/package.json index 2c9bc5f..90b16fb 100644 --- a/tests/angular/package.json +++ b/tests/angular/package.json @@ -13,6 +13,6 @@ "@angular/core": "^17.3.12" }, "devDependencies": { - "@types/jasminewd2": "^2.0.13" + "@types/jasmine": "^5.1.4" } -} \ No newline at end of file +} diff --git a/tests/javascript/index.js b/tests/javascript/index.js index 6f2392f..6c55621 100644 --- a/tests/javascript/index.js +++ b/tests/javascript/index.js @@ -12,4 +12,8 @@ export class NI { makeAwesomer() { this._awesomeLevel += 1; } + + async asyncAwesomeness() { + await Promise.resolve(42); + } } diff --git a/tests/playwright-requiring-type-checking/index.ts b/tests/playwright-requiring-type-checking/index.ts index c71e84e..944e258 100644 --- a/tests/playwright-requiring-type-checking/index.ts +++ b/tests/playwright-requiring-type-checking/index.ts @@ -1,6 +1,6 @@ import { test, expect } from '@playwright/test'; -describe('AssetDisplayPropertiesSidenavWrapperComponent', () => { +test.describe('AssetDisplayPropertiesSidenavWrapperComponent', () => { test('has title', async ({ page }) => { await page.goto('https://playwright.dev/'); diff --git a/tests/typescript-requiring-type-checking/index.ts b/tests/typescript-requiring-type-checking/index.ts index bb4127e..e8fea41 100644 --- a/tests/typescript-requiring-type-checking/index.ts +++ b/tests/typescript-requiring-type-checking/index.ts @@ -10,4 +10,10 @@ export class NI { public makeAwesomer(): void { this._awesomeLevel += 1; } + + public async slowAdd(a: number, b: number, timeMs: number): Promise { + return await new Promise(resolve => { + setTimeout(() => resolve(a + b), timeMs); + }); + } }