|
4 | 4 | */
|
5 | 5 | "use strict"
|
6 | 6 |
|
| 7 | +/** @import { Linter } from 'eslint' */ |
| 8 | + |
7 | 9 | const RuleTester = require("../../../test-helpers").RuleTester
|
8 | 10 | const rule = require("../../../../lib/rules/no-unsupported-features/node-builtins")
|
9 | 11 |
|
| 12 | +/** |
| 13 | + * @typedef ValidTestCase |
| 14 | + * @property {string} [name] |
| 15 | + * @property {string} code |
| 16 | + * @property {any} [options] |
| 17 | + * @property {string | undefined} [filename] |
| 18 | + * @property {boolean} [only] |
| 19 | + * @property {Linter.LanguageOptions | undefined} [languageOptions] |
| 20 | + * @property {{ [name: string]: any } | undefined} [settings] |
| 21 | + */ |
| 22 | +/** |
| 23 | + * @typedef SuggestionOutput |
| 24 | + * @property {string} [messageId] |
| 25 | + * @property {string} [desc] |
| 26 | + * @property {Record<string, unknown> | undefined} [data] |
| 27 | + * @property {string} output |
| 28 | + */ |
| 29 | +/** |
| 30 | + * @typedef InvalidTestExtras |
| 31 | + * @property {number | Array<TestCaseError | string>} errors |
| 32 | + * @property {string | null | undefined} [output] |
| 33 | + */ |
| 34 | +/** |
| 35 | + * @typedef {ValidTestCase & InvalidTestExtras} InvalidTestCase |
| 36 | + */ |
| 37 | +/** |
| 38 | + * @typedef TestCaseError |
| 39 | + * @property {string | RegExp} [message] |
| 40 | + * @property {string} [messageId] |
| 41 | + * @property {string | undefined} [type] |
| 42 | + * @property {any} [data] |
| 43 | + * @property {number | undefined} [line] |
| 44 | + * @property {number | undefined} [column] |
| 45 | + * @property {number | undefined} [endLine] |
| 46 | + * @property {number | undefined} [endColumn] |
| 47 | + * @property {SuggestionOutput[] | undefined} [suggestions] |
| 48 | + */ |
| 49 | +/** |
| 50 | + * @typedef Pattern |
| 51 | + * @property {ValidTestCase[]} [valid] |
| 52 | + * @property {InvalidTestCase[]} [invalid] |
| 53 | + */ |
| 54 | + |
10 | 55 | /**
|
11 | 56 | * Concatenate patterns.
|
12 |
| - * @param {Array<{valid:Array,invalid:Array}>} patterns The patterns to concat. |
13 |
| - * @returns {{valid:Array,invalid:Array}} The concatenated patterns. |
| 57 | + * @param {Pattern[]} patterns The patterns to concat. |
| 58 | + * @returns {Pattern} The concatenated patterns. |
14 | 59 | */
|
15 | 60 | function concat(patterns) {
|
16 | 61 | const ret = {
|
@@ -5372,6 +5417,47 @@ new RuleTester({ languageOptions: { sourceType: "module" } }).run(
|
5372 | 5417 | ],
|
5373 | 5418 | },
|
5374 | 5419 |
|
| 5420 | + //---------------------------------------------------------------------- |
| 5421 | + // timers/promises |
| 5422 | + //---------------------------------------------------------------------- |
| 5423 | + { |
| 5424 | + valid: [ |
| 5425 | + { |
| 5426 | + code: ` |
| 5427 | + import { scheduler } from 'node:timers/promises'; |
| 5428 | + await scheduler.wait( 1000 ); |
| 5429 | + `, |
| 5430 | + options: [ |
| 5431 | + { |
| 5432 | + version: ">= 20.0.0", |
| 5433 | + ignores: ["timers/promises.scheduler.wait"], |
| 5434 | + }, |
| 5435 | + ], |
| 5436 | + languageOptions: { ecmaVersion: "latest" }, |
| 5437 | + }, |
| 5438 | + ], |
| 5439 | + invalid: [ |
| 5440 | + { |
| 5441 | + code: ` |
| 5442 | + import { scheduler } from 'node:timers/promises'; |
| 5443 | + await scheduler.wait( 1000 ); |
| 5444 | + `, |
| 5445 | + options: [{ version: ">= 20.0.0" }], |
| 5446 | + languageOptions: { ecmaVersion: "latest" }, |
| 5447 | + |
| 5448 | + errors: [ |
| 5449 | + { |
| 5450 | + messageId: "not-supported-yet", |
| 5451 | + data: { |
| 5452 | + name: "timers/promises.scheduler.wait", |
| 5453 | + version: ">= 20.0.0", |
| 5454 | + }, |
| 5455 | + }, |
| 5456 | + ], |
| 5457 | + }, |
| 5458 | + ], |
| 5459 | + }, |
| 5460 | + |
5375 | 5461 | {
|
5376 | 5462 | valid: [
|
5377 | 5463 | {
|
|
0 commit comments