Skip to content

Commit 1927d60

Browse files
committed
Fix flatMap for tests using old Node versions
1 parent 888d84d commit 1927d60

File tree

1 file changed

+27
-23
lines changed

1 file changed

+27
-23
lines changed

Diff for: tests/src/rules/no-duplicates.js

+27-23
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import jsxConfig from '../../../config/react';
55
import { RuleTester } from 'eslint';
66
import eslintPkg from 'eslint/package.json';
77
import semver from 'semver';
8+
import flatMap from 'array.prototype.flatmap';
89

910
const ruleTester = new RuleTester();
1011
const rule = require('rules/no-duplicates');
@@ -131,31 +132,34 @@ ruleTester.run('no-duplicates', rule, {
131132
}),
132133

133134
// These test cases use duplicate import identifiers, which causes a fatal parsing error using ESPREE (default) and TS_OLD.
134-
...[parsers.BABEL_OLD, parsers.TS_NEW].flatMap((parser => !parser ? [] : [
135-
// #2347: duplicate identifiers should be removed
136-
test({
137-
code: "import {a} from './foo'; import { a } from './foo'",
138-
output: "import {a} from './foo'; ",
139-
errors: ['\'./foo\' imported multiple times.', '\'./foo\' imported multiple times.'],
140-
parser,
141-
}),
135+
...flatMap([parsers.BABEL_OLD, parsers.TS_NEW], parser => {
136+
if (!parser) return []; // TS_NEW is not always available
137+
return [
138+
// #2347: duplicate identifiers should be removed
139+
test({
140+
code: "import {a} from './foo'; import { a } from './foo'",
141+
output: "import {a} from './foo'; ",
142+
errors: ['\'./foo\' imported multiple times.', '\'./foo\' imported multiple times.'],
143+
parser,
144+
}),
142145

143-
// #2347: duplicate identifiers should be removed
144-
test({
145-
code: "import {a,b} from './foo'; import { b, c } from './foo'; import {b,c,d} from './foo'",
146-
output: "import {a,b, c ,d} from './foo'; ",
147-
errors: ['\'./foo\' imported multiple times.', '\'./foo\' imported multiple times.', '\'./foo\' imported multiple times.'],
148-
parser,
149-
}),
146+
// #2347: duplicate identifiers should be removed
147+
test({
148+
code: "import {a,b} from './foo'; import { b, c } from './foo'; import {b,c,d} from './foo'",
149+
output: "import {a,b, c ,d} from './foo'; ",
150+
errors: ['\'./foo\' imported multiple times.', '\'./foo\' imported multiple times.', '\'./foo\' imported multiple times.'],
151+
parser,
152+
}),
150153

151-
// #2347: duplicate identifiers should be removed, but not if they are adjacent to comments
152-
test({
153-
code: "import {a} from './foo'; import { a/*,b*/ } from './foo'",
154-
output: "import {a, a/*,b*/ } from './foo'; ",
155-
errors: ['\'./foo\' imported multiple times.', '\'./foo\' imported multiple times.'],
156-
parser,
157-
}),
158-
])),
154+
// #2347: duplicate identifiers should be removed, but not if they are adjacent to comments
155+
test({
156+
code: "import {a} from './foo'; import { a/*,b*/ } from './foo'",
157+
output: "import {a, a/*,b*/ } from './foo'; ",
158+
errors: ['\'./foo\' imported multiple times.', '\'./foo\' imported multiple times.'],
159+
parser,
160+
}),
161+
];
162+
}),
159163

160164
test({
161165
code: "import {x} from './foo'; import {} from './foo'; import {/*c*/} from './foo'; import {y} from './foo'",

0 commit comments

Comments
 (0)