Skip to content

Commit ab89e19

Browse files
committed
inputs: allow removal of follows-only inputs
1 parent 2cb0c36 commit ab89e19

8 files changed

+109
-1
lines changed

src/walk/inputs.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -806,7 +806,9 @@ fn handle_follows_attr(
806806
let follows = attr.parent().unwrap().next_sibling().unwrap();
807807
let input = Input::with_url(id.to_string(), follows.to_string(), follows.text_range());
808808
insert_with_ctx(inputs, id.to_string(), input.clone(), ctx);
809-
if ctx.is_some() && should_remove_nested_input(change, ctx, input.id()) {
809+
if should_remove_input(change, ctx, input.id())
810+
|| should_remove_nested_input(change, ctx, input.id())
811+
{
810812
return Some(empty_node());
811813
}
812814
None

tests/edit.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,10 @@ fn test_first_nested_node_add_with_list(#[case] is_flake: bool) {
142142
#[case("leading_comma_outputs", "fenix")]
143143
#[case("outputs_paren", "flake-parts")]
144144
#[case("quoted_input_with_dots", "\"hls-1.10\"")]
145+
#[case("follows_only_toplevel", "sizelint")]
146+
#[case("follows_only_toplevel", "treefmt-nix")]
147+
#[case("follows_only_nested", "sizelint")]
148+
#[case("follows_only_nested", "treefmt-nix")]
145149
fn test_remove_input(#[case] fixture: &str, #[case] input_id: &str) {
146150
let content = load_flake(fixture);
147151
let mut flake_edit = FlakeEdit::from_text(&content).unwrap();
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
description = "Test flake with follows-only inputs in nested block";
3+
4+
inputs = {
5+
nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
6+
harmonia.url = "github:nix-community/harmonia";
7+
sizelint.follows = "nixpkgs";
8+
treefmt-nix.follows = "harmonia/treefmt-nix";
9+
};
10+
11+
outputs = _: { };
12+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
description = "Test flake with follows-only top-level inputs";
3+
4+
inputs.nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
5+
inputs.harmonia.url = "github:nix-community/harmonia";
6+
inputs.sizelint.follows = "nixpkgs";
7+
inputs.treefmt-nix.follows = "harmonia/treefmt-nix";
8+
9+
outputs = _: { };
10+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
---
2+
source: tests/edit.rs
3+
expression: result
4+
info:
5+
flake_nix: ""
6+
changes:
7+
- Remove:
8+
ids:
9+
- sizelint
10+
---
11+
{
12+
description = "Test flake with follows-only inputs in nested block";
13+
14+
inputs = {
15+
nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
16+
harmonia.url = "github:nix-community/harmonia";
17+
treefmt-nix.follows = "harmonia/treefmt-nix";
18+
};
19+
20+
outputs = _: { };
21+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
---
2+
source: tests/edit.rs
3+
expression: result
4+
info:
5+
flake_nix: ""
6+
changes:
7+
- Remove:
8+
ids:
9+
- treefmt-nix
10+
---
11+
{
12+
description = "Test flake with follows-only inputs in nested block";
13+
14+
inputs = {
15+
nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
16+
harmonia.url = "github:nix-community/harmonia";
17+
sizelint.follows = "nixpkgs";
18+
};
19+
20+
outputs = _: { };
21+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
---
2+
source: tests/edit.rs
3+
expression: result
4+
info:
5+
flake_nix: ""
6+
changes:
7+
- Remove:
8+
ids:
9+
- sizelint
10+
---
11+
{
12+
description = "Test flake with follows-only top-level inputs";
13+
14+
inputs.nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
15+
inputs.harmonia.url = "github:nix-community/harmonia";
16+
inputs.treefmt-nix.follows = "harmonia/treefmt-nix";
17+
18+
outputs = _: { };
19+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
---
2+
source: tests/edit.rs
3+
expression: result
4+
info:
5+
flake_nix: ""
6+
changes:
7+
- Remove:
8+
ids:
9+
- treefmt-nix
10+
---
11+
{
12+
description = "Test flake with follows-only top-level inputs";
13+
14+
inputs.nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
15+
inputs.harmonia.url = "github:nix-community/harmonia";
16+
inputs.sizelint.follows = "nixpkgs";
17+
18+
outputs = _: { };
19+
}

0 commit comments

Comments
 (0)