@@ -5,6 +5,7 @@ import jsxConfig from '../../../config/react';
5
5
import { RuleTester } from 'eslint' ;
6
6
import eslintPkg from 'eslint/package.json' ;
7
7
import semver from 'semver' ;
8
+ import flatMap from 'array.prototype.flatmap' ;
8
9
9
10
const ruleTester = new RuleTester ( ) ;
10
11
const rule = require ( 'rules/no-duplicates' ) ;
@@ -131,31 +132,34 @@ ruleTester.run('no-duplicates', rule, {
131
132
} ) ,
132
133
133
134
// 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
+ } ) ,
142
145
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
+ } ) ,
150
153
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
+ } ) ,
159
163
160
164
test ( {
161
165
code : "import {x} from './foo'; import {} from './foo'; import {/*c*/} from './foo'; import {y} from './foo'" ,
0 commit comments