Skip to content

Commit

Permalink
Don't evaluate comment lines if ignore-comment is set
Browse files Browse the repository at this point in the history
  • Loading branch information
casey committed Oct 5, 2022
1 parent d27b720 commit 4ad5ada
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 8 deletions.
3 changes: 0 additions & 3 deletions src/line.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
use super::*;

// TODO
// - don't evaluate comments

/// A single line in a recipe body, consisting of any number of `Fragment`s.
#[derive(Debug, Clone, PartialEq, Serialize)]
#[serde(transparent)]
Expand Down
13 changes: 8 additions & 5 deletions src/recipe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,14 +124,21 @@ impl<'src, D> Recipe<'src, D> {
}
let line = lines.next().unwrap();
line_number += 1;
evaluated += &evaluator.evaluate_line(line, continued)?;
if !comment_line {
evaluated += &evaluator.evaluate_line(line, continued)?;
}
if line.is_continuation() && !comment_line {
continued = true;
evaluated.pop();
} else {
break;
}
}

if comment_line {
continue;
}

let mut command = evaluated.as_str();

if quiet_command {
Expand All @@ -142,10 +149,6 @@ impl<'src, D> Recipe<'src, D> {
command = &command[1..];
}

if comment_line {
continue;
}

if command.is_empty() {
continue;
}
Expand Down
14 changes: 14 additions & 0 deletions tests/ignore_comments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,3 +83,17 @@ fn continuations_with_echo_comments_true() {
.stderr("# comment lines can be continued echo something-useful\n")
.run();
}

#[test]
fn dont_evalute_comments() {
Test::new()
.justfile(
"
set ignore-comments
some_recipe:
# {{ error('foo') }}
",
)
.run();
}

0 comments on commit 4ad5ada

Please sign in to comment.