fix(rome_cli): correctly compute `can_handle` in CI mode
MODIFY
crates/rome_cli/src/traversal.rs
crates/rome_cli/src/traversal.rs
@@ -531,6 +531,14 @@ impl<'ctx, 'app> TraversalOptions<'ctx, 'app> {
feature: FeatureName::Lint,
})
}
+
+ fn miss_handler_err(&self, err: RomeError, rome_path: &RomePath) {
+ self.push_diagnostic(
+ StdError::from(err)
+ .with_category(category!("files/missingHandler"))
+ .with_file_path(rome_path.file_id()),
+ );
+ }
}
impl<'ctx, 'app> TraversalContext for TraversalOptions<'ctx, 'app> {
@@ -543,23 +551,32 @@ impl<'ctx, 'app> TraversalContext for TraversalOptions<'ctx, 'app> {
}
fn can_handle(&self, rome_path: &RomePath) -> bool {
- let result = match self.execution.traversal_mode() {
- TraversalMode::Check { .. } => self.can_lint(rome_path),
- TraversalMode::CI { .. } => self
- .can_lint(rome_path)
- .and_then(|_| self.can_format(rome_path)),
- TraversalMode::Format { .. } => self.can_format(rome_path),
- };
- match result {
- Ok(result) => result.reason.is_none(),
- Err(err) => {
- self.push_diagnostic(
- StdError::from(err)
- .with_category(category!("files/missingHandler"))
- .with_file_path(rome_path.file_id()),
- );
+ let can_lint = self.can_lint(rome_path);
+ let can_format = self.can_format(rome_path);
+
+ match self.execution.traversal_mode() {
+ TraversalMode::Check { .. } => can_lint
+ .map(|result| result.reason.is_none())
+ .unwrap_or_else(|err| {
+ self.miss_handler_err(err, rome_path);
+ false
+ }),
+ TraversalMode::CI { .. } => match (can_format, can_lint) {
+ // the result of the error is the same, rome can't handle the file
+ (Err(err), _) | (_, Err(err)) => {
+ self.miss_handler_err(err, rome_path);
false
}
+ (Ok(can_format), Ok(can_lint)) => {
+ can_lint.reason.is_none() || can_format.reason.is_none()
+ }
+ },
+ TraversalMode::Format { .. } => can_format
+ .map(|result| result.reason.is_none())
+ .unwrap_or_else(|err| {
+ self.miss_handler_err(err, rome_path);
+ false
+ }),
}
}

MODIFY
crates/rome_cli/tests/commands/ci.rs
crates/rome_cli/tests/commands/ci.rs
@@ -12,6 +12,8 @@ use rome_service::DynRef;
use std::ffi::OsString;
use std::path::Path;
+const INCORRECT_CODE: &str = "let a = !b || !c";
+
#[test]
fn ok() {
let mut fs = MemoryFileSystem::default();
@@ -242,3 +244,40 @@ fn file_too_large() {
result,
));
}
+
+#[test]
+fn ci_runs_linter_not_formatter_issue_3495() {
+ let mut fs = MemoryFileSystem::default();
+ let mut console = BufferConsole::default();
+
+ let file_path = Path::new("rome.json");
+ fs.insert(file_path.into(), CONFIG_DISABLED_FORMATTER.as_bytes());
+
+ let file_path = Path::new("file.js");
+ fs.insert(file_path.into(), INCORRECT_CODE.as_bytes());
+
+ let result = run_cli(
+ DynRef::Borrowed(&mut fs),
+ DynRef::Borrowed(&mut console),
+ Arguments::from_vec(vec![OsString::from("ci"), file_path.as_os_str().into()]),
+ );
+
+ assert!(result.is_err(), "run_cli returned {result:?}");
+
+ let mut file = fs
+ .open(file_path)
+ .expect("ci target file was removed by the CLI");
+
+ let mut content = String::new();
+ file.read_to_string(&mut content)
+ .expect("failed to read file from memory FS");
+
+ drop(file);
+ assert_cli_snapshot(SnapshotPayload::new(
+ module_path!(),
+ "ci_runs_linter_not_formatter_issue_3495",
+ fs,
+ console,
+ result,
+ ));
+}

fix(rome_cli): correctly compute `can_handle` in CI mode (#3500)