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(cli): correctly lint HTML-ish piped from stdin #2686

Merged
merged 12 commits into from
May 4, 2024
10 changes: 9 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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`
Expand Down
55 changes: 43 additions & 12 deletions crates/biome_cli/src/execute/std_in.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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! {
<Warn>"The content was not formatted because the formatter is currently disabled."</Warn>
})
}
Expand Down Expand Up @@ -105,29 +115,43 @@ 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);
}
}

if file_features.supports_organize_imports() && mode.is_check() {
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);
}
}
}
Expand All @@ -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(),
},
};
Expand Down
Loading