Skip to content

Commit

Permalink
tools: enable ESLint require-yield rule
Browse files Browse the repository at this point in the history
PR-URL: nodejs#41463
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Geoffrey Booth <webadmin@geoffreybooth.com>
  • Loading branch information
Trott committed Jan 14, 2022
1 parent 9bfe60f commit 592f184
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 20 deletions.
1 change: 1 addition & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'],
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-readable-from.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}

Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-stream-compose.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-stream-duplex-from.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
33 changes: 16 additions & 17 deletions test/parallel/test-stream-pipeline.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}));
Expand All @@ -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');
}));
Expand All @@ -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');
Expand All @@ -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');
Expand All @@ -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');
Expand All @@ -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');
Expand All @@ -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) => {
Expand All @@ -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) => {
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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); })()
});

Expand Down

0 comments on commit 592f184

Please sign in to comment.