Code Monkey home page Code Monkey logo

Comments (12)

zimbatm avatar zimbatm commented on June 7, 2024 1

don't give up @layus ! the format is definitely up for discussion

from nixpkgs-fmt.

matklad avatar matklad commented on June 7, 2024

This is sort of intentional, see #46.

The problem with placing first parameter after { is that it forces parameters to align to {, which doesn't work to well in cases like this:

{
  f = { x
      , y 
      }: body
}

from nixpkgs-fmt.

layus avatar layus commented on June 7, 2024

Fair point indeed.

That being said, top-level functions are a bit different and could be handled differently, because this example looks like an unfinished tetris game. The curly bracket is itching to fall one square below ;-).

But this has already been discussed, so closing for now.

{ 
  foo
, bar
, baz
}:
foo + bar

Okay examples

{
  foo,
  bar,
  baz
}:
foo + bar
{ foo
, bar
, baz
}:
foo + bar
{
  f = { x
      , y
      , z
      }: body;
}
{
  f = { 
    x,
    y,
    z,
  }: body;
}

Not okay examples

{ 
  foo
, bar
, baz
}:
foo + bar
{
  f = { 
    x
  , y
  , z
  }: body;
}

from nixpkgs-fmt.

zimbatm avatar zimbatm commented on June 7, 2024

This is the hardest problem we've had with the nix format, making it work in the top-level and deeper levels. We haven't found a solution that keep the rules simple.

I guess an alternative would be to force the deeper level to be on multiple lines like that:

{
  f =
    { x
    , y
    , z
    }: body;
}

from nixpkgs-fmt.

layus avatar layus commented on June 7, 2024

I guess an alternative would be to force the deeper level to be on multiple lines like that:

{
  f =
    { x
    , y
    , z
    }: body;
}

That's definitely an option, and it looks quite nice to me. Especially given that nested functions that receive an attrset as argument do not look too frequent in nixpkgs.

from nixpkgs-fmt.

layus avatar layus commented on June 7, 2024

Function parameters are hard, because they have no opening and closing symbols. We could use λ a: b: c: 1 for the sake of reasoning. then an argument list is just like a normal list. See the simmilarity between these two ?

{
  f = λ
    { x, y, z}:
    foo:
    { a, b, c}:
    bar:
	  body;
}
{
  f = [
    { x, y, z}
    foo
    { a, b, c}
    bar
  ];
}

So either the arguments are on the same line, or they are on separate lines, with a leading newline. That rule is easy to state, and somewhat alleviates our current issue.

Fully expanded ;-):

{
  f =
    { x
    , y
    , z
    }:
    foo:
    { a
    , b
    , c
    }:
    bar:
      body;
}

[Edit] replace tabs with spaces

from nixpkgs-fmt.

zimbatm avatar zimbatm commented on June 7, 2024

Why are foo: and bar: indented once more in your example? The array argument should dictate that all the function arguments would be aligned on the same indent?

from nixpkgs-fmt.

layus avatar layus commented on June 7, 2024

they say a figure is better than a thousand words ;-), so here it comes:

{
  f =
    set1:
    foo:
    set2:
    bar:
	  body;
}
{
  f =
    {
      x,
      y,
      z
    }:
    foo:
    { 
      a,
      b,
      c
    }:
    bar:
	  body;
}

from nixpkgs-fmt.

layus avatar layus commented on June 7, 2024

Why are foo: and bar: indented once more in your example? The array argument should dictate that all the function arguments would be aligned on the same indent?

They are not. Could it be a tab vs spaces issue ? I edited my previous comment to fix that.

from nixpkgs-fmt.

zimbatm avatar zimbatm commented on June 7, 2024

Okay that makes more sense now with the indent fixed :)

I think the body will have to be on the same level as the argument to avoid too much movement:

single-line:

{
  f = a: b: c:
    body;
}

multi-line:

{
  f =
    a:
    b:
    c:
    body;
}

If the body is really large it will create a lot of whitespace diff otherwise.

from nixpkgs-fmt.

zimbatm avatar zimbatm commented on June 7, 2024

And if that's applied then we can keep the comma-first notation for the function arguments. This notation is quite pervasive in nixpkgs:

{ foo
, bar
, baz
}:

from nixpkgs-fmt.

domenkozar avatar domenkozar commented on June 7, 2024

What we do in canonix is to format top-level differently than inline.

from nixpkgs-fmt.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.