Skip to content

Commit

Permalink
Better lambda indent (#673)
Browse files Browse the repository at this point in the history
* Start of better indent for lamda

closes #669

* Don't forget the test cases

* Only format this way for lambdas with a block

* Trying out simple lambdas with blocks

* Cleanup
  • Loading branch information
belav authored May 23, 2022
1 parent c3d384b commit 20f214d
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 66 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -197,21 +197,17 @@ class ClassName
// comment shouldn't do weird stuff
SomeObject.CallMethod();

CallMethod(
lambdaWithBlock =>
{
return;
}
)
CallMethod(lambdaWithBlock =>
{
return;
})
.CallMethod()
.CallMethod();

someObject.CallMethod(
lambdaWithBlock =>
{
return;
}
);
someObject.CallMethod(lambdaWithBlock =>
{
return;
});

o.CallMethod(parameter_____________, parameter_____________)
.CallMethod(parameter_____________, parameter_____________);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,52 +61,44 @@ class ClassName
>();

private static readonly Action<IApplicationBuilder> ActionNotImplemented =
new Action<IApplicationBuilder>(
_ =>
{
throw new NotImplementedException();
}
);
new Action<IApplicationBuilder>(_ =>
{
throw new NotImplementedException();
});

public void MapFrom<TResult>(Func<TSource, TDestination, TMember, TResult> mappingFunction)
{
if (true)
{
PropertyMapActions.Add(
pm =>
{
Expression<
Func<TSource, TDestination, TMember, ResolutionContext, TResult>
> expr = (src, dest, destMember, ctxt) =>
mappingFunction(src, dest, destMember);
PropertyMapActions.Add(pm =>
{
Expression<Func<TSource, TDestination, TMember, ResolutionContext, TResult>> expr =
(src, dest, destMember, ctxt) => mappingFunction(src, dest, destMember);

pm.CustomMapFunction = expr;
}
);
pm.CustomMapFunction = expr;
});
}
}

public void Condition(
Func<ConditionParameters<TSource, TDestination, TMember>, bool> condition
) =>
PathMapActions.Add(
pm =>
{
Expression<
Func<TSource, TDestination, TMember, TMember, ResolutionContext, bool>
> expr = (src, dest, srcMember, destMember, ctxt) =>
condition(
new ConditionParameters<TSource, TDestination, TMember>(
src,
dest,
srcMember,
destMember,
ctxt
)
);
pm.Condition = expr;
}
);
PathMapActions.Add(pm =>
{
Expression<
Func<TSource, TDestination, TMember, TMember, ResolutionContext, bool>
> expr = (src, dest, srcMember, destMember, ctxt) =>
condition(
new ConditionParameters<TSource, TDestination, TMember>(
src,
dest,
srcMember,
destMember,
ctxt
)
);
pm.Condition = expr;
});

public override Type SourceType
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,22 @@ public class ClassName
) => evenLongerParameter
);

var task = Task.Factory.StartNew(
async () =>
{
return await new WebClient().DownloadStringTaskAsync____________________(
"http://example.com"
);
}
CallMethod(() =>
{
CallOtherMethod();
});

CallMethod(
() => CallOtherMethod___________________________________________________________()
);

var task = Task.Factory.StartNew(async () =>
{
return await new WebClient().DownloadStringTaskAsync____________________(
"http://example.com"
);
});

Action find = () =>
EntryPointDiscoverer.FindStaticEntryMethod(typeof(IEnumerable<>).Assembly);

Expand All @@ -62,12 +69,10 @@ public class ClassName

var reusedCommand = new Command("reused")
{
Handler = CommandHandler.Create(
() =>
{
doSomething();
}
)
Handler = CommandHandler.Create(() =>
{
doSomething();
})
};

CallSomeMethod(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,9 @@ public class ClassName
someOtherLongName_______________________________
);

this.Where___________________(
superLongName________________________________ =>
{
return someOtherLongName__________________;
}
);
this.Where___________________(superLongName________________________________ =>
{
return someOtherLongName__________________;
});
}
}
15 changes: 14 additions & 1 deletion Src/CSharpier/SyntaxPrinter/ArgumentListLikeSyntax.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,20 @@ FormattingContext context
{
var docs = new List<Doc> { Token.Print(openParenToken, context) };

if (arguments.Any())
if (
arguments.Count == 1
&& arguments[0].Expression
is ParenthesizedLambdaExpressionSyntax
{
ParameterList.Parameters.Count: 0,
Block: { }
}
or SimpleLambdaExpressionSyntax { Block: { } }
)
{
docs.Add(Argument.Print(arguments[0], context));
}
else if (arguments.Any())
{
docs.Add(
Doc.Indent(
Expand Down

0 comments on commit 20f214d

Please sign in to comment.