nixpkgs-fmt icon indicating copy to clipboard operation
nixpkgs-fmt copied to clipboard

"#dontformat" directive

Open cab404 opened this issue 2 years ago • 4 comments

Is your feature request related to a problem? Please describe. Some blocks of code are just better formatted by humans:

colors = [
   "3A3C43" "BE3E48" "869A3A" "C4A535" "4E76A1" "855B8D" "568EA3" "B8BCB9"
   "888987" "FB001E" "0E712E" "C37033" "176CE3" "FB0067" "2D6F6C" "FCFFB8"
];

turns into

colors = [
   "3A3C43"
   "BE3E48"
   ...
   "2D6F6C"
   "FCFFB8"
];

Describe the solution you'd like #dontformat directives, turning off formatting for a given code block:

colors = [
    #dontformat
    "3A3C43" "BE3E48" "869A3A" "C4A535" "4E76A1" "855B8D" "568EA3" "B8BCB9"
    "888987" "FB001E" "0E712E" "C37033" "176CE3" "FB0067" "2D6F6C" "FCFFB8"
    #/dontformat
];

Describe alternatives you've considered

  1. Per-block formatting, which would ignore formatting in tree and it's descendants
    {
        something = [
           #dontfornat
           "3A3C43" "BE3E48" "869A3A" "C4A535" "4E76A1" "855B8D"
        ];
        thiswillbeformatted = { a = 12; b = 5; };
    }
    
  2. Just giving up hope and accepting blackness of this formatter.

cab404 avatar Oct 22 '21 12:10 cab404

I'd prefer what you call "per-block formatting", because I think writing end sequences for the directive is more tedious than it helps.

piegamesde avatar Oct 24 '21 14:10 piegamesde

Potentially it could also target a specific rule if we give them proper names.

{
  # nixpkgs-fmt skip=list-formatting
  something = [
     "3A3C43" "BE3E48" "869A3A" "C4A535"
     "4E76A1" "855B8D"
  ];
}

zimbatm avatar Oct 25 '21 16:10 zimbatm

This is the only thing I've found missing from this tool. It's nice to be able to control whitespace indentation sometimes

PAI5REECHO avatar Mar 07 '22 00:03 PAI5REECHO

Potentially it could also target a specific rule if we give them proper names.

This feels like the right way to do and aligns with other linter tools.

SuperSandro2000 avatar Mar 07 '22 11:03 SuperSandro2000