Skip to content

Commit

Permalink
jsondocck: catch and error on deprecated syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
yotamofek committed Mar 1, 2025
1 parent 11e7aaf commit 94645f6
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/tools/jsondocck/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,18 @@ static LINE_PATTERN: LazyLock<Regex> = LazyLock::new(|| {
.unwrap()
});

static DEPRECATED_LINE_PATTERN: LazyLock<Regex> = LazyLock::new(|| {
RegexBuilder::new(
r#"
//\s+@
"#,
)
.ignore_whitespace(true)
.unicode(true)
.build()
.unwrap()
});

fn print_err(msg: &str, lineno: usize) {
eprintln!("Invalid command: {} on line {}", msg, lineno)
}
Expand All @@ -183,6 +195,12 @@ fn get_commands(template: &str) -> Result<Vec<Command>, ()> {
for (lineno, line) in file.split('\n').enumerate() {
let lineno = lineno + 1;

if DEPRECATED_LINE_PATTERN.is_match(line) {
print_err("Deprecated command syntax, replace `// @` with `//@ `", lineno);
errors = true;
continue;
}

let Some(cap) = LINE_PATTERN.captures(line) else {
continue;
};
Expand Down

0 comments on commit 94645f6

Please sign in to comment.