Skip to content
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
35 changes: 35 additions & 0 deletions .changeset/silly-walls-build.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
---
"@biomejs/biome": patch
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While I think it's fair to release this in a patch release (it's experimental after all), we may want to keep this as a highlight somewhere, so that if we write a blog post for the next minor, this gets some extra attention. IMO this represents a major milestone!

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes that was intention since the very beginning

---

Improved the rules `useConst`, `noUnusedImports`, `useImportTypes` and `noUnusedVariables` inside
Vue, Svelte and Astro files when `experimentalFullSupportEnabled` is set to `true`.

Now variables and components that are imported or defined inside the files won't trigger false positives.

Until now, we suggested disabling these rules with an override. _Now the rules are more stable_; however, you might still experience
a few false positives. Those are probably issues caused by our parser.
Comment thread
ematipico marked this conversation as resolved.

**If you use `experimentalFullSupportEnabled`, you can remove the following override:**

```diff
{
- "overrides": [
- {
- "includes": ["**/*.svelte", "**/*.astro", "**/*.vue"],
- "linter": {
- "rules": {
- "style": {
- "useConst": "off",
- "useImportType": "off"
- },
- "correctness": {
- "noUnusedVariables": "off",
- "noUnusedImports": "off"
- }
- }
- }
- }
- ]
}
```
129 changes: 129 additions & 0 deletions crates/biome_cli/tests/cases/handle_astro_files.rs
Original file line number Diff line number Diff line change
Expand Up @@ -751,3 +751,132 @@ fn does_not_throw_parse_error_for_return_full_support() {
result,
));
}

#[test]
fn embedded_bindings_are_tracked_correctly() {
let fs = MemoryFileSystem::default();
let mut console = BufferConsole::default();

fs.insert(
"biome.json".into(),
r#"{ "html": { "linter": {"enabled": true}, "experimentalFullSupportEnabled": true } }"#
.as_bytes(),
);

let file = Utf8Path::new("file.astro");
fs.insert(
file.into(),
r#"---
import { Component } from "./component.svelte";
let hello = "Hello World";
let array = [];
---

<html>
<span>{hello}</span>
<span>{notDefined}</span>
{ array.map(item => (<span>{item}</span>)) }
<Component />
</html>
"#
.as_bytes(),
);

let (fs, result) = run_cli(
fs,
&mut console,
Args::from(["lint", "--only=noUnusedVariables", file.as_str()].as_slice()),
);

assert!(result.is_ok(), "run_cli returned {result:?}");

assert_cli_snapshot(SnapshotPayload::new(
module_path!(),
"embedded_bindings_are_tracked_correctly",
fs,
console,
result,
));
}

#[test]
fn use_const_not_triggered_in_snippet_sources() {
let fs = MemoryFileSystem::default();
let mut console = BufferConsole::default();

fs.insert(
"biome.json".into(),
r#"{ "html": { "linter": {"enabled": true}, "experimentalFullSupportEnabled": true } }"#
.as_bytes(),
);

let file = Utf8Path::new("file.astro");
fs.insert(
file.into(),
r#"---
let hello = "Hello World";
---

<html>
<span>{hello}</span>
</html>
"#
.as_bytes(),
);

let (fs, result) = run_cli(
fs,
&mut console,
Args::from(["lint", "--only=useConst", file.as_str()].as_slice()),
);

assert!(result.is_ok(), "run_cli returned {result:?}");

assert_cli_snapshot(SnapshotPayload::new(
module_path!(),
"use_const_not_triggered_in_snippet_sources",
fs,
console,
result,
));
}

#[test]
fn no_unused_imports_is_not_triggered_in_snippet_sources() {
let fs = MemoryFileSystem::default();
let mut console = BufferConsole::default();

fs.insert(
"biome.json".into(),
r#"{ "html": { "linter": {"enabled": true}, "experimentalFullSupportEnabled": true } }"#
.as_bytes(),
);

let file = Utf8Path::new("file.astro");
fs.insert(
file.into(),
r#"---
import Component from "./Component.vue"
---

<Component />
"#
.as_bytes(),
);

let (fs, result) = run_cli(
fs,
&mut console,
Args::from(["lint", "--only=noUnusedImports", file.as_str()].as_slice()),
);

assert!(result.is_ok(), "run_cli returned {result:?}");

assert_cli_snapshot(SnapshotPayload::new(
module_path!(),
"no_unused_imports_is_not_triggered_in_snippet_sources",
fs,
console,
result,
));
}
82 changes: 82 additions & 0 deletions crates/biome_cli/tests/cases/handle_svelte_files.rs
Original file line number Diff line number Diff line change
Expand Up @@ -590,3 +590,85 @@ let array = [];
result,
));
}

#[test]
fn use_const_not_triggered_in_snippet_sources() {
let fs = MemoryFileSystem::default();
let mut console = BufferConsole::default();

fs.insert(
"biome.json".into(),
r#"{ "html": { "linter": {"enabled": true}, "experimentalFullSupportEnabled": true } }"#
.as_bytes(),
);

let file = Utf8Path::new("file.svelte");
fs.insert(
file.into(),
r#"<script>
let hello = "Hello World";
</script>

<html>
<span>{hello}</span>
</html>
"#
.as_bytes(),
);

let (fs, result) = run_cli(
fs,
&mut console,
Args::from(["lint", "--only=useConst", file.as_str()].as_slice()),
);

assert!(result.is_ok(), "run_cli returned {result:?}");

assert_cli_snapshot(SnapshotPayload::new(
module_path!(),
"use_const_not_triggered_in_snippet_sources",
fs,
console,
result,
));
}

#[test]
fn no_unused_imports_is_not_triggered_in_snippet_sources() {
let fs = MemoryFileSystem::default();
let mut console = BufferConsole::default();

fs.insert(
"biome.json".into(),
r#"{ "html": { "linter": {"enabled": true}, "experimentalFullSupportEnabled": true } }"#
.as_bytes(),
);

let file = Utf8Path::new("file.svelte");
fs.insert(
file.into(),
r#"<script>
import Component from "./Component.vue"
</script>

<Component />
"#
.as_bytes(),
);

let (fs, result) = run_cli(
fs,
&mut console,
Args::from(["lint", "--only=noUnusedImports", file.as_str()].as_slice()),
);

assert!(result.is_ok(), "run_cli returned {result:?}");

assert_cli_snapshot(SnapshotPayload::new(
module_path!(),
"no_unused_imports_is_not_triggered_in_snippet_sources",
fs,
console,
result,
));
}
135 changes: 135 additions & 0 deletions crates/biome_cli/tests/cases/handle_vue_files.rs
Original file line number Diff line number Diff line change
Expand Up @@ -960,3 +960,138 @@ fn vue_compiler_macros_as_globals() {
result,
));
}

#[test]
fn embedded_bindings_are_tracked_correctly() {
let fs = MemoryFileSystem::default();
let mut console = BufferConsole::default();

fs.insert(
"biome.json".into(),
r#"{ "html": { "linter": {"enabled": true}, "experimentalFullSupportEnabled": true } }"#
.as_bytes(),
);

let file = Utf8Path::new("file.vue");
fs.insert(
file.into(),
r#"<script>
import { Component } from "./component.vue";
let hello = "Hello World";
</script>

<script>
let greeting = "Hello World";
</script>


<template>
<span>{hello}</span>
<span>{notDefined}</span>
<span>{greeting}</span>
<Component />
</template>
"#
.as_bytes(),
);

let (fs, result) = run_cli(
fs,
&mut console,
Args::from(["lint", "--only=noUnusedVariables", file.as_str()].as_slice()),
);

assert!(result.is_ok(), "run_cli returned {result:?}");

assert_cli_snapshot(SnapshotPayload::new(
module_path!(),
"embedded_bindings_are_tracked_correctly",
fs,
console,
result,
));
}

#[test]
fn use_const_not_triggered_in_snippet_sources() {
let fs = MemoryFileSystem::default();
let mut console = BufferConsole::default();

fs.insert(
"biome.json".into(),
r#"{ "html": { "linter": {"enabled": true}, "experimentalFullSupportEnabled": true } }"#
.as_bytes(),
);

let file = Utf8Path::new("file.vue");
fs.insert(
file.into(),
r#"<script>
let hello = "Hello World";
</script>

<template>
<span>{hello}</span>
</template>
"#
.as_bytes(),
);

let (fs, result) = run_cli(
fs,
&mut console,
Args::from(["lint", "--only=useConst", file.as_str()].as_slice()),
);

assert!(result.is_ok(), "run_cli returned {result:?}");

assert_cli_snapshot(SnapshotPayload::new(
module_path!(),
"use_const_not_triggered_in_snippet_sources",
fs,
console,
result,
));
}

#[test]
fn no_unused_imports_is_not_triggered_in_snippet_sources() {
let fs = MemoryFileSystem::default();
let mut console = BufferConsole::default();

fs.insert(
"biome.json".into(),
r#"{ "html": { "linter": {"enabled": true}, "experimentalFullSupportEnabled": true } }"#
.as_bytes(),
);

let file = Utf8Path::new("file.vue");
fs.insert(
file.into(),
r#"<script>
import Component from "./Component.vue"
</script>

<template>
<Component />
</template>
"#
.as_bytes(),
);

let (fs, result) = run_cli(
fs,
&mut console,
Args::from(["lint", "--only=noUnusedImports", file.as_str()].as_slice()),
);

assert!(result.is_ok(), "run_cli returned {result:?}");

assert_cli_snapshot(SnapshotPayload::new(
module_path!(),
"no_unused_imports_is_not_triggered_in_snippet_sources",
fs,
console,
result,
));
}
Loading