Skip to content

Commit

Permalink
Mark recipes with private attribute as private in JSON dump (#2415)
Browse files Browse the repository at this point in the history
  • Loading branch information
casey authored Oct 5, 2024
1 parent 85c6e05 commit 6230354
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -901,6 +901,8 @@ impl<'run, 'src> Parser<'run, 'src> {
}));
}

let private = name.lexeme().starts_with('_') || attributes.contains(&Attribute::Private);

Ok(Recipe {
shebang: shebang || script,
attributes,
Expand All @@ -914,7 +916,7 @@ impl<'run, 'src> Parser<'run, 'src> {
namepath: self.module_namepath.join(name),
parameters: positional.into_iter().chain(variadic).collect(),
priors,
private: name.lexeme().starts_with('_'),
private,
quiet,
})
}
Expand Down
54 changes: 54 additions & 0 deletions tests/json.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1375,3 +1375,57 @@ fn module_group() {
))
.run();
}

#[test]
fn recipes_with_private_attribute_are_private() {
case(
"
[private]
foo:
",
json!({
"aliases": {},
"assignments": {},
"first": "foo",
"doc": null,
"groups": [],
"modules": {},
"recipes": {
"foo": {
"attributes": ["private"],
"body": [],
"dependencies": [],
"doc": null,
"name": "foo",
"namepath": "foo",
"parameters": [],
"priors": 0,
"private": true,
"quiet": false,
"shebang": false,
}
},
"settings": {
"allow_duplicate_recipes": false,
"allow_duplicate_variables": false,
"dotenv_filename": null,
"dotenv_load": false,
"dotenv_path": null,
"dotenv_required": false,
"export": false,
"fallback": false,
"ignore_comments": false,
"positional_arguments": false,
"quiet": false,
"shell": null,
"tempdir" : null,
"unstable": false,
"windows_powershell": false,
"windows_shell": null,
"working_directory" : null,
},
"unexports": [],
"warnings": [],
}),
);
}

0 comments on commit 6230354

Please sign in to comment.