|
| 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 | +}); |
0 commit comments