Skip to main content

Module fix

Module fix 

Source
Expand description

String-level auto-fix applier shared by the CLI, LSP, and MCP server.

The linter attaches an optional Fix to each LintWarning. This module turns those fixes into concrete edits on a YAML source string using the yamlpath/yamlpatch crates, preserving comments and formatting outside the edited spans.

Only FixDisposition::Safe fixes are applied; unsafe fixes are skipped so a batch fixer never makes a change that needs human judgement.

§Usage

use rsigma_parser::lint::{lint_yaml_str, fix::apply_fixes_to_source};

let source = "title: Test\nStatus: test\nlogsource:\n    category: test\ndetection:\n    sel:\n        field: value\n    condition: sel\n";
let warnings = lint_yaml_str(source);
let fixable: Vec<_> = warnings.iter().filter(|w| w.fix.is_some()).collect();
let outcome = apply_fixes_to_source(source, &fixable);
assert!(outcome.fixed_source.contains("status: test"));

Structs§

SourceFixOutcome
Outcome of applying fixes to a single YAML source string.

Functions§

apply_fixes_to_source
Apply every safe fix from warnings to source, returning the rewritten source plus applied/failed counts.
apply_rename_key
Rename a YAML key in-place using query_key_only to get the exact byte span of the key, then replacing it in the document source.
apply_single_fix_patch
Apply a single FixPatch to a yamlpath::Document, returning a new Document.
json_pointer_to_route
Convert an rsigma JSON-pointer path (e.g. “/tags/2”, “/detection/sel/CommandLine|contains”) into a yamlpath::Route with owned components.