astro / deadnix

Scan Nix files for dead code
GNU General Public License v3.0
512 stars 13 forks source link

Don't mark required attributes in an attribute set as unused #67

Closed phip1611 closed 1 year ago

phip1611 commented 1 year ago

Hi,

Suppose the following code snippet (with focus on makeGenericEnvironment):

let
  kernel = ...;
  makeGenericEnvironment =
    { testNamePrefix
    , isNative
    , ...
    }@environment: {
      inherit foobar;
    } // environment;
in
{
  one = makeGenericEnvironment {
    testNamePrefix = "TestFOO";
    isNative = true;
    foo = "bar";
  };
  two = makeGenericEnvironment {
    testNamePrefix = "TestBAR";
    isNative = false;
    bar = "foo";
  };
}

The idea is to force users to always provide testNamePrefix and isNative. Apart from that, arbitrary attributes can be passed. Inside makeGenericEnvironment, the provided attribute set is merged with some predefined attributes (here, foobar).

However, deadnix tells that testNamePrefix and isNative are unused. Well, regarding the AST, they are technically. To satisfy deadnix, I have to add inherit testNamePrefix isNative;.

Is there a solution how deadnix can find out that this is valid?

astro commented 1 year ago

Run deadnix with -L, --no-lambda-pattern-names

Would that work for you?

Side note: because that flag is already needed when deadnixing nixpkgs, it would have been smarter to make it default behavior, with opt-in to checking. Too late now. I don't like breaking changes.

phip1611 commented 1 year ago

yes, thanks. That helps