Skip to content

Commit

Permalink
Add multiple parsers for test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
jportner committed Oct 21, 2022
1 parent f9e3f43 commit d9ca6a2
Showing 1 changed file with 24 additions and 21 deletions.
45 changes: 24 additions & 21 deletions tests/src/rules/no-duplicates.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,29 +129,32 @@ ruleTester.run('no-duplicates', rule, {
errors: ['\'./foo\' imported multiple times.', '\'./foo\' imported multiple times.'],
}),

// #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: parsers.BABEL_OLD, // Needed to avoid "A fatal parsing error occurred: Parsing error: Identifier 'a' has already been declared"
}),
// 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 => [
// #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: parsers.BABEL_OLD, // Needed to avoid "A fatal parsing error occurred: Parsing error: Identifier 'b' has already been declared"
}),
// #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: parsers.BABEL_OLD, // Needed to avoid "A fatal parsing error occurred: Parsing error: Identifier 'a' has already been declared"
}),
// #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'",
Expand Down

0 comments on commit d9ca6a2

Please sign in to comment.