Skip to content

Commit 9c8255f

Browse files
committed
feedback
1 parent ee31df7 commit 9c8255f

File tree

1 file changed

+179
-184
lines changed

1 file changed

+179
-184
lines changed

tests/src/rules/no-duplicates.js

Lines changed: 179 additions & 184 deletions
Original file line numberDiff line numberDiff line change
@@ -428,193 +428,188 @@ context('TypeScript', function () {
428428
},
429429
};
430430

431-
ruleTester.run('no-duplicates', rule, {
432-
valid: [
433-
// #1667: ignore duplicate if is a typescript type import
434-
test({
435-
code: "import type { x } from './foo'; import y from './foo'",
436-
...parserConfig,
437-
}),
438-
test({
439-
code: "import type x from './foo'; import type y from './bar'",
440-
...parserConfig,
441-
}),
442-
test({
443-
code: "import type {x} from './foo'; import type {y} from './bar'",
444-
...parserConfig,
445-
}),
446-
test({
447-
code: "import type x from './foo'; import type {y} from './foo'",
448-
...parserConfig,
449-
}),
450-
test({
451-
code: `
452-
import type {} from './module';
453-
import {} from './module2';
454-
`,
455-
...parserConfig,
456-
}),
457-
test({
458-
code: `
431+
const valid = [
432+
// #1667: ignore duplicate if is a typescript type import
433+
test({
434+
code: "import type { x } from './foo'; import y from './foo'",
435+
...parserConfig,
436+
}),
437+
test({
438+
code: "import type x from './foo'; import type y from './bar'",
439+
...parserConfig,
440+
}),
441+
test({
442+
code: "import type {x} from './foo'; import type {y} from './bar'",
443+
...parserConfig,
444+
}),
445+
test({
446+
code: "import type x from './foo'; import type {y} from './foo'",
447+
...parserConfig,
448+
}),
449+
test({
450+
code: `
451+
import type {} from './module';
452+
import {} from './module2';
453+
`,
454+
...parserConfig,
455+
}),
456+
test({
457+
code: `
458+
import type { Identifier } from 'module';
459+
460+
declare module 'module2' {
459461
import type { Identifier } from 'module';
462+
}
460463
461-
declare module 'module2' {
462-
import type { Identifier } from 'module';
463-
}
464-
465-
declare module 'module3' {
466-
import type { Identifier } from 'module';
467-
}
468-
`,
469-
...parserConfig,
470-
}),
471-
],
472-
invalid: [
473-
test({
474-
code: "import type x from './foo'; import type y from './foo'",
475-
...parserConfig,
476-
errors: [
477-
{
478-
line: 1,
479-
column: 20,
480-
message: "'./foo' imported multiple times.",
481-
},
482-
{
483-
line: 1,
484-
column: 48,
485-
message: "'./foo' imported multiple times.",
486-
},
487-
],
488-
}),
489-
test({
490-
code: "import type x from './foo'; import type x from './foo'",
491-
output: "import type x from './foo'; ",
492-
...parserConfig,
493-
errors: [
494-
{
495-
line: 1,
496-
column: 20,
497-
message: "'./foo' imported multiple times.",
498-
},
499-
{
500-
line: 1,
501-
column: 48,
502-
message: "'./foo' imported multiple times.",
503-
},
504-
],
505-
}),
506-
test({
507-
code: "import type {x} from './foo'; import type {y} from './foo'",
508-
...parserConfig,
509-
output: `import type {x,y} from './foo'; `,
510-
errors: [
511-
{
512-
line: 1,
513-
column: 22,
514-
message: "'./foo' imported multiple times.",
515-
},
516-
{
517-
line: 1,
518-
column: 52,
519-
message: "'./foo' imported multiple times.",
520-
},
521-
],
522-
}),
523-
],
524-
});
464+
declare module 'module3' {
465+
import type { Identifier } from 'module';
466+
}
467+
`,
468+
...parserConfig,
469+
}),
470+
].concat(!tsVersionSatisfies('>= 4.5') || !typescriptEslintParserSatisfies('>= 5.7.0') ? [] : [
471+
// #2470: ignore duplicate if is a typescript inline type import
472+
test({
473+
code: "import { type x } from './foo'; import y from './foo'",
474+
...parserConfig,
475+
}),
476+
test({
477+
code: "import { type x } from './foo'; import { y } from './foo'",
478+
...parserConfig,
479+
}),
480+
test({
481+
code: "import { type x } from './foo'; import type y from 'foo'",
482+
...parserConfig,
483+
}),
484+
]);
485+
486+
const invalid = [
487+
test({
488+
code: "import type x from './foo'; import type y from './foo'",
489+
...parserConfig,
490+
errors: [
491+
{
492+
line: 1,
493+
column: 20,
494+
message: "'./foo' imported multiple times.",
495+
},
496+
{
497+
line: 1,
498+
column: 48,
499+
message: "'./foo' imported multiple times.",
500+
},
501+
],
502+
}),
503+
test({
504+
code: "import type x from './foo'; import type x from './foo'",
505+
output: "import type x from './foo'; ",
506+
...parserConfig,
507+
errors: [
508+
{
509+
line: 1,
510+
column: 20,
511+
message: "'./foo' imported multiple times.",
512+
},
513+
{
514+
line: 1,
515+
column: 48,
516+
message: "'./foo' imported multiple times.",
517+
},
518+
],
519+
}),
520+
test({
521+
code: "import type {x} from './foo'; import type {y} from './foo'",
522+
...parserConfig,
523+
output: `import type {x,y} from './foo'; `,
524+
errors: [
525+
{
526+
line: 1,
527+
column: 22,
528+
message: "'./foo' imported multiple times.",
529+
},
530+
{
531+
line: 1,
532+
column: 52,
533+
message: "'./foo' imported multiple times.",
534+
},
535+
],
536+
}),
537+
].concat(!tsVersionSatisfies('>= 4.5') || !typescriptEslintParserSatisfies('>= 5.7.0') ? [] : [
538+
test({
539+
code: "import {type x} from './foo'; import type {y} from './foo'",
540+
...parserConfig,
541+
options: [{ 'inlineTypeImport': false }],
542+
output: `import {type x,y} from './foo'; `,
543+
errors: [
544+
{
545+
line: 1,
546+
column: 22,
547+
message: "'./foo' imported multiple times.",
548+
},
549+
{
550+
line: 1,
551+
column: 52,
552+
message: "'./foo' imported multiple times.",
553+
},
554+
],
555+
}),
556+
test({
557+
code: "import {type x} from 'foo'; import type {y} from 'foo'",
558+
...parserConfig,
559+
options: [{ 'inlineTypeImport': true }],
560+
output: `import {type x,type y} from 'foo'; `,
561+
errors: [
562+
{
563+
line: 1,
564+
column: 22,
565+
message: "'foo' imported multiple times.",
566+
},
567+
{
568+
line: 1,
569+
column: 50,
570+
message: "'foo' imported multiple times.",
571+
},
572+
],
573+
}),
574+
test({
575+
code: "import {type x} from './foo'; import {type y} from './foo'",
576+
...parserConfig,
577+
output: `import {type x,type y} from './foo'; `,
578+
errors: [
579+
{
580+
line: 1,
581+
column: 22,
582+
message: "'./foo' imported multiple times.",
583+
},
584+
{
585+
line: 1,
586+
column: 52,
587+
message: "'./foo' imported multiple times.",
588+
},
589+
],
590+
}),
591+
test({
592+
code: "import {AValue, type x, BValue} from './foo'; import {type y} from './foo'",
593+
...parserConfig,
594+
output: `import {AValue, type x, BValue,type y} from './foo'; `,
595+
errors: [
596+
{
597+
line: 1,
598+
column: 38,
599+
message: "'./foo' imported multiple times.",
600+
},
601+
{
602+
line: 1,
603+
column: 68,
604+
message: "'./foo' imported multiple times.",
605+
},
606+
],
607+
}),
608+
]);
525609

526-
if (!tsVersionSatisfies('>= 4.5') || !typescriptEslintParserSatisfies('>= 5.7.0')) {
527-
return;
528-
}
529-
530-
ruleTester.run('no-duplicates inline type', rule, {
531-
valid: [
532-
// #2470: ignore duplicate if is a typescript inline type import
533-
test({
534-
code: "import { type x } from './foo'; import y from './foo'",
535-
...parserConfig,
536-
}),
537-
test({
538-
code: "import { type x } from './foo'; import { y } from './foo'",
539-
...parserConfig,
540-
}),
541-
test({
542-
code: "import { type x } from './foo'; import type y from 'foo'",
543-
...parserConfig,
544-
}),
545-
],
546-
invalid: [
547-
test({
548-
code: "import {type x} from './foo'; import type {y} from './foo'",
549-
...parserConfig,
550-
options: [{ 'inlineTypeImport': false }],
551-
output: `import {type x,y} from './foo'; `,
552-
errors: [
553-
{
554-
line: 1,
555-
column: 22,
556-
message: "'./foo' imported multiple times.",
557-
},
558-
{
559-
line: 1,
560-
column: 52,
561-
message: "'./foo' imported multiple times.",
562-
},
563-
],
564-
}),
565-
test({
566-
code: "import {type x} from 'foo'; import type {y} from 'foo'",
567-
...parserConfig,
568-
options: [{ 'inlineTypeImport': true }],
569-
output: `import {type x,type y} from 'foo'; `,
570-
errors: [
571-
{
572-
line: 1,
573-
column: 22,
574-
message: "'foo' imported multiple times.",
575-
},
576-
{
577-
line: 1,
578-
column: 50,
579-
message: "'foo' imported multiple times.",
580-
},
581-
],
582-
}),
583-
test({
584-
code: "import {type x} from './foo'; import {type y} from './foo'",
585-
...parserConfig,
586-
output: `import {type x,type y} from './foo'; `,
587-
errors: [
588-
{
589-
line: 1,
590-
column: 22,
591-
message: "'./foo' imported multiple times.",
592-
},
593-
{
594-
line: 1,
595-
column: 52,
596-
message: "'./foo' imported multiple times.",
597-
},
598-
],
599-
}),
600-
test({
601-
code: "import {AValue, type x, BValue} from './foo'; import {type y} from './foo'",
602-
...parserConfig,
603-
output: `import {AValue, type x, BValue,type y} from './foo'; `,
604-
errors: [
605-
{
606-
line: 1,
607-
column: 38,
608-
message: "'./foo' imported multiple times.",
609-
},
610-
{
611-
line: 1,
612-
column: 68,
613-
message: "'./foo' imported multiple times.",
614-
},
615-
],
616-
}),
617-
],
610+
ruleTester.run('no-duplicates', rule, {
611+
valid,
612+
invalid,
618613
});
619614
});
620615
});

0 commit comments

Comments
 (0)