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(codegen): support embedded kind code blocks #243

Merged
merged 2 commits into from
May 6, 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
49 changes: 40 additions & 9 deletions codegen/src/lintdoc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use biome_css_syntax::CssLanguage;
use biome_diagnostics::termcolor::NoColor;
use biome_diagnostics::{Diagnostic, DiagnosticExt, PrintDiagnostic};
use biome_js_parser::JsParserOptions;
use biome_js_syntax::{JsFileSource, JsLanguage, Language, ModuleKind};
use biome_js_syntax::{EmbeddingKind, JsFileSource, JsLanguage, Language, ModuleKind};
use biome_json_parser::JsonParserOptions;
use biome_json_syntax::JsonLanguage;
use biome_service::settings::WorkspaceSettings;
Expand Down Expand Up @@ -459,15 +459,20 @@ fn parse_documentation(
write!(content, "```")?;
if !meta.is_empty() {
match test.block_type {
BlockType::Js(source_type) => {
match source_type.language() {
Language::JavaScript => write!(content, "js")?,
Language::TypeScript { .. } => write!(content, "ts")?,
}
if source_type.variant().is_jsx() {
write!(content, "x")?;
BlockType::Js(source_type) => match source_type.as_embedding_kind() {
EmbeddingKind::Astro => write!(content, "astro")?,
EmbeddingKind::Svelte => write!(content, "svelte")?,
EmbeddingKind::Vue => write!(content, "vue")?,
_ => {
match source_type.language() {
Language::JavaScript => write!(content, "js")?,
Language::TypeScript { .. } => write!(content, "ts")?,
};
if source_type.variant().is_jsx() {
write!(content, "x")?;
}
}
}
},
BlockType::Json => write!(content, "json")?,
BlockType::Css => write!(content, "css")?,
}
Expand Down Expand Up @@ -687,6 +692,15 @@ impl FromStr for CodeBlockTest {
"tsx" => {
test.block_type = BlockType::Js(JsFileSource::tsx());
}
"svelte" => {
test.block_type = BlockType::Js(JsFileSource::svelte());
}
"astro" => {
test.block_type = BlockType::Js(JsFileSource::astro());
}
"vue" => {
test.block_type = BlockType::Js(JsFileSource::vue());
}

// Other attributes
"expect_diagnostic" => {
Expand Down Expand Up @@ -791,6 +805,23 @@ fn assert_lint(
settings.register_current_project(key);
match test.block_type {
BlockType::Js(source_type) => {
// Temporary support for astro, svelte and vue code blocks
let (code, source_type) = match source_type.as_embedding_kind() {
EmbeddingKind::Astro => (
biome_service::file_handlers::AstroFileHandler::input(code),
JsFileSource::ts(),
),
EmbeddingKind::Svelte => (
biome_service::file_handlers::SvelteFileHandler::input(code),
biome_service::file_handlers::SvelteFileHandler::file_source(code),
),
EmbeddingKind::Vue => (
biome_service::file_handlers::VueFileHandler::input(code),
biome_service::file_handlers::VueFileHandler::file_source(code),
),
_ => (code, source_type),
};

let parse = biome_js_parser::parse(code, source_type, JsParserOptions::default());

if parse.has_errors() {
Expand Down
8 changes: 8 additions & 0 deletions src/content/docs/linter/rules/no-confusing-labels.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ Disallow labeled statements that are not loops.
Labeled statements in JavaScript are used in conjunction with `break` and `continue` to control flow around multiple loops.
Their use for other statements is suspicious and unfamiliar.

The rule ignores reactive Svelte statements in Svelte components.

## Examples

### Invalid
Expand Down Expand Up @@ -110,6 +112,12 @@ outer: while (a) {
}
```

```svelte
<script>
$: { /* reactive block */ }
</script>
```

## Related links

- [Disable a rule](/linter/#disable-a-lint-rule)
Expand Down
8 changes: 8 additions & 0 deletions src/content/docs/linter/rules/no-unused-labels.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ Disallow unused labels.

Labels that are declared and never used are most likely an error due to incomplete refactoring.

The rule ignores reactive Svelte statements in Svelte components.

## Examples

### Invalid
Expand Down Expand Up @@ -64,6 +66,12 @@ function nonNegative(n) {
}
```

```svelte
<script>
$: { /* reactive block */ }
</script>
```

## Related links

- [Disable a rule](/linter/#disable-a-lint-rule)
Expand Down