Skip to content

Commit

Permalink
feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
snewcomer committed Oct 2, 2022
1 parent 58eaf0d commit 855e6e9
Showing 1 changed file with 179 additions and 184 deletions.
363 changes: 179 additions & 184 deletions tests/src/rules/no-duplicates.js
Original file line number Diff line number Diff line change
Expand Up @@ -428,193 +428,188 @@ context('TypeScript', function () {
},
};

ruleTester.run('no-duplicates', rule, {
valid: [
// #1667: ignore duplicate if is a typescript type import
test({
code: "import type { x } from './foo'; import y from './foo'",
...parserConfig,
}),
test({
code: "import type x from './foo'; import type y from './bar'",
...parserConfig,
}),
test({
code: "import type {x} from './foo'; import type {y} from './bar'",
...parserConfig,
}),
test({
code: "import type x from './foo'; import type {y} from './foo'",
...parserConfig,
}),
test({
code: `
import type {} from './module';
import {} from './module2';
`,
...parserConfig,
}),
test({
code: `
const valid = [
// #1667: ignore duplicate if is a typescript type import
test({
code: "import type { x } from './foo'; import y from './foo'",
...parserConfig,
}),
test({
code: "import type x from './foo'; import type y from './bar'",
...parserConfig,
}),
test({
code: "import type {x} from './foo'; import type {y} from './bar'",
...parserConfig,
}),
test({
code: "import type x from './foo'; import type {y} from './foo'",
...parserConfig,
}),
test({
code: `
import type {} from './module';
import {} from './module2';
`,
...parserConfig,
}),
test({
code: `
import type { Identifier } from 'module';
declare module 'module2' {
import type { Identifier } from 'module';
}
declare module 'module2' {
import type { Identifier } from 'module';
}
declare module 'module3' {
import type { Identifier } from 'module';
}
`,
...parserConfig,
}),
],
invalid: [
test({
code: "import type x from './foo'; import type y from './foo'",
...parserConfig,
errors: [
{
line: 1,
column: 20,
message: "'./foo' imported multiple times.",
},
{
line: 1,
column: 48,
message: "'./foo' imported multiple times.",
},
],
}),
test({
code: "import type x from './foo'; import type x from './foo'",
output: "import type x from './foo'; ",
...parserConfig,
errors: [
{
line: 1,
column: 20,
message: "'./foo' imported multiple times.",
},
{
line: 1,
column: 48,
message: "'./foo' imported multiple times.",
},
],
}),
test({
code: "import type {x} from './foo'; import type {y} from './foo'",
...parserConfig,
output: `import type {x,y} from './foo'; `,
errors: [
{
line: 1,
column: 22,
message: "'./foo' imported multiple times.",
},
{
line: 1,
column: 52,
message: "'./foo' imported multiple times.",
},
],
}),
],
});
declare module 'module3' {
import type { Identifier } from 'module';
}
`,
...parserConfig,
}),
].concat(!tsVersionSatisfies('>= 4.5') || !typescriptEslintParserSatisfies('>= 5.7.0') ? [] : [
// #2470: ignore duplicate if is a typescript inline type import
test({
code: "import { type x } from './foo'; import y from './foo'",
...parserConfig,
}),
test({
code: "import { type x } from './foo'; import { y } from './foo'",
...parserConfig,
}),
test({
code: "import { type x } from './foo'; import type y from 'foo'",
...parserConfig,
}),
]);

const invalid = [
test({
code: "import type x from './foo'; import type y from './foo'",
...parserConfig,
errors: [
{
line: 1,
column: 20,
message: "'./foo' imported multiple times.",
},
{
line: 1,
column: 48,
message: "'./foo' imported multiple times.",
},
],
}),
test({
code: "import type x from './foo'; import type x from './foo'",
output: "import type x from './foo'; ",
...parserConfig,
errors: [
{
line: 1,
column: 20,
message: "'./foo' imported multiple times.",
},
{
line: 1,
column: 48,
message: "'./foo' imported multiple times.",
},
],
}),
test({
code: "import type {x} from './foo'; import type {y} from './foo'",
...parserConfig,
output: `import type {x,y} from './foo'; `,
errors: [
{
line: 1,
column: 22,
message: "'./foo' imported multiple times.",
},
{
line: 1,
column: 52,
message: "'./foo' imported multiple times.",
},
],
}),
].concat(!tsVersionSatisfies('>= 4.5') || !typescriptEslintParserSatisfies('>= 5.7.0') ? [] : [
test({
code: "import {type x} from './foo'; import type {y} from './foo'",
...parserConfig,
options: [{ 'inlineTypeImport': false }],
output: `import {type x,y} from './foo'; `,
errors: [
{
line: 1,
column: 22,
message: "'./foo' imported multiple times.",
},
{
line: 1,
column: 52,
message: "'./foo' imported multiple times.",
},
],
}),
test({
code: "import {type x} from 'foo'; import type {y} from 'foo'",
...parserConfig,
options: [{ 'inlineTypeImport': true }],
output: `import {type x,type y} from 'foo'; `,
errors: [
{
line: 1,
column: 22,
message: "'foo' imported multiple times.",
},
{
line: 1,
column: 50,
message: "'foo' imported multiple times.",
},
],
}),
test({
code: "import {type x} from './foo'; import {type y} from './foo'",
...parserConfig,
output: `import {type x,type y} from './foo'; `,
errors: [
{
line: 1,
column: 22,
message: "'./foo' imported multiple times.",
},
{
line: 1,
column: 52,
message: "'./foo' imported multiple times.",
},
],
}),
test({
code: "import {AValue, type x, BValue} from './foo'; import {type y} from './foo'",
...parserConfig,
output: `import {AValue, type x, BValue,type y} from './foo'; `,
errors: [
{
line: 1,
column: 38,
message: "'./foo' imported multiple times.",
},
{
line: 1,
column: 68,
message: "'./foo' imported multiple times.",
},
],
}),
]);

if (!tsVersionSatisfies('>= 4.5') || !typescriptEslintParserSatisfies('>= 5.7.0')) {
return;
}

ruleTester.run('no-duplicates inline type', rule, {
valid: [
// #2470: ignore duplicate if is a typescript inline type import
test({
code: "import { type x } from './foo'; import y from './foo'",
...parserConfig,
}),
test({
code: "import { type x } from './foo'; import { y } from './foo'",
...parserConfig,
}),
test({
code: "import { type x } from './foo'; import type y from 'foo'",
...parserConfig,
}),
],
invalid: [
test({
code: "import {type x} from './foo'; import type {y} from './foo'",
...parserConfig,
options: [{ 'inlineTypeImport': false }],
output: `import {type x,y} from './foo'; `,
errors: [
{
line: 1,
column: 22,
message: "'./foo' imported multiple times.",
},
{
line: 1,
column: 52,
message: "'./foo' imported multiple times.",
},
],
}),
test({
code: "import {type x} from 'foo'; import type {y} from 'foo'",
...parserConfig,
options: [{ 'inlineTypeImport': true }],
output: `import {type x,type y} from 'foo'; `,
errors: [
{
line: 1,
column: 22,
message: "'foo' imported multiple times.",
},
{
line: 1,
column: 50,
message: "'foo' imported multiple times.",
},
],
}),
test({
code: "import {type x} from './foo'; import {type y} from './foo'",
...parserConfig,
output: `import {type x,type y} from './foo'; `,
errors: [
{
line: 1,
column: 22,
message: "'./foo' imported multiple times.",
},
{
line: 1,
column: 52,
message: "'./foo' imported multiple times.",
},
],
}),
test({
code: "import {AValue, type x, BValue} from './foo'; import {type y} from './foo'",
...parserConfig,
output: `import {AValue, type x, BValue,type y} from './foo'; `,
errors: [
{
line: 1,
column: 38,
message: "'./foo' imported multiple times.",
},
{
line: 1,
column: 68,
message: "'./foo' imported multiple times.",
},
],
}),
],
ruleTester.run('no-duplicates', rule, {
valid,
invalid,
});
});
});

0 comments on commit 855e6e9

Please sign in to comment.