statix
statix copied to clipboard
W04 creates multiple redundant `inherit` statements (`Assignment instead of inherit from`)
With this code:
let
config = {
host = "host";
user = "user";
port = 22;
};
in {
host = config.host;
user = config.user;
port = config.port;
}
statix correctly identifies that these assignments could be inherit statements instead:
$ statix check inherit-repeat.nix
[W04] Warning: Assignment instead of inherit from
╭─[inherit-repeat.nix:8:3]
│
8 │ host = config.host;
· ─────────┬─────────
· ╰─────────── This assignment is better written with inherit
───╯
[W04] Warning: Assignment instead of inherit from
╭─[inherit-repeat.nix:9:3]
│
9 │ user = config.user;
· ─────────┬─────────
· ╰─────────── This assignment is better written with inherit
───╯
[W04] Warning: Assignment instead of inherit from
╭─[inherit-repeat.nix:10:3]
│
10 │ port = config.port;
· ─────────┬─────────
· ╰─────────── This assignment is better written with inherit
────╯
But it creates three inherit statements when I run statix fix, rather than one:
let
config = {
host = "host";
user = "user";
port = 22;
};
in {
inherit (config) host;
inherit (config) user;
inherit (config) port;
}
Expected
let
config = {
host = "host";
user = "user";
port = 22;
};
in {
inherit (config) host user port;
}
Version
$ statix --version
statix 0.5.8
Similarly, if there already exists an inherit statement, the added inherits aren't combined into it:
let
config = {
host = "host";
user = "user";
port = 22;
options = "";
};
in {
inherit (config) options;
host = config.host;
user = config.user;
port = config.port;
}