Skip to main content

format_yaml

Function format_yaml 

Source
pub fn format_yaml(source: &str) -> Result<FormatOutcome, FormatError>
Expand description

Format a whole Sigma YAML file.

The output uses the same canonical layout as emit_rule_yaml: four-space indentation, canonical key order, block collections, and canonical scalar quoting. Comments move with the entries they are attached to.

use rsigma_parser::format_yaml;

let source = "title: Test\n# note\nlogsource:\n  category: test\ndetection:\n  selection:\n    Field: value\n  condition: selection\n";
let outcome = format_yaml(source).unwrap();
assert!(outcome.formatted.contains("\n    category: test\n"));
assert_eq!(
    outcome.formatted,
    "title: Test\n# note\nlogsource:\n    category: test\ndetection:\n    selection:\n        Field: value\n    condition: selection\n",
);