diff --git a/Cargo.toml b/Cargo.toml index 1985afb3a61..138a7f74b94 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -31,6 +31,9 @@ rome_aria_metadata = { path = "./crates/rome_aria_metadata" } rome_cli = { path = "./crates/rome_cli" } rome_console = { version = "0.0.1", path = "./crates/rome_console" } rome_control_flow = { path = "./crates/rome_control_flow" } +rome_css_factory = { path = "./crates/rome_css_factory" } +rome_css_parser = { path = "./crates/rome_css_parser" } +rome_css_syntax = { path = "./crates/rome_css_syntax" } rome_deserialize = { version = "0.0.0", path = "./crates/rome_deserialize" } rome_diagnostics = { version = "0.0.1", path = "./crates/rome_diagnostics" } rome_diagnostics_categories = { version = "0.0.1", path = "./crates/rome_diagnostics_categories" } @@ -51,9 +54,6 @@ rome_json_factory = { version = "0.0.1", path = "./crates/rome_json_fa rome_json_formatter = { path = "./crates/rome_json_formatter" } rome_json_parser = { path = "./crates/rome_json_parser" } rome_json_syntax = { version = "0.0.1", path = "./crates/rome_json_syntax" } -rome_css_factory = { path = "./crates/rome_css_factory" } -rome_css_parser = { path = "./crates/rome_css_parser" } -rome_css_syntax = { path = "./crates/rome_css_syntax" } rome_lsp = { path = "./crates/rome_lsp" } rome_markup = { version = "0.0.1", path = "./crates/rome_markup" } rome_migrate = { path = "./crates/rome_migrate" } @@ -65,24 +65,24 @@ rome_text_size = { version = "0.0.1", path = "./crates/rome_text_si tests_macros = { path = "./crates/tests_macros" } # Crates needed in the workspace +bitflags = "2.3.1" +bpaf = { version = "0.9.2", features = ["derive"] } +countme = "3.0.1" +dashmap = "5.4.0" +indexmap = "1.9.3" +insta = "1.29.0" +lazy_static = "1.4.0" +quickcheck = "1.0.3" quickcheck_macros = "1.0.0" -quickcheck = "1.0.3" -bitflags = "2.3.1" -bpaf = { version = "0.9.2", features = ["derive"] } -countme = "3.0.1" -dashmap = "5.4.0" -indexmap = "1.9.3" -insta = "1.29.0" -lazy_static = "1.4.0" -quote = { version = "1.0.28" } -rustc-hash = "1.1.0" -schemars = { version = "0.8.12" } -serde = { version = "1.0.163", features = ["derive"], default-features = false } -serde_json = "1.0.96" -smallvec = { version = "1.10.0", features = ["union", "const_new"] } -tracing = { version = "0.1.37", default-features = false, features = ["std"] } +quote = { version = "1.0.28" } +rustc-hash = "1.1.0" +schemars = { version = "0.8.12" } +serde = { version = "1.0.163", features = ["derive"], default-features = false } +serde_json = "1.0.96" +smallvec = { version = "1.10.0", features = ["union", "const_new"] } +tracing = { version = "0.1.37", default-features = false, features = ["std"] } # pinning to version 1.18 to avoid multiple versions of windows-sys as dependency -tokio = { version = "~1.18.5" } +tokio = { version = "~1.18.5" } [profile.dev.package.rome_wasm] diff --git a/crates/rome_cli/src/execute/migrate.rs b/crates/rome_cli/src/execute/migrate.rs index 513d4ad8551..576279dee23 100644 --- a/crates/rome_cli/src/execute/migrate.rs +++ b/crates/rome_cli/src/execute/migrate.rs @@ -3,6 +3,7 @@ use crate::{CliDiagnostic, CliSession}; use rome_console::{markup, ConsoleExt}; use rome_diagnostics::{category, PrintDiagnostic}; use rome_fs::OpenOptions; +use rome_json_parser::JsonParserOptions; use rome_json_syntax::JsonRoot; use rome_migrate::{migrate_configuration, ControlFlow}; use rome_rowan::AstNode; @@ -26,7 +27,7 @@ pub(crate) fn run( fs.open_with_options(configuration_path.as_path(), open_options)?; let mut configuration_content = String::new(); configuration_file.read_to_string(&mut configuration_content)?; - let parsed = rome_json_parser::parse_json(&configuration_content); + let parsed = rome_json_parser::parse_json(&configuration_content, JsonParserOptions::default()); let mut errors = 0; let mut tree = parsed.tree(); let mut actions = Vec::new(); diff --git a/crates/rome_cli/src/execute/traverse.rs b/crates/rome_cli/src/execute/traverse.rs index 38a711a9d04..221d045816a 100644 --- a/crates/rome_cli/src/execute/traverse.rs +++ b/crates/rome_cli/src/execute/traverse.rs @@ -62,7 +62,6 @@ pub(crate) fn traverse( inputs: Vec, ) -> Result<(), CliDiagnostic> { init_thread_pool(); - if inputs.is_empty() && execution.as_stdin_file().is_none() { return Err(CliDiagnostic::missing_argument( "", diff --git a/crates/rome_cli/tests/commands/format.rs b/crates/rome_cli/tests/commands/format.rs index d09b870edb6..4091095bac5 100644 --- a/crates/rome_cli/tests/commands/format.rs +++ b/crates/rome_cli/tests/commands/format.rs @@ -1839,3 +1839,40 @@ fn doesnt_error_if_no_files_were_processed() { result, )); } + +#[test] +fn ignore_comments_error_when_allow_comments() { + let mut fs = MemoryFileSystem::default(); + let mut console = BufferConsole::default(); + + let config_json = r#"{ + "json": { + "parser": { "allowComments": true } + } +} + + "#; + let rome_config = "rome.json"; + let code = r#" +/*test*/ [1, 2, 3] + "#; + let file_path = Path::new("tsconfig.json"); + fs.insert(file_path.into(), code.as_bytes()); + fs.insert(rome_config.into(), config_json); + + let result = run_cli( + DynRef::Borrowed(&mut fs), + &mut console, + Args::from([("format"), file_path.as_os_str().to_str().unwrap()].as_slice()), + ); + + // assert!(result.is_ok(), "run_cli returned {result:?}"); + + assert_cli_snapshot(SnapshotPayload::new( + module_path!(), + "ignore_comments_error_when_allow_comments", + fs, + console, + result, + )); +} diff --git a/crates/rome_cli/tests/commands/init.rs b/crates/rome_cli/tests/commands/init.rs index fd217a937b1..730ca275605 100644 --- a/crates/rome_cli/tests/commands/init.rs +++ b/crates/rome_cli/tests/commands/init.rs @@ -5,7 +5,7 @@ use bpaf::Args; use rome_console::BufferConsole; use rome_fs::{FileSystemExt, MemoryFileSystem}; use rome_json_formatter::context::JsonFormatOptions; -use rome_json_parser::parse_json; +use rome_json_parser::{parse_json, JsonParserOptions}; use rome_service::DynRef; use std::path::Path; @@ -52,7 +52,7 @@ fn creates_config_file() { let mut content = String::new(); file.read_to_string(&mut content) .expect("failed to read file from memory FS"); - let parsed = parse_json(CONFIG_INIT_DEFAULT); + let parsed = parse_json(CONFIG_INIT_DEFAULT, JsonParserOptions::default()); let formatted = rome_json_formatter::format_node(JsonFormatOptions::default(), &parsed.syntax()) .expect("valid format document") @@ -95,7 +95,10 @@ fn creates_config_file_when_rome_installed_via_package_manager() { let mut content = String::new(); file.read_to_string(&mut content) .expect("failed to read file from memory FS"); - let parsed = parse_json(CONFIG_INIT_DEFAULT_WHEN_INSTALLED); + let parsed = parse_json( + CONFIG_INIT_DEFAULT_WHEN_INSTALLED, + JsonParserOptions::default(), + ); let formatted = rome_json_formatter::format_node(JsonFormatOptions::default(), &parsed.syntax()) .expect("valid format document") diff --git a/crates/rome_cli/tests/snap_test.rs b/crates/rome_cli/tests/snap_test.rs index 3807271d174..d2cfcd958e1 100644 --- a/crates/rome_cli/tests/snap_test.rs +++ b/crates/rome_cli/tests/snap_test.rs @@ -7,7 +7,7 @@ use rome_formatter::IndentStyle; use rome_fs::{FileSystemExt, MemoryFileSystem}; use rome_json_formatter::context::JsonFormatOptions; use rome_json_formatter::format_node; -use rome_json_parser::parse_json; +use rome_json_parser::{parse_json, JsonParserOptions}; use std::borrow::Cow; use std::collections::BTreeMap; use std::env::{current_exe, temp_dir}; @@ -49,7 +49,10 @@ impl CliSnapshot { let mut content = String::new(); if let Some(configuration) = &self.configuration { - let parsed = parse_json(&redact_snapshot(configuration)); + let parsed = parse_json( + &redact_snapshot(configuration), + JsonParserOptions::default(), + ); let formatted = format_node( JsonFormatOptions::default().with_indent_style(IndentStyle::Space(2)), &parsed.syntax(), diff --git a/crates/rome_cli/tests/snapshots/main_commands_format/ignore_comments_error_when_allow_comments.snap b/crates/rome_cli/tests/snapshots/main_commands_format/ignore_comments_error_when_allow_comments.snap new file mode 100644 index 00000000000..8533db6ebd7 --- /dev/null +++ b/crates/rome_cli/tests/snapshots/main_commands_format/ignore_comments_error_when_allow_comments.snap @@ -0,0 +1,52 @@ +--- +source: crates/rome_cli/tests/snap_test.rs +expression: content +--- +## `rome.json` + +```json +{ + "json": { + "parser": { "allowComments": true } + } +} +``` + +## `tsconfig.json` + +```json + +/*test*/ [1, 2, 3] + +``` + +# Termination Message + +```block +internalError/io ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + × No files were processed in the specified paths. + + + +``` + +# Emitted Messages + +```block +tsconfig.json format ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + × Format with errors is disabled. + + +``` + +```block +Compared 1 file(s) in