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
83 changes: 83 additions & 0 deletions crates/biome_cli/tests/cases/handle_astro_files.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ if (foo) {
const ASTRO_CARRIAGE_RETURN_LINE_FEED_FILE_UNFORMATTED: &str =
"---\r\n const a = \"b\";\r\n---\r\n<div></div>";

const ASTRO_RETURN_IN_TEMPLATE: &str = r#"---
const x = 5;
---
<div>{ return x }</div>"#;

const ASTRO_FILE_CHECK_BEFORE: &str = r#"---
import {a as a} from 'mod';
import { something } from "file.astro";
Expand Down Expand Up @@ -1018,3 +1023,81 @@ let {
result,
));
}

#[test]
fn no_useless_lone_block_statements_is_not_triggered() {
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#"---
{
const x = 1;
}
---

<div>{x}</div>
"#
.as_bytes(),
);

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

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

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

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

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

let astro_file_path = Utf8Path::new("file.astro");
fs.insert(astro_file_path.into(), ASTRO_RETURN_IN_TEMPLATE.as_bytes());

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

// The result should have errors because return is not allowed in template expressions
// We expect the check to fail with errors
assert!(
result.is_err(),
"Expected errors but run_cli returned {result:?}"
);

assert_cli_snapshot(SnapshotPayload::new(
module_path!(),
"return_in_template_expression_should_error",
fs,
console,
result,
));
}
43 changes: 43 additions & 0 deletions crates/biome_cli/tests/cases/handle_svelte_files.rs
Original file line number Diff line number Diff line change
Expand Up @@ -757,3 +757,46 @@ let {
result,
));
}
#[test]
fn no_useless_lone_block_statements_is_not_triggered() {
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#"<CollapsiblePrimitive.Content>
{#snippet child({ props, open })}
{#if open}
<div {...props} transition:slide={{ duration }}>
{@render children?.()}
</div>
{/if}
{/snippet}
</CollapsiblePrimitive.Content>
"#
.as_bytes(),
);

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

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

assert_cli_snapshot(SnapshotPayload::new(
module_path!(),
"no_useless_lone_block_statements_is_not_triggered",
fs,
console,
result,
));
}
48 changes: 48 additions & 0 deletions crates/biome_cli/tests/cases/handle_vue_files.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1026,6 +1026,9 @@ let hello = "Hello World";

<script>
let greeting = "Hello World";
function reasonText() {
return "foo"
}
</script>


Expand All @@ -1034,6 +1037,7 @@ let greeting = "Hello World";
<span>{notDefined}</span>
<span>{greeting}</span>
<Component />
<span class="dc-reason">{{ reasonText() }}</span>
</template>
"#
.as_bytes(),
Expand Down Expand Up @@ -1229,3 +1233,47 @@ let {
result,
));
}

#[test]
fn no_useless_lone_block_statements_is_not_triggered() {
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>
{
const x = 1;
}
</script>

<template>
<div>{{ x }}</div>
</template>
"#
.as_bytes(),
);

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

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

assert_cli_snapshot(SnapshotPayload::new(
module_path!(),
"no_useless_lone_block_statements_is_not_triggered",
fs,
console,
result,
));
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
---
source: crates/biome_cli/tests/snap_test.rs
expression: redactor(content)
---
## `biome.json`

```json
{
"html": {
"linter": { "enabled": true },
"experimentalFullSupportEnabled": true
}
}
```

## `file.astro`

```astro
---
{
const x = 1;
}
---

<div>{x}</div>

```

# Emitted Messages

```block
Checked 1 file in <TIME>. No fixes applied.
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
---
source: crates/biome_cli/tests/snap_test.rs
expression: redactor(content)
---
## `biome.json`

```json
{
"html": {
"linter": { "enabled": true },
"experimentalFullSupportEnabled": true
}
}
```

## `file.astro`

```astro
---
const x = 5;
---
<div>{ return x }</div>
```

# Termination Message

```block
lint ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

× Some errors were emitted while running checks.



```

# Emitted Messages

```block
file.astro:4:8 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

× Expected a valid expression in template syntax

2 │ const x = 5;
3 │ ---
> 4 │ <div>{ return x }</div>
│ ^^^^^^

i Template expressions can only contain JavaScript expressions, not statements like 'let', 'if', or 'function'.


```

```block
Checked 1 file in <TIME>. No fixes applied.
Found 1 error.
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
---
source: crates/biome_cli/tests/snap_test.rs
expression: redactor(content)
---
## `biome.json`

```json
{
"html": {
"linter": { "enabled": true },
"experimentalFullSupportEnabled": true
}
}
```

## `file.svelte`

```svelte
<CollapsiblePrimitive.Content>
{#snippet child({ props, open })}
{#if open}
<div {...props} transition:slide={{ duration }}>
{@render children?.()}
</div>
{/if}
{/snippet}
</CollapsiblePrimitive.Content>

```

# Emitted Messages

```block
Checked 1 file in <TIME>. No fixes applied.
```
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ let hello = "Hello World";

<script>
let greeting = "Hello World";
function reasonText() {
return "foo"
}
</script>


Expand All @@ -31,6 +34,7 @@ let greeting = "Hello World";
<span>{notDefined}</span>
<span>{greeting}</span>
<Component />
<span class="dc-reason">{{ reasonText() }}</span>
</template>

```
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
---
source: crates/biome_cli/tests/snap_test.rs
expression: redactor(content)
---
## `biome.json`

```json
{
"html": {
"linter": { "enabled": true },
"experimentalFullSupportEnabled": true
}
}
```

## `file.vue`

```vue
<script>
{
const x = 1;
}
</script>

<template>
<div>{{ x }}</div>
</template>

```

# Emitted Messages

```block
Checked 1 file in <TIME>. No fixes applied.
```
Original file line number Diff line number Diff line change
Expand Up @@ -281,8 +281,9 @@ pub fn kind_by_name(node_name: &str) -> Option<JsSyntaxKind> {
.iter()
.next(),
"JsExportNamedSpecifier" => lang::JsExportNamedSpecifier::KIND_SET.iter().next(),
"JsExpressionSnipped" => lang::JsExpressionSnipped::KIND_SET.iter().next(),
"JsExpressionSnippet" => lang::JsExpressionSnippet::KIND_SET.iter().next(),
"JsExpressionStatement" => lang::JsExpressionStatement::KIND_SET.iter().next(),
"JsExpressionTemplateRoot" => lang::JsExpressionTemplateRoot::KIND_SET.iter().next(),
"JsExtendsClause" => lang::JsExtendsClause::KIND_SET.iter().next(),
"JsFinallyClause" => lang::JsFinallyClause::KIND_SET.iter().next(),
"JsForInStatement" => lang::JsForInStatement::KIND_SET.iter().next(),
Expand Down
Loading