Skip to content

Commit ad6057e

Browse files
committed
add a new pattern to catch ignored directives on mixed lines
1 parent 65e4edc commit ad6057e

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

src/tools/jsondocck/src/main.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,16 @@ static LINE_PATTERN: LazyLock<Regex> = LazyLock::new(|| {
3131
static DEPRECATED_LINE_PATTERN: LazyLock<Regex> =
3232
LazyLock::new(|| RegexBuilder::new(r#"//\s+@"#).build().unwrap());
3333

34+
/// ```
35+
/// // Directive on its own line
36+
/// //@ correct-directive
37+
///
38+
/// // Directive on a line after code
39+
/// struct S; //@ ignored-directive
40+
/// ```
41+
static MIXED_LINE: LazyLock<Regex> =
42+
LazyLock::new(|| RegexBuilder::new(r#".*\S.*//@"#).build().unwrap());
43+
3444
struct ErrorReporter<'a> {
3545
/// See [`Config::template`].
3646
template: &'a str,
@@ -63,6 +73,13 @@ fn main() -> ExitCode {
6373
continue;
6474
}
6575

76+
if MIXED_LINE.is_match(line) {
77+
error_reporter.print(
78+
"directives must be on their own line, directives after code are ignored",
79+
lineno,
80+
);
81+
}
82+
6683
let Some(cap) = LINE_PATTERN.captures(line) else {
6784
continue;
6885
};

0 commit comments

Comments
 (0)