From 6230354ec0362c6ca3dc68a7eb807d5019fbf454 Mon Sep 17 00:00:00 2001 From: Casey Rodarmor Date: Sat, 5 Oct 2024 14:19:28 -0700 Subject: [PATCH] Mark recipes with private attribute as private in JSON dump (#2415) --- src/parser.rs | 4 +++- tests/json.rs | 54 +++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 57 insertions(+), 1 deletion(-) diff --git a/src/parser.rs b/src/parser.rs index c9b499d0e6..ea727204e5 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -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, @@ -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, }) } diff --git a/tests/json.rs b/tests/json.rs index bf962a1e3f..3819c0405a 100644 --- a/tests/json.rs +++ b/tests/json.rs @@ -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": [], + }), + ); +}