diff --git a/CHANGELOG.md b/CHANGELOG.md index 0b2afd95e6ec..a4a109c44299 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,14 @@ our [guidelines for writing a good changelog entry](https://github.com/biomejs/b ### CLI +#### Bug fixes + +- The [stdin-file-path](https://biomejs.dev/guides/integrate-in-editor/#use-stdin) option now works correctly for Astro/Svelte/Vue files ([#2686](https://github.com/biomejs/biome/pull/2686)) + + Fix [#2225](https://github.com/biomejs/biome/issues/2225) where lint output become empty for Vue files. + + Contributed by @tasshi-me + ### Configuration ### Editors @@ -216,7 +224,7 @@ our [guidelines for writing a good changelog entry](https://github.com/biomejs/b Contributed by @Conaclos - [noMisplacedAssertion](https://biomejs.dev/linter/rules/no-misplaced-assertion/) now allow these matchers - + - `expect.any()` - `expect.anything()` - `expect.closeTo` diff --git a/crates/biome_cli/src/execute/std_in.rs b/crates/biome_cli/src/execute/std_in.rs index 1bed1ebaab27..bdbe938e15f5 100644 --- a/crates/biome_cli/src/execute/std_in.rs +++ b/crates/biome_cli/src/execute/std_in.rs @@ -7,6 +7,7 @@ use biome_console::{markup, ConsoleExt}; use biome_diagnostics::Diagnostic; use biome_diagnostics::PrintDiagnostic; use biome_fs::BiomePath; +use biome_service::file_handlers::{AstroFileHandler, SvelteFileHandler, VueFileHandler}; use biome_service::workspace::{ ChangeFileParams, DropPatternParams, FeaturesBuilder, FixFileParams, FormatFileParams, OpenFileParams, OrganizeImportsParams, PullDiagnosticsParams, RuleCategories, @@ -51,16 +52,25 @@ pub(crate) fn run<'a>( content: content.into(), document_file_source: None, })?; - let printed = workspace.format_file(FormatFileParams { path: biome_path })?; + let printed = workspace.format_file(FormatFileParams { + path: biome_path.clone(), + })?; + let code = printed.into_code(); + let output = match biome_path.extension_as_str() { + "astro" => AstroFileHandler::output(content, code.as_str()), + "vue" => VueFileHandler::output(content, code.as_str()), + "svelte" => SvelteFileHandler::output(content, code.as_str()), + _ => code, + }; console.append(markup! { - {printed.as_code()} + {output} }); } else { console.append(markup! { {content} }); - console.error(markup!{ + console.error(markup! { "The content was not formatted because the formatter is currently disabled." }) } @@ -105,14 +115,21 @@ pub(crate) fn run<'a>( path: biome_path.clone(), should_format: mode.is_check() && file_features.supports_format(), })?; - if fix_file_result.code != new_content { + let code = fix_file_result.code; + let output = match biome_path.extension_as_str() { + "astro" => AstroFileHandler::output(&new_content, code.as_str()), + "vue" => VueFileHandler::output(&new_content, code.as_str()), + "svelte" => SvelteFileHandler::output(&new_content, code.as_str()), + _ => code, + }; + if output != new_content { version += 1; workspace.change_file(ChangeFileParams { - content: fix_file_result.code.clone(), + content: output.clone(), path: biome_path.clone(), version, })?; - new_content = Cow::Owned(fix_file_result.code); + new_content = Cow::Owned(output); } } @@ -120,14 +137,21 @@ pub(crate) fn run<'a>( let result = workspace.organize_imports(OrganizeImportsParams { path: biome_path.clone(), })?; - if result.code != new_content { + let code = result.code; + let output = match biome_path.extension_as_str() { + "astro" => AstroFileHandler::output(&new_content, code.as_str()), + "vue" => VueFileHandler::output(&new_content, code.as_str()), + "svelte" => SvelteFileHandler::output(&new_content, code.as_str()), + _ => code, + }; + if output != new_content { version += 1; workspace.change_file(ChangeFileParams { - content: result.code.clone(), + content: output.clone(), path: biome_path.clone(), version, })?; - new_content = Cow::Owned(result.code); + new_content = Cow::Owned(output); } } } @@ -145,15 +169,22 @@ pub(crate) fn run<'a>( let printed = workspace.format_file(FormatFileParams { path: biome_path.clone(), })?; + let code = printed.into_code(); + let output = match biome_path.extension_as_str() { + "astro" => AstroFileHandler::output(&new_content, code.as_str()), + "vue" => VueFileHandler::output(&new_content, code.as_str()), + "svelte" => SvelteFileHandler::output(&new_content, code.as_str()), + _ => code, + }; if mode.is_check_apply() || mode.is_check_apply_unsafe() { - if printed.as_code() != new_content { - new_content = Cow::Owned(printed.into_code()); + if output != new_content { + new_content = Cow::Owned(output); } } else { let diagnostic = FormatDiffDiagnostic { file_name: biome_path.display().to_string(), diff: ContentDiffAdvice { - new: printed.as_code().to_string(), + new: output, old: content.to_string(), }, }; diff --git a/crates/biome_cli/tests/cases/handle_astro_files.rs b/crates/biome_cli/tests/cases/handle_astro_files.rs index a3bf8c4abcc3..b623030fd1b9 100644 --- a/crates/biome_cli/tests/cases/handle_astro_files.rs +++ b/crates/biome_cli/tests/cases/handle_astro_files.rs @@ -1,6 +1,8 @@ use crate::run_cli; -use crate::snap_test::{assert_cli_snapshot, assert_file_contents, SnapshotPayload}; -use biome_console::BufferConsole; +use crate::snap_test::{ + assert_cli_snapshot, assert_file_contents, markup_to_string, SnapshotPayload, +}; +use biome_console::{markup, BufferConsole}; use biome_fs::MemoryFileSystem; use biome_service::DynRef; use bpaf::Args; @@ -30,6 +32,16 @@ const ASTRO_FILE_DEBUGGER_AFTER: &str = r#"--- ---
"#; +const ASTRO_FILE_USELESS_RENAME_BEFORE: &str = r#"--- +import {a as a} from 'mod'; +--- +
"#; + +const ASTRO_FILE_USELESS_RENAME_AFTER: &str = r#"--- +import {a} from 'mod'; +--- +
"#; + const ASTRO_FILE_IMPORTS_BEFORE: &str = r#"--- import { getLocale } from "astro:i18n"; import { Code } from "astro:components"; @@ -54,6 +66,32 @@ import { getLocale } from "astro:i18n"; const ASTRO_CARRIAGE_RETURN_LINE_FEED_FILE_UNFORMATTED: &str = "---\r\n const a = \"b\";\r\n---\r\n
"; +const ASTRO_FILE_CHECK_BEFORE: &str = r#"--- +import {a as a} from 'mod'; +import { something } from "file.astro"; +debugger; +statement ( ) ; +var foo: string = ""; +--- +
"#; + +const ASTRO_FILE_CHECK_APPLY_AFTER: &str = r#"--- +import { something } from "file.astro"; +import { a } from "mod"; +debugger; +statement(); +var foo = ""; +--- +
"#; + +const ASTRO_FILE_CHECK_APPLY_UNSAFE_AFTER: &str = r#"--- +import { something } from "file.astro"; +import { a } from "mod"; +statement(); +const foo = ""; +--- +
"#; + #[test] fn format_astro_files() { let mut fs = MemoryFileSystem::default(); @@ -343,3 +381,289 @@ fn does_not_throw_parse_error_for_return() { result, )); } + +#[test] +fn format_stdin_successfully() { + let mut fs = MemoryFileSystem::default(); + let mut console = BufferConsole::default(); + + console.in_buffer.push(ASTRO_FILE_UNFORMATTED.to_string()); + + let result = run_cli( + DynRef::Borrowed(&mut fs), + &mut console, + Args::from(["format", "--stdin-file-path", "file.astro"].as_slice()), + ); + + assert!(result.is_ok(), "run_cli returned {result:?}"); + + let message = console + .out_buffer + .first() + .expect("Console should have written a message"); + + let content = markup_to_string(markup! { + {message.content} + }); + + assert_eq!(content, ASTRO_FILE_FORMATTED); + + assert_cli_snapshot(SnapshotPayload::new( + module_path!(), + "format_stdin_successfully", + fs, + console, + result, + )); +} + +#[test] +fn format_stdin_write_successfully() { + let mut fs = MemoryFileSystem::default(); + let mut console = BufferConsole::default(); + + console.in_buffer.push(ASTRO_FILE_UNFORMATTED.to_string()); + + let result = run_cli( + DynRef::Borrowed(&mut fs), + &mut console, + Args::from(["format", "--write", "--stdin-file-path", "file.astro"].as_slice()), + ); + + assert!(result.is_ok(), "run_cli returned {result:?}"); + + let message = console + .out_buffer + .first() + .expect("Console should have written a message"); + + let content = markup_to_string(markup! { + {message.content} + }); + + assert_eq!(content, ASTRO_FILE_FORMATTED); + + assert_cli_snapshot(SnapshotPayload::new( + module_path!(), + "format_stdin_write_successfully", + fs, + console, + result, + )); +} + +#[test] +fn lint_stdin_successfully() { + let mut fs = MemoryFileSystem::default(); + let mut console = BufferConsole::default(); + + console + .in_buffer + .push(ASTRO_FILE_USELESS_RENAME_BEFORE.to_string()); + + let result = run_cli( + DynRef::Borrowed(&mut fs), + &mut console, + Args::from(["lint", "--stdin-file-path", "file.astro"].as_slice()), + ); + + assert!(result.is_ok(), "run_cli returned {result:?}"); + + let message = console + .out_buffer + .first() + .expect("Console should have written a message"); + + let content = markup_to_string(markup! { + {message.content} + }); + + assert_eq!(content, ASTRO_FILE_USELESS_RENAME_BEFORE); + + assert_cli_snapshot(SnapshotPayload::new( + module_path!(), + "lint_stdin_successfully", + fs, + console, + result, + )); +} + +#[test] +fn lint_stdin_apply_successfully() { + let mut fs = MemoryFileSystem::default(); + let mut console = BufferConsole::default(); + + console + .in_buffer + .push(ASTRO_FILE_USELESS_RENAME_BEFORE.to_string()); + + let result = run_cli( + DynRef::Borrowed(&mut fs), + &mut console, + Args::from(["lint", "--apply", "--stdin-file-path", "file.astro"].as_slice()), + ); + + assert!(result.is_ok(), "run_cli returned {result:?}"); + + let message = console + .out_buffer + .first() + .expect("Console should have written a message"); + + let content = markup_to_string(markup! { + {message.content} + }); + + assert_eq!(content, ASTRO_FILE_USELESS_RENAME_AFTER); + + assert_cli_snapshot(SnapshotPayload::new( + module_path!(), + "lint_stdin_apply_successfully", + fs, + console, + result, + )); +} + +#[test] +fn lint_stdin_apply_unsafe_successfully() { + let mut fs = MemoryFileSystem::default(); + let mut console = BufferConsole::default(); + + console + .in_buffer + .push(ASTRO_FILE_DEBUGGER_BEFORE.to_string()); + + let result = run_cli( + DynRef::Borrowed(&mut fs), + &mut console, + Args::from(["lint", "--apply-unsafe", "--stdin-file-path", "file.astro"].as_slice()), + ); + + assert!(result.is_ok(), "run_cli returned {result:?}"); + + let message = console + .out_buffer + .first() + .expect("Console should have written a message"); + + let content = markup_to_string(markup! { + {message.content} + }); + + assert_eq!(content, ASTRO_FILE_DEBUGGER_AFTER); + + assert_cli_snapshot(SnapshotPayload::new( + module_path!(), + "lint_stdin_apply_unsafe_successfully", + fs, + console, + result, + )); +} + +#[test] +fn check_stdin_successfully() { + let mut fs = MemoryFileSystem::default(); + let mut console = BufferConsole::default(); + + console.in_buffer.push(ASTRO_FILE_CHECK_BEFORE.to_string()); + + let result = run_cli( + DynRef::Borrowed(&mut fs), + &mut console, + Args::from(["check", "--stdin-file-path", "file.astro"].as_slice()), + ); + + assert!(result.is_ok(), "run_cli returned {result:?}"); + + let message = console + .out_buffer + .first() + .expect("Console should have written a message"); + + let content = markup_to_string(markup! { + {message.content} + }); + + assert_eq!(content, ASTRO_FILE_CHECK_BEFORE); + + assert_cli_snapshot(SnapshotPayload::new( + module_path!(), + "check_stdin_successfully", + fs, + console, + result, + )); +} + +#[test] +fn check_stdin_apply_successfully() { + let mut fs = MemoryFileSystem::default(); + let mut console = BufferConsole::default(); + + console.in_buffer.push(ASTRO_FILE_CHECK_BEFORE.to_string()); + + let result = run_cli( + DynRef::Borrowed(&mut fs), + &mut console, + Args::from(["check", "--apply", "--stdin-file-path", "file.astro"].as_slice()), + ); + + assert!(result.is_ok(), "run_cli returned {result:?}"); + + let message = console + .out_buffer + .first() + .expect("Console should have written a message"); + + let content = markup_to_string(markup! { + {message.content} + }); + + assert_eq!(content, ASTRO_FILE_CHECK_APPLY_AFTER); + + assert_cli_snapshot(SnapshotPayload::new( + module_path!(), + "check_stdin_apply_successfully", + fs, + console, + result, + )); +} + +#[test] +fn check_stdin_apply_unsafe_successfully() { + let mut fs = MemoryFileSystem::default(); + let mut console = BufferConsole::default(); + + console.in_buffer.push(ASTRO_FILE_CHECK_BEFORE.to_string()); + + let result = run_cli( + DynRef::Borrowed(&mut fs), + &mut console, + Args::from(["check", "--apply-unsafe", "--stdin-file-path", "file.astro"].as_slice()), + ); + + assert!(result.is_ok(), "run_cli returned {result:?}"); + + let message = console + .out_buffer + .first() + .expect("Console should have written a message"); + + let content = markup_to_string(markup! { + {message.content} + }); + + assert_eq!(content, ASTRO_FILE_CHECK_APPLY_UNSAFE_AFTER); + + assert_cli_snapshot(SnapshotPayload::new( + module_path!(), + "check_stdin_apply_unsafe_successfully", + fs, + console, + result, + )); +} diff --git a/crates/biome_cli/tests/cases/handle_svelte_files.rs b/crates/biome_cli/tests/cases/handle_svelte_files.rs index 3989de764fba..4e6d6e196edf 100644 --- a/crates/biome_cli/tests/cases/handle_svelte_files.rs +++ b/crates/biome_cli/tests/cases/handle_svelte_files.rs @@ -1,6 +1,8 @@ use crate::run_cli; -use crate::snap_test::{assert_cli_snapshot, assert_file_contents, SnapshotPayload}; -use biome_console::BufferConsole; +use crate::snap_test::{ + assert_cli_snapshot, assert_file_contents, markup_to_string, SnapshotPayload, +}; +use biome_console::{markup, BufferConsole}; use biome_fs::MemoryFileSystem; use biome_service::DynRef; use bpaf::Args; @@ -33,6 +35,47 @@ const hello: string = "world"; const SVELTE_CARRIAGE_RETURN_LINE_FEED_FILE_UNFORMATTED: &str = "\r\n
"; +const SVELTE_TS_FILE_LINT_BEFORE: &str = r#" +
"#; + +const SVELTE_TS_FILE_LINT_APPLY_AFTER: &str = r#" +
"#; + +const SVELTE_TS_FILE_LINT_APPLY_UNSAFE_AFTER: &str = r#" +
"#; + +const SVELTE_TS_FILE_CHECK_BEFORE: &str = r#" +
"#; + +const SVELTE_TS_FILE_CHECK_APPLY_AFTER: &str = r#" +
"#; + +const SVELTE_TS_FILE_CHECK_APPLY_UNSAFE_AFTER: &str = r#" +
"#; + #[test] fn sorts_imports_check() { let mut fs = MemoryFileSystem::default(); @@ -218,3 +261,307 @@ fn format_svelte_carriage_return_line_feed_files() { result, )); } + +#[test] +fn format_stdin_successfully() { + let mut fs = MemoryFileSystem::default(); + let mut console = BufferConsole::default(); + + console + .in_buffer + .push(SVELTE_TS_CONTEXT_MODULE_FILE_UNFORMATTED.to_string()); + + let result = run_cli( + DynRef::Borrowed(&mut fs), + &mut console, + Args::from(["format", "--stdin-file-path", "file.svelte"].as_slice()), + ); + + assert!(result.is_ok(), "run_cli returned {result:?}"); + + let message = console + .out_buffer + .first() + .expect("Console should have written a message"); + + let content = markup_to_string(markup! { + {message.content} + }); + + assert_eq!(content, SVELTE_TS_CONTEXT_MODULE_FILE_FORMATTED); + + assert_cli_snapshot(SnapshotPayload::new( + module_path!(), + "format_stdin_successfully", + fs, + console, + result, + )); +} + +#[test] +fn format_stdin_write_successfully() { + let mut fs = MemoryFileSystem::default(); + let mut console = BufferConsole::default(); + + console + .in_buffer + .push(SVELTE_TS_CONTEXT_MODULE_FILE_UNFORMATTED.to_string()); + + let result = run_cli( + DynRef::Borrowed(&mut fs), + &mut console, + Args::from(["format", "--write", "--stdin-file-path", "file.svelte"].as_slice()), + ); + + assert!(result.is_ok(), "run_cli returned {result:?}"); + + let message = console + .out_buffer + .first() + .expect("Console should have written a message"); + + let content = markup_to_string(markup! { + {message.content} + }); + + assert_eq!(content, SVELTE_TS_CONTEXT_MODULE_FILE_FORMATTED); + + assert_cli_snapshot(SnapshotPayload::new( + module_path!(), + "format_stdin_write_successfully", + fs, + console, + result, + )); +} + +#[test] +fn lint_stdin_successfully() { + let mut fs = MemoryFileSystem::default(); + let mut console = BufferConsole::default(); + + console + .in_buffer + .push(SVELTE_TS_FILE_LINT_BEFORE.to_string()); + + let result = run_cli( + DynRef::Borrowed(&mut fs), + &mut console, + Args::from(["lint", "--stdin-file-path", "file.svelte"].as_slice()), + ); + + assert!(result.is_ok(), "run_cli returned {result:?}"); + + let message = console + .out_buffer + .first() + .expect("Console should have written a message"); + + let content = markup_to_string(markup! { + {message.content} + }); + + assert_eq!(content, SVELTE_TS_FILE_LINT_BEFORE); + + assert_cli_snapshot(SnapshotPayload::new( + module_path!(), + "lint_stdin_successfully", + fs, + console, + result, + )); +} + +#[test] +fn lint_stdin_apply_successfully() { + let mut fs = MemoryFileSystem::default(); + let mut console = BufferConsole::default(); + + console + .in_buffer + .push(SVELTE_TS_FILE_LINT_BEFORE.to_string()); + + let result = run_cli( + DynRef::Borrowed(&mut fs), + &mut console, + Args::from(["lint", "--apply", "--stdin-file-path", "file.svelte"].as_slice()), + ); + + assert!(result.is_ok(), "run_cli returned {result:?}"); + + let message = console + .out_buffer + .first() + .expect("Console should have written a message"); + + let content = markup_to_string(markup! { + {message.content} + }); + + assert_eq!(content, SVELTE_TS_FILE_LINT_APPLY_AFTER); + + assert_cli_snapshot(SnapshotPayload::new( + module_path!(), + "lint_stdin_apply_successfully", + fs, + console, + result, + )); +} + +#[test] +fn lint_stdin_apply_unsafe_successfully() { + let mut fs = MemoryFileSystem::default(); + let mut console = BufferConsole::default(); + + console + .in_buffer + .push(SVELTE_TS_FILE_LINT_BEFORE.to_string()); + + let result = run_cli( + DynRef::Borrowed(&mut fs), + &mut console, + Args::from(["lint", "--apply-unsafe", "--stdin-file-path", "file.svelte"].as_slice()), + ); + + assert!(result.is_ok(), "run_cli returned {result:?}"); + + let message = console + .out_buffer + .first() + .expect("Console should have written a message"); + + let content = markup_to_string(markup! { + {message.content} + }); + + assert_eq!(content, SVELTE_TS_FILE_LINT_APPLY_UNSAFE_AFTER); + + assert_cli_snapshot(SnapshotPayload::new( + module_path!(), + "lint_stdin_apply_unsafe_successfully", + fs, + console, + result, + )); +} + +#[test] +fn check_stdin_successfully() { + let mut fs = MemoryFileSystem::default(); + let mut console = BufferConsole::default(); + + console + .in_buffer + .push(SVELTE_TS_FILE_CHECK_BEFORE.to_string()); + + let result = run_cli( + DynRef::Borrowed(&mut fs), + &mut console, + Args::from(["check", "--stdin-file-path", "file.svelte"].as_slice()), + ); + + assert!(result.is_ok(), "run_cli returned {result:?}"); + + let message = console + .out_buffer + .first() + .expect("Console should have written a message"); + + let content = markup_to_string(markup! { + {message.content} + }); + + assert_eq!(content, SVELTE_TS_FILE_CHECK_BEFORE); + + assert_cli_snapshot(SnapshotPayload::new( + module_path!(), + "check_stdin_successfully", + fs, + console, + result, + )); +} + +#[test] +fn check_stdin_apply_successfully() { + let mut fs = MemoryFileSystem::default(); + let mut console = BufferConsole::default(); + + console + .in_buffer + .push(SVELTE_TS_FILE_CHECK_BEFORE.to_string()); + + let result = run_cli( + DynRef::Borrowed(&mut fs), + &mut console, + Args::from(["check", "--apply", "--stdin-file-path", "file.svelte"].as_slice()), + ); + + assert!(result.is_ok(), "run_cli returned {result:?}"); + + let message = console + .out_buffer + .first() + .expect("Console should have written a message"); + + let content = markup_to_string(markup! { + {message.content} + }); + + assert_eq!(content, SVELTE_TS_FILE_CHECK_APPLY_AFTER); + + assert_cli_snapshot(SnapshotPayload::new( + module_path!(), + "check_stdin_apply_successfully", + fs, + console, + result, + )); +} + +#[test] +fn check_stdin_apply_unsafe_successfully() { + let mut fs = MemoryFileSystem::default(); + let mut console = BufferConsole::default(); + + console + .in_buffer + .push(SVELTE_TS_FILE_CHECK_BEFORE.to_string()); + + let result = run_cli( + DynRef::Borrowed(&mut fs), + &mut console, + Args::from( + [ + "check", + "--apply-unsafe", + "--stdin-file-path", + "file.svelte", + ] + .as_slice(), + ), + ); + + assert!(result.is_ok(), "run_cli returned {result:?}"); + + let message = console + .out_buffer + .first() + .expect("Console should have written a message"); + + let content = markup_to_string(markup! { + {message.content} + }); + + assert_eq!(content, SVELTE_TS_FILE_CHECK_APPLY_UNSAFE_AFTER); + + assert_cli_snapshot(SnapshotPayload::new( + module_path!(), + "check_stdin_apply_unsafe_successfully", + fs, + console, + result, + )); +} diff --git a/crates/biome_cli/tests/cases/handle_vue_files.rs b/crates/biome_cli/tests/cases/handle_vue_files.rs index 3586375820d5..96d5cd90f342 100644 --- a/crates/biome_cli/tests/cases/handle_vue_files.rs +++ b/crates/biome_cli/tests/cases/handle_vue_files.rs @@ -1,6 +1,8 @@ use crate::run_cli; -use crate::snap_test::{assert_cli_snapshot, assert_file_contents, SnapshotPayload}; -use biome_console::BufferConsole; +use crate::snap_test::{ + assert_cli_snapshot, assert_file_contents, markup_to_string, SnapshotPayload, +}; +use biome_console::{markup, BufferConsole}; use biome_fs::MemoryFileSystem; use biome_service::DynRef; use bpaf::Args; @@ -58,6 +60,22 @@ var foo: string = ""; "#; +const VUE_TS_FILE_SAFE_LINTED: &str = r#" +"#; + +const VUE_TS_FILE_UNSAFE_LINTED: &str = r#" +"#; + const VUE_FILE_IMPORTS_BEFORE: &str = r#""#; +const VUE_TS_FILE_CHECK_BEFORE: &str = r#" +"#; + +const VUE_TS_FILE_CHECK_APPLY_AFTER: &str = r#" +"#; + +const VUE_TS_FILE_CHECK_APPLY_UNSAFE_AFTER: &str = r#" +"#; + #[test] fn format_vue_implicit_js_files() { let mut fs = MemoryFileSystem::default(); @@ -524,3 +566,283 @@ fn sorts_imports_write() { result, )); } + +#[test] +fn format_stdin_successfully() { + let mut fs = MemoryFileSystem::default(); + let mut console = BufferConsole::default(); + + console.in_buffer.push(VUE_TS_FILE_UNFORMATTED.to_string()); + + let result = run_cli( + DynRef::Borrowed(&mut fs), + &mut console, + Args::from(["format", "--stdin-file-path", "file.vue"].as_slice()), + ); + + assert!(result.is_ok(), "run_cli returned {result:?}"); + + let message = console + .out_buffer + .first() + .expect("Console should have written a message"); + + let content = markup_to_string(markup! { + {message.content} + }); + + assert_eq!(content, VUE_TS_FILE_FORMATTED); + + assert_cli_snapshot(SnapshotPayload::new( + module_path!(), + "format_stdin_successfully", + fs, + console, + result, + )); +} + +#[test] +fn format_stdin_write_successfully() { + let mut fs = MemoryFileSystem::default(); + let mut console = BufferConsole::default(); + + console.in_buffer.push(VUE_TS_FILE_UNFORMATTED.to_string()); + + let result = run_cli( + DynRef::Borrowed(&mut fs), + &mut console, + Args::from(["format", "--write", "--stdin-file-path", "file.vue"].as_slice()), + ); + + assert!(result.is_ok(), "run_cli returned {result:?}"); + + let message = console + .out_buffer + .first() + .expect("Console should have written a message"); + + let content = markup_to_string(markup! { + {message.content} + }); + + assert_eq!(content, VUE_TS_FILE_FORMATTED); + + assert_cli_snapshot(SnapshotPayload::new( + module_path!(), + "format_stdin_write_successfully", + fs, + console, + result, + )); +} + +#[test] +fn lint_stdin_successfully() { + let mut fs = MemoryFileSystem::default(); + let mut console = BufferConsole::default(); + + console.in_buffer.push(VUE_TS_FILE_NOT_LINTED.to_string()); + + let result = run_cli( + DynRef::Borrowed(&mut fs), + &mut console, + Args::from(["lint", "--stdin-file-path", "file.svelte"].as_slice()), + ); + + assert!(result.is_ok(), "run_cli returned {result:?}"); + + let message = console + .out_buffer + .first() + .expect("Console should have written a message"); + + let content = markup_to_string(markup! { + {message.content} + }); + + assert_eq!(content, VUE_TS_FILE_NOT_LINTED); + + assert_cli_snapshot(SnapshotPayload::new( + module_path!(), + "lint_stdin_successfully", + fs, + console, + result, + )); +} + +#[test] +fn lint_stdin_apply_successfully() { + let mut fs = MemoryFileSystem::default(); + let mut console = BufferConsole::default(); + + console.in_buffer.push(VUE_TS_FILE_NOT_LINTED.to_string()); + + let result = run_cli( + DynRef::Borrowed(&mut fs), + &mut console, + Args::from(["lint", "--apply", "--stdin-file-path", "file.svelte"].as_slice()), + ); + + assert!(result.is_ok(), "run_cli returned {result:?}"); + + let message = console + .out_buffer + .first() + .expect("Console should have written a message"); + + let content = markup_to_string(markup! { + {message.content} + }); + + assert_eq!(content, VUE_TS_FILE_SAFE_LINTED); + + assert_cli_snapshot(SnapshotPayload::new( + module_path!(), + "lint_stdin_apply_successfully", + fs, + console, + result, + )); +} + +#[test] +fn lint_stdin_apply_unsafe_successfully() { + let mut fs = MemoryFileSystem::default(); + let mut console = BufferConsole::default(); + + console.in_buffer.push(VUE_TS_FILE_NOT_LINTED.to_string()); + + let result = run_cli( + DynRef::Borrowed(&mut fs), + &mut console, + Args::from(["lint", "--apply-unsafe", "--stdin-file-path", "file.svelte"].as_slice()), + ); + + assert!(result.is_ok(), "run_cli returned {result:?}"); + + let message = console + .out_buffer + .first() + .expect("Console should have written a message"); + + let content = markup_to_string(markup! { + {message.content} + }); + + assert_eq!(content, VUE_TS_FILE_UNSAFE_LINTED); + + assert_cli_snapshot(SnapshotPayload::new( + module_path!(), + "lint_stdin_apply_unsafe_successfully", + fs, + console, + result, + )); +} + +#[test] +fn check_stdin_successfully() { + let mut fs = MemoryFileSystem::default(); + let mut console = BufferConsole::default(); + + console.in_buffer.push(VUE_TS_FILE_CHECK_BEFORE.to_string()); + + let result = run_cli( + DynRef::Borrowed(&mut fs), + &mut console, + Args::from(["check", "--stdin-file-path", "file.vue"].as_slice()), + ); + + assert!(result.is_ok(), "run_cli returned {result:?}"); + + let message = console + .out_buffer + .first() + .expect("Console should have written a message"); + + let content = markup_to_string(markup! { + {message.content} + }); + + assert_eq!(content, VUE_TS_FILE_CHECK_BEFORE); + + assert_cli_snapshot(SnapshotPayload::new( + module_path!(), + "check_stdin_successfully", + fs, + console, + result, + )); +} + +#[test] +fn check_stdin_apply_successfully() { + let mut fs = MemoryFileSystem::default(); + let mut console = BufferConsole::default(); + + console.in_buffer.push(VUE_TS_FILE_CHECK_BEFORE.to_string()); + + let result = run_cli( + DynRef::Borrowed(&mut fs), + &mut console, + Args::from(["check", "--apply", "--stdin-file-path", "file.vue"].as_slice()), + ); + + assert!(result.is_ok(), "run_cli returned {result:?}"); + + let message = console + .out_buffer + .first() + .expect("Console should have written a message"); + + let content = markup_to_string(markup! { + {message.content} + }); + + assert_eq!(content, VUE_TS_FILE_CHECK_APPLY_AFTER); + + assert_cli_snapshot(SnapshotPayload::new( + module_path!(), + "check_stdin_apply_successfully", + fs, + console, + result, + )); +} + +#[test] +fn check_stdin_apply_unsafe_successfully() { + let mut fs = MemoryFileSystem::default(); + let mut console = BufferConsole::default(); + + console.in_buffer.push(VUE_TS_FILE_CHECK_BEFORE.to_string()); + + let result = run_cli( + DynRef::Borrowed(&mut fs), + &mut console, + Args::from(["check", "--apply-unsafe", "--stdin-file-path", "file.vue"].as_slice()), + ); + + assert!(result.is_ok(), "run_cli returned {result:?}"); + + let message = console + .out_buffer + .first() + .expect("Console should have written a message"); + + let content = markup_to_string(markup! { + {message.content} + }); + + assert_eq!(content, VUE_TS_FILE_CHECK_APPLY_UNSAFE_AFTER); + + assert_cli_snapshot(SnapshotPayload::new( + module_path!(), + "check_stdin_apply_unsafe_successfully", + fs, + console, + result, + )); +} diff --git a/crates/biome_cli/tests/snapshots/main_cases_handle_astro_files/check_stdin_apply_successfully.snap b/crates/biome_cli/tests/snapshots/main_cases_handle_astro_files/check_stdin_apply_successfully.snap new file mode 100644 index 000000000000..6c678832c2fe --- /dev/null +++ b/crates/biome_cli/tests/snapshots/main_cases_handle_astro_files/check_stdin_apply_successfully.snap @@ -0,0 +1,65 @@ +--- +source: crates/biome_cli/tests/snap_test.rs +expression: content +--- +# Input messages + +```block +--- +import {a as a} from 'mod'; +import { something } from "file.astro"; +debugger; +statement ( ) ; +var foo: string = ""; +--- +
+``` + +# Emitted Messages + +```block +--- +import { something } from "file.astro"; +import { a } from "mod"; +debugger; +statement(); +var foo = ""; +--- +
+``` + +```block +file.astro lint/suspicious/noDebugger FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + × This is an unexpected use of the debugger statement. + + i Unsafe fix: Remove debugger statement + + 2 2 │ import { something } from "file.astro"; + 3 3 │ import { a } from "mod"; + 4 │ - debugger; + 5 4 │ statement(); + 6 5 │ var foo = ""; + + +``` + +```block +file.astro lint/style/noVar FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + × Use let or const instead of var. + + i A variable declared with var is accessible in the whole module. Thus, the variable can be accessed before its initialization and outside the block where it is declared. + + i See MDN web docs for more details. + + i Unsafe fix: Use 'const' instead. + + 4 4 │ debugger; + 5 5 │ statement(); + 6 │ - var·foo·=·""; + 6 │ + const·foo·=·""; + 7 7 │ + + +``` diff --git a/crates/biome_cli/tests/snapshots/main_cases_handle_astro_files/check_stdin_apply_unsafe_successfully.snap b/crates/biome_cli/tests/snapshots/main_cases_handle_astro_files/check_stdin_apply_unsafe_successfully.snap new file mode 100644 index 000000000000..69713baf7043 --- /dev/null +++ b/crates/biome_cli/tests/snapshots/main_cases_handle_astro_files/check_stdin_apply_unsafe_successfully.snap @@ -0,0 +1,28 @@ +--- +source: crates/biome_cli/tests/snap_test.rs +expression: content +--- +# Input messages + +```block +--- +import {a as a} from 'mod'; +import { something } from "file.astro"; +debugger; +statement ( ) ; +var foo: string = ""; +--- +
+``` + +# Emitted Messages + +```block +--- +import { something } from "file.astro"; +import { a } from "mod"; +statement(); +const foo = ""; +--- +
+``` diff --git a/crates/biome_cli/tests/snapshots/main_cases_handle_astro_files/check_stdin_successfully.snap b/crates/biome_cli/tests/snapshots/main_cases_handle_astro_files/check_stdin_successfully.snap new file mode 100644 index 000000000000..d1d880e50dad --- /dev/null +++ b/crates/biome_cli/tests/snapshots/main_cases_handle_astro_files/check_stdin_successfully.snap @@ -0,0 +1,112 @@ +--- +source: crates/biome_cli/tests/snap_test.rs +expression: content +--- +# Input messages + +```block +--- +import {a as a} from 'mod'; +import { something } from "file.astro"; +debugger; +statement ( ) ; +var foo: string = ""; +--- +
+``` + +# Emitted Messages + +```block +--- +import {a as a} from 'mod'; +import { something } from "file.astro"; +debugger; +statement ( ) ; +var foo: string = ""; +--- +
+``` + +```block +file.astro lint/complexity/noUselessRename FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + × Useless rename. + + i Safe fix: Remove the renaming. + + 2 │ import·{a·as·a}·from·'mod'; + │ ----- + +``` + +```block +file.astro lint/suspicious/noDebugger FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + × This is an unexpected use of the debugger statement. + + i Unsafe fix: Remove debugger statement + + 2 2 │ import {a as a} from 'mod'; + 3 3 │ import { something } from "file.astro"; + 4 │ - debugger; + 5 4 │ statement ( ) ; + 6 5 │ var foo: string = ""; + + +``` + +```block +file.astro lint/style/noInferrableTypes FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + × This type annotation is trivially inferred from its initialization. + + i Safe fix: Remove the type annotation. + + 4 4 │ debugger; + 5 5 │ statement ( ) ; + 6 │ - var·foo:·string·=·""; + 6 │ + var·foo·=·""; + 7 7 │ + + +``` + +```block +file.astro lint/style/noVar FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + × Use let or const instead of var. + + i A variable declared with var is accessible in the whole module. Thus, the variable can be accessed before its initialization and outside the block where it is declared. + + i See MDN web docs for more details. + + i Unsafe fix: Use 'const' instead. + + 4 4 │ debugger; + 5 5 │ statement ( ) ; + 6 │ - var·foo:·string·=·""; + 6 │ + const·foo:·string·=·""; + 7 7 │ + + +``` + +```block +file.astro format ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + × Formatter would have printed the following content: + + 1 1 │ --- + 2 │ - import·{a·as·a}·from·'mod'; + 3 │ - import·{····something·}·from·"file.astro"; + 2 │ + import·{·a·as·a·}·from·"mod"; + 3 │ + import·{·something·}·from·"file.astro"; + 4 4 │ debugger; + 5 │ - statement·(·)·; + 5 │ + statement(); + 6 6 │ var foo: string = ""; + 7 7 │ --- + + +``` diff --git a/crates/biome_cli/tests/snapshots/main_cases_handle_astro_files/format_stdin_successfully.snap b/crates/biome_cli/tests/snapshots/main_cases_handle_astro_files/format_stdin_successfully.snap new file mode 100644 index 000000000000..f35db9c9f4ea --- /dev/null +++ b/crates/biome_cli/tests/snapshots/main_cases_handle_astro_files/format_stdin_successfully.snap @@ -0,0 +1,26 @@ +--- +source: crates/biome_cli/tests/snap_test.rs +expression: content +--- +# Input messages + +```block +--- +import { something } from "file.astro"; + +statement ( ) ; + +--- +
+``` + +# Emitted Messages + +```block +--- +import { something } from "file.astro"; + +statement(); +--- +
+``` diff --git a/crates/biome_cli/tests/snapshots/main_cases_handle_astro_files/format_stdin_write_successfully.snap b/crates/biome_cli/tests/snapshots/main_cases_handle_astro_files/format_stdin_write_successfully.snap new file mode 100644 index 000000000000..f35db9c9f4ea --- /dev/null +++ b/crates/biome_cli/tests/snapshots/main_cases_handle_astro_files/format_stdin_write_successfully.snap @@ -0,0 +1,26 @@ +--- +source: crates/biome_cli/tests/snap_test.rs +expression: content +--- +# Input messages + +```block +--- +import { something } from "file.astro"; + +statement ( ) ; + +--- +
+``` + +# Emitted Messages + +```block +--- +import { something } from "file.astro"; + +statement(); +--- +
+``` diff --git a/crates/biome_cli/tests/snapshots/main_cases_handle_astro_files/lint_stdin_apply_successfully.snap b/crates/biome_cli/tests/snapshots/main_cases_handle_astro_files/lint_stdin_apply_successfully.snap new file mode 100644 index 000000000000..2cb7f35a837e --- /dev/null +++ b/crates/biome_cli/tests/snapshots/main_cases_handle_astro_files/lint_stdin_apply_successfully.snap @@ -0,0 +1,21 @@ +--- +source: crates/biome_cli/tests/snap_test.rs +expression: content +--- +# Input messages + +```block +--- +import {a as a} from 'mod'; +--- +
+``` + +# Emitted Messages + +```block +--- +import {a} from 'mod'; +--- +
+``` diff --git a/crates/biome_cli/tests/snapshots/main_cases_handle_astro_files/lint_stdin_apply_unsafe_successfully.snap b/crates/biome_cli/tests/snapshots/main_cases_handle_astro_files/lint_stdin_apply_unsafe_successfully.snap new file mode 100644 index 000000000000..b7f146f1f149 --- /dev/null +++ b/crates/biome_cli/tests/snapshots/main_cases_handle_astro_files/lint_stdin_apply_unsafe_successfully.snap @@ -0,0 +1,20 @@ +--- +source: crates/biome_cli/tests/snap_test.rs +expression: content +--- +# Input messages + +```block +--- +debugger; +--- +
+``` + +# Emitted Messages + +```block +--- +--- +
+``` diff --git a/crates/biome_cli/tests/snapshots/main_cases_handle_astro_files/lint_stdin_successfully.snap b/crates/biome_cli/tests/snapshots/main_cases_handle_astro_files/lint_stdin_successfully.snap new file mode 100644 index 000000000000..a1b48c86f48e --- /dev/null +++ b/crates/biome_cli/tests/snapshots/main_cases_handle_astro_files/lint_stdin_successfully.snap @@ -0,0 +1,33 @@ +--- +source: crates/biome_cli/tests/snap_test.rs +expression: content +--- +# Input messages + +```block +--- +import {a as a} from 'mod'; +--- +
+``` + +# Emitted Messages + +```block +--- +import {a as a} from 'mod'; +--- +
+``` + +```block +file.astro lint/complexity/noUselessRename FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + × Useless rename. + + i Safe fix: Remove the renaming. + + 2 │ import·{a·as·a}·from·'mod'; + │ ----- + +``` diff --git a/crates/biome_cli/tests/snapshots/main_cases_handle_svelte_files/check_stdin_apply_successfully.snap b/crates/biome_cli/tests/snapshots/main_cases_handle_svelte_files/check_stdin_apply_successfully.snap new file mode 100644 index 000000000000..016541813bfb --- /dev/null +++ b/crates/biome_cli/tests/snapshots/main_cases_handle_svelte_files/check_stdin_apply_successfully.snap @@ -0,0 +1,65 @@ +--- +source: crates/biome_cli/tests/snap_test.rs +expression: content +--- +# Input messages + +```block + +
+``` + +# Emitted Messages + +```block + +
+``` + +```block +file.svelte lint/suspicious/noDebugger FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + × This is an unexpected use of the debugger statement. + + i Unsafe fix: Remove debugger statement + + 1 1 │ import Button from "./components/Button.svelte"; + 2 2 │ import { Form } from "./components/Form.svelte"; + 3 │ - debugger; + 4 3 │ statement(); + 5 4 │ var foo = ""; + + +``` + +```block +file.svelte lint/style/noVar FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + × Use let or const instead of var. + + i A variable declared with var is accessible in the whole module. Thus, the variable can be accessed before its initialization and outside the block where it is declared. + + i See MDN web docs for more details. + + i Unsafe fix: Use 'const' instead. + + 3 3 │ debugger; + 4 4 │ statement(); + 5 │ - var·foo·=·""; + 5 │ + const·foo·=·""; + 6 6 │ + + +``` diff --git a/crates/biome_cli/tests/snapshots/main_cases_handle_svelte_files/check_stdin_apply_unsafe_successfully.snap b/crates/biome_cli/tests/snapshots/main_cases_handle_svelte_files/check_stdin_apply_unsafe_successfully.snap new file mode 100644 index 000000000000..0a98c5fcd685 --- /dev/null +++ b/crates/biome_cli/tests/snapshots/main_cases_handle_svelte_files/check_stdin_apply_unsafe_successfully.snap @@ -0,0 +1,28 @@ +--- +source: crates/biome_cli/tests/snap_test.rs +expression: content +--- +# Input messages + +```block + +
+``` + +# Emitted Messages + +```block + +
+``` diff --git a/crates/biome_cli/tests/snapshots/main_cases_handle_svelte_files/check_stdin_successfully.snap b/crates/biome_cli/tests/snapshots/main_cases_handle_svelte_files/check_stdin_successfully.snap new file mode 100644 index 000000000000..92e6b419ec1b --- /dev/null +++ b/crates/biome_cli/tests/snapshots/main_cases_handle_svelte_files/check_stdin_successfully.snap @@ -0,0 +1,112 @@ +--- +source: crates/biome_cli/tests/snap_test.rs +expression: content +--- +# Input messages + +```block + +
+``` + +# Emitted Messages + +```block + +
+``` + +```block +file.svelte lint/complexity/noUselessRename FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + × Useless rename. + + i Safe fix: Remove the renaming. + + 1 │ import·{·Form·as···Form·}·····from·'./components/Form.svelte'·; + │ ---------- + +``` + +```block +file.svelte lint/suspicious/noDebugger FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + × This is an unexpected use of the debugger statement. + + i Unsafe fix: Remove debugger statement + + 1 1 │ import { Form as Form } from './components/Form.svelte' ; + 2 2 │ import Button from "./components/Button.svelte"; + 3 │ - debugger; + 4 3 │ statement ( ) ; + 5 4 │ var foo: string = ""; + + +``` + +```block +file.svelte lint/style/noInferrableTypes FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + × This type annotation is trivially inferred from its initialization. + + i Safe fix: Remove the type annotation. + + 3 3 │ debugger; + 4 4 │ statement ( ) ; + 5 │ - var·foo:·string·=·""; + 5 │ + var·foo·=·""; + 6 6 │ + + +``` + +```block +file.svelte lint/style/noVar FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + × Use let or const instead of var. + + i A variable declared with var is accessible in the whole module. Thus, the variable can be accessed before its initialization and outside the block where it is declared. + + i See MDN web docs for more details. + + i Unsafe fix: Use 'const' instead. + + 3 3 │ debugger; + 4 4 │ statement ( ) ; + 5 │ - var·foo:·string·=·""; + 5 │ + const·foo:·string·=·""; + 6 6 │ + + +``` + +```block +file.svelte format ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + × Formatter would have printed the following content: + + 1 1 │ + + +``` diff --git a/crates/biome_cli/tests/snapshots/main_cases_handle_svelte_files/format_stdin_successfully.snap b/crates/biome_cli/tests/snapshots/main_cases_handle_svelte_files/format_stdin_successfully.snap new file mode 100644 index 000000000000..92327807f837 --- /dev/null +++ b/crates/biome_cli/tests/snapshots/main_cases_handle_svelte_files/format_stdin_successfully.snap @@ -0,0 +1,23 @@ +--- +source: crates/biome_cli/tests/snap_test.rs +expression: content +--- +# Input messages + +```block + +
+``` + +# Emitted Messages + +```block + +
+``` diff --git a/crates/biome_cli/tests/snapshots/main_cases_handle_svelte_files/format_stdin_write_successfully.snap b/crates/biome_cli/tests/snapshots/main_cases_handle_svelte_files/format_stdin_write_successfully.snap new file mode 100644 index 000000000000..92327807f837 --- /dev/null +++ b/crates/biome_cli/tests/snapshots/main_cases_handle_svelte_files/format_stdin_write_successfully.snap @@ -0,0 +1,23 @@ +--- +source: crates/biome_cli/tests/snap_test.rs +expression: content +--- +# Input messages + +```block + +
+``` + +# Emitted Messages + +```block + +
+``` diff --git a/crates/biome_cli/tests/snapshots/main_cases_handle_svelte_files/lint_stdin_apply_successfully.snap b/crates/biome_cli/tests/snapshots/main_cases_handle_svelte_files/lint_stdin_apply_successfully.snap new file mode 100644 index 000000000000..adb7edf1c642 --- /dev/null +++ b/crates/biome_cli/tests/snapshots/main_cases_handle_svelte_files/lint_stdin_apply_successfully.snap @@ -0,0 +1,39 @@ +--- +source: crates/biome_cli/tests/snap_test.rs +expression: content +--- +# Input messages + +```block + +
+``` + +# Emitted Messages + +```block + +
+``` + +```block +file.svelte lint/style/noVar FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + × Use let or const instead of var. + + i A variable declared with var is accessible in the whole module. Thus, the variable can be accessed before its initialization and outside the block where it is declared. + + i See MDN web docs for more details. + + i Unsafe fix: Use 'const' instead. + + 1 │ - var·foo·=·""; + 1 │ + const·foo·=·""; + 2 2 │ + + +``` diff --git a/crates/biome_cli/tests/snapshots/main_cases_handle_svelte_files/lint_stdin_apply_unsafe_successfully.snap b/crates/biome_cli/tests/snapshots/main_cases_handle_svelte_files/lint_stdin_apply_unsafe_successfully.snap new file mode 100644 index 000000000000..0dc49a8449e6 --- /dev/null +++ b/crates/biome_cli/tests/snapshots/main_cases_handle_svelte_files/lint_stdin_apply_unsafe_successfully.snap @@ -0,0 +1,21 @@ +--- +source: crates/biome_cli/tests/snap_test.rs +expression: content +--- +# Input messages + +```block + +
+``` + +# Emitted Messages + +```block + +
+``` diff --git a/crates/biome_cli/tests/snapshots/main_cases_handle_svelte_files/lint_stdin_successfully.snap b/crates/biome_cli/tests/snapshots/main_cases_handle_svelte_files/lint_stdin_successfully.snap new file mode 100644 index 000000000000..bbda7d248e3c --- /dev/null +++ b/crates/biome_cli/tests/snapshots/main_cases_handle_svelte_files/lint_stdin_successfully.snap @@ -0,0 +1,53 @@ +--- +source: crates/biome_cli/tests/snap_test.rs +expression: content +--- +# Input messages + +```block + +
+``` + +# Emitted Messages + +```block + +
+``` + +```block +file.svelte lint/style/noInferrableTypes FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + × This type annotation is trivially inferred from its initialization. + + i Safe fix: Remove the type annotation. + + 1 │ - var·foo:·string·=·""; + 1 │ + var·foo·=·""; + 2 2 │ + + +``` + +```block +file.svelte lint/style/noVar FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + × Use let or const instead of var. + + i A variable declared with var is accessible in the whole module. Thus, the variable can be accessed before its initialization and outside the block where it is declared. + + i See MDN web docs for more details. + + i Unsafe fix: Use 'const' instead. + + 1 │ - var·foo:·string·=·""; + 1 │ + const·foo:·string·=·""; + 2 2 │ + + +``` diff --git a/crates/biome_cli/tests/snapshots/main_cases_handle_vue_files/check_stdin_apply_successfully.snap b/crates/biome_cli/tests/snapshots/main_cases_handle_vue_files/check_stdin_apply_successfully.snap new file mode 100644 index 000000000000..d69d07b2ece7 --- /dev/null +++ b/crates/biome_cli/tests/snapshots/main_cases_handle_vue_files/check_stdin_apply_successfully.snap @@ -0,0 +1,43 @@ +--- +source: crates/biome_cli/tests/snap_test.rs +expression: content +--- +# Input messages + +```block + + +``` + +# Emitted Messages + +```block + + +``` + +```block +file.vue lint/performance/noDelete FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + × Avoid the delete operator which can impact performance. + + i Unsafe fix: Use an undefined assignment instead. + + 2 2 │ import { Button } from "./components/Button.vue"; + 3 3 │ + 4 │ - delete·a.c; + 4 │ + a.c·=·undefined; + 5 5 │ + + +``` diff --git a/crates/biome_cli/tests/snapshots/main_cases_handle_vue_files/check_stdin_apply_unsafe_successfully.snap b/crates/biome_cli/tests/snapshots/main_cases_handle_vue_files/check_stdin_apply_unsafe_successfully.snap new file mode 100644 index 000000000000..d15b62375da3 --- /dev/null +++ b/crates/biome_cli/tests/snapshots/main_cases_handle_vue_files/check_stdin_apply_unsafe_successfully.snap @@ -0,0 +1,27 @@ +--- +source: crates/biome_cli/tests/snap_test.rs +expression: content +--- +# Input messages + +```block + + +``` + +# Emitted Messages + +```block + + +``` diff --git a/crates/biome_cli/tests/snapshots/main_cases_handle_vue_files/check_stdin_successfully.snap b/crates/biome_cli/tests/snapshots/main_cases_handle_vue_files/check_stdin_successfully.snap new file mode 100644 index 000000000000..330279a22d52 --- /dev/null +++ b/crates/biome_cli/tests/snapshots/main_cases_handle_vue_files/check_stdin_successfully.snap @@ -0,0 +1,71 @@ +--- +source: crates/biome_cli/tests/snap_test.rs +expression: content +--- +# Input messages + +```block + + +``` + +# Emitted Messages + +```block + + +``` + +```block +file.vue lint/complexity/noUselessRename FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + × Useless rename. + + i Safe fix: Remove the renaming. + + 1 │ import·{······Button··as·Button··}···from··"./components/Button.vue"···; + │ ----------- + +``` + +```block +file.vue lint/performance/noDelete FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + × Avoid the delete operator which can impact performance. + + i Unsafe fix: Use an undefined assignment instead. + + 2 2 │ import * as vueUse from "vue-use" ; + 3 3 │ + 4 │ - delete·a.c; + 4 │ + a.c·=·undefined; + 5 5 │ + + +``` + +```block +file.vue format ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + × Formatter would have printed the following content: + + 1 1 │ + +``` + +# Emitted Messages + +```block + + +``` diff --git a/crates/biome_cli/tests/snapshots/main_cases_handle_vue_files/format_stdin_write_successfully.snap b/crates/biome_cli/tests/snapshots/main_cases_handle_vue_files/format_stdin_write_successfully.snap new file mode 100644 index 000000000000..d058d5a113cf --- /dev/null +++ b/crates/biome_cli/tests/snapshots/main_cases_handle_vue_files/format_stdin_write_successfully.snap @@ -0,0 +1,23 @@ +--- +source: crates/biome_cli/tests/snap_test.rs +expression: content +--- +# Input messages + +```block + + +``` + +# Emitted Messages + +```block + + +``` diff --git a/crates/biome_cli/tests/snapshots/main_cases_handle_vue_files/lint_stdin_apply_successfully.snap b/crates/biome_cli/tests/snapshots/main_cases_handle_vue_files/lint_stdin_apply_successfully.snap new file mode 100644 index 000000000000..ee3e28ddb047 --- /dev/null +++ b/crates/biome_cli/tests/snapshots/main_cases_handle_vue_files/lint_stdin_apply_successfully.snap @@ -0,0 +1,79 @@ +--- +source: crates/biome_cli/tests/snap_test.rs +expression: content +--- +# Input messages + +```block + + +``` + +# Emitted Messages + +```block + + +``` + +```block +file.svelte lint/suspicious/noDoubleEquals FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + × Use === instead of == + + i == is only allowed when comparing against null + + i Using == may be unsafe if you are relying on type coercion + + i Unsafe fix: Use === + + 1 │ a·===·b; + │ + + +``` + +```block +file.svelte lint/performance/noDelete FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + × Avoid the delete operator which can impact performance. + + i Unsafe fix: Use an undefined assignment instead. + + 1 1 │ a == b; + 2 │ - delete·a.c; + 2 │ + a.c·=·undefined; + 3 3 │ + 4 4 │ var foo = ""; + + +``` + +```block +file.svelte lint/style/noVar FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + × Use let or const instead of var. + + i A variable declared with var is accessible in the whole module. Thus, the variable can be accessed before its initialization and outside the block where it is declared. + + i See MDN web docs for more details. + + i Unsafe fix: Use 'const' instead. + + 2 2 │ delete a.c; + 3 3 │ + 4 │ - var·foo·=·""; + 4 │ + const·foo·=·""; + 5 5 │ + + +``` diff --git a/crates/biome_cli/tests/snapshots/main_cases_handle_vue_files/lint_stdin_apply_unsafe_successfully.snap b/crates/biome_cli/tests/snapshots/main_cases_handle_vue_files/lint_stdin_apply_unsafe_successfully.snap new file mode 100644 index 000000000000..cb97f85e05a2 --- /dev/null +++ b/crates/biome_cli/tests/snapshots/main_cases_handle_vue_files/lint_stdin_apply_unsafe_successfully.snap @@ -0,0 +1,27 @@ +--- +source: crates/biome_cli/tests/snap_test.rs +expression: content +--- +# Input messages + +```block + + +``` + +# Emitted Messages + +```block + + +``` diff --git a/crates/biome_cli/tests/snapshots/main_cases_handle_vue_files/lint_stdin_successfully.snap b/crates/biome_cli/tests/snapshots/main_cases_handle_vue_files/lint_stdin_successfully.snap new file mode 100644 index 000000000000..ff4f470ecf14 --- /dev/null +++ b/crates/biome_cli/tests/snapshots/main_cases_handle_vue_files/lint_stdin_successfully.snap @@ -0,0 +1,95 @@ +--- +source: crates/biome_cli/tests/snap_test.rs +expression: content +--- +# Input messages + +```block + + +``` + +# Emitted Messages + +```block + + +``` + +```block +file.svelte lint/suspicious/noDoubleEquals FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + × Use === instead of == + + i == is only allowed when comparing against null + + i Using == may be unsafe if you are relying on type coercion + + i Unsafe fix: Use === + + 1 │ a·===·b; + │ + + +``` + +```block +file.svelte lint/performance/noDelete FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + × Avoid the delete operator which can impact performance. + + i Unsafe fix: Use an undefined assignment instead. + + 1 1 │ a == b; + 2 │ - delete·a.c; + 2 │ + a.c·=·undefined; + 3 3 │ + 4 4 │ var foo: string = ""; + + +``` + +```block +file.svelte lint/style/noInferrableTypes FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + × This type annotation is trivially inferred from its initialization. + + i Safe fix: Remove the type annotation. + + 2 2 │ delete a.c; + 3 3 │ + 4 │ - var·foo:·string·=·""; + 4 │ + var·foo·=·""; + 5 5 │ + + +``` + +```block +file.svelte lint/style/noVar FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + × Use let or const instead of var. + + i A variable declared with var is accessible in the whole module. Thus, the variable can be accessed before its initialization and outside the block where it is declared. + + i See MDN web docs for more details. + + i Unsafe fix: Use 'const' instead. + + 2 2 │ delete a.c; + 3 3 │ + 4 │ - var·foo:·string·=·""; + 4 │ + const·foo:·string·=·""; + 5 5 │ + + +```