Synthetica9 / nix-linter

Linter for the Nix expression language
BSD 3-Clause "New" or "Revised" License
158 stars 16 forks source link

EtaReduce results in failing flake check #66

Open pinpox opened 2 years ago

pinpox commented 2 years ago

The following line in a flake gives me an error:

      overlays.default = final: prev: (import ./overlays inputs) final prev;
Possible η-reduction of argument `prev` at flake.nix:99:33-76
-W EtaReduce

    {
      # When you have a function abstraction, only to immediately apply the
      # argument to a function, this is called an η-abstraction (or eta-abstraction)
      # See also: https://wiki.haskell.org/Eta_conversion
      bad = x: f x;

      # Generally, it nicer to be direct:
      good = f;
    }

I tried simplifying it to:

      overlays.default = (import ./overlays inputs);

But then nix flake check is not happy:

shell ❯ nix flake check                                                                                                                                                                    
error: overlay does not take an argument named 'final'
(use '--show-trace' to show detailed location information)

Is this a bug or am I misunderstanding the help message?

Synthetica9 commented 2 years ago

No, you are correctly understanding the message. However, flake check doesn't only look at the semantics of the code (which are equal after this transformation), but also at the formatting. nix-linter has no flake-specific code to handle this, so it throws this warning.

As an aside, I think flake check should be a bit less stringent here, because the simplified code is perfectly reasonable.

pinpox commented 2 years ago

So basically I can't use the linter with flakes in their current state with that check? I have found other occurances that seem to have a similar problem. E.g. I'm not using the final: argument in the overlay, but flake check tells me I have to pass it.