nixd icon indicating copy to clipboard operation
nixd copied to clipboard

Allow unused config/lib/pkgs without warning

Open bennofs opened this issue 7 months ago • 5 comments

Is your feature request related to a problem? Please describe. In NixOS modules, it is common to start every file with { config, lib, pkgs, ... }: even if they are not used. Nixd creates a warning for unused arguments in this case.

Describe the solution you'd like Provide an option to ignore unused arguments by name, so "standard" arguments like config, lib and pkgs can be ignored without fully disabling the unused arguments lint.

Describe alternatives you've considered I could disable unused arguments warning, or simply not care about the warning..

bennofs avatar Apr 25 '25 13:04 bennofs

Perhaps this could also be restricted to the beginning of the file, not sure about that though.

bennofs avatar Apr 25 '25 13:04 bennofs

Why not just remove unused things?

For example it is allowed & safe to do:

{ config, ... }:

inclyc avatar Apr 25 '25 13:04 inclyc

Yes, that's also a possibility. My argument against that approach is this:

  • Removing the unused arguments IMO does not improve readability at all
  • Keeping them is more economic when modifying the file later. If the arguments are reduced to the minimal form, I need to check each time I modify the file if the arguments I am using are declared.

So for me, removing them has no benefit but some disadvantages.

But I am open to a discussion about this. Perhaps this feature would complicate nixd too much for a marginal improvement?

bennofs avatar Apr 26 '25 08:04 bennofs

does not improve readability

Readability is difficult to quantify objectively. However, determining whether something is unused is straightforward: name is unused iff name.users().length() == 0.

If the arguments are reduced to the minimal form, I need to check each time I modify the file if the arguments I am using are declared.

A better solution might be to implement a code action that automatically adds a name to the top-level lambda when needed. This is feasible for LSP servers.

Perhaps this feature would complicate nixd too much

Yes, I generally prefer to avoid adding any special rules altogether—nothing should be treated as exceptional. Special cases aren't special enough to break the rules.

inclyc avatar Apr 26 '25 09:04 inclyc

@bennofs May I close this issue?

inclyc avatar May 01 '25 11:05 inclyc

Yes feel free to

bennofs avatar May 07 '25 14:05 bennofs