Skip to main content

scan

Function scan 

Source
pub fn scan(
    source: &[u8],
    language: Language,
    options: ScanOptions,
) -> ScanReport
Expand description

Find every comment in source and decide what happens to each.

One pass over the bytes, with the source never decoded as a whole: the spans that come back are byte offsets into source, which does not have to be valid UTF-8. Nothing is written and no output is built — that is transform.

A source that will not lex, such as one with an unterminated comment or string, comes back with a Severity::Error diagnostic and ScanReport::valid false.

§Examples

use ocomment_core::{CommentKind, Language, ScanOptions, scan};

let report = scan(b"let x = 1; // note\n", Language::Rust, ScanOptions::default());
assert!(report.valid);
assert_eq!(report.comments.len(), 1);
assert_eq!(report.comments[0].kind, CommentKind::Line);
assert!(report.comments[0].disposition.is_remove());

// A build tag is a directive, and the default policy keeps one.
let tagged = scan(b"//go:build linux\n", Language::Go, ScanOptions::default());
assert_eq!(tagged.comments[0].kind, CommentKind::Directive);
assert!(!tagged.comments[0].disposition.is_remove());