Skip to main content

explain_comment

Function explain_comment 

Source
pub fn explain_comment(
    comment: &Comment,
    raw: &[u8],
    language: Language,
    options: &ScanOptions,
) -> DispositionExplanation
Expand description

Name the rule that decided the fate of a comment a scan actually found.

explain_disposition accounts for every rule a comment’s own bytes can trigger. One rule is not one of those: a YAML block scalar leaning on the comment that ends it keeps that comment because of where it sits, and no amount of reading its bytes could say so. This is that answer, and for every other comment it is exactly explain_disposition.

comment must be one the scan of raw’s file produced, and raw its complete bytes as Comment::span delimits them.

§Examples

use ocomment_core::{
    Action, DispositionExplanation, Language, ScanOptions, explain_comment, scan,
};

let source = b"k: |\n  a\n# ends the block\n  # yamllint disable\nz: 1\n";
let report = scan(source, Language::Yaml, ScanOptions::default());
let comment = &report.comments[0];
let why = explain_comment(
    comment,
    &source[comment.span.start..comment.span.end],
    Language::Yaml,
    &ScanOptions::default(),
);
assert_eq!(why.action(), Action::Keep);
assert!(matches!(
    why,
    DispositionExplanation::KeptStructural { language: Language::Yaml }
));