Skip to main content

explain_disposition

Function explain_disposition 

Source
pub fn explain_disposition(
    kind: CommentKind,
    raw: &[u8],
    language: Language,
    options: &ScanOptions,
) -> DispositionExplanation
Expand description

Name the rule that decides this comment’s fate.

The branches below are the branches of disposition() in the same order, so explain_disposition(..).action().is_remove() always equals disposition(..).is_remove() for the same comment and options. An unparseable pattern list is ignored here as the scanner ignores it, which keeps the two in step even on input the scanner has already flagged.

That agreement is with the bytes-only rule table and with nothing else. A scan applies one rule no reading of raw can reach — DispositionExplanation::KeptStructural, where a YAML block scalar leans on the comment that ends it — and a comment kept by where it sits is reported here as the table alone would have it. That verdict comes only from explain_comment, which is handed the Comment a scan produced.

raw is the comment’s complete bytes, delimiters included, exactly as Comment::span delimits them.

§Examples

use ocomment_core::{
    Action, CommentKind, DispositionExplanation, Language, Policy, ScanOptions,
    explain_disposition,
};

let mut options = ScanOptions::default();
let why = explain_disposition(CommentKind::Line, b"// note", Language::Rust, &options);
assert_eq!(why.action(), Action::Remove);
assert!(matches!(why, DispositionExplanation::RemovedByDefault(Policy::Safe)));

options.keep_regex.push(r"^//\s*NOTE\b".into());
let kept = explain_disposition(CommentKind::Line, b"// NOTE: why", Language::Rust, &options);
assert_eq!(kept.action(), Action::Keep);
assert!(matches!(kept, DispositionExplanation::KeptByRegex { index: 0, .. }));
assert_eq!(kept.to_string(), r"kept: matched keep_regex #0 `^//\s*NOTE\b`");