Skip to content

Commit

Permalink
feat(linter/import) change the rule path to index.ts and add snapshot…
Browse files Browse the repository at this point in the history
… in export rule
  • Loading branch information
Dunqing committed Mar 15, 2024
1 parent 9609c34 commit 3d27756
Show file tree
Hide file tree
Showing 2 changed files with 174 additions and 75 deletions.
150 changes: 75 additions & 75 deletions crates/oxc_linter/src/rules/import/export.rs
Expand Up @@ -140,12 +140,12 @@ fn test() {
export * as A from './named-export-collision/a';
export * as B from './named-export-collision/b';
"),
// ("
// export default function foo(param: string): boolean;
// export default function foo(param: string, param1: number): boolean;
// export default function foo(param: string, param1?: number): boolean {
// return param && param1;
// }
("
export default function foo(param: string): boolean;
export default function foo(param: string, param1: number): boolean;
export default function foo(param: string, param1?: number): boolean {
return param && param1;
}
// "),
// Typescript
("
Expand All @@ -156,15 +156,15 @@ fn test() {
export const Foo = 1;
export interface Foo {}
"),
// ("
// export function fff(a: string);
// export function fff(a: number);
// "),
// ("
// export function fff(a: string);
// export function fff(a: number);
// export function fff(a: string|number) {};
// "),
("
export function fff(a: string);
export function fff(a: number);
"),
("
export function fff(a: string);
export function fff(a: number);
export function fff(a: string|number) {};
"),
("
export const Bar = 1;
export namespace Foo {
Expand Down Expand Up @@ -203,19 +203,19 @@ fn test() {
export class Bar {}
}
"),
// ("
// export function Foo();
// export namespace Foo { }
// "),
// ("
// export function Foo(a: string);
// export namespace Foo { }
// "),
// ("
// export function Foo(a: string);
// export function Foo(a: number);
// export namespace Foo { }
// "),
("
export function Foo();
export namespace Foo { }
"),
("
export function Foo(a: string);
export namespace Foo { }
"),
("
export function Foo(a: string);
export function Foo(a: number);
export namespace Foo { }
"),
("
export enum Foo { }
export namespace Foo { }
Expand All @@ -225,24 +225,24 @@ fn test() {
export * as A from './named-export-collision/a';
export * as B from './named-export-collision/b';
"),
// (r#"
// declare module "a" {
// const Foo = 1;
// export {Foo as default};
// }
// declare module "b" {
// const Bar = 2;
// export {Bar as default};
// }
// "#),
// (r#"
// declare module "a" {
// const Foo = 1;
// export {Foo as default};
// }
// const Bar = 2;
// export {Bar as default};
// "#),
(r#"
declare module "a" {
const Foo = 1;
export {Foo as default};
}
declare module "b" {
const Bar = 2;
export {Bar as default};
}
"#),
(r#"
declare module "a" {
const Foo = 1;
export {Foo as default};
}
const Bar = 2;
export {Bar as default};
"#),
];
let fail = vec![
(r#"let foo; export { foo }; export * from "./export-all""#),
Expand All @@ -262,13 +262,13 @@ fn test() {
export const a = 3;
}
"),
("
declare module 'foo' {
const Foo = 1;
export default Foo;
export default Foo;
}
"),
// ("
// declare module 'foo' {
// const Foo = 1;
// export default Foo;
// export default Foo;
// }
// "),
("
export namespace Foo {
export namespace Bar {
Expand Down Expand Up @@ -301,36 +301,36 @@ fn test() {
export class Foo { }
export namespace Foo { }
"),
("
export function Foo();
export class Foo { }
export namespace Foo { }
"),
("
export const Foo = 'bar';
export function Foo();
export namespace Foo { }
"),
// ("
// export function Foo();
// export class Foo { }
// export namespace Foo { }
// "),
// ("
// export const Foo = 'bar';
// export function Foo();
// export namespace Foo { }
// "),
(r#"
declare module "a" {
const Foo = 1;
export {Foo as default};
}
const Bar = 2;
export {Bar as default};
const Baz = 3;
export {Baz as default};
"#),
// ("
// export const Foo = 'bar';
// export namespace Foo { }
// "),
// (r#"
// declare module "a" {
// const Foo = 1;
// export {Foo as default};
// }
// const Bar = 2;
// export {Bar as default};
// const Baz = 3;
// export {Baz as default};
// "#),
];

Tester::new(Export::NAME, pass, fail)
.with_import_plugin(true)
.change_rule_path("index.js")
.test();
.change_rule_path("index.ts")
.test_and_snapshot();
}

{
Expand Down
99 changes: 99 additions & 0 deletions crates/oxc_linter/src/snapshots/export.snap
@@ -0,0 +1,99 @@
---
source: crates/oxc_linter/src/tester.rs
expression: export
---
eslint-plugin-import(export): Multiple exports of name 'foo'.
╭─[index.ts:1:19]
1let foo; export { foo }; export * from "./export-all"
· ───
╰────

eslint-plugin-import(export): Multiple exports of name 'foo'.
╭─[index.ts:1:26]
1let foo; export { foo as "foo" }; export * from "./export-all"
· ─────
╰────

× Identifier `Foo` has already been declared
╭─[index.ts:2:29]
1
2export type Foo = string;
· ─┬─
· ╰── `Foo` has already been declared here
3export type Foo = number;
· ─┬─
· ╰── It can not be redeclared here
4
╰────

× Identifier `a` has already been declared
╭─[index.ts:4:30]
3export namespace Foo {
4export const a = 2;
· ┬
· ╰── `a` has already been declared here
5export const a = 3;
· ┬
· ╰── It can not be redeclared here
6 │ }
╰────

× Identifier `Foo` has already been declared
╭─[index.ts:4:38]
3export namespace Bar {
4export const Foo = 1;
· ─┬─
· ╰── `Foo` has already been declared here
5export const Foo = 2;
· ─┬─
· ╰── It can not be redeclared here
6 │ }
╰────

× Identifier `Bar` has already been declared
╭─[index.ts:8:38]
7export namespace Baz {
8export const Bar = 3;
· ─┬─
· ╰── `Bar` has already been declared here
9export const Bar = 4;
· ─┬─
· ╰── It can not be redeclared here
10 │ }
╰────

× Identifier `Foo` has already been declared
╭─[index.ts:2:30]
1
2export class Foo { }
· ─┬─
· ╰── `Foo` has already been declared here
3export class Foo { }
· ─┬─
· ╰── It can not be redeclared here
4export namespace Foo { }
╰────

× Identifier `Foo` has already been declared
╭─[index.ts:2:29]
1
2export enum Foo { }
· ─┬─
· ╰── `Foo` has already been declared here
3export class Foo { }
· ─┬─
· ╰── It can not be redeclared here
4export namespace Foo { }
╰────

× Identifier `Foo` has already been declared
╭─[index.ts:2:30]
1
2export const Foo = 'bar';
· ─┬─
· ╰── `Foo` has already been declared here
3export class Foo { }
· ─┬─
· ╰── It can not be redeclared here
4export namespace Foo { }
╰────

0 comments on commit 3d27756

Please sign in to comment.