crate-cli 11.0.0

A command-line tool for managing Cargo package lifecycles: version bump, workspace dependency sync, members-ordered publish and code formatting.
Documentation
use super::*;

/// Formats JSON (`.json`, `tsconfig.json`, `.vscode/*.json`) matching VS Code Prettier 3.7.4 `json` parser (`tabWidth: 2`, `printWidth: 80`, `objectWrap: "preserve"`, allows comments, strips trailing commas).
///
/// # Arguments
///
/// - `&str` - Raw JSON source text.
///
/// # Returns
///
/// - `Result<String, io::Error>` - Formatted JSON text, or an invalid-data I/O error on syntax failure.
#[inline]
pub fn format_json(input: &str) -> Result<String, io::Error> {
    tidy::json::format(input, &VSCODE_JSON_OPTIONS)
        .map_err(|_: tidy::Error| io::Error::new(ErrorKind::InvalidData, ERROR_JSON_PARSE_FAILED))
}

/// Formats JSON manifests (`package.json`, `package-lock.json`, `composer.json`) matching VS Code Prettier 3.7.4 `json-stringify` parser.
///
/// # Arguments
///
/// - `&str` - Raw JSON manifest text.
///
/// # Returns
///
/// - `Result<String, io::Error>` - Expanded JSON text, or an invalid-data I/O error on syntax failure.
#[inline]
pub fn format_json_stringify(input: &str) -> Result<String, io::Error> {
    tidy::json::format(input, &VSCODE_JSON_STRINGIFY_OPTIONS)
        .map_err(|_: tidy::Error| io::Error::new(ErrorKind::InvalidData, ERROR_JSON_PARSE_FAILED))
}

/// Formats JSONC (`.jsonc`, `.cjson`) matching VS Code Prettier 3.7.4 `jsonc` parser (preserving comments and `trailingComma: "all"`).
///
/// # Arguments
///
/// - `&str` - Raw JSONC source text.
///
/// # Returns
///
/// - `String` - Formatted JSONC text, or unchanged input if syntax errors occur.
#[inline]
pub fn format_jsonc(input: &str) -> String {
    tidy::json::format(input, &VSCODE_JSONC_OPTIONS)
        .unwrap_or_else(|_: tidy::Error| input.to_string())
}