Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't analyze comments when ignore-comments is set #2180

Merged
merged 1 commit into from
Jun 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/analyzer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ impl<'src> Analyzer<'src> {
}
}

let recipes = RecipeResolver::resolve_recipes(recipe_table, &self.assignments)?;
let recipes = RecipeResolver::resolve_recipes(&self.assignments, &settings, recipe_table)?;

let mut aliases = Table::new();
while let Some(alias) = self.aliases.pop() {
Expand Down
7 changes: 6 additions & 1 deletion src/recipe_resolver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ pub(crate) struct RecipeResolver<'src: 'run, 'run> {

impl<'src: 'run, 'run> RecipeResolver<'src, 'run> {
pub(crate) fn resolve_recipes(
unresolved_recipes: Table<'src, UnresolvedRecipe<'src>>,
assignments: &'run Table<'src, Assignment<'src>>,
settings: &Settings,
unresolved_recipes: Table<'src, UnresolvedRecipe<'src>>,
) -> CompileResult<'src, Table<'src, Rc<Recipe<'src>>>> {
let mut resolver = Self {
resolved_recipes: Table::new(),
Expand Down Expand Up @@ -39,6 +40,10 @@ impl<'src: 'run, 'run> RecipeResolver<'src, 'run> {
}

for line in &recipe.body {
if line.is_comment() && settings.ignore_comments {
continue;
}

for fragment in &line.fragments {
if let Fragment::Interpolation { expression, .. } = fragment {
for variable in expression.variables() {
Expand Down
38 changes: 38 additions & 0 deletions tests/ignore_comments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,3 +97,41 @@ fn dont_evaluate_comments() {
)
.run();
}

#[test]
fn dont_analyze_comments() {
Test::new()
.justfile(
"
set ignore-comments

some_recipe:
# {{ bar }}
",
)
.run();
}

#[test]
fn comments_still_must_be_parsable_when_ignored() {
Test::new()
.justfile(
"
set ignore-comments

some_recipe:
# {{ foo bar }}
",
)
.stderr(
"
error: Expected '}}', '(', '+', or '/', but found identifier
——▶ justfile:4:12
4 │ # {{ foo bar }}
│ ^^^
",
)
.status(EXIT_FAILURE)
.run();
}