From cec36528d4f51948c1cbfb5e0c4fde326e08569c Mon Sep 17 00:00:00 2001 From: Joe Portner <5295965+jportner@users.noreply.github.com> Date: Mon, 23 Jan 2023 14:58:43 -0500 Subject: [PATCH] Fix flatMap for tests using old Node versions --- tests/src/rules/no-duplicates.js | 50 +++++++++++++++++--------------- 1 file changed, 27 insertions(+), 23 deletions(-) diff --git a/tests/src/rules/no-duplicates.js b/tests/src/rules/no-duplicates.js index ebfd582166..ac76c3070a 100644 --- a/tests/src/rules/no-duplicates.js +++ b/tests/src/rules/no-duplicates.js @@ -5,6 +5,7 @@ import jsxConfig from '../../../config/react'; import { RuleTester } from 'eslint'; import eslintPkg from 'eslint/package.json'; import semver from 'semver'; +import flatMap from 'array.prototype.flatmap'; const ruleTester = new RuleTester(); const rule = require('rules/no-duplicates'); @@ -131,31 +132,34 @@ ruleTester.run('no-duplicates', rule, { }), // These test cases use duplicate import identifiers, which causes a fatal parsing error using ESPREE (default) and TS_OLD. - ...[parsers.BABEL_OLD, parsers.TS_NEW].flatMap((parser => !parser ? [] : [ - // #2347: duplicate identifiers should be removed - test({ - code: "import {a} from './foo'; import { a } from './foo'", - output: "import {a} from './foo'; ", - errors: ['\'./foo\' imported multiple times.', '\'./foo\' imported multiple times.'], - parser, - }), + ...flatMap([parsers.BABEL_OLD, parsers.TS_NEW], parser => { + if (!parser) return []; // TS_NEW is not always available + return [ + // #2347: duplicate identifiers should be removed + test({ + code: "import {a} from './foo'; import { a } from './foo'", + output: "import {a} from './foo'; ", + errors: ['\'./foo\' imported multiple times.', '\'./foo\' imported multiple times.'], + parser, + }), - // #2347: duplicate identifiers should be removed - test({ - code: "import {a,b} from './foo'; import { b, c } from './foo'; import {b,c,d} from './foo'", - output: "import {a,b, c ,d} from './foo'; ", - errors: ['\'./foo\' imported multiple times.', '\'./foo\' imported multiple times.', '\'./foo\' imported multiple times.'], - parser, - }), + // #2347: duplicate identifiers should be removed + test({ + code: "import {a,b} from './foo'; import { b, c } from './foo'; import {b,c,d} from './foo'", + output: "import {a,b, c ,d} from './foo'; ", + errors: ['\'./foo\' imported multiple times.', '\'./foo\' imported multiple times.', '\'./foo\' imported multiple times.'], + parser, + }), - // #2347: duplicate identifiers should be removed, but not if they are adjacent to comments - test({ - code: "import {a} from './foo'; import { a/*,b*/ } from './foo'", - output: "import {a, a/*,b*/ } from './foo'; ", - errors: ['\'./foo\' imported multiple times.', '\'./foo\' imported multiple times.'], - parser, - }), - ])), + // #2347: duplicate identifiers should be removed, but not if they are adjacent to comments + test({ + code: "import {a} from './foo'; import { a/*,b*/ } from './foo'", + output: "import {a, a/*,b*/ } from './foo'; ", + errors: ['\'./foo\' imported multiple times.', '\'./foo\' imported multiple times.'], + parser, + }), + ]; + }), test({ code: "import {x} from './foo'; import {} from './foo'; import {/*c*/} from './foo'; import {y} from './foo'",