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

W04 creates multiple redundant inherit statements (Assignment instead of inherit from) #83

Open
9999years opened this issue Mar 4, 2024 · 1 comment

Comments

@9999years
Copy link

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
@9999years
Copy link
Author

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;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant