Skip to content
This repository has been archived by the owner on Aug 31, 2023. It is now read-only.

Commit

Permalink
fix: rome check via standard in
Browse files Browse the repository at this point in the history
  • Loading branch information
ematipico committed May 9, 2023
1 parent 4d4d87a commit b8f8a08
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 14 deletions.
3 changes: 2 additions & 1 deletion crates/rome_cli/src/execute/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ impl Execution {
}
}

#[derive(Debug)]
pub(crate) enum TraversalMode {
/// This mode is enabled when running the command `rome check`
Check {
Expand Down Expand Up @@ -207,7 +208,7 @@ pub(crate) fn execute_mode(
// don't do any traversal if there's some content coming from stdin
if let Some((path, content)) = mode.as_stdin_file() {
let rome_path = RomePath::new(path);
std_in::run(session, &mode, rome_path, content.as_str())
std_in::run(session, &mode, rome_path, content.as_str(), &cli_options)
} else if let TraversalMode::Migrate {
write,
configuration_path,
Expand Down
53 changes: 44 additions & 9 deletions crates/rome_cli/src/execute/std_in.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,13 @@ use crate::{CliDiagnostic, CliSession};
use rome_console::{markup, ConsoleExt};
use rome_fs::RomePath;

use crate::cli_options::CliOptions;
use crate::execute::diagnostics::{ContentDiffAdvice, FormatDiffDiagnostic};
use rome_diagnostics::{PrintDiagnostic, MAXIMUM_DISPLAYABLE_DIAGNOSTICS};
use rome_service::workspace::{
ChangeFileParams, FeatureName, FeaturesBuilder, FixFileParams, FormatFileParams, Language,
OpenFileParams, OrganizeImportsParams, SupportsFeatureParams,
OpenFileParams, OrganizeImportsParams, PullDiagnosticsParams, RuleCategories,
SupportsFeatureParams,
};
use std::borrow::Cow;

Expand All @@ -16,6 +20,7 @@ pub(crate) fn run<'a>(
mode: &'a Execution,
rome_path: RomePath,
content: &'a str,
cli_options: &CliOptions,
) -> Result<(), CliDiagnostic> {
let workspace = &*session.app.workspace;
let console = &mut *session.app.console;
Expand Down Expand Up @@ -47,6 +52,7 @@ pub(crate) fn run<'a>(
})
}
} else if mode.is_check() {
let mut diagnostics = Vec::new();
let mut new_content = Cow::Borrowed(content);

workspace.open_file(OpenFileParams {
Expand Down Expand Up @@ -96,25 +102,54 @@ pub(crate) fn run<'a>(
}
}
}

if !mode.is_check_apply_unsafe() {
let result = workspace.pull_diagnostics(PullDiagnosticsParams {
categories: RuleCategories::LINT | RuleCategories::SYNTAX,
path: rome_path.clone(),
max_diagnostics: cli_options
.max_diagnostics
.unwrap_or(MAXIMUM_DISPLAYABLE_DIAGNOSTICS)
as u64,
})?;
diagnostics.extend(result.diagnostics);
}

if file_features.supports_for(&FeatureName::Format) {
let printed = workspace.format_file(FormatFileParams { path: rome_path })?;
if printed.as_code() != new_content {
new_content = Cow::Owned(printed.into_code());
let printed = workspace.format_file(FormatFileParams {
path: rome_path.clone(),
})?;
if mode.is_check_apply() || mode.is_check_apply_unsafe() {
if printed.as_code() != new_content {
new_content = Cow::Owned(printed.into_code());
}
} else {
let diagnostic = FormatDiffDiagnostic {
file_name: &*rome_path.display().to_string(),
diff: ContentDiffAdvice {
new: printed.as_code(),
old: &content,
},
};
diagnostics.push(rome_diagnostics::serde::Diagnostic::new(diagnostic));
}
}

match new_content {
Cow::Borrowed(original) => {
console.append(markup! {
{original}
});
}
Cow::Borrowed(_) => {}
Cow::Owned(new_content) => {
console.append(markup! {
{new_content}
});
}
}
if !diagnostics.is_empty() {
for diag in diagnostics {
console.error(markup! {
{PrintDiagnostic::simple(&diag)}
})
}
}
}
Ok(())
}
8 changes: 4 additions & 4 deletions website/src/playground/tabs/SettingsTab.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,7 @@ function SyntaxSettings({

return (
<>
<h2>Syntax</h2>
<h2>Syntax options</h2>
<section>
<div className="field-row">
<label htmlFor="sourceType">Source Type</label>
Expand Down Expand Up @@ -527,7 +527,7 @@ function FormatterSettings({
}) {
return (
<>
<h2>Formatter</h2>
<h2>Formatter options</h2>
<section>
<LineWidthInput lineWidth={lineWidth} setLineWidth={setLineWidth} />

Expand Down Expand Up @@ -631,7 +631,7 @@ function LinterSettings({
}) {
return (
<>
<h2>Linter</h2>
<h2>Linter options</h2>
<section>
<div className="field-row">
<input
Expand Down Expand Up @@ -671,7 +671,7 @@ export function ImportSortingSettings({
}) {
return (
<>
<h2>Import sorting</h2>
<h2>Import sorting options</h2>
<section>
<div className="field-row">
<input
Expand Down

0 comments on commit b8f8a08

Please sign in to comment.