Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion crates/oxc_formatter/src/service/oxfmtrc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,6 @@ impl Oxfmtrc {
/// - file content is not valid JSONC
/// - deserialization fails for string enum values
pub fn from_file(path: &Path) -> Result<Self, String> {
// TODO: Use `simdutf8` like `oxc_linter`?
let mut string = std::fs::read_to_string(path)
// Do not include OS error, it differs between platforms
.map_err(|_| format!("Failed to read config {}: File not found", path.display()))?;
Expand All @@ -228,6 +227,24 @@ impl Oxfmtrc {
let json = serde_json::from_str::<serde_json::Value>(&string)
.map_err(|err| format!("Failed to parse config {}: {err}", path.display()))?;

// Report unsupported experimental options.
// NOTE: If we define them as fields in `Oxfmtrc`, we can handle errors in `into_format_options()`,
// but if they are not supported, there is no need to define them as fields.
if let Some(obj) = json.as_object() {
if obj.contains_key("experimentalOperatorPosition") {
return Err(format!(
"Unsupported option `experimentalOperatorPosition` in config {}",
path.display()
));
}
if obj.contains_key("experimentalTernaries") {
return Err(format!(
"Unsupported option `experimentalTernaries` in config {}",
path.display()
));
}
}

// NOTE: String enum deserialization errors are handled here
Self::deserialize(&json)
.map_err(|err| format!("Failed to deserialize config {}: {err}", path.display()))
Expand Down
Loading