Skip to content

Commit

Permalink
fix: noVar ignores TsGlobalDeclaration (#1669)
Browse files Browse the repository at this point in the history
  • Loading branch information
vasucp1207 authored Jan 26, 2024
1 parent 5d14c94 commit c2dd5f0
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 2 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ Read our [guidelines for writing a good changelog entry](https://github.com/biom

#### Bug fixes

- Fix [#1651](https://github.com/biomejs/biome/issues/1651). [noVar](https://biomejs.dev/linter/rules/no-var/) now ignores TsGlobalDeclaration. Contributed by @vasucp1207

- Fix [#1640](https://github.com/biomejs/biome/issues/1640). [useEnumInitializers](https://biomejs.dev/linter/rules/use-enum-initializers) code action now generates valid code when last member has a comment but no comma. Contributed by @kalleep

- Fix [#1653](https://github.com/biomejs/biome/issues/1653). Handle a shorthand value in `useForOf` to avoid the false-positive case. Contributed by @togami2864
Expand Down
17 changes: 15 additions & 2 deletions crates/biome_js_analyze/src/semantic_analyzers/style/no_var.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ use biome_analyze::{
use biome_console::markup;
use biome_diagnostics::Applicability;
use biome_js_factory::make;
use biome_js_syntax::{AnyJsVariableDeclaration, JsModule, JsScript, JsSyntaxKind};
use biome_js_syntax::{
AnyJsVariableDeclaration, JsModule, JsScript, JsSyntaxKind, TsGlobalDeclaration,
};

use biome_rowan::{AstNode, BatchMutationExt};

Expand Down Expand Up @@ -49,7 +51,18 @@ impl Rule for NoVar {

fn run(ctx: &RuleContext<Self>) -> Self::Signals {
let declaration = ctx.query();
declaration.is_var().then_some(())
if declaration.is_var() {
let ts_global_declaratio = &declaration
.syntax()
.ancestors()
.find_map(TsGlobalDeclaration::cast);

if ts_global_declaratio.is_some() {
return None;
}
return Some(());
}
None
}

fn diagnostic(ctx: &RuleContext<Self>, _state: &Self::State) -> Option<RuleDiagnostic> {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
declare global {
var Txt: CustomWindow['Txt'];
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
source: crates/biome_js_analyze/tests/spec_tests.rs
expression: validTsGlobalDeclaration.ts
---
# Input
```ts
declare global {
var Txt: CustomWindow['Txt'];
}
```


2 changes: 2 additions & 0 deletions website/src/content/docs/internals/changelog.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ Read our [guidelines for writing a good changelog entry](https://github.com/biom

#### Bug fixes

- Fix [#1651](https://github.com/biomejs/biome/issues/1651). [noVar](https://biomejs.dev/linter/rules/no-var/) now ignores TsGlobalDeclaration. Contributed by @vasucp1207

- Fix [#1640](https://github.com/biomejs/biome/issues/1640). [useEnumInitializers](https://biomejs.dev/linter/rules/use-enum-initializers) code action now generates valid code when last member has a comment but no comma. Contributed by @kalleep

- Fix [#1653](https://github.com/biomejs/biome/issues/1653). Handle a shorthand value in `useForOf` to avoid the false-positive case. Contributed by @togami2864
Expand Down

0 comments on commit c2dd5f0

Please sign in to comment.