Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(noEmptyInterface): ignore empty interfaces in ambient modules #3116

Merged
merged 1 commit into from
Jun 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ our [guidelines for writing a good changelog entry](https://github.com/biomejs/b

Contributed by @Conaclos

- [noEmptyInterface](https://biomejs.dev/linter/rules/no-empty-interface/) now ignores empty interfaces in ambient modules ([#3110](https://github.com/biomejs/biome/issues/3110)). Contributed by @Conaclos

### Parser

## 1.8.0 (2024-06-04)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ use biome_js_factory::{
syntax::{AnyTsType, T},
};
use biome_js_syntax::{
AnyJsDeclarationClause, TriviaPieceKind, TsInterfaceDeclaration, TsTypeAliasDeclaration,
AnyJsDeclarationClause, JsSyntaxKind, TriviaPieceKind, TsInterfaceDeclaration,
TsTypeAliasDeclaration,
};
use biome_rowan::{AstNode, AstNodeList, BatchMutationExt, SyntaxResult};

Expand Down Expand Up @@ -38,6 +39,11 @@ declare_rule! {
///
/// // Allow empty interfaces that extend a type.
/// interface B extends A {}
///
/// // Allow empty interfaces in ambient modules
/// declare module "mod" {
/// interface C {}
/// }
/// ```
pub NoEmptyInterface {
version: "1.0.0",
Expand All @@ -58,6 +64,15 @@ impl Rule for NoEmptyInterface {

fn run(ctx: &RuleContext<Self>) -> Self::Signals {
let node = ctx.query();
let is_in_ambient_module = node.syntax().ancestors().skip(1).any(|ancestor| {
matches!(
ancestor.kind(),
JsSyntaxKind::TS_GLOBAL_DECLARATION | JsSyntaxKind::TS_EXTERNAL_MODULE_DECLARATION
)
});
if is_in_ambient_module {
return None;
}
(node.members().is_empty() && node.extends_clause().is_none()).then_some(())
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
declare global {
export interface App extends Services {}
export namespace Ns {
export interface Empty {}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ expression: valid.d.ts
```ts
declare global {
export interface App extends Services {}
export namespace Ns {
export interface Empty {}
}
}

```


Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ interface Baz extends Foo, Bar {}
// See https://github.com/biomejs/biome/issues/959
declare module "external" {
export interface App extends Services {}
export interface Empty {}

global {
export interface App extends Services {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ interface Baz extends Foo, Bar {}
// See https://github.com/biomejs/biome/issues/959
declare module "external" {
export interface App extends Services {}
export interface Empty {}

global {
export interface App extends Services {}
Expand All @@ -37,5 +38,3 @@ namespace Ns {
}

```