| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 7bc93a6 commit 325087b
9 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -417,6 +417,7 @@ export default [ | |||
| 417 | 417 | 'node-core/alphabetize-errors': 'error', | |
| 418 | 418 | 'node-core/alphabetize-primordials': 'error', | |
| 419 | 419 | 'node-core/avoid-prototype-pollution': 'error', | |
| 420 | + 'node-core/iterator-result-done-first': 'error', | ||
| 420 | 421 | 'node-core/lowercase-name-for-primitive': 'error', | |
| 421 | 422 | 'node-core/non-ascii-character': 'error', | |
| 422 | 423 | 'node-core/no-array-destructuring': 'error', | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1032,7 +1032,7 @@ async function once(emitter, name, options = kEmptyObject) { | |||
| 1032 | 1032 | } | |
| 1033 | 1033 | ||
| 1034 | 1034 | function createIterResult(value, done) { | |
| 1035 | - return { value, done }; | ||
| 1035 | + return { done, value }; | ||
| 1036 | 1036 | } | |
| 1037 | 1037 | ||
| 1038 | 1038 | function eventTargetAgnosticRemoveListener(emitter, name, listener, flags) { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -660,7 +660,7 @@ if (getOptionValue('--experimental-stream-iter')) { | |||
| 660 | 660 | done = true; | |
| 661 | 661 | cleanup(); | |
| 662 | 662 | } | |
| 663 | - return { value: undefined, done: true }; | ||
| 663 | + return { done: true, value: undefined }; | ||
| 664 | 664 | } | |
| 665 | 665 | const toRead = remaining > 0 ? | |
| 666 | 666 | MathMin(readSize, remaining) : readSize; | |
@@ -676,20 +676,20 @@ if (getOptionValue('--experimental-stream-iter')) { | |||
| 676 | 676 | if (bytesRead === 0) { | |
| 677 | 677 | done = true; | |
| 678 | 678 | cleanup(); | |
| 679 | - return { value: undefined, done: true }; | ||
| 679 | + return { done: true, value: undefined }; | ||
| 680 | 680 | } | |
| 681 | 681 | if (pos >= 0) pos += bytesRead; | |
| 682 | 682 | if (remaining > 0) remaining -= bytesRead; | |
| 683 | 683 | const chunk = bytesRead < toRead ? | |
| 684 | 684 | buf.subarray(0, bytesRead) : buf; | |
| 685 | - return { value: [chunk], done: false }; | ||
| 685 | + return { done: false, value: [chunk] }; | ||
| 686 | 686 | }, | |
| 687 | 687 | return() { | |
| 688 | 688 | if (!done) { | |
| 689 | 689 | done = true; | |
| 690 | 690 | cleanup(); | |
| 691 | 691 | } | |
| 692 | - return { value: undefined, done: true }; | ||
| 692 | + return { done: true, value: undefined }; | ||
| 693 | 693 | }, | |
| 694 | 694 | }; | |
| 695 | 695 | }, | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -385,17 +385,17 @@ class PushQueue { | |||
| 385 | 385 | if (this.#writerState === 'closing' && this.#slots.length === 0) { | |
| 386 | 386 | this.endDrained(); | |
| 387 | 387 | } | |
| 388 | - return { __proto__: null, value: result, done: false }; | ||
| 388 | + return { __proto__: null, done: false, value: result }; | ||
| 389 | 389 | } | |
| 390 | 390 | ||
| 391 | 391 | // Buffer empty and writer closing = drain complete | |
| 392 | 392 | if (this.#writerState === 'closing') { | |
| 393 | 393 | this.endDrained(); | |
| 394 | - return { __proto__: null, value: undefined, done: true }; | ||
| 394 | + return { __proto__: null, done: true, value: undefined }; | ||
| 395 | 395 | } | |
| 396 | 396 | ||
| 397 | 397 | if (this.#writerState === 'closed') { | |
| 398 | - return { __proto__: null, value: undefined, done: true }; | ||
| 398 | + return { __proto__: null, done: true, value: undefined }; | ||
| 399 | 399 | } | |
| 400 | 400 | ||
| 401 | 401 | if (this.#writerState === 'errored' && this.#error) { | |
@@ -465,14 +465,14 @@ class PushQueue { | |||
| 465 | 465 | const pending = this.#pendingReads.shift(); | |
| 466 | 466 | const result = this.#drain(); | |
| 467 | 467 | this.#resolvePendingWrites(); | |
| 468 | - pending.resolve({ __proto__: null, value: result, done: false }); | ||
| 468 | + pending.resolve({ __proto__: null, done: false, value: result }); | ||
| 469 | 469 | } else if (this.#writerState === 'closing' && this.#slots.length === 0) { | |
| 470 | 470 | this.endDrained(); | |
| 471 | 471 | const pending = this.#pendingReads.shift(); | |
| 472 | - pending.resolve({ __proto__: null, value: undefined, done: true }); | ||
| 472 | + pending.resolve({ __proto__: null, done: true, value: undefined }); | ||
| 473 | 473 | } else if (this.#writerState === 'closed') { | |
| 474 | 474 | const pending = this.#pendingReads.shift(); | |
| 475 | - pending.resolve({ __proto__: null, value: undefined, done: true }); | ||
| 475 | + pending.resolve({ __proto__: null, done: true, value: undefined }); | ||
| 476 | 476 | } else if (this.#writerState === 'errored' && this.#error) { | |
| 477 | 477 | const pending = this.#pendingReads.shift(); | |
| 478 | 478 | pending.reject(this.#error); | |
@@ -659,11 +659,11 @@ function createReadable(queue) { | |||
| 659 | 659 | }, | |
| 660 | 660 | async return() { | |
| 661 | 661 | queue.consumerReturn(); | |
| 662 | - return { __proto__: null, value: undefined, done: true }; | ||
| 662 | + return { __proto__: null, done: true, value: undefined }; | ||
| 663 | 663 | }, | |
| 664 | 664 | async throw(error) { | |
| 665 | 665 | queue.consumerThrow(error); | |
| 666 | - return { __proto__: null, value: undefined, done: true }; | ||
| 666 | + return { __proto__: null, done: true, value: undefined }; | ||
| 667 | 667 | }, | |
| 668 | 668 | }; | |
| 669 | 669 | }, | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -242,8 +242,8 @@ class URLSearchParamsIterator { | |||
| 242 | 242 | const len = values.length; | |
| 243 | 243 | if (index >= len) { | |
| 244 | 244 | return { | |
| 245 | - value: undefined, | ||
| 246 | 245 | done: true, | |
| 246 | + value: undefined, | ||
| 247 | 247 | }; | |
| 248 | 248 | } | |
| 249 | 249 | ||
@@ -261,8 +261,8 @@ class URLSearchParamsIterator { | |||
| 261 | 261 | } | |
| 262 | 262 | ||
| 263 | 263 | return { | |
| 264 | - value: result, | ||
| 265 | 264 | done: false, | |
| 265 | + value: result, | ||
| 266 | 266 | }; | |
| 267 | 267 | } | |
| 268 | 268 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -599,7 +599,7 @@ class VFSWatchAsyncIterable { | |||
| 599 | 599 | const event = { eventType, filename }; | |
| 600 | 600 | if (this.#pendingResolvers.length > 0) { | |
| 601 | 601 | const { resolve } = this.#pendingResolvers.shift(); | |
| 602 | - resolve({ value: event, done: false }); | ||
| 602 | + resolve({ done: false, value: event }); | ||
| 603 | 603 | } else if (this.#pendingEvents.length < kMaxPendingEvents) { | |
| 604 | 604 | ArrayPrototypePush(this.#pendingEvents, event); | |
| 605 | 605 | } | |
@@ -611,7 +611,7 @@ class VFSWatchAsyncIterable { | |||
| 611 | 611 | // Resolve any pending iterators | |
| 612 | 612 | while (this.#pendingResolvers.length > 0) { | |
| 613 | 613 | const { resolve } = this.#pendingResolvers.shift(); | |
| 614 | - resolve({ value: undefined, done: true }); | ||
| 614 | + resolve({ done: true, value: undefined }); | ||
| 615 | 615 | } | |
| 616 | 616 | }); | |
| 617 | 617 | ||
@@ -648,12 +648,12 @@ class VFSWatchAsyncIterable { | |||
| 648 | 648 | */ | |
| 649 | 649 | next() { | |
| 650 | 650 | if (this.#closed) { | |
| 651 | - return PromiseResolve({ value: undefined, done: true }); | ||
| 651 | + return PromiseResolve({ done: true, value: undefined }); | ||
| 652 | 652 | } | |
| 653 | 653 | ||
| 654 | 654 | if (this.#pendingEvents.length > 0) { | |
| 655 | 655 | const event = this.#pendingEvents.shift(); | |
| 656 | - return PromiseResolve({ value: event, done: false }); | ||
| 656 | + return PromiseResolve({ done: false, value: event }); | ||
| 657 | 657 | } | |
| 658 | 658 | ||
| 659 | 659 | return new Promise((resolve, reject) => { | |
@@ -667,7 +667,7 @@ class VFSWatchAsyncIterable { | |||
| 667 | 667 | */ | |
| 668 | 668 | return() { | |
| 669 | 669 | this.#watcher.close(); | |
| 670 | - return PromiseResolve({ value: undefined, done: true }); | ||
| 670 | + return PromiseResolve({ done: true, value: undefined }); | ||
| 671 | 671 | } | |
| 672 | 672 | ||
| 673 | 673 | /** | |
@@ -677,7 +677,7 @@ class VFSWatchAsyncIterable { | |||
| 677 | 677 | */ | |
| 678 | 678 | throw(error) { | |
| 679 | 679 | this.#watcher.close(); | |
| 680 | - return PromiseResolve({ value: undefined, done: true }); | ||
| 680 | + return PromiseResolve({ done: true, value: undefined }); | ||
| 681 | 681 | } | |
| 682 | 682 | } | |
| 683 | 683 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -824,7 +824,7 @@ class ReadableStreamAsyncIteratorReadRequest { | |||
| 824 | 824 | ||
| 825 | 825 | [kChunk](chunk) { | |
| 826 | 826 | this.state.current = undefined; | |
| 827 | - this.promise.resolve({ value: chunk, done: false }); | ||
| 827 | + this.promise.resolve({ done: false, value: chunk }); | ||
| 828 | 828 | } | |
| 829 | 829 | ||
| 830 | 830 | [kClose]() { | |
@@ -848,11 +848,11 @@ class DefaultReadRequest { | |||
| 848 | 848 | } | |
| 849 | 849 | ||
| 850 | 850 | [kChunk](value) { | |
| 851 | - this[kState].resolve?.({ value, done: false }); | ||
| 851 | + this[kState].resolve?.({ done: false, value }); | ||
| 852 | 852 | } | |
| 853 | 853 | ||
| 854 | 854 | [kClose]() { | |
| 855 | - this[kState].resolve?.({ value: undefined, done: true }); | ||
| 855 | + this[kState].resolve?.({ done: true, value: undefined }); | ||
| 856 | 856 | } | |
| 857 | 857 | ||
| 858 | 858 | [kError](error) { | |
@@ -868,11 +868,11 @@ class ReadIntoRequest { | |||
| 868 | 868 | } | |
| 869 | 869 | ||
| 870 | 870 | [kChunk](value) { | |
| 871 | - this[kState].resolve?.({ value, done: false }); | ||
| 871 | + this[kState].resolve?.({ done: false, value }); | ||
| 872 | 872 | } | |
| 873 | 873 | ||
| 874 | 874 | [kClose](value) { | |
| 875 | - this[kState].resolve?.({ value, done: true }); | ||
| 875 | + this[kState].resolve?.({ done: true, value }); | ||
| 876 | 876 | } | |
| 877 | 877 | ||
| 878 | 878 | [kError](error) { | |
@@ -935,7 +935,7 @@ class ReadableStreamDefaultReader { | |||
| 935 | 935 | readableStreamDefaultControllerCallPullIfNeeded(controller); | |
| 936 | 936 | } | |
| 937 | 937 | ||
| 938 | - return PromiseResolve({ value: chunk, done: false }); | ||
| 938 | + return PromiseResolve({ done: false, value: chunk }); | ||
| 939 | 939 | } | |
| 940 | 940 | ||
| 941 | 941 | // Slow path: create request and go through normal flow | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,60 @@ | |||
| 1 | + 'use strict'; | ||
| 2 | + | ||
| 3 | + const common = require('../common'); | ||
| 4 | + if ((!common.hasCrypto) || (!common.hasIntl)) { | ||
| 5 | + common.skip('ESLint tests require crypto and Intl'); | ||
| 6 | + } | ||
| 7 | + | ||
| 8 | + common.skipIfEslintMissing(); | ||
| 9 | + | ||
| 10 | + const { RuleTester } = require('../../tools/eslint/node_modules/eslint'); | ||
| 11 | + const rule = require('../../tools/eslint-rules/iterator-result-done-first'); | ||
| 12 | + | ||
| 13 | + const message = 'Iterator result objects should place `done` before `value`.'; | ||
| 14 | + | ||
| 15 | + new RuleTester().run('iterator-result-done-first', rule, { | ||
| 16 | + valid: [ | ||
| 17 | + 'function next() { return { done: true, value: undefined }; }', | ||
| 18 | + 'function next() { return { __proto__: null, done: false, value: chunk }; }', | ||
| 19 | + 'function next() { return { done, value }; }', | ||
| 20 | + 'function next() { return { value }; }', | ||
| 21 | + 'function next() { return { done }; }', | ||
| 22 | + 'function next() { return { value: 1, other: 2 }; }', | ||
| 23 | + 'function next() { return { [value]: 1, done: true }; }', | ||
| 24 | + 'function next() { return { value: 1, [done]: true }; }', | ||
| 25 | + 'function next() { return { "done": true, "value": undefined }; }', | ||
| 26 | + 'function next() { return { ["done"]: true, ["value"]: undefined }; }', | ||
| 27 | + ], | ||
| 28 | + invalid: [ | ||
| 29 | + { | ||
| 30 | + code: 'function next() { return { value: undefined, done: true }; }', | ||
| 31 | + errors: [{ message }], | ||
| 32 | + output: 'function next() { return { done: true, value: undefined }; }', | ||
| 33 | + }, | ||
| 34 | + { | ||
| 35 | + code: 'function next() { return { __proto__: null, value: chunk, done: false }; }', | ||
| 36 | + errors: [{ message }], | ||
| 37 | + output: 'function next() { return { __proto__: null, done: false, value: chunk }; }', | ||
| 38 | + }, | ||
| 39 | + { | ||
| 40 | + code: 'function next() { return { value, done }; }', | ||
| 41 | + errors: [{ message }], | ||
| 42 | + output: 'function next() { return { done, value }; }', | ||
| 43 | + }, | ||
| 44 | + { | ||
| 45 | + code: 'function next() { return { "value": undefined, "done": true }; }', | ||
| 46 | + errors: [{ message }], | ||
| 47 | + output: 'function next() { return { "done": true, "value": undefined }; }', | ||
| 48 | + }, | ||
| 49 | + { | ||
| 50 | + code: 'function next() { return { ["value"]: undefined, ["done"]: true }; }', | ||
| 51 | + errors: [{ message }], | ||
| 52 | + output: 'function next() { return { ["done"]: true, ["value"]: undefined }; }', | ||
| 53 | + }, | ||
| 54 | + { | ||
| 55 | + code: 'function next() { return { value: result, extra: true, done: false }; }', | ||
| 56 | + errors: [{ message }], | ||
| 57 | + output: 'function next() { return { done: false, extra: true, value: result }; }', | ||
| 58 | + }, | ||
| 59 | + ], | ||
| 60 | + }); | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,66 @@ | |||
| 1 | + 'use strict'; | ||
| 2 | + | ||
| 3 | + const MESSAGE = 'Iterator result objects should place `done` before `value`.'; | ||
| 4 | + | ||
| 5 | + function getStaticPropertyName(property) { | ||
| 6 | + const { key } = property; | ||
| 7 | + | ||
| 8 | + if (!key) { | ||
| 9 | + return; | ||
| 10 | + } | ||
| 11 | + | ||
| 12 | + if (key.type === 'Identifier' && !property.computed) { | ||
| 13 | + return key.name; | ||
| 14 | + } | ||
| 15 | + | ||
| 16 | + if (key.type === 'Literal') { | ||
| 17 | + return key.value; | ||
| 18 | + } | ||
| 19 | + } | ||
| 20 | + | ||
| 21 | + module.exports = { | ||
| 22 | + meta: { | ||
| 23 | + type: 'suggestion', | ||
| 24 | + fixable: 'code', | ||
| 25 | + schema: [], | ||
| 26 | + }, | ||
| 27 | + | ||
| 28 | + create(context) { | ||
| 29 | + const sourceCode = context.sourceCode; | ||
| 30 | + | ||
| 31 | + return { | ||
| 32 | + ObjectExpression(node) { | ||
| 33 | + let doneProperty; | ||
| 34 | + let valueProperty; | ||
| 35 | + | ||
| 36 | + for (const property of node.properties) { | ||
| 37 | + if (property.type !== 'Property') { | ||
| 38 | + continue; | ||
| 39 | + } | ||
| 40 | + | ||
| 41 | + switch (getStaticPropertyName(property)) { | ||
| 42 | + case 'done': | ||
| 43 | + doneProperty ??= property; | ||
| 44 | + break; | ||
| 45 | + case 'value': | ||
| 46 | + valueProperty ??= property; | ||
| 47 | + break; | ||
| 48 | + } | ||
| 49 | + } | ||
| 50 | + | ||
| 51 | + if (doneProperty && valueProperty && valueProperty.range[0] < doneProperty.range[0]) { | ||
| 52 | + context.report({ | ||
| 53 | + node: valueProperty, | ||
| 54 | + message: MESSAGE, | ||
| 55 | + fix(fixer) { | ||
| 56 | + return [ | ||
| 57 | + fixer.replaceText(valueProperty, sourceCode.getText(doneProperty)), | ||
| 58 | + fixer.replaceText(doneProperty, sourceCode.getText(valueProperty)), | ||
| 59 | + ]; | ||
| 60 | + }, | ||
| 61 | + }); | ||
| 62 | + } | ||
| 63 | + }, | ||
| 64 | + }; | ||
| 65 | + }, | ||
| 66 | + }; | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments