Repository: biomejs/biome (language: rust)

Issue:
Remove support for arbitrary extension for `--config-path` and `BIOME_CONFIG_PATH`. We should handle only `.json` and `.jsonc` and emit an error otherwise.
At the moment, a command like the following is *accepted*:

```bash
biome --config-path=file.yml
```

The `file.yml` gets interpreted as a JSON/JSONC file, which is incorrect. The task is to reject such cases. 


Discussion / hints:

Fix patch:
diff --git a/.changeset/fix_a_bug_where_config_path_accepted_configuration_files_with_unsupported_extensions.md b/.changeset/fix_a_bug_where_config_path_accepted_configuration_files_with_unsupported_extensions.md
new file mode 100644
index 000000000000..4b6583a720fd
--- /dev/null
+++ b/.changeset/fix_a_bug_where_config_path_accepted_configuration_files_with_unsupported_extensions.md
@@ -0,0 +1,5 @@
+---
+cli: patch
+---
+
+# Fix a bug where `--config-path` accepted configuration files with unsupported extensions. Now only `.json` and `.jsonc` are accepted, and an error is raised otherwise.
diff --git a/crates/biome_configuration/src/diagnostics.rs b/crates/biome_configuration/src/diagnostics.rs
index 6dc8d889a249..9f5f10b92ef0 100644
--- a/crates/biome_configuration/src/diagnostics.rs
+++ b/crates/biome_configuration/src/diagnostics.rs
@@ -4,6 +4,7 @@ use biome_deserialize::DeserializationDiagnostic;
 use biome_diagnostics::ResolveError;
 use biome_diagnostics::{Advices, Diagnostic, Error, LogCategory, MessageAndDescription, Visit};
 use biome_rowan::SyntaxError;
+use camino::Utf8Path;
 use serde::{Deserialize, Serialize};
 use std::fmt::{Debug, Formatter};
 
@@ -46,6 +47,9 @@ pub enum BiomeDiagnostic {
     /// When something is wrong with the configuration
     InvalidConfiguration(InvalidConfiguration),
 
+    /// When a user provide a configuration file path that isn't a JSON/JSONC file
+    InvalidConfigurationFile(InvalidConfigurationFile),
+
     /// Thrown when the pattern inside the `ignore` field errors
     InvalidIgnorePattern(InvalidIgnorePattern),
 
@@ -111,6 +115,12 @@ impl BiomeDiagnostic {
         })
     }
 
+    pub fn invalid_configuration_file(path: &Utf8Path) -> Self {
+        Self::InvalidConfigurationFile(InvalidConfigurationFile {
+            path: path.to_string(),
+        })
+    }
+
     pub fn cant_resolve(path: impl Display, source: oxc_resolver::ResolveError) -> Self {
         Self::CantResolve(CantResolve {
             message: MessageAndDescription::from(
@@ -225,6 +235,20 @@ pub struct InvalidConfiguration {
     message: MessageAndDescription,
 }
 
+#[derive(Debug, Serialize, Deserialize, Diagnostic)]
+#[diagnostic(
+    category = "configuration",
+    severity = Error,
+    message(
+        description = "Invalid configuration file. Expected JSON or JSONC file, but got {path}.",
+        message("Invalid configuration file. Expected JSON or JSONC file, but got "{self.path}".")
+    )
+)]
+pub struct InvalidConfigurationFile {
+    #[location(resource)]
+    path: String,
+}
+
 #[derive(Debug, Serialize, Deserialize, Diagnostic)]
 #[diagnostic(
     category = "configuration",
diff --git a/crates/biome_service/src/configuration.rs b/crates/biome_service/src/configuration.rs
index 426ae63f68fd..c5d20757b592 100644
--- a/crates/biome_service/src/configuration.rs
+++ b/crates/biome_service/src/configuration.rs
@@ -193,9 +193,14 @@ fn load_config(fs: &dyn FileSystem, base_path: ConfigurationPathHint) -> LoadCon
             let content = fs.read_file_from_path(config_file_path)?;
             let parser_options = match config_file_path.extension() {
                 Some("json") => JsonParserOptions::default(),
-                _ => JsonParserOptions::default()
+                Some("jsonc") => JsonParserOptions::default()
                     .with_allow_comments()
                     .with_allow_trailing_commas(),
+                _ => {
+                    return Err(
+                        BiomeDiagnostic::invalid_configuration_file(config_file_path).into(),
+                    )
+                }
             };
             let deserialized =
                 deserialize_from_json_str::<Configuration>(&content, parser_options, "");
@@ -571,3 +576,22 @@ impl ConfigurationExt for Configuration {
         Ok((None, vec![]))
     }
 }
+
+#[cfg(test)]
+mod test {
+    use crate::configuration::load_configuration;
+    use biome_configuration::ConfigurationPathHint;
+    use biome_fs::MemoryFileSystem;
+    use camino::Utf8PathBuf;
+
+    #[test]
+    fn should_not_load_a_configuration_yml() {
+        let mut fs = MemoryFileSystem::default();
+        fs.insert(Utf8PathBuf::from("biome.yml"), "content".to_string());
+        let path_hint = ConfigurationPathHint::FromUser(Utf8PathBuf::from("biome.yml"));
+
+        let result = load_configuration(&fs, path_hint);
+
+        assert!(result.is_err());
+    }
+}


Test patch:
diff --git a/crates/biome_cli/tests/cases/config_path.rs b/crates/biome_cli/tests/cases/config_path.rs
index 94da3d081749..8e29c2a1b33a 100644
--- a/crates/biome_cli/tests/cases/config_path.rs
+++ b/crates/biome_cli/tests/cases/config_path.rs
@@ -98,3 +98,28 @@ fn set_config_path_to_file() {
         result,
     ));
 }
+
+#[test]
+fn raises_an_error_when_the_config_file_is_not_json() {
+    let mut fs = MemoryFileSystem::default();
+    let mut console = BufferConsole::default();
+
+    let config_path = Utf8Path::new("biome.yml");
+    fs.insert(config_path.into(), r#"blah: foo"#.as_bytes());
+
+    let (fs, result) = run_cli(
+        fs,
+        &mut console,
+        Args::from(["check", "--config-path=biome.yml", "src"].as_slice()),
+    );
+
+    assert!(result.is_err(), "run_cli returned {result:?}");
+
+    assert_cli_snapshot(SnapshotPayload::new(
+        module_path!(),
+        "raises_an_error_when_the_config_file_is_not_json",
+        fs,
+        console,
+        result,
+    ));
+}
diff --git a/crates/biome_cli/tests/snapshots/main_cases_config_path/raises_an_error_when_the_config_file_is_not_json.snap b/crates/biome_cli/tests/snapshots/main_cases_config_path/raises_an_error_when_the_config_file_is_not_json.snap
new file mode 100644
index 000000000000..22dc7b58335d
--- /dev/null
+++ b/crates/biome_cli/tests/snapshots/main_cases_config_path/raises_an_error_when_the_config_file_is_not_json.snap
@@ -0,0 +1,21 @@
+---
+source: crates/biome_cli/tests/snap_test.rs
+expression: redactor(content)
+snapshot_kind: text
+---
+## `biome.yml`
+
+```yml
+blah: foo
+```
+
+# Termination Message
+
+```block
+biome.yml configuration ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
+
+  × Invalid configuration file. Expected JSON or JSONC file, but got biome.yml.
+  
+
+
+```