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

Implement all ideas from haskell-nix/hnix#136 #4

Open
Synthetica9 opened this issue Nov 6, 2018 · 2 comments
Open

Implement all ideas from haskell-nix/hnix#136 #4

Synthetica9 opened this issue Nov 6, 2018 · 2 comments

Comments

@Synthetica9
Copy link
Owner

Synthetica9 commented Nov 6, 2018

haskell-nix/hnix#136 (comment)

  • Check for unused with bindings
  • Check for patterns which fit common builtin/lib functions like map, mapAttrs, genAttrs, etc.
  • Check for quoted/unquoted URLs (depending on style)
  • Check if inherit sources are in lexicographic order e.g. { inherit foo; inherit (a) bar; inherit (b) baz; }
  • Check for eval-time building, e.g. "import from derivation" like import (fetchgit { ... }) or callPackage "${someDerivation}/foo" {}
  • Check for reading of derivations or store paths, e.g. builtins.readFile "${someDerivation}" since this can either trigger someDerivation to be built at eval time or cause a file-not-found error (it will work if someDerivation just-so-happens to already exist in the store)
  • Check for potentially-dodgy quoting. Some quote/splice combinations don't interact well together (which?)
  • Check for "prematurely-forced derivations". I think this comes from builds being triggered due to some string manipulation of derivation paths. For example derivation { foo = "${bar}:${baz}"; ... } could (I think) cause some sort of building to figure out the string representations of bar and baz (if, for example, these were imported from another derivation's output). Not sure if it's an actual issue, has been fixed in newer Nix versions, or if it was just a figment of my imagination...
  • Check for complicated splice escaping. For example doing things like foo = ''echo "${"$" + "{MY_VAR}"}"'' to work around ${} being special syntax for both Nix and Bash.
  • Check for unquoted splices, e.g. foo = bar.${baz};, since leaving off quotes is just horrible ;)
  • Check for let/in and recommend replacing with with or with rec. Presumably controversial, but I don't see the point of let/in in Nix ;)
  • Check if names are inherited in lexicographic order e.g. { inherit a b c; }
  • Check if arguments are declared in lexicographic order e.g. { a, b, c }: ...
  • Check if attributes are defined in lexicographic order e.g. { x = ...; y = ...; z = ...; }
  • Look for eta-expansions, e.g. map (x: foo bar x) baz could be map (foo bar) baz
  • Check for "misnamed" arguments. For example in foo = bar: baz { quux = bar; }; the only thing we do to the argument bar is bind it to quux. We could suggest aligning the APIs of foo and baz, by either renaming foo's bar argument to quux or baz's quux argument to bar; in either case we could then use inherit rather than renaming. Renaming bar like this is low impact since it's just an alpha-rename, but if it were a named argument (e.g. foo = { bar }: ...) or if we rename quux then that changes those functions' API.
  • Look for use-cases of inherit, e.g. { foo = foo; } could be { inherit foo; } and { foo = bar.foo; } could be { inherit (bar) foo; }.
  • Check for unused let/in bindings
  • Check for unused function arguments
  • Check for unused rec, e.g. x = rec { y = "hello"; }; doesn't need the rec; likewise for with rec {...}
@domenkozar
Copy link

@jtojnar
Copy link

jtojnar commented May 11, 2021

if builtins.hasAttr attr attrset then
  builtins.getAttr attr attrset
else
  alternative

can be changed to

attrset.${attr} or alternative

Same with dot instead of getAttr.

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

3 participants