Skip to content

Commit

Permalink
fix(lint/noRedeclare): allow overloads
Browse files Browse the repository at this point in the history
  • Loading branch information
Conaclos committed Dec 5, 2023
1 parent f2d0bf8 commit d6aaf79
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 1 deletion.
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,18 @@ Read our [guidelines for writing a good changelog entry](https://github.com/biom
}
```

- Fix [#1061](https://github.com/biomejs/biome/issues/1061). [noRedeclare](https://biomejs.dev/linter/rules/no-redeclare) no longer reports overloads of `export default function`. Contributed by @Conaclos

The following code is no longer reported:

```ts
export default function(a: boolean): boolean;
export default function(a: number): number;
export default function(a: number | boolean): number | boolean {
return a;
}
```

### Parser


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,3 +108,16 @@ export enum Orientation2 {
East = 2,
West = 3,
}

// overloads
function f(a: boolean): boolean;
function f(a: number): number;
function f(a: number | boolean): number | boolean {
return a;
}

export default function(a: boolean): boolean;
export default function(a: number): number;
export default function(a: number | boolean): number | boolean {
return a;
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
---
source: crates/biome_js_analyze/tests/spec_tests.rs
assertion_line: 80
expression: valid-declaration-merging.ts
---
# Input
Expand Down Expand Up @@ -116,6 +115,19 @@ export enum Orientation2 {
West = 3,
}

// overloads
function f(a: boolean): boolean;
function f(a: number): number;
function f(a: number | boolean): number | boolean {
return a;
}

export default function(a: boolean): boolean;
export default function(a: number): number;
export default function(a: number | boolean): number | boolean {
return a;
}

```


5 changes: 5 additions & 0 deletions crates/biome_js_syntax/src/binding_ext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,11 @@ impl AnyJsBindingDeclaration {
AnyJsBindingDeclaration::JsFunctionDeclaration(_)
| AnyJsBindingDeclaration::TsDeclareFunctionDeclaration(_),
) => true,
(
AnyJsBindingDeclaration::TsDeclareFunctionExportDefaultDeclaration(_),
AnyJsBindingDeclaration::JsFunctionExportDefaultDeclaration(_)
| AnyJsBindingDeclaration::TsDeclareFunctionExportDefaultDeclaration(_),
) => true,
(
AnyJsBindingDeclaration::TsEnumDeclaration(_),
AnyJsBindingDeclaration::TsEnumDeclaration(_),
Expand Down
12 changes: 12 additions & 0 deletions website/src/content/docs/internals/changelog.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,18 @@ Read our [guidelines for writing a good changelog entry](https://github.com/biom
}
```

- Fix [#1061](https://github.com/biomejs/biome/issues/1061). [noRedeclare](https://biomejs.dev/linter/rules/no-redeclare) no longer reports overloads of `export default function`. Contributed by @Conaclos

The following code is no longer reported:

```ts
export default function(a: boolean): boolean;
export default function(a: number): number;
export default function(a: number | boolean): number | boolean {
return a;
}
```

### Parser


Expand Down

0 comments on commit d6aaf79

Please sign in to comment.