oppiliappan / statix

lints and suggestions for the nix programming language
https://git.peppe.rs/languages/statix/about
MIT License
557 stars 21 forks source link

[Question] Why are unquoted splices an anti-pattern? #8

Closed Gerschtli closed 2 years ago

Gerschtli commented 2 years ago

Very cool project! I tried it out and wondered why are unquoted splices an anti-pattern?

Thank you very much :)

oppiliappan commented 2 years ago

Splices evaluate to strings anyway, and should be quoted for uniformity IMO.

I know there are some edge cases right now (if the splice evaluates to null, this suggestion actually results in invalid nix code; interaction between quoted splices and paths may be affected). There are some bugs with parsing certain cases in the underlying library (rnix-parser) as well.

If you find that this rule results in too many false positives, or if suggestions result in too many syntax errors, please feel free to report here!

Gerschtli commented 2 years ago

I am still not sure how quoting slices would help in readability, correctness and/or maintainability..

figsoda commented 2 years ago

Is it possible to disable? I also find this not very useful

figsoda commented 2 years ago

There was actually a pr in nixpkgs that removed quotes this: https://github.com/NixOS/nixpkgs/pull/68339 (that was not the only thing that pr did)

oppiliappan commented 2 years ago

Hmm interesting, I did see a couple of PRs that added quotes. It looks like adding quotes to unquoted splices was also on the nix-linter roadmap as well:

Check for unquoted splices, e.g. foo = bar.${baz};, since leaving off quotes is just horrible ;)

Anyhow, if folks generally dislike this lint, I think it would be better as opt-in. There is no way to disable lints right now, a configuration file or similar is definitely on the roadmap.

As a side, do you think it would be worth adding a lint that removes quotes from splices that don't require it?

figsoda commented 2 years ago

I think that's a good idea. Maybe a configuration option like

string-interpolation-quotation = "quoted" | "unquoted" | "unchanged"
oppiliappan commented 2 years ago

This lint has been removed on master, changes will be reflected in the next release. The fix suggested by this lint breaks a bunch of valid nix 2.4 syntax.

oppiliappan commented 2 years ago

This lint has been removed altogether.