Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

EditorConfig new line per parameter for function calls

I've been trawling the docs and I don't think this exists as an option but basically I want to enforce each parameter of a function call to be on a new line.

e.g. I hate this:

var result = GetResult(request, startDate, endDate, myTypes,
                    false, false, pageNumber);

and I hate this even more (different numbers of parameters per line):

var result = GetResult(request, startDate, endDate, myTypes,
                    person, thing, 
                    false, false, pageNumber, penny, job, situation, context);

I would love an editorconfig entry to make the above into:

var result = GetResult(
    request, 
    startDate, 
    endDate, 
    myTypes,
    false, 
    false, 
    pageNumber);

and

var result = GetResult(
    request, 
    startDate, 
    endDate, 
    myTypes,
    person, 
    thing, 
    false, 
    false, 
    pageNumber, 
    penny, 
    job, 
    situation, 
    context);

Ideally I'd be able to specify the maximum number of parameters before it forces the above, but this is probably a pipe dream e.g. I would want 1 or 2, maybe even 3 parameters to remain on one line line below:

var result1 = GetResult(request);
var result2 = GetResult(request, startDate);
var result3 = GetResult(request, startDate, endDate);
//only after 3 force the rule
var result4 = GetResult(
    request, 
    startDate, 
    endDate, 
    myTypes);
like image 965
Percy Avatar asked Oct 17 '22 15:10

Percy


1 Answers

I'm not aware of an EditorConfig-specific solution for this, but if you use Rider (or ReSharper, I'd assume), you can change the settings at Editor -> Code Style -> C# -> Line Breaks and Wrapping.

Under Arrangement of Method Signatures, set Wrap formal parameters to Chop if long or multiline. Under Arrangement of Invocations, set Wrap invocation arguments to Chop if long or multiline.

From Rider's code style preview pane:

enter image description here

like image 56
Matt Mills Avatar answered Oct 21 '22 00:10

Matt Mills