From 1f4369a106715f564de46ca7bdd7ee2642d7135c Mon Sep 17 00:00:00 2001 From: Rich Trott Date: Sun, 9 Jan 2022 08:23:28 -0800 Subject: [PATCH] tools: enable ESLint require-yield rule MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit PR-URL: https://github.com/nodejs/node/pull/41463 Reviewed-By: Tobias Nießen Reviewed-By: Michaël Zasso Reviewed-By: Luigi Pinca Reviewed-By: Colin Ihrig Reviewed-By: Geoffrey Booth --- .eslintrc.js | 1 + test/parallel/test-readable-from.js | 2 +- test/parallel/test-stream-compose.js | 2 +- test/parallel/test-stream-duplex-from.js | 2 +- test/parallel/test-stream-pipeline.js | 33 +++++++++---------- ...er-message-port-terminate-transfer-list.js | 1 + 6 files changed, 21 insertions(+), 20 deletions(-) diff --git a/.eslintrc.js b/.eslintrc.js index e36e428d931e7d..b1af0005c8dd6d 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -320,6 +320,7 @@ module.exports = { 'quotes': ['error', 'single', { avoidEscape: true }], 'quote-props': ['error', 'consistent'], 'rest-spread-spacing': 'error', + 'require-yield': 'error', 'semi': 'error', 'semi-spacing': 'error', 'space-before-blocks': ['error', 'always'], diff --git a/test/parallel/test-readable-from.js b/test/parallel/test-readable-from.js index 24dee0dce20050..b844574dc9e347 100644 --- a/test/parallel/test-readable-from.js +++ b/test/parallel/test-readable-from.js @@ -126,7 +126,7 @@ async function toReadableOnDataNonObject() { } async function destroysTheStreamWhenThrowing() { - async function* generate() { + async function* generate() { // eslint-disable-line require-yield throw new Error('kaboom'); } diff --git a/test/parallel/test-stream-compose.js b/test/parallel/test-stream-compose.js index c3d52e08e0048e..3b336a8c1c73b3 100644 --- a/test/parallel/test-stream-compose.js +++ b/test/parallel/test-stream-compose.js @@ -234,7 +234,7 @@ const assert = require('assert'); callback(null, chunk); }) }), - async function*(source) { + async function*(source) { // eslint-disable-line require-yield let tmp = ''; for await (const chunk of source) { tmp += chunk; diff --git a/test/parallel/test-stream-duplex-from.js b/test/parallel/test-stream-duplex-from.js index 446768d6eef3e3..6c9c59a5c82d52 100644 --- a/test/parallel/test-stream-duplex-from.js +++ b/test/parallel/test-stream-duplex-from.js @@ -134,7 +134,7 @@ const { Duplex, Readable, Writable, pipeline } = require('stream'); } yield rest; }), - async function * (source) { + async function * (source) { // eslint-disable-line require-yield let ret = ''; for await (const x of source) { ret += x; diff --git a/test/parallel/test-stream-pipeline.js b/test/parallel/test-stream-pipeline.js index bf1cb84ecda341..192f971b29daca 100644 --- a/test/parallel/test-stream-pipeline.js +++ b/test/parallel/test-stream-pipeline.js @@ -699,8 +699,8 @@ const tsp = require('timers/promises'); const ret = pipeline(async function*() { await Promise.resolve(); yield 'hello'; - }, async function*(source) { - for await (const chunk of source) {} + }, async function*(source) { // eslint-disable-line require-yield + for await (const chunk of source) {} // eslint-disable-line no-unused-vars }, common.mustCall((err) => { assert.strictEqual(err, undefined); })); @@ -712,11 +712,11 @@ const tsp = require('timers/promises'); // AsyncFunction destination is not returned and error is // propagated. - const ret = pipeline(async function*() { + const ret = pipeline(async function*() { // eslint-disable-line require-yield await Promise.resolve(); throw new Error('kaboom'); - }, async function*(source) { - for await (const chunk of source) {} + }, async function*(source) { // eslint-disable-line require-yield + for await (const chunk of source) {} // eslint-disable-line no-unused-vars }, common.mustCall((err) => { assert.strictEqual(err.message, 'kaboom'); })); @@ -726,7 +726,7 @@ const tsp = require('timers/promises'); { const s = new PassThrough(); - pipeline(async function*() { + pipeline(async function*() { // eslint-disable-line require-yield throw new Error('kaboom'); }, s, common.mustCall((err) => { assert.strictEqual(err.message, 'kaboom'); @@ -736,7 +736,7 @@ const tsp = require('timers/promises'); { const s = new PassThrough(); - pipeline(async function*() { + pipeline(async function*() { // eslint-disable-line require-yield throw new Error('kaboom'); }(), s, common.mustCall((err) => { assert.strictEqual(err.message, 'kaboom'); @@ -746,7 +746,7 @@ const tsp = require('timers/promises'); { const s = new PassThrough(); - pipeline(function*() { + pipeline(function*() { // eslint-disable-line require-yield throw new Error('kaboom'); }, s, common.mustCall((err, val) => { assert.strictEqual(err.message, 'kaboom'); @@ -756,7 +756,7 @@ const tsp = require('timers/promises'); { const s = new PassThrough(); - pipeline(function*() { + pipeline(function*() { // eslint-disable-line require-yield throw new Error('kaboom'); }(), s, common.mustCall((err, val) => { assert.strictEqual(err.message, 'kaboom'); @@ -771,7 +771,7 @@ const tsp = require('timers/promises'); yield 'hello'; yield 'world'; }, s, async function(source) { - for await (const chunk of source) { + for await (const chunk of source) { // eslint-disable-line no-unused-vars throw new Error('kaboom'); } }, common.mustCall((err, val) => { @@ -784,8 +784,8 @@ const tsp = require('timers/promises'); const s = new PassThrough(); const ret = pipeline(function() { return ['hello', 'world']; - }, s, async function*(source) { - for await (const chunk of source) { + }, s, async function*(source) { // eslint-disable-line require-yield + for await (const chunk of source) { // eslint-disable-line no-unused-vars throw new Error('kaboom'); } }, common.mustCall((err) => { @@ -1054,12 +1054,11 @@ const tsp = require('timers/promises'); const ws = new Writable({ write: common.mustNotCall() }); - pipeline(rs, async function*(stream) { - /* eslint no-unused-vars: off */ - for await (const chunk of stream) { + pipeline(rs, async function*(stream) { // eslint-disable-line require-yield + for await (const chunk of stream) { // eslint-disable-line no-unused-vars throw new Error('kaboom'); } - }, async function *(source) { + }, async function *(source) { // eslint-disable-line require-yield for await (const chunk of source) { res += chunk; } @@ -1394,7 +1393,7 @@ const tsp = require('timers/promises'); const ac = new AbortController(); const signal = ac.signal; pipelinep( - async function * ({ signal }) { + async function * ({ signal }) { // eslint-disable-line require-yield await tsp.setTimeout(1e6, signal); }, async function(source) { diff --git a/test/parallel/test-worker-message-port-terminate-transfer-list.js b/test/parallel/test-worker-message-port-terminate-transfer-list.js index a066405d9d14de..a5c7a34c55ed72 100644 --- a/test/parallel/test-worker-message-port-terminate-transfer-list.js +++ b/test/parallel/test-worker-message-port-terminate-transfer-list.js @@ -18,6 +18,7 @@ if (!process.env.HAS_STARTED_WORKER) { // Make sure we don’t end up running JS after the infinite loop is broken. port1.postMessage({}, { + // eslint-disable-next-line require-yield transfer: (function*() { while (true); })() });